loleaflet/src/layer/tile/GridLayer.js |  238 +++++++++++++++++++++-------------
 loleaflet/src/layer/tile/TileLayer.js |    1 
 2 files changed, 153 insertions(+), 86 deletions(-)

New commits:
commit 22e8f8b1fefc2cbb50c4be27d3a04df0604d8859
Author: Jan Holesovsky <ke...@collabora.com>
Date:   Thu Apr 21 11:31:32 2016 +0200

    loleaflet: Group tile requests into rectangular areas, and call tilecombine.
    
    Instead of asking for individual tiles, try to find rectangular areas in the
    tile requests, and ask for the large rectangles using tilecombine, instead 
of
    asking for individual tiles.

diff --git a/loleaflet/src/layer/tile/GridLayer.js 
b/loleaflet/src/layer/tile/GridLayer.js
index 2954ed0..fad90c0 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -779,7 +779,7 @@ L.GridLayer = L.Layer.extend({
 
        _addTiles: function (coordsQueue, fragment) {
                // first take care of the DOM
-               for (i = 0; i < coordsQueue.length; i++) {
+               for (var i = 0; i < coordsQueue.length; i++) {
                        var coords = coordsQueue[i];
 
                        var tilePos = this._getTilePos(coords),
@@ -821,25 +821,124 @@ L.GridLayer = L.Layer.extend({
                        }
                }
 
-               // then ask for the actual tiles
-               for (i = 0; i < coordsQueue.length; i++) {
-                       var coords = coordsQueue[i];
+               // sort the tiles by the rows
+               coordsQueue.sort(function(a, b){
+                       if (a.y != b.y ) {
+                               return a.y-b.y;
+                       } else {
+                               return a.x-b.x;
+                       }
+               });
+
+               // try group the tiles into rectangular areas
+               var rectangles = [];
+               while (coordsQueue.length > 0) {
+                       var coords = coordsQueue[0];
 
+                       // tiles that do not interest us
                        var key = this._tileCoordsToKey(coords);
+                       if (this._tileCache[key] || coords.part !== 
this._selectedPart) {
+                               coordsQueue.splice(0, 1);
+                               continue;
+                       }
 
-                       if (!this._tileCache[key]) {
-                               if (coords.part === this._selectedPart) {
+                       var rectQueue = [ coords ];
+                       var bound = new L.Point(coords.x, coords.y);
+
+                       // remove it
+                       coordsQueue.splice(0, 1);
+
+                       // find the close ones
+                       var rowLocked = false;
+                       var hasHole = false
+                       var i = 0;
+                       while (i < coordsQueue.length) {
+                               var current = coordsQueue[i];
+
+                               // extend the bound vertically if possible (so 
far it was
+                               // continous)
+                               if (!hasHole && (current.y == bound.y + 1)) {
+                                       rowLocked = true;
+                                       ++bound.y;
+                               }
+
+                               if (current.y > bound.y) {
+                                       break;
+                               }
+
+                               if (!rowLocked) {
+                                       if (current.y == bound.y && current.x 
== bound.x + 1) {
+                                               // extend the bound horizontally
+                                               ++bound.x;
+                                               rectQueue.push(current);
+                                               coordsQueue.splice(i, 1);
+                                       } else {
+                                               // ignore the rest of the row
+                                               rowLocked = true;
+                                               ++i;
+                                       }
+                               } else if (current.x <= bound.x && current.y <= 
bound.y) {
+                                       // we are inside the bound
+                                       rectQueue.push(current);
+                                       coordsQueue.splice(i, 1);
+                               } else {
+                                       // ignore this one, but there still may 
be other tiles
+                                       hasHole = true;
+                                       ++i;
+                               }
+                       }
+
+                       rectangles.push(rectQueue);
+               }
+
+               for (var r = 0; r < rectangles.length; ++r) {
+                       var rectQueue = rectangles[r];
+
+                       if (rectQueue.length == 1) {
+                               // only one tile here
+                               var coords = rectQueue[0];
+                               var key = this._tileCoordsToKey(coords);
+
+                               var twips = this._coordsToTwips(coords);
+                               var msg = 'tile ' +
+                                               'part=' + coords.part + ' ' +
+                                               'width=' + this._tileSize + ' ' 
+
+                                               'height=' + this._tileSize + ' 
' +
+                                               'tileposx=' + twips.x + ' '     
+
+                                               'tileposy=' + twips.y + ' ' +
+                                               'tilewidth=' + 
this._tileWidthTwips + ' ' +
+                                               'tileheight=' + 
this._tileHeightTwips;
+                               this._map._socket.sendMessage(msg, key);
+                       }
+                       else {
+                               // more tiles, use tilecombine
+                               var tilePositionsX = '';
+                               var tilePositionsY = '';
+                               for (var i = 0; i < rectQueue.length; i++) {
+                                       var coords = rectQueue[i];
                                        var twips = this._coordsToTwips(coords);
-                                       var msg = 'tile ' +
-                                                       'part=' + coords.part + 
' ' +
-                                                       'width=' + 
this._tileSize + ' ' +
-                                                       'height=' + 
this._tileSize + ' ' +
-                                                       'tileposx=' + twips.x + 
' '     +
-                                                       'tileposy=' + twips.y + 
' ' +
-                                                       'tilewidth=' + 
this._tileWidthTwips + ' ' +
-                                                       'tileheight=' + 
this._tileHeightTwips;
-                                       this._map._socket.sendMessage(msg, key);
+
+                                       if (tilePositionsX !== '') {
+                                               tilePositionsX += ',';
+                                       }
+                                       tilePositionsX += twips.x;
+
+                                       if (tilePositionsY !== '') {
+                                               tilePositionsY += ',';
+                                       }
+                                       tilePositionsY += twips.y;
                                }
+
+                               var twips = this._coordsToTwips(coords);
+                               var msg = 'tilecombine ' +
+                                               'part=' + coords.part + ' ' +
+                                               'width=' + this._tileSize + ' ' 
+
+                                               'height=' + this._tileSize + ' 
' +
+                                               'tileposx=' + tilePositionsX + 
' '      +
+                                               'tileposy=' + tilePositionsY + 
' ' +
+                                               'tilewidth=' + 
this._tileWidthTwips + ' ' +
+                                               'tileheight=' + 
this._tileHeightTwips;
+                               this._map._socket.sendMessage(msg, '');
                        }
                }
        },
commit 4a21e21627b5b9bbd55201239233c274900fe39d
Author: Jan Holesovsky <ke...@collabora.com>
Date:   Wed Apr 20 19:42:15 2016 +0200

    loleaflet: Split the DOM handling from the actual asking for tiles.

diff --git a/loleaflet/src/layer/tile/GridLayer.js 
b/loleaflet/src/layer/tile/GridLayer.js
index e65c152..2954ed0 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -778,6 +778,7 @@ L.GridLayer = L.Layer.extend({
        },
 
        _addTiles: function (coordsQueue, fragment) {
+               // first take care of the DOM
                for (i = 0; i < coordsQueue.length; i++) {
                        var coords = coordsQueue[i];
 
@@ -815,6 +816,17 @@ L.GridLayer = L.Layer.extend({
                                });
                        }
 
+                       if (this._tileCache[key]) {
+                               tile.src = this._tileCache[key];
+                       }
+               }
+
+               // then ask for the actual tiles
+               for (i = 0; i < coordsQueue.length; i++) {
+                       var coords = coordsQueue[i];
+
+                       var key = this._tileCoordsToKey(coords);
+
                        if (!this._tileCache[key]) {
                                if (coords.part === this._selectedPart) {
                                        var twips = this._coordsToTwips(coords);
@@ -829,9 +841,6 @@ L.GridLayer = L.Layer.extend({
                                        this._map._socket.sendMessage(msg, key);
                                }
                        }
-                       else {
-                               tile.src = this._tileCache[key];
-                       }
                }
        },
 
commit a11aa8565cd7da7cb8abac353080c670e4027043
Author: Jan Holesovsky <ke...@collabora.com>
Date:   Wed Apr 20 19:39:13 2016 +0200

    loleaflet: Change _addTile to _addTiles, and pass the entire queue.

diff --git a/loleaflet/src/layer/tile/GridLayer.js 
b/loleaflet/src/layer/tile/GridLayer.js
index f20edb3..e65c152 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -549,11 +549,7 @@ L.GridLayer = L.Layer.extend({
 
                        // create DOM fragment to append tiles in one batch
                        var fragment = document.createDocumentFragment();
-
-                       for (i = 0; i < queue.length; i++) {
-                               this._addTile(queue[i], fragment);
-                       }
-
+                       this._addTiles(queue, fragment);
                        this._level.el.appendChild(fragment);
                }
        },
@@ -781,57 +777,61 @@ L.GridLayer = L.Layer.extend({
                }
        },
 
-       _addTile: function (coords, fragment) {
-               var tilePos = this._getTilePos(coords),
-                       key = this._tileCoordsToKey(coords);
+       _addTiles: function (coordsQueue, fragment) {
+               for (i = 0; i < coordsQueue.length; i++) {
+                       var coords = coordsQueue[i];
 
-               if (coords.part === this._selectedPart) {
-                       var tile = this.createTile(this._wrapCoords(coords), 
L.bind(this._tileReady, this, coords));
+                       var tilePos = this._getTilePos(coords),
+                               key = this._tileCoordsToKey(coords);
 
-                       this._initTile(tile);
+                       if (coords.part === this._selectedPart) {
+                               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);
 
-               if (!this._tileCache[key]) {
-                       if (coords.part === this._selectedPart) {
-                               var twips = this._coordsToTwips(coords);
-                               var msg = 'tile ' +
-                                               'part=' + coords.part + ' ' +
-                                               'width=' + this._tileSize + ' ' 
+
-                                               'height=' + this._tileSize + ' 
' +
-                                               'tileposx=' + twips.x + ' '     
+
-                                               'tileposy=' + twips.y + ' ' +
-                                               'tilewidth=' + 
this._tileWidthTwips + ' ' +
-                                               'tileheight=' + 
this._tileHeightTwips;
-                               this._map._socket.sendMessage(msg, key);
+                               this.fire('tileloadstart', {
+                                       tile: tile,
+                                       coords: coords
+                               });
+                       }
+
+                       if (!this._tileCache[key]) {
+                               if (coords.part === this._selectedPart) {
+                                       var twips = this._coordsToTwips(coords);
+                                       var msg = 'tile ' +
+                                                       'part=' + coords.part + 
' ' +
+                                                       'width=' + 
this._tileSize + ' ' +
+                                                       'height=' + 
this._tileSize + ' ' +
+                                                       'tileposx=' + twips.x + 
' '     +
+                                                       'tileposy=' + twips.y + 
' ' +
+                                                       'tilewidth=' + 
this._tileWidthTwips + ' ' +
+                                                       'tileheight=' + 
this._tileHeightTwips;
+                                       this._map._socket.sendMessage(msg, key);
+                               }
+                       }
+                       else {
+                               tile.src = this._tileCache[key];
                        }
-               }
-               else {
-                       tile.src = this._tileCache[key];
                }
        },
 
@@ -1060,9 +1060,7 @@ L.GridLayer = L.Layer.extend({
 
                if (finalQueue.length > 0) {
                        var fragment = document.createDocumentFragment();
-                       for (i = 0; i < finalQueue.length; i++) {
-                               this._addTile(finalQueue[i], fragment);
-                       }
+                       this._addTiles(finalQueue, fragment);
                        this._level.el.appendChild(fragment);
                }
        },
commit 538c1f571da2c210e86b294571ec019001aa0f19
Author: Jan Holesovsky <ke...@collabora.com>
Date:   Wed Apr 20 19:34:14 2016 +0200

    loleaflet: Don't create the message if not necessary.

diff --git a/loleaflet/src/layer/tile/GridLayer.js 
b/loleaflet/src/layer/tile/GridLayer.js
index a032141..f20edb3 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -817,16 +817,16 @@ L.GridLayer = L.Layer.extend({
                }
 
                if (!this._tileCache[key]) {
-                       var twips = this._coordsToTwips(coords);
-                       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._selectedPart) {
+                               var twips = this._coordsToTwips(coords);
+                               var msg = 'tile ' +
+                                               'part=' + coords.part + ' ' +
+                                               'width=' + this._tileSize + ' ' 
+
+                                               'height=' + this._tileSize + ' 
' +
+                                               'tileposx=' + twips.x + ' '     
+
+                                               'tileposy=' + twips.y + ' ' +
+                                               'tilewidth=' + 
this._tileWidthTwips + ' ' +
+                                               'tileheight=' + 
this._tileHeightTwips;
                                this._map._socket.sendMessage(msg, key);
                        }
                }
commit d8741d5ec35054deda2879386d65c9da45e68596
Author: Jan Holesovsky <ke...@collabora.com>
Date:   Wed Apr 20 18:20:00 2016 +0200

    loleaflet: Remove code for prefetching in other parts.
    
    Not that a typical use case I'm afraid, and trying to switch parts for
    prefetching was causing trouble in the past anyway.

diff --git a/loleaflet/src/layer/tile/GridLayer.js 
b/loleaflet/src/layer/tile/GridLayer.js
index af62ef1..a032141 100644
--- a/loleaflet/src/layer/tile/GridLayer.js
+++ b/loleaflet/src/layer/tile/GridLayer.js
@@ -1056,44 +1056,6 @@ L.GridLayer = L.Layer.extend({
                                tileBorder.max.y += 1;
                        }
                        borderWidth += 1;
-                       if (!(tileBorder.min.x >= 0 || tileBorder.min.y >= 0 ||
-                                       tileBorder.max.x * this._tileWidthTwips 
< this._docWidthTwips ||
-                                        tileBorder.max.y * 
this._tileHeightTwips < this._docHeightTwips) &&
-                                       this.options.preFetchOtherParts) {
-                               var diff = this._preFetchPart - 
this._selectedPart;
-                               if (diff === 0 && this._selectedPart < 
this._parts - 1) {
-                                       this._preFetchPart += 1;
-                                       this._preFetchBorder = null;
-                               }
-                               else if (diff === 0 && this._selectedPart > 0) {
-                                       this._preFetchPart -= 1;
-                                       this._preFetchBorder = null;
-                               }
-                               else if (diff > 0) {
-                                       if (this._selectedPart - diff >= 0) {
-                                               // lower part number
-                                               this._preFetchPart = 
this._selectedPart - diff;
-                                               this._preFetchBorder = null;
-                                       }
-                                       else if (this._selectedPart + diff + 1 
< this._parts) {
-                                               // higher part number
-                                               this._preFetchPart = 
this._selectedPart + diff + 1;
-                                               this._preFetchBorder = null;
-                                       }
-                               }
-                               else if (diff < 0) {
-                                       if (this._selectedPart - diff + 1 < 
this._parts) {
-                                               // higher part number
-                                               this._preFetchPart = 
this._selectedPart - diff + 1;
-                                               this._preFetchBorder = null;
-                                       }
-                                       else if (this._selectedPart + diff - 1 
>= 0) {
-                                               // lower part number
-                                               this._preFetchPart = 
this._selectedPart + diff - 1;
-                                               this._preFetchBorder = null;
-                                       }
-                               }
-                       }
                }
 
                if (finalQueue.length > 0) {
diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index 753fc34..34ff0c0 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -47,7 +47,6 @@ L.TileLayer = L.GridLayer.extend({
                zoomReverse: false,
                detectRetina: false,
                crossOrigin: false,
-               preFetchOtherParts: false,
                previewInvalidationTimeout: 1000,
                defaultPermission: 'view'
        },
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to