Title: [148923] trunk
Revision
148923
Author
[email protected]
Date
2013-04-22 16:06:16 -0700 (Mon, 22 Apr 2013)

Log Message

[Cairo] Canvas-shadow behavior is not being as expected
https://bugs.webkit.org/show_bug.cgi?id=108897

Patch by Rashmi Shyamasundar <[email protected]> on 2013-04-22
Reviewed by Martin Robinson.

Source/WebCore:

Use the pattern-extend-mode "CAIRO_EXTEND_NONE" instead of "CAIRO_EXTEND_PAD" in
PlatformContextCairo::drawSurfaceToContext().

In the function PlatformContextCairo::drawSurfaceToContext(), a pattern is being
created from the source surface and this pattern is drawn onto the destination
context. There is no gradient involved. Hence the extend mode for filling the
pattern should be "CAIRO_EXTEND_NONE". If we use the extend mode
"CAIRO_EXTEND_PAD" in PlatformContextCairo::drawSurfaceToContext(), the original
image area is also filled with the shadow color which is not the expected behavior.

Test: fast/canvas/canvas-image-shadow.html

* platform/graphics/cairo/PlatformContextCairo.cpp:
(WebCore::PlatformContextCairo::drawSurfaceToContext):

LayoutTests:

Test to verify the shadow of an image drawn on canvas.
This test uses an image whose size is smaller than,
the size of the rectangle which should be filled with the image.

* fast/canvas/canvas-image-shadow-expected.txt: Added.
* fast/canvas/canvas-image-shadow.html: Added.
* fast/canvas/green.png: Added.
* fast/canvas/script-tests/canvas-image-shadow.js: Added.
(draw):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (148922 => 148923)


--- trunk/LayoutTests/ChangeLog	2013-04-22 22:56:19 UTC (rev 148922)
+++ trunk/LayoutTests/ChangeLog	2013-04-22 23:06:16 UTC (rev 148923)
@@ -1,3 +1,20 @@
+2013-04-22  Rashmi Shyamasundar  <[email protected]>
+
+        [Cairo] Canvas-shadow behavior is not being as expected
+        https://bugs.webkit.org/show_bug.cgi?id=108897
+
+        Reviewed by Martin Robinson.
+
+        Test to verify the shadow of an image drawn on canvas. 
+        This test uses an image whose size is smaller than,
+        the size of the rectangle which should be filled with the image. 
+
+        * fast/canvas/canvas-image-shadow-expected.txt: Added.
+        * fast/canvas/canvas-image-shadow.html: Added.
+        * fast/canvas/green.png: Added.
+        * fast/canvas/script-tests/canvas-image-shadow.js: Added.
+        (draw):
+
 2013-04-22  Benjamin Poulain  <[email protected]>
 
         Remove the memory instrumentation code

Added: trunk/LayoutTests/fast/canvas/script-tests/shadow-image.js (0 => 148923)


--- trunk/LayoutTests/fast/canvas/script-tests/shadow-image.js	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/script-tests/shadow-image.js	2013-04-22 23:06:16 UTC (rev 148923)
@@ -0,0 +1,48 @@
+description("Test to verify the shadow of an image drawn on canvas");
+
+// Create an auxiliary canvas to draw to and create an image from.
+// This is done instead of simply loading an image from the file system
+// because that would throw a SECURITY_ERR DOM Exception.
+var aCanvas = document.createElement('canvas');
+aCanvas.setAttribute('width', '200');
+aCanvas.setAttribute('height', '200');
+var aCtx = aCanvas.getContext('2d');
+
+// Draw a rectangle on the same canvas.
+aCtx.fillStyle = 'rgb(0, 255, 0)';
+aCtx.rect(0, 0, 100, 50);
+aCtx.fill();
+
+// Create the image object to be drawn on the master canvas.
+var img = new Image();
+img._onload_ = draw;
+img.src = ""
+
+function draw()
+{
+var canvas = document.getElementById('myCanvas');
+var ctx = canvas.getContext('2d');
+ctx.shadowOffsetX = 200;
+ctx.shadowOffsetY = 50;
+ctx.fillStyle=ctx.createPattern(img, 'repeat-x');
+ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
+ctx.fillRect(0, 0, 200, 200);
+
+var imageData = ctx.getImageData(10, 10, 1, 1);
+imgdata = imageData.data;
+shouldBe("imgdata[0]", "0");
+shouldBe("imgdata[1]", "255");
+shouldBe("imgdata[2]", "0");
+
+imageData = ctx.getImageData(290, 60, 1, 1);
+imgdata = imageData.data;
+shouldBe("imgdata[0]", "255");
+shouldBe("imgdata[1]", "0");
+shouldBe("imgdata[2]", "0");
+
+imageData = ctx.getImageData(90, 60, 1, 1);
+imgdata = imageData.data;
+shouldBe("imgdata[0]", "0");
+shouldBe("imgdata[1]", "0");
+shouldBe("imgdata[2]", "0");
+}
Property changes on: trunk/LayoutTests/fast/canvas/script-tests/shadow-image.js
___________________________________________________________________

Added: svn:executable

Added: svn:eol-style

Added: trunk/LayoutTests/fast/canvas/shadow-image-expected.txt (0 => 148923)


--- trunk/LayoutTests/fast/canvas/shadow-image-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/shadow-image-expected.txt	2013-04-22 23:06:16 UTC (rev 148923)
@@ -0,0 +1,18 @@
+Test to verify the shadow of an image drawn on canvas
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS imgdata[0] is 0
+PASS imgdata[1] is 255
+PASS imgdata[2] is 0
+PASS imgdata[0] is 255
+PASS imgdata[1] is 0
+PASS imgdata[2] is 0
+PASS imgdata[0] is 0
+PASS imgdata[1] is 0
+PASS imgdata[2] is 0
+
Property changes on: trunk/LayoutTests/fast/canvas/shadow-image-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/fast/canvas/shadow-image.html (0 => 148923)


--- trunk/LayoutTests/fast/canvas/shadow-image.html	                        (rev 0)
+++ trunk/LayoutTests/fast/canvas/shadow-image.html	2013-04-22 23:06:16 UTC (rev 148923)
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<canvas id="myCanvas" width="400" height="400"></canvas>
+<script src=""
+<script src=""
+</body>
+</html>
Property changes on: trunk/LayoutTests/fast/canvas/shadow-image.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/ChangeLog (148922 => 148923)


--- trunk/Source/WebCore/ChangeLog	2013-04-22 22:56:19 UTC (rev 148922)
+++ trunk/Source/WebCore/ChangeLog	2013-04-22 23:06:16 UTC (rev 148923)
@@ -1,3 +1,25 @@
+2013-04-22  Rashmi Shyamasundar  <[email protected]>
+
+        [Cairo] Canvas-shadow behavior is not being as expected
+        https://bugs.webkit.org/show_bug.cgi?id=108897
+
+        Reviewed by Martin Robinson.
+
+        Use the pattern-extend-mode "CAIRO_EXTEND_NONE" instead of "CAIRO_EXTEND_PAD" in
+        PlatformContextCairo::drawSurfaceToContext().
+
+        In the function PlatformContextCairo::drawSurfaceToContext(), a pattern is being
+        created from the source surface and this pattern is drawn onto the destination
+        context. There is no gradient involved. Hence the extend mode for filling the
+        pattern should be "CAIRO_EXTEND_NONE". If we use the extend mode
+        "CAIRO_EXTEND_PAD" in PlatformContextCairo::drawSurfaceToContext(), the original
+        image area is also filled with the shadow color which is not the expected behavior.
+
+        Test: fast/canvas/canvas-image-shadow.html
+
+        * platform/graphics/cairo/PlatformContextCairo.cpp:
+        (WebCore::PlatformContextCairo::drawSurfaceToContext):
+
 2013-04-22  Benjamin Poulain  <[email protected]>
 
         Remove the memory instrumentation code

Modified: trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp (148922 => 148923)


--- trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp	2013-04-22 22:56:19 UTC (rev 148922)
+++ trunk/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp	2013-04-22 23:06:16 UTC (rev 148923)
@@ -191,7 +191,7 @@
         cairo_pattern_set_filter(pattern.get(), CAIRO_FILTER_BILINEAR);
         break;
     }
-    cairo_pattern_set_extend(pattern.get(), CAIRO_EXTEND_PAD);
+    cairo_pattern_set_extend(pattern.get(), CAIRO_EXTEND_NONE);
 
     // The pattern transformation properly scales the pattern for when the source rectangle is a
     // different size than the destination rectangle. We also account for any offset we introduced
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to