WebCore:
authorhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Apr 2008 19:14:20 +0000 (19:14 +0000)
committerhyatt@apple.com <hyatt@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 28 Apr 2008 19:14:20 +0000 (19:14 +0000)
2008-04-28  David Hyatt  <hyatt@apple.com>

        https://bugs.webkit.org/show_bug.cgi?id=18780

        Canvas can't draw itself into its own buffer.  Make sure the dirtying call comes after the image()
        has been accessed.  Technically willDraw should be renamed to didDraw and all calls should be moved
        to after draws have occurred (since if the draw op itself wants to reference the image it shouldn't get
        a dirty copy either), but I'll take that up with olliej when he wakes up. :)

        Reviewed by Dan Bernstein

        Added fast/canvas/canvasDrawsIntoSelf.html

        * html/CanvasRenderingContext2D.cpp:
        (WebCore::CanvasRenderingContext2D::drawImage):

LayoutTests:

2008-04-28  David Hyatt  <hyatt@apple.com>

        Add layout test for canvas self-drawing bug.

        Reviewed by Dan Bernstein

        * fast/canvas/canvasDrawingIntoSelf.html: Added.
        * platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.checksum: Added.
        * platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.png: Added.
        * platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.txt: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/canvas/canvasDrawingIntoSelf.html [new file with mode: 0644]
LayoutTests/platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.checksum [new file with mode: 0644]
LayoutTests/platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.txt [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/CanvasRenderingContext2D.cpp

index 5be9ba5..1c435f4 100644 (file)
@@ -1,5 +1,16 @@
 2008-04-28  David Hyatt  <hyatt@apple.com>
 
+        Add layout test for canvas self-drawing bug.
+
+        Reviewed by Dan Bernstein
+
+        * fast/canvas/canvasDrawingIntoSelf.html: Added.
+        * platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.checksum: Added.
+        * platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.png: Added.
+        * platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.txt: Added.
+
+2008-04-28  David Hyatt  <hyatt@apple.com>
+
         Add layout test for canvas.
 
         Reviewed by Tim Hatcher
diff --git a/LayoutTests/fast/canvas/canvasDrawingIntoSelf.html b/LayoutTests/fast/canvas/canvasDrawingIntoSelf.html
new file mode 100644 (file)
index 0000000..23515a7
--- /dev/null
@@ -0,0 +1,11 @@
+If this renders correctly you should see one big friendly green square.
+<canvas id="canvas" width="200" height="200" ></canvas>
+<script>
+var canvas = document.getElementById("canvas");
+var context = canvas.getContext("2d");
+context.fillStyle = 'red';
+context.fillRect(0,0,200,200);
+context.fillStyle = 'green';
+context.fillRect(50,50,100,100);
+context.drawImage(canvas, 50, 50, 100, 100, 0, 0, 200, 200);
+</script>
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.checksum b/LayoutTests/platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.checksum
new file mode 100644 (file)
index 0000000..c6e1bcb
--- /dev/null
@@ -0,0 +1 @@
+640ad41fe81631f8afaf26bf1eaa080e
\ No newline at end of file
diff --git a/LayoutTests/platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.png b/LayoutTests/platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.png
new file mode 100644 (file)
index 0000000..6a810f8
Binary files /dev/null and b/LayoutTests/platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.png differ
diff --git a/LayoutTests/platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.txt b/LayoutTests/platform/mac/fast/canvas/canvasDrawingIntoSelf-expected.txt
new file mode 100644 (file)
index 0000000..4ced19d
--- /dev/null
@@ -0,0 +1,9 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderText {#text} at (0,186) size 439x18
+        text run at (0,186) width 439: "If this renders correctly you should see one big friendly green square. "
+      RenderHTMLCanvas {CANVAS} at (439,0) size 200x200
+      RenderText {#text} at (0,0) size 0x0
index 4636a36..fdc4079 100644 (file)
@@ -1,3 +1,19 @@
+2008-04-28  David Hyatt  <hyatt@apple.com>
+
+        https://bugs.webkit.org/show_bug.cgi?id=18780
+
+        Canvas can't draw itself into its own buffer.  Make sure the dirtying call comes after the image()
+        has been accessed.  Technically willDraw should be renamed to didDraw and all calls should be moved
+        to after draws have occurred (since if the draw op itself wants to reference the image it shouldn't get
+        a dirty copy either), but I'll take that up with olliej when he wakes up. :)
+
+        Reviewed by Dan Bernstein
+
+        Added fast/canvas/canvasDrawsIntoSelf.html
+
+        * html/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::drawImage):
+
 2008-04-28  Alexey Proskuryakov  <ap@webkit.org>
 
         Reviewed by Geoff Garen.
index 62f5a0c..9ba27e7 100644 (file)
@@ -1022,8 +1022,9 @@ void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas, const FloatR
     if (!canvas->originClean())
         m_canvas->setOriginTainted();
 
-    willDraw(destRect);
     c->drawImage(buffer->image(), destRect, sourceRect);
+    willDraw(destRect); // This call comes after drawImage, since the buffer we draw into may be our own, and we need to make sure it is dirty.
+                        // FIXME: Arguably willDraw should become didDraw and occur after drawing calls and not before them to avoid problems like this.
 }
 
 // FIXME: Why isn't this just another overload of drawImage? Why have a different name?