[Libreoffice-commits] online.git: Branch 'feature/calc-canvas' - 2 commits - loleaflet/src

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Tue Sep 8 15:04:27 UTC 2020


 loleaflet/src/geometry/Bounds.js            |    7 ++++++
 loleaflet/src/layer/tile/CanvasTileLayer.js |   31 ++++++++++++++++++++--------
 2 files changed, 30 insertions(+), 8 deletions(-)

New commits:
commit 02ff5aba43627e28b1ebf3726a370305edf97780
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Tue Sep 8 16:03:34 2020 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Sep 8 16:04:06 2020 +0100

    calc canvas: use sub image blitting instead of clipping.
    
    Avoids thrashing the canvas rendering context / clip state.
    
    Change-Id: I547ce22a171874cd7be3a0fac50b4afc56faf084

diff --git a/loleaflet/src/layer/tile/CanvasTileLayer.js b/loleaflet/src/layer/tile/CanvasTileLayer.js
index 9f6f4c42b..c44e2ae47 100644
--- a/loleaflet/src/layer/tile/CanvasTileLayer.js
+++ b/loleaflet/src/layer/tile/CanvasTileLayer.js
@@ -178,7 +178,9 @@ L.CanvasTilePainter = L.Class.extend({
 			if (topLeft.y)
 				topLeft.y = viewBounds.min.y;
 
-			this._canvasCtx.setTransform(1,0,0,1,-topLeft.x, -topLeft.y);
+			this._canvasCtx.setTransform(1,0,
+						     0,1,
+						     -topLeft.x, -topLeft.y);
 			// when using the pinch to zoom, set additional translation based
 			// on the pinch movement
 			if (this._map._animatingZoom) {
@@ -186,13 +188,22 @@ L.CanvasTilePainter = L.Class.extend({
 				this._canvasCtx.translate(-Math.round(centerOffset.x), -Math.round(centerOffset.y));
 			}
 
-			// create a clip for the pane/view.
-			this._canvasCtx.beginPath();
-			var paneSize = paneBounds.getSize();
-			this._canvasCtx.rect(paneBounds.min.x, paneBounds.min.y, paneSize.x + 1, paneSize.y + 1);
-			this._canvasCtx.clip();
-
-			this._canvasCtx.drawImage(tile.el, tile.coords.x, tile.coords.y);
+			// intersect - to avoid state thrash through clipping
+			var crop = new L.Bounds(tileBounds.min, tileBounds.max);
+			crop.min.x = Math.max(paneBounds.min.x, tileBounds.min.x);
+			crop.min.y = Math.max(paneBounds.min.y, tileBounds.min.y);
+			crop.max.x = Math.min(paneBounds.max.x, tileBounds.max.x);
+			crop.max.y = Math.min(paneBounds.max.y, tileBounds.max.y);
+
+			var cropWidth = crop.max.x - crop.min.x;
+			var cropHeight = crop.max.y - crop.min.y;
+
+			this._canvasCtx.drawImage(tile.el,
+						  crop.min.x - tileBounds.min.x,
+						  crop.min.y - tileBounds.min.y,
+						  cropWidth, cropHeight,
+						  crop.min.x, crop.min.y,
+						  cropWidth, cropHeight);
 			if (this._layer._debug)
 			{
 				this._canvasCtx.strokeStyle = 'rgba(255, 0, 0, 0.5)';
commit 53f3ef5bfb21d5a2ff0c61dd6500ca4c850a821a
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Tue Sep 8 16:03:15 2020 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Tue Sep 8 16:04:06 2020 +0100

    calc canvas: round view co-ordinates to the real pixels we need.
    
    Change-Id: I768cd9015da1f1301f3ddad242130d4eddb426d1

diff --git a/loleaflet/src/geometry/Bounds.js b/loleaflet/src/geometry/Bounds.js
index 8dacdc832..e9ac075e8 100644
--- a/loleaflet/src/geometry/Bounds.js
+++ b/loleaflet/src/geometry/Bounds.js
@@ -83,6 +83,13 @@ L.Bounds.prototype = {
 		        (this.min.y + this.max.y) / 2, round);
 	},
 
+	round: function() {
+		this.min.x = Math.round(this.min.x);
+		this.min.y = Math.round(this.min.y);
+		this.max.x = Math.round(this.max.x);
+		this.max.y = Math.round(this.max.y);
+	},
+
 	getBottomLeft: function () { // -> Point
 		return new L.Point(this.min.x, this.max.y);
 	},
diff --git a/loleaflet/src/layer/tile/CanvasTileLayer.js b/loleaflet/src/layer/tile/CanvasTileLayer.js
index 5a030050a..9f6f4c42b 100644
--- a/loleaflet/src/layer/tile/CanvasTileLayer.js
+++ b/loleaflet/src/layer/tile/CanvasTileLayer.js
@@ -165,6 +165,10 @@ L.CanvasTilePainter = L.Class.extend({
 			var paneBounds = this._layer._cssBoundsToCore(ctx.paneBoundsList[i]);
 			var viewBounds = this._layer._cssBoundsToCore(ctx.viewBounds);
 
+			// into real pixel-land ...
+			paneBounds.round();
+			viewBounds.round();
+
 			if (!paneBounds.intersects(tileBounds))
 				continue;
 


More information about the Libreoffice-commits mailing list