Title: [166785] trunk
Revision
166785
Author
k...@webkit.org
Date
2014-04-04 09:41:09 -0700 (Fri, 04 Apr 2014)

Log Message

Gradient offsets are off if compositing operator != source-over
https://bugs.webkit.org/show_bug.cgi?id=129791

Reviewed by Andreas Kling.

Source/WebCore:

Instead of transforming the path before drawing it on the context,
the whole context should be transformed. This will make the gradient
map correctly to the context space.

Test: fast/canvas/canvas-gradient-on-compositing.html

* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::fullCanvasCompositedFill):

LayoutTests:

Test that the gradient space maps correctly to context space after
applying compositing mode.

* fast/canvas/canvas-gradient-on-compositing-expected.txt: Added.
* fast/canvas/canvas-gradient-on-compositing.html: Added.
* fast/canvas/script-tests/canvas-gradient-on-compositing.js: Added.
(dataToArray):
(getPixel):
(pixelShouldBe):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (166784 => 166785)


--- trunk/LayoutTests/ChangeLog	2014-04-04 16:30:18 UTC (rev 166784)
+++ trunk/LayoutTests/ChangeLog	2014-04-04 16:41:09 UTC (rev 166785)
@@ -1,3 +1,20 @@
+2014-04-04  Dirk Schulze  <k...@webkit.org>
+
+        Gradient offsets are off if compositing operator != source-over
+        https://bugs.webkit.org/show_bug.cgi?id=129791
+
+        Reviewed by Andreas Kling.
+
+        Test that the gradient space maps correctly to context space after
+        applying compositing mode.
+
+        * fast/canvas/canvas-gradient-on-compositing-expected.txt: Added.
+        * fast/canvas/canvas-gradient-on-compositing.html: Added.
+        * fast/canvas/script-tests/canvas-gradient-on-compositing.js: Added.
+        (dataToArray):
+        (getPixel):
+        (pixelShouldBe):
+
 2014-04-04  Zalan Bujtas  <za...@apple.com>
 
         Subpixel rendering: Move background images to device pixel boundaries.

Added: trunk/LayoutTests/fast/canvas/canvas-gradient-on-compositing-expected.txt (0 => 166785)


--- trunk/LayoutTests/fast/canvas/canvas-gradient-on-compositing-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-gradient-on-compositing-expected.txt	2014-04-04 16:41:09 UTC (rev 166785)
@@ -0,0 +1,11 @@
+Test that compositing does not influence the gradient space to context space mapping.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS getPixel(125,50) is [0,0,0,0]
+PASS getPixel(175,50) is [0,128,0,255]
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/canvas/canvas-gradient-on-compositing.html (0 => 166785)


--- trunk/LayoutTests/fast/canvas/canvas-gradient-on-compositing.html	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-gradient-on-compositing.html	2014-04-04 16:41:09 UTC (rev 166785)
@@ -0,0 +1,10 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script src=""
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/canvas/script-tests/canvas-gradient-on-compositing.js (0 => 166785)


--- trunk/LayoutTests/fast/canvas/script-tests/canvas-gradient-on-compositing.js	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/script-tests/canvas-gradient-on-compositing.js	2014-04-04 16:41:09 UTC (rev 166785)
@@ -0,0 +1,45 @@
+description("Test that compositing does not influence the gradient space to context space mapping.");
+var ctx = document.createElement('canvas').getContext('2d');
+
+function dataToArray(data) {
+    var result = new Array(data.length)
+    for (var i = 0; i < data.length; i++)
+        result[i] = data[i];
+    return result;
+}
+
+function getPixel(x, y) {
+    var data = ""
+    if (!data) // getImageData failed, which should never happen
+        return [-1,-1,-1,-1];
+    return dataToArray(data.data);
+}
+
+function pixelShouldBe(x, y, colour) {
+    shouldBe("getPixel(" + [x, y] +")", "["+colour+"]");
+}
+
+var grad = ctx.createLinearGradient(100,0,200,0);
+grad.addColorStop(0, 'rgba(0,0,0,0)');
+grad.addColorStop(0.5, 'rgba(0,0,0,0)');
+grad.addColorStop(0.5, 'rgba(0,128,0,1)');
+grad.addColorStop(1, 'rgba(0,128,0,1)');
+
+ctx.fillStyle = "rgba(0,0,0,0)";
+ctx.beginPath();
+ctx.moveTo(100,0);
+ctx.rect(100,0,100,100);
+ctx.closePath();
+ctx.fill();
+
+ctx.globalCompositeOperation = 'destination-atop';
+
+ctx.fillStyle = grad;
+ctx.beginPath();
+ctx.moveTo(100,0);
+ctx.rect(100,0,100,100);
+ctx.closePath();
+ctx.fill();
+
+pixelShouldBe(125,50,[0,0,0,0]);
+pixelShouldBe(175,50,[0,128,0,255]);

Modified: trunk/Source/WebCore/ChangeLog (166784 => 166785)


--- trunk/Source/WebCore/ChangeLog	2014-04-04 16:30:18 UTC (rev 166784)
+++ trunk/Source/WebCore/ChangeLog	2014-04-04 16:41:09 UTC (rev 166785)
@@ -1,3 +1,19 @@
+2014-04-04  Dirk Schulze  <k...@webkit.org>
+
+        Gradient offsets are off if compositing operator != source-over
+        https://bugs.webkit.org/show_bug.cgi?id=129791
+
+        Reviewed by Andreas Kling.
+
+        Instead of transforming the path before drawing it on the context,
+        the whole context should be transformed. This will make the gradient
+        map correctly to the context space.
+
+        Test: fast/canvas/canvas-gradient-on-compositing.html
+
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::fullCanvasCompositedFill):
+
 2014-04-04  Zalan Bujtas  <za...@apple.com>
 
         Subpixel rendering: Move background images to device pixel boundaries.

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (166784 => 166785)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2014-04-04 16:30:18 UTC (rev 166784)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2014-04-04 16:41:09 UTC (rev 166785)
@@ -1679,10 +1679,10 @@
         return;
 
     Path path = transformAreaToDevice(area);
-    path.translate(FloatSize(-bufferRect.x(), -bufferRect.y()));
-
     buffer->context()->setCompositeOperation(CompositeSourceOver);
+    buffer->context()->translate(FloatSize(-bufferRect.x(), -bufferRect.y()));
     modifiableState().m_fillStyle.applyFillColor(buffer->context());
+
     buffer->context()->fillPath(path);
 
     compositeBuffer(buffer.get(), bufferRect, state().m_globalComposite);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to