From 3a277f3ba558692415ee8b00ff6e8082dbe6f535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sat, 12 Sep 2020 16:16:34 +0200 Subject: [PATCH 1/2] canvas: restore() should reflect that smask groups are finished when stateStack is empty. This fixes the issue that caused #12363 to get reverted, see #12367. When we end the SMask group and stateStack.length is zero, nothing updates this.current to reflect it. --- src/display/canvas.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/display/canvas.js b/src/display/canvas.js index 58b65d631..abf958e96 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -1192,7 +1192,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { groupCtx.clearRect(0, 0, groupCtx.canvas.width, groupCtx.canvas.height); groupCtx.restore(); }, - resumeSMaskGroup: function CanvasGraphics_endSMaskGroup() { + resumeSMaskGroup: function CanvasGraphics_resumeSMaskGroup() { // Resuming state saved by suspendSMaskGroup. We don't need to restore // any groupCtx state since restore() command (the only caller) will do // that for us. See also beginSMaskGroup. @@ -1254,6 +1254,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { this.pendingClip = null; this._cachedGetSinglePixelWidth = null; + } else { + // We've finished all the SMask groups, reflect that in our state. + this.current.activeSMask = null; } }, transform: function CanvasGraphics_transform(a, b, c, d, e, f) { From bf8b1adf73812aa0918032573ba17fae0b47f9c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 11 Sep 2020 12:13:30 +0200 Subject: [PATCH 2/2] canvas: Properly restore all the remaining items in stateStack in endDrawing. We were correctly finishing the SMask group but not restoring all the extra transformations applied in stateStack, so if somebody ends up drawing to the same context after canceling mid-draw we'd get artifacts. This re-lands #12363 and fixes Mozilla bug 1664178[1]. [1]: https://bugzilla.mozilla.org/show_bug.cgi?id=1664178 --- src/display/canvas.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/display/canvas.js b/src/display/canvas.js index abf958e96..b98d0598c 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -1009,8 +1009,8 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { endDrawing: function CanvasGraphics_endDrawing() { // Finishing all opened operations such as SMask group painting. - if (this.current.activeSMask !== null) { - this.endSMaskGroup(); + while (this.stateStack.length || this.current.activeSMask !== null) { + this.restore(); } this.ctx.restore();