From 994ff4c84366d0efc408dd65ba48ea83a157a04a Mon Sep 17 00:00:00 2001 From: "mrobinson@webkit.org" Date: Mon, 22 Apr 2013 23:06:16 +0000 Subject: [PATCH 1/1] [Cairo] Canvas-shadow behavior is not being as expected https://bugs.webkit.org/show_bug.cgi?id=108897 Patch by Rashmi Shyamasundar 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 | 17 ++++++++ .../fast/canvas/script-tests/shadow-image.js | 48 ++++++++++++++++++++++ LayoutTests/fast/canvas/shadow-image-expected.txt | 18 ++++++++ LayoutTests/fast/canvas/shadow-image.html | 11 +++++ Source/WebCore/ChangeLog | 22 ++++++++++ .../graphics/cairo/PlatformContextCairo.cpp | 2 +- 6 files changed, 117 insertions(+), 1 deletion(-) create mode 100755 LayoutTests/fast/canvas/script-tests/shadow-image.js create mode 100644 LayoutTests/fast/canvas/shadow-image-expected.txt create mode 100644 LayoutTests/fast/canvas/shadow-image.html diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index dbee394..396a1ae 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,20 @@ +2013-04-22 Rashmi Shyamasundar + + [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 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 index 0000000..ce6f924 --- /dev/null +++ b/LayoutTests/fast/canvas/script-tests/shadow-image.js @@ -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 index 0000000..d41220b --- /dev/null +++ b/LayoutTests/fast/canvas/shadow-image-expected.txt @@ -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 index 0000000..c3b476c --- /dev/null +++ b/LayoutTests/fast/canvas/shadow-image.html @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index ce6073f..13080f1 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,25 @@ +2013-04-22 Rashmi Shyamasundar + + [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 Remove the memory instrumentation code diff --git a/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp b/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp index 147dc15..5d77419 100644 --- a/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp +++ b/Source/WebCore/platform/graphics/cairo/PlatformContextCairo.cpp @@ -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 -- 1.8.3.1