From 880d4b89a20840c4dc19849d893321502c0502d1 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Thu, 7 Apr 2016 16:30:04 +0200 Subject: [PATCH 1/2] Revert "Batch polygon fill and stroke instructions" --- src/ol/render/canvas/canvasreplay.js | 86 +++++++++++----------------- 1 file changed, 35 insertions(+), 51 deletions(-) diff --git a/src/ol/render/canvas/canvasreplay.js b/src/ol/render/canvas/canvasreplay.js index 4cb107c3ae..b907b04eb5 100644 --- a/src/ol/render/canvas/canvasreplay.js +++ b/src/ol/render/canvas/canvasreplay.js @@ -153,10 +153,11 @@ goog.inherits(ol.render.canvas.Replay, ol.render.VectorContext); * @param {number} offset Offset. * @param {number} end End. * @param {number} stride Stride. + * @param {boolean} close Close. * @protected * @return {number} My end. */ -ol.render.canvas.Replay.prototype.appendFlatCoordinates = function(flatCoordinates, offset, end, stride) { +ol.render.canvas.Replay.prototype.appendFlatCoordinates = function(flatCoordinates, offset, end, stride, close) { var myEnd = this.coordinates.length; var extent = this.getBufferedMaxExtent(); @@ -195,6 +196,10 @@ ol.render.canvas.Replay.prototype.appendFlatCoordinates = function(flatCoordinat this.coordinates[myEnd++] = lastCoord[1]; } + if (close) { + this.coordinates[myEnd++] = flatCoordinates[offset]; + this.coordinates[myEnd++] = flatCoordinates[offset + 1]; + } return myEnd; }; @@ -766,7 +771,8 @@ goog.inherits(ol.render.canvas.ImageReplay, ol.render.canvas.Replay); * @return {number} My end. */ ol.render.canvas.ImageReplay.prototype.drawCoordinates_ = function(flatCoordinates, offset, end, stride) { - return this.appendFlatCoordinates(flatCoordinates, offset, end, stride); + return this.appendFlatCoordinates( + flatCoordinates, offset, end, stride, false); }; @@ -987,7 +993,8 @@ goog.inherits(ol.render.canvas.LineStringReplay, ol.render.canvas.Replay); */ ol.render.canvas.LineStringReplay.prototype.drawFlatCoordinates_ = function(flatCoordinates, offset, end, stride) { var myBegin = this.coordinates.length; - var myEnd = this.appendFlatCoordinates(flatCoordinates, offset, end, stride); + var myEnd = this.appendFlatCoordinates( + flatCoordinates, offset, end, stride, false); var moveToLineToInstruction = [ol.render.canvas.Instruction.MOVE_TO_LINE_TO, myBegin, myEnd]; this.instructions.push(moveToLineToInstruction); @@ -1189,9 +1196,7 @@ ol.render.canvas.PolygonReplay = function(tolerance, maxExtent, resolution) { * lineDash: Array., * lineJoin: (string|undefined), * lineWidth: (number|undefined), - * miterLimit: (number|undefined), - * pendingFill: number, - * pendingStroke: number}|null} + * miterLimit: (number|undefined)}|null} */ this.state_ = { currentFillStyle: undefined, @@ -1207,9 +1212,7 @@ ol.render.canvas.PolygonReplay = function(tolerance, maxExtent, resolution) { lineDash: null, lineJoin: undefined, lineWidth: undefined, - miterLimit: undefined, - pendingFill: 0, - pendingStroke: 0 + miterLimit: undefined }; }; @@ -1226,19 +1229,15 @@ goog.inherits(ol.render.canvas.PolygonReplay, ol.render.canvas.Replay); */ ol.render.canvas.PolygonReplay.prototype.drawFlatCoordinatess_ = function(flatCoordinates, offset, ends, stride) { var state = this.state_; - if (state.pendingFill > 200 || state.pendingStroke > 200) { - this.fillStroke_(); - } var beginPathInstruction = [ol.render.canvas.Instruction.BEGIN_PATH]; - if (!state.pendingFill && !state.pendingStroke) { - this.instructions.push(beginPathInstruction); - } + this.instructions.push(beginPathInstruction); this.hitDetectionInstructions.push(beginPathInstruction); var i, ii; for (i = 0, ii = ends.length; i < ii; ++i) { var end = ends[i]; var myBegin = this.coordinates.length; - var myEnd = this.appendFlatCoordinates(flatCoordinates, offset, end, stride); + var myEnd = this.appendFlatCoordinates( + flatCoordinates, offset, end, stride, true); var moveToLineToInstruction = [ol.render.canvas.Instruction.MOVE_TO_LINE_TO, myBegin, myEnd]; var closePathInstruction = [ol.render.canvas.Instruction.CLOSE_PATH]; @@ -1247,15 +1246,19 @@ ol.render.canvas.PolygonReplay.prototype.drawFlatCoordinatess_ = function(flatCo closePathInstruction); offset = end; } - this.hitDetectionInstructions.push([ol.render.canvas.Instruction.FILL]); + // FIXME is it quicker to fill and stroke each polygon individually, + // FIXME or all polygons together? + var fillInstruction = [ol.render.canvas.Instruction.FILL]; + this.hitDetectionInstructions.push(fillInstruction); if (state.fillStyle !== undefined) { - state.pendingFill++; + this.instructions.push(fillInstruction); } if (state.strokeStyle !== undefined) { goog.asserts.assert(state.lineWidth !== undefined, 'state.lineWidth should be defined'); - state.pendingStroke++; - this.hitDetectionInstructions.push([ol.render.canvas.Instruction.STROKE]); + var strokeInstruction = [ol.render.canvas.Instruction.STROKE]; + this.instructions.push(strokeInstruction); + this.hitDetectionInstructions.push(strokeInstruction); } return offset; }; @@ -1292,23 +1295,22 @@ ol.render.canvas.PolygonReplay.prototype.drawCircle = function(circleGeometry, f var stride = circleGeometry.getStride(); var myBegin = this.coordinates.length; this.appendFlatCoordinates( - flatCoordinates, 0, flatCoordinates.length, stride); + flatCoordinates, 0, flatCoordinates.length, stride, false); var beginPathInstruction = [ol.render.canvas.Instruction.BEGIN_PATH]; var circleInstruction = [ol.render.canvas.Instruction.CIRCLE, myBegin]; - if (!state.pendingFill && !state.pendingStroke) { - this.instructions.push(beginPathInstruction); - } - this.instructions.push(circleInstruction); - this.hitDetectionInstructions.push(circleInstruction, beginPathInstruction); - this.hitDetectionInstructions.push([ol.render.canvas.Instruction.FILL]); + this.instructions.push(beginPathInstruction, circleInstruction); + this.hitDetectionInstructions.push(beginPathInstruction, circleInstruction); + var fillInstruction = [ol.render.canvas.Instruction.FILL]; + this.hitDetectionInstructions.push(fillInstruction); if (state.fillStyle !== undefined) { - state.pendingFill++; + this.instructions.push(fillInstruction); } if (state.strokeStyle !== undefined) { goog.asserts.assert(state.lineWidth !== undefined, 'state.lineWidth should be defined'); - state.pendingStroke++; - this.hitDetectionInstructions.push([ol.render.canvas.Instruction.STROKE]); + var strokeInstruction = [ol.render.canvas.Instruction.STROKE]; + this.instructions.push(strokeInstruction); + this.hitDetectionInstructions.push(strokeInstruction); } this.endGeometry(circleGeometry, feature); }; @@ -1389,28 +1391,13 @@ ol.render.canvas.PolygonReplay.prototype.drawMultiPolygon = function(multiPolygo }; -/** - * @private - */ -ol.render.canvas.PolygonReplay.prototype.fillStroke_ = function() { - var state = this.state_; - if (state.pendingFill) { - this.instructions.push([ol.render.canvas.Instruction.FILL]); - state.pendingFill = 0; - } - if (state.pendingStroke) { - this.instructions.push([ol.render.canvas.Instruction.STROKE]); - state.pendingStroke = 0; - } -}; - - /** * @inheritDoc */ ol.render.canvas.PolygonReplay.prototype.finish = function() { goog.asserts.assert(this.state_, 'this.state_ should not be null'); this.reverseHitDetectionInstructions_(); + this.state_ = null; // We want to preserve topology when drawing polygons. Polygons are // simplified using quantization and point elimination. However, we might // have received a mix of quantized and non-quantized geometries, so ensure @@ -1423,8 +1410,6 @@ ol.render.canvas.PolygonReplay.prototype.finish = function() { coordinates[i] = ol.geom.flat.simplify.snap(coordinates[i], tolerance); } } - this.fillStroke_(); - this.state_ = null; }; @@ -1507,7 +1492,6 @@ ol.render.canvas.PolygonReplay.prototype.setFillStrokeStyles_ = function() { var lineWidth = state.lineWidth; var miterLimit = state.miterLimit; if (fillStyle !== undefined && state.currentFillStyle != fillStyle) { - this.fillStroke_(); this.instructions.push( [ol.render.canvas.Instruction.SET_FILL_STYLE, fillStyle]); state.currentFillStyle = state.fillStyle; @@ -1525,7 +1509,6 @@ ol.render.canvas.PolygonReplay.prototype.setFillStrokeStyles_ = function() { state.currentLineJoin != lineJoin || state.currentLineWidth != lineWidth || state.currentMiterLimit != miterLimit) { - this.fillStroke_(); this.instructions.push( [ol.render.canvas.Instruction.SET_STROKE_STYLE, strokeStyle, lineWidth, lineCap, lineJoin, miterLimit, lineDash]); @@ -1640,7 +1623,8 @@ ol.render.canvas.TextReplay.prototype.drawText = function(flatCoordinates, offse this.setReplayTextState_(this.textState_); this.beginGeometry(geometry, feature); var myBegin = this.coordinates.length; - var myEnd = this.appendFlatCoordinates(flatCoordinates, offset, end, stride); + var myEnd = + this.appendFlatCoordinates(flatCoordinates, offset, end, stride, false); var fill = !!this.textFillState_; var stroke = !!this.textStrokeState_; var drawTextInstruction = [ From 481bcbd5b3c4e248008ee9fbce26169584c394f2 Mon Sep 17 00:00:00 2001 From: Frederic Junod Date: Thu, 7 Apr 2016 16:34:17 +0200 Subject: [PATCH 2/2] Changelog for v3.15.1 --- changelog/v3.15.1.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 changelog/v3.15.1.md diff --git a/changelog/v3.15.1.md b/changelog/v3.15.1.md new file mode 100644 index 0000000000..c37a2754ea --- /dev/null +++ b/changelog/v3.15.1.md @@ -0,0 +1,9 @@ +# v3.15.1 + +## Summary + +The v3.15.1 release is a patch release that addresses a regression in the v3.15.0 release. See the [v3.15.0 release notes](https://github.com/openlayers/ol3/releases/tag/v3.15.0) for details on upgrading from v3.14.x. + +## Fixes + +* [#5190](https://github.com/openlayers/ol3/pull/5190) - Revert "Batch polygon fill and stroke instructions" ([@ahocevar](https://github.com/ahocevar))