2010-12-13 Helder Correia <helder@sencha.com>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Dec 2010 08:56:31 +0000 (08:56 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 13 Dec 2010 08:56:31 +0000 (08:56 +0000)
        Reviewed by Eric Seidel.

        [Qt] StillImage::draw() should use ContextShadow
        https://bugs.webkit.org/show_bug.cgi?id=50849

        The branch that checks for a shadow requirement in StillImage::draw()
        is executed when drawing a canvas onto a canvas with
        ctx1.drawImage(canvas2, x, y). The current implementation supports
        solid shadows only. And if transformations are present, the offset gets
        transformed as well. Thus, ContextShadow must be used instead in order
        to support blur and correct offset transformations.

        * fast/canvas/canvas-draw-canvas-on-canvas-shadow-expected.txt: Added.
        * fast/canvas/canvas-draw-canvas-on-canvas-shadow.html: Added.
        * fast/canvas/script-tests/canvas-draw-canvas-on-canvas-shadow.js: Added.
2010-12-13  Helder Correia  <helder@sencha.com>

        Reviewed by Eric Seidel.

        [Qt] StillImage::draw() should use ContextShadow
        https://bugs.webkit.org/show_bug.cgi?id=50849

        The branch that checks for a shadow requirement in StillImage::draw()
        is executed when drawing a canvas onto a canvas with
        ctx1.drawImage(canvas2, x, y). The current implementation supports
        solid shadows only. And if transformations are present, the offset gets
        transformed as well. Thus, ContextShadow must be used instead in order
        to support blur and correct offset transformations.

        Test: fast/canvas/canvas-draw-canvas-on-canvas-shadow.html

        * platform/graphics/qt/StillImageQt.cpp:
        (WebCore::StillImage::draw):

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

LayoutTests/ChangeLog
LayoutTests/fast/canvas/canvas-draw-canvas-on-canvas-shadow-expected.txt [new file with mode: 0644]
LayoutTests/fast/canvas/canvas-draw-canvas-on-canvas-shadow.html [new file with mode: 0644]
LayoutTests/fast/canvas/script-tests/canvas-draw-canvas-on-canvas-shadow.js [new file with mode: 0644]
WebCore/ChangeLog
WebCore/platform/graphics/qt/StillImageQt.cpp

index b098c84..475c27e 100644 (file)
@@ -1,3 +1,21 @@
+2010-12-13  Helder Correia  <helder@sencha.com>
+
+        Reviewed by Eric Seidel.
+
+        [Qt] StillImage::draw() should use ContextShadow
+        https://bugs.webkit.org/show_bug.cgi?id=50849
+
+        The branch that checks for a shadow requirement in StillImage::draw()
+        is executed when drawing a canvas onto a canvas with
+        ctx1.drawImage(canvas2, x, y). The current implementation supports
+        solid shadows only. And if transformations are present, the offset gets
+        transformed as well. Thus, ContextShadow must be used instead in order
+        to support blur and correct offset transformations.
+
+        * fast/canvas/canvas-draw-canvas-on-canvas-shadow-expected.txt: Added.
+        * fast/canvas/canvas-draw-canvas-on-canvas-shadow.html: Added.
+        * fast/canvas/script-tests/canvas-draw-canvas-on-canvas-shadow.js: Added.
+
 2010-10-28  MORITA Hajime  <morrita@google.com>
 
         Reviewed by Ojan Vafai.
diff --git a/LayoutTests/fast/canvas/canvas-draw-canvas-on-canvas-shadow-expected.txt b/LayoutTests/fast/canvas/canvas-draw-canvas-on-canvas-shadow-expected.txt
new file mode 100644 (file)
index 0000000..5b3196b
--- /dev/null
@@ -0,0 +1,57 @@
+Ensure correct behavior when drawing a canvas on a canvas with shadows. A blue and red checkered pattern should be displayed.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS d[0] is 255
+PASS d[1] is 0
+PASS d[2] is 0
+PASS d[3] is 255
+PASS d[0] is 255
+PASS d[1] is 0
+PASS d[2] is 0
+PASS d[3] is 255
+PASS d[0] is 255
+PASS d[1] is 0
+PASS d[2] is 0
+PASS d[3] is 255
+PASS d[0] is 255
+PASS d[1] is 0
+PASS d[2] is 0
+PASS d[3] is around 127
+PASS d[0] is 255
+PASS d[1] is 0
+PASS d[2] is 0
+PASS d[3] is around 127
+PASS d[0] is 255
+PASS d[1] is 0
+PASS d[2] is 0
+PASS d[3] is around 127
+PASS d[0] is 255
+PASS d[1] is 0
+PASS d[2] is 0
+PASS d[3] is around 100
+PASS d[0] is 255
+PASS d[1] is 0
+PASS d[2] is 0
+PASS d[3] is around 100
+PASS d[0] is 255
+PASS d[1] is 0
+PASS d[2] is 0
+PASS d[3] is around 100
+PASS d[0] is 255
+PASS d[1] is 0
+PASS d[2] is 0
+PASS d[3] is around 50
+PASS d[0] is 255
+PASS d[1] is 0
+PASS d[2] is 0
+PASS d[3] is around 50
+PASS d[0] is 255
+PASS d[1] is 0
+PASS d[2] is 0
+PASS d[3] is around 50
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/canvas/canvas-draw-canvas-on-canvas-shadow.html b/LayoutTests/fast/canvas/canvas-draw-canvas-on-canvas-shadow.html
new file mode 100644 (file)
index 0000000..ae71a6b
--- /dev/null
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script src="script-tests/canvas-draw-canvas-on-canvas-shadow.js"></script>
+<script src="../js/resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/canvas/script-tests/canvas-draw-canvas-on-canvas-shadow.js b/LayoutTests/fast/canvas/script-tests/canvas-draw-canvas-on-canvas-shadow.js
new file mode 100644 (file)
index 0000000..83ab990
--- /dev/null
@@ -0,0 +1,135 @@
+description("Ensure correct behavior when drawing a canvas on a canvas with shadows. A blue and red checkered pattern should be displayed.");
+
+function print(message, color)
+{
+    var paragraph = document.createElement("div");
+    paragraph.appendChild(document.createTextNode(message));
+    paragraph.style.fontFamily = "monospace";
+    if (color)
+        paragraph.style.color = color;
+    document.getElementById("console").appendChild(paragraph);
+}
+
+function shouldBeAround(a, b)
+{
+    var evalA;
+    try {
+        evalA = eval(a);
+    } catch(e) {
+        evalA = e;
+    }
+
+    if (Math.abs(evalA - b) < 15)
+        print("PASS " + a + " is around " + b , "green")
+    else
+        print("FAIL " + a + " is not around " + b + " (actual: " + evalA + ")", "red");
+}
+
+var canvas = document.createElement('canvas');
+document.body.appendChild(canvas);
+canvas.setAttribute('width', '600');
+canvas.setAttribute('height', '600');
+var ctx = canvas.getContext('2d');
+ctx.shadowOffsetX = 100;
+ctx.shadowOffsetY = 100;
+
+var aCanvas = document.createElement('canvas');
+aCanvas.width = 300;
+aCanvas.height = 300;
+
+var aCtx = aCanvas.getContext('2d');
+aCtx.fillStyle = 'rgba(0, 0, 255, 1.0)';
+aCtx.fillRect(100, 100, 100, 100);
+
+ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
+ctx.drawImage(aCanvas, 0, 0);
+
+ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
+ctx.drawImage(aCanvas, 0, 200);
+
+ctx.shadowBlur = 5;
+ctx.shadowColor = 'rgba(255, 0, 0, 1.0)';
+ctx.drawImage(aCanvas, 200, 0);
+
+ctx.shadowColor = 'rgba(255, 0, 0, 0.5)';
+ctx.drawImage(aCanvas, 200, 200);
+
+var d; // imageData.data
+
+// Verify solid shadow.
+d = ctx.getImageData(200, 205, 1, 1).data;
+shouldBe('d[0]', '255');
+shouldBe('d[1]', '0');
+shouldBe('d[2]', '0');
+shouldBe('d[3]', '255');
+
+d = ctx.getImageData(299, 295, 1, 1).data;
+shouldBe('d[0]', '255');
+shouldBe('d[1]', '0');
+shouldBe('d[2]', '0');
+shouldBe('d[3]', '255');
+
+d = ctx.getImageData(200, 299, 1, 1).data;
+shouldBe('d[0]', '255');
+shouldBe('d[1]', '0');
+shouldBe('d[2]', '0');
+shouldBe('d[3]', '255');
+
+// Verify solid alpha shadow.
+d = ctx.getImageData(200, 405, 1, 1).data;
+shouldBe('d[0]', '255');
+shouldBe('d[1]', '0');
+shouldBe('d[2]', '0');
+shouldBeAround('d[3]', '127');
+
+d = ctx.getImageData(299, 405, 1, 1).data;
+shouldBe('d[0]', '255');
+shouldBe('d[1]', '0');
+shouldBe('d[2]', '0');
+shouldBeAround('d[3]', '127');
+
+d = ctx.getImageData(205, 499, 1, 1).data;
+shouldBe('d[0]', '255');
+shouldBe('d[1]', '0');
+shouldBe('d[2]', '0');
+shouldBeAround('d[3]', '127');
+
+// Verify blurry shadow.
+d = ctx.getImageData(500, 211, 1, 1).data;
+shouldBe('d[0]', '255');
+shouldBe('d[1]', '0');
+shouldBe('d[2]', '0');
+shouldBeAround('d[3]', '100');
+
+d = ctx.getImageData(399, 205, 1, 1).data;
+shouldBe('d[0]', '255');
+shouldBe('d[1]', '0');
+shouldBe('d[2]', '0');
+shouldBeAround('d[3]', '100');
+
+d = ctx.getImageData(450, 300, 1, 1).data;
+shouldBe('d[0]', '255');
+shouldBe('d[1]', '0');
+shouldBe('d[2]', '0');
+shouldBeAround('d[3]', '100');
+
+// Verify blurry alpha shadow.
+d = ctx.getImageData(500, 411, 1, 1).data;
+shouldBe('d[0]', '255');
+shouldBe('d[1]', '0');
+shouldBe('d[2]', '0');
+shouldBeAround('d[3]', '50');
+
+d = ctx.getImageData(399, 405, 1, 1).data;
+shouldBe('d[0]', '255');
+shouldBe('d[1]', '0');
+shouldBe('d[2]', '0');
+shouldBeAround('d[3]', '50');
+
+d = ctx.getImageData(450, 500, 1, 1).data;
+shouldBe('d[0]', '255');
+shouldBe('d[1]', '0');
+shouldBe('d[2]', '0');
+shouldBeAround('d[3]', '50');
+
+var successfullyParsed = true;
index c115ead..0fc895d 100644 (file)
@@ -1,3 +1,22 @@
+2010-12-13  Helder Correia  <helder@sencha.com>
+
+        Reviewed by Eric Seidel.
+
+        [Qt] StillImage::draw() should use ContextShadow
+        https://bugs.webkit.org/show_bug.cgi?id=50849
+
+        The branch that checks for a shadow requirement in StillImage::draw()
+        is executed when drawing a canvas onto a canvas with
+        ctx1.drawImage(canvas2, x, y). The current implementation supports
+        solid shadows only. And if transformations are present, the offset gets
+        transformed as well. Thus, ContextShadow must be used instead in order
+        to support blur and correct offset transformations.
+
+        Test: fast/canvas/canvas-draw-canvas-on-canvas-shadow.html
+
+        * platform/graphics/qt/StillImageQt.cpp:
+        (WebCore::StillImage::draw):
+
 2010-12-12  Jon Honeycutt  <jhoneycutt@apple.com>
 
         Unreviewed build fix.
index 3038356..f1e5dcd 100644 (file)
@@ -28,6 +28,7 @@
 #include "config.h"
 #include "StillImageQt.h"
 
+#include "ContextShadow.h"
 #include "GraphicsContext.h"
 #include "IntSize.h"
 
@@ -67,7 +68,6 @@ void StillImage::draw(GraphicsContext* ctxt, const FloatRect& dst,
     if (m_pixmap->isNull())
         return;
 
-
     FloatRect normalizedSrc = src.normalized();
     FloatRect normalizedDst = dst.normalized();
 
@@ -76,21 +76,14 @@ void StillImage::draw(GraphicsContext* ctxt, const FloatRect& dst,
 
     ctxt->setCompositeOperation(op);
 
-    FloatSize shadowOffset;
-    float shadowBlur;
-    Color shadowColor;
-    if (ctxt->getShadow(shadowOffset, shadowBlur, shadowColor)) {
-        FloatRect shadowImageRect(normalizedDst);
-        shadowImageRect.move(shadowOffset.width(), shadowOffset.height());
-
-        QImage shadowImage(QSize(static_cast<int>(normalizedSrc.width()), static_cast<int>(normalizedSrc.height())), QImage::Format_ARGB32_Premultiplied);
-        QPainter p(&shadowImage);
-        p.setCompositionMode(QPainter::CompositionMode_Source);
-        p.fillRect(shadowImage.rect(), shadowColor);
-        p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
-        p.drawPixmap(QRect(0, 0, normalizedDst.width(), normalizedDst.height()), *m_pixmap, normalizedSrc);
-        p.end();
-        painter->drawImage(shadowImageRect, shadowImage, normalizedSrc);
+    ContextShadow* shadow = ctxt->contextShadow();
+    if (shadow->m_type != ContextShadow::NoShadow) {
+        QPainter* shadowPainter = shadow->beginShadowLayer(painter, normalizedDst);
+        if (shadowPainter) {
+            shadowPainter->setOpacity(static_cast<qreal>(shadow->m_color.alpha()) / 255);
+            shadowPainter->drawPixmap(normalizedDst, *m_pixmap, normalizedSrc);
+            shadow->endShadowLayer(painter);
+        }
     }
 
     painter->drawPixmap(normalizedDst, *m_pixmap, normalizedSrc);