loleaflet/src/layer/tile/GridLayer.js |   79 +++++++++++++++++++---------------
 loleaflet/src/layer/tile/TileLayer.js |    7 +++
 2 files changed, 53 insertions(+), 33 deletions(-)

New commits:
commit 99089a9dd3d241e2b72bd8b1043ccaa5f78729f0
Author: Mihai Varga <mihai.va...@collabora.com>
Date:   Thu Jul 30 15:11:00 2015 +0300

    loleaflet: don't create img object for prefetched tiles from other parts
    
    Instead, add an extra parameter to the 'tile' command (prefetch=true)
    to know to cache it when it arrives on the client

diff --git a/loleaflet/src/layer/tile/GridLayer.js 
b/loleaflet/src/layer/tile/GridLayer.js
index 689bbe3..75db98f 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -612,46 +612,53 @@ L.GridLayer = L.Layer.extend({
        _addTile: function (coords, fragment) {
                var tilePos = this._getTilePos(coords),
                        key = this._tileCoordsToKey(coords);
-               var tile = this.createTile(this._wrapCoords(coords), 
L.bind(this._tileReady, this, coords));
 
-               this._initTile(tile);
+               if (coords.part === this._currentPart) {
+                       var tile = this.createTile(this._wrapCoords(coords), 
L.bind(this._tileReady, this, coords));
 
-               // if createTile is defined with a second argument ("done" 
callback),
-               // we know that tile is async and will be ready later; otherwise
-               if (this.createTile.length < 2) {
-                       // mark tile as ready, but delay one frame for opacity 
animation to happen
-                       setTimeout(L.bind(this._tileReady, this, coords, null, 
tile), 0);
-               }
+                       this._initTile(tile);
 
-               // we prefer top/left over translate3d so that we don't create 
a HW-accelerated layer from each tile
-               // which is slow, and it also fixes gaps between tiles in Safari
-               L.DomUtil.setPosition(tile, tilePos, true);
+                       // if createTile is defined with a second argument 
("done" callback),
+                       // we know that tile is async and will be ready later; 
otherwise
+                       if (this.createTile.length < 2) {
+                               // mark tile as ready, but delay one frame for 
opacity animation to happen
+                               setTimeout(L.bind(this._tileReady, this, 
coords, null, tile), 0);
+                       }
 
-               // save tile in cache
-               this._tiles[key] = {
-                       el: tile,
-                       coords: coords,
-                       current: true
-               };
+                       // we prefer top/left over translate3d so that we don't 
create a HW-accelerated layer from each tile
+                       // which is slow, and it also fixes gaps between tiles 
in Safari
+                       L.DomUtil.setPosition(tile, tilePos, true);
 
-               fragment.appendChild(tile);
+                       // save tile in cache
+                       this._tiles[key] = {
+                               el: tile,
+                               coords: coords,
+                               current: true
+                       };
 
-               this.fire('tileloadstart', {
-                       tile: tile,
-                       coords: coords
-               });
+                       fragment.appendChild(tile);
+
+                       this.fire('tileloadstart', {
+                               tile: tile,
+                               coords: coords
+                       });
+               }
 
                if (!this._tileCache[key]) {
                        if (this.options.useSocket && this._map.socket) {
                                var twips = this._coordsToTwips(coords);
-                               this.sendMessage('tile ' +
-                                                               'part=' + 
coords.part + ' ' +
-                                                               'width=' + 
this._tileSize + ' ' +
-                                                               'height=' + 
this._tileSize + ' ' +
-                                                               'tileposx=' + 
twips.x + ' '     +
-                                                               'tileposy=' + 
twips.y + ' ' +
-                                                               'tilewidth=' + 
this._tileWidthTwips + ' ' +
-                                                               'tileheight=' + 
this._tileHeightTwips, key);
+                               var msg = 'tile ' +
+                                               'part=' + coords.part + ' ' +
+                                               'width=' + this._tileSize + ' ' 
+
+                                               'height=' + this._tileSize + ' 
' +
+                                               'tileposx=' + twips.x + ' '     
+
+                                               'tileposy=' + twips.y + ' ' +
+                                               'tilewidth=' + 
this._tileWidthTwips + ' ' +
+                                               'tileheight=' + 
this._tileHeightTwips;
+                               if (coords.part !== this._currentPart) {
+                                       msg += ' prefetch=true';
+                               }
+                               this.sendMessage(msg, key);
                        }
                }
                else {
diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index 83d489c..e537922 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -401,6 +401,10 @@ L.TileLayer = L.GridLayer.extend({
                                }
                                tile.el.src = img;
                        }
+                       else if (command.preFetch === 'true') {
+                               this._emptyTilesCount -= 1;
+                               this._tileCache[key] = img;
+                       }
                        L.Log.log(textMsg, L.INCOMING, key);
                }
                else if (textMsg.startsWith('textselection:')) {
@@ -530,6 +534,9 @@ L.TileLayer = L.GridLayer.extend({
                                // remove newline characters
                                command.type = 
tokens[i].substring(5).replace(/(\r\n|\n|\r)/gm, '');
                        }
+                       else if (tokens[i].substring(0,9) === 'prefetch=') {
+                               command.preFetch = tokens[i].substring(9);
+                       }
                }
                if (command.tileWidth && command.tileHeight) {
                        var scale = command.tileWidth / 
this.options.tileWidthTwips;
commit 71750599bdc5c8b9c31512386a952829b4c1a4b0
Author: Mihai Varga <mihai.va...@collabora.com>
Date:   Thu Jul 30 14:41:22 2015 +0300

    loleaflet: prefetch all tiles from other parts
    
    not only those outside of the visible area

diff --git a/loleaflet/src/layer/tile/GridLayer.js 
b/loleaflet/src/layer/tile/GridLayer.js
index 70f3c10..689bbe3 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -759,9 +759,15 @@ L.GridLayer = L.Layer.extend({
                }
 
                if (!this._preFetchBorder) {
-                       var pixelBounds = this._map.getPixelBounds(center, 
zoom),
-                               tileBorder = 
this._pxBoundsToTileRange(pixelBounds);
-                       this._preFetchBorder = tileBorder;
+                       if (this._currentPart !== this._preFetchPart) {
+                               // all tiles from the new part have to be 
pre-fetched
+                               tileBorder = this._preFetchBorder = new 
L.Bounds(new L.Point(0, 0), new L.Point(0, 0));
+                       }
+                       else {
+                               var pixelBounds = 
this._map.getPixelBounds(center, zoom),
+                                       tileBorder = 
this._pxBoundsToTileRange(pixelBounds);
+                               this._preFetchBorder = tileBorder;
+                       }
                }
                else {
                        tileBorder = this._preFetchBorder;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to