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-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: http://svn.webkit.org/repository/webkit/trunk@73889 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 362d5d17
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.
......
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
<!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>
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;
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.
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment