From: oliver@apple.com Date: Tue, 30 Dec 2008 06:15:31 +0000 (+0000) Subject: Bug 23030: Cannot setTransform with a non-invertible ctm X-Git-Url: http://git.webkit.org/?p=WebKit-https.git;a=commitdiff_plain;h=18af97ec509f35f00f653a300b0faacef7c9671c Bug 23030: Cannot setTransform with a non-invertible ctm Reviewed by Cameron Zwarich. Removed a series of unnecessary and incorrect checks for an invertible transform. Test: fast/canvas/canvas-set-properties-with-non-invertible-ctm.html git-svn-id: https://svn.webkit.org/repository/webkit/trunk@39508 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index dd38cc8..1261967 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,17 @@ +2008-12-29 Oliver Hunt + + Reviewed by Cameron Zwarich. + + Bug 23030: Cannot setTransform with a non-invertible ctm + + Tests to ensure correct behaviour when the canvas context does not + have an invertible CTM. + + * fast/canvas/canvas-set-properties-with-non-invertible-ctm-expected.txt: Added. + * fast/canvas/canvas-set-properties-with-non-invertible-ctm.html: Added. + * fast/canvas/resources/canvas-set-properties-with-non-invertible-ctm.js: Added. + (testPixel): + 2008-12-29 Alexey Proskuryakov Reviewed by Mark Rowe. diff --git a/LayoutTests/fast/canvas/canvas-set-properties-with-non-invertible-ctm-expected.txt b/LayoutTests/fast/canvas/canvas-set-properties-with-non-invertible-ctm-expected.txt new file mode 100644 index 0000000..db05ec0 --- /dev/null +++ b/LayoutTests/fast/canvas/canvas-set-properties-with-non-invertible-ctm-expected.txt @@ -0,0 +1,23 @@ +Tests to make sure we can assign to non-ctm effected properties with a non-invertible ctm set + +On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". + + +PASS ctx.fillStyle is "green" +PASS imageData.data[0] is 0 +PASS imageData.data[1] is 128 +PASS imageData.data[2] is 0 +PASS ctx.strokeStyle is "green" +PASS imageData.data[0] is 0 +PASS imageData.data[1] is 128 +PASS imageData.data[2] is 0 +PASS imageData.data[0] is 0 +PASS imageData.data[1] is 128 +PASS imageData.data[2] is 0 +PASS imageData.data[0] is 0 +PASS imageData.data[1] is 128 +PASS imageData.data[2] is 0 +PASS successfullyParsed is true + +TEST COMPLETE + diff --git a/LayoutTests/fast/canvas/canvas-set-properties-with-non-invertible-ctm.html b/LayoutTests/fast/canvas/canvas-set-properties-with-non-invertible-ctm.html new file mode 100644 index 0000000..b4527ab --- /dev/null +++ b/LayoutTests/fast/canvas/canvas-set-properties-with-non-invertible-ctm.html @@ -0,0 +1,13 @@ + + + + + + + +

+
+ + + + diff --git a/LayoutTests/fast/canvas/resources/canvas-set-properties-with-non-invertible-ctm.js b/LayoutTests/fast/canvas/resources/canvas-set-properties-with-non-invertible-ctm.js new file mode 100644 index 0000000..ff0053e --- /dev/null +++ b/LayoutTests/fast/canvas/resources/canvas-set-properties-with-non-invertible-ctm.js @@ -0,0 +1,70 @@ +description("Tests to make sure we can assign to non-ctm effected properties with a non-invertible ctm set"); +var canvas = document.createElement("canvas"); +canvas.width = 100; +canvas.height = 100; +var ctx = canvas.getContext('2d'); +document.body.appendChild(canvas); + +function testPixel(x,y, r, g, b) { + imageData = ctx.getImageData(x, y, 1, 1); + shouldBe("imageData.data[0]", ""+r); + shouldBe("imageData.data[1]", ""+g); + shouldBe("imageData.data[2]", ""+b); +} + +// Test our ability to set fillStyle +ctx.save(); +ctx.scale(0, 0); +ctx.fillStyle = "green"; +shouldBe('ctx.fillStyle', '"green"'); +ctx.setTransform(1, 0, 0, 1, 0, 0); +ctx.fillRect(0,0,100,100); +testPixel(50, 50, 0, 128, 0); +ctx.restore(); + +// Test our ability to set strokeStyle +ctx.save(); +ctx.fillStyle = "red"; +ctx.fillRect(0,0,100,100); +ctx.scale(0, 0); +ctx.strokeStyle = "green"; +shouldBe('ctx.strokeStyle', '"green"'); +ctx.lineWidth = 100; +ctx.setTransform(1, 0, 0, 1, 0, 0); +ctx.strokeRect(0,0,100,100); +testPixel(50, 50, 0, 128, 0); +ctx.restore(); + + +// test closePath +ctx.save(); +ctx.fillStyle = "red"; +ctx.fillRect(0,0,100,100); + +ctx.beginPath(); +ctx.strokeStyle = "green"; +ctx.lineWidth = 100; +ctx.moveTo(-100, 50); +ctx.lineTo(-100, -100); +ctx.lineTo( 200, -100); +ctx.lineTo( 200, 50); +ctx.scale(0, 0); +ctx.closePath(); +ctx.setTransform(1, 0, 0, 1, 0, 0); +ctx.stroke(); +ctx.restore(); +testPixel(50, 50, 0, 128, 0); + +// Test beginPath behaviour +ctx.fillStyle = "green"; +ctx.fillRect(0,0,100,100); +ctx.fillStyle = "red"; +ctx.rect(0,0,100,100); +ctx.scale(0,0); +ctx.beginPath(); +ctx.setTransform(1, 0, 0, 1, 0, 0); +ctx.fill(); + +testPixel(50, 50, 0, 128, 0); + +successfullyParsed = true; diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index f9de570..9aa3bbb 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,30 @@ +2008-12-29 Oliver Hunt + + Reviewed by Cameron Zwarich. + + Bug 23030: Cannot setTransform with a non-invertible ctm + + Removed a series of unnecessary and incorrect checks for an invertible + transform. + + Test: fast/canvas/canvas-set-properties-with-non-invertible-ctm.html + + * html/CanvasRenderingContext2D.cpp: + (WebCore::CanvasRenderingContext2D::setStrokeStyle): + (WebCore::CanvasRenderingContext2D::setFillStyle): + These properties are not effected by the current CTM, so there + is no need to prevent them from being assigned. + + (WebCore::CanvasRenderingContext2D::setTransform): + The whole point of tracking whether the current CTM was expected to be + non-invertible was to allow setTransform to be used when the CTM had become + non-invertible. + + (WebCore::CanvasRenderingContext2D::beginPath): + (WebCore::CanvasRenderingContext2D::closePath): + beginPath and closePath change the state of the path, but not any of + its coordinates so there is no need prevent them from being called. + 2008-12-29 Josh Roesslein Reviewed by Oliver Hunt. diff --git a/WebCore/html/CanvasRenderingContext2D.cpp b/WebCore/html/CanvasRenderingContext2D.cpp index 5a1f3d0..8dda6c9 100644 --- a/WebCore/html/CanvasRenderingContext2D.cpp +++ b/WebCore/html/CanvasRenderingContext2D.cpp @@ -153,8 +153,6 @@ void CanvasRenderingContext2D::setStrokeStyle(PassRefPtr style) GraphicsContext* c = drawingContext(); if (!c) return; - if (!state().m_invertibleCTM) - return; state().m_strokeStyle->applyStrokeColor(c); } @@ -179,8 +177,6 @@ void CanvasRenderingContext2D::setFillStyle(PassRefPtr style) GraphicsContext* c = drawingContext(); if (!c) return; - if (!state().m_invertibleCTM) - return; state().m_fillStyle->applyFillColor(c); } @@ -420,8 +416,6 @@ void CanvasRenderingContext2D::setTransform(float m11, float m12, float m21, flo GraphicsContext* c = drawingContext(); if (!c) return; - if (!state().m_invertibleCTM) - return; // HTML5 3.14.11.1 -- ignore any calls that pass non-finite numbers if (!isfinite(m11) | !isfinite(m21) | !isfinite(dx) | @@ -436,6 +430,7 @@ void CanvasRenderingContext2D::setTransform(float m11, float m12, float m21, flo state().m_transform.multiply(ctm.inverse()); m_path.transform(ctm); + state().m_invertibleCTM = true; transform(m11, m12, m21, m22, dx, dy); } @@ -501,15 +496,11 @@ void CanvasRenderingContext2D::setFillColor(float c, float m, float y, float k, void CanvasRenderingContext2D::beginPath() { - if (!state().m_invertibleCTM) - return; m_path.clear(); } void CanvasRenderingContext2D::closePath() { - if (!state().m_invertibleCTM) - return; m_path.closeSubpath(); }