[Cairo] Canvas-shadow behavior is not being as expected
authormrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Apr 2013 23:06:16 +0000 (23:06 +0000)
committermrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 22 Apr 2013 23:06:16 +0000 (23:06 +0000)
https://bugs.webkit.org/show_bug.cgi?id=108897

Patch by Rashmi Shyamasundar <rashmi.s2@samsung.com> 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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@148923 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/canvas/script-tests/shadow-image.js [new file with mode: 0755]
LayoutTests/fast/canvas/shadow-image-expected.txt [new file with mode: 0644]
LayoutTests/fast/canvas/shadow-image.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp

index dbee394..396a1ae 100644 (file)
@@ -1,3 +1,20 @@
+2013-04-22  Rashmi Shyamasundar  <rashmi.s2@samsung.com>
+
+        [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  <benjamin@webkit.org>
 
         Remove the memory instrumentation code
diff --git a/LayoutTests/fast/canvas/script-tests/shadow-image.js b/LayoutTests/fast/canvas/script-tests/shadow-image.js
new file mode 100755 (executable)
index 0000000..ce6f924
--- /dev/null
@@ -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 = aCanvas.toDataURL();
+
+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");
+}
diff --git a/LayoutTests/fast/canvas/shadow-image-expected.txt b/LayoutTests/fast/canvas/shadow-image-expected.txt
new file mode 100644 (file)
index 0000000..d41220b
--- /dev/null
@@ -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
+
diff --git a/LayoutTests/fast/canvas/shadow-image.html b/LayoutTests/fast/canvas/shadow-image.html
new file mode 100644 (file)
index 0000000..c3b476c
--- /dev/null
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<canvas id="myCanvas" width="400" height="400"></canvas>
+<script src="script-tests/shadow-image.js"></script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
index ce6073f..13080f1 100644 (file)
@@ -1,3 +1,25 @@
+2013-04-22  Rashmi Shyamasundar  <rashmi.s2@samsung.com>
+
+        [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  <benjamin@webkit.org>
 
         Remove the memory instrumentation code
index 147dc15..5d77419 100644 (file)
@@ -191,7 +191,7 @@ void PlatformContextCairo::drawSurfaceToContext(cairo_surface_t* surface, const
         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