Title: [103118] trunk/Source/WebCore
Revision
103118
Author
[email protected]
Date
2011-12-16 15:29:12 -0800 (Fri, 16 Dec 2011)

Log Message

Canvas should respect backing store scale ratio when used as drawImage() source
https://bugs.webkit.org/show_bug.cgi?id=74758
<rdar://problem/10350194>

Reviewed by Simon Fraser.

Interpret the source rectangle passed into drawImage() when using a Canvas source in the source Canvas coordinate space,
instead of in the backing store coordinate space, without changing the behavior of drawImage(canvas, x, y).

No new tests.

* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::convertDeviceToLogical):
* html/HTMLCanvasElement.h:
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::drawImage):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (103117 => 103118)


--- trunk/Source/WebCore/ChangeLog	2011-12-16 23:26:31 UTC (rev 103117)
+++ trunk/Source/WebCore/ChangeLog	2011-12-16 23:29:12 UTC (rev 103118)
@@ -1,3 +1,22 @@
+2011-12-16  Tim Horton  <[email protected]>
+
+        Canvas should respect backing store scale ratio when used as drawImage() source
+        https://bugs.webkit.org/show_bug.cgi?id=74758
+        <rdar://problem/10350194>
+
+        Reviewed by Simon Fraser.
+
+        Interpret the source rectangle passed into drawImage() when using a Canvas source in the source Canvas coordinate space,
+        instead of in the backing store coordinate space, without changing the behavior of drawImage(canvas, x, y).
+
+        No new tests.
+
+        * html/HTMLCanvasElement.cpp:
+        (WebCore::HTMLCanvasElement::convertDeviceToLogical):
+        * html/HTMLCanvasElement.h:
+        * html/canvas/CanvasRenderingContext2D.cpp:
+        (WebCore::CanvasRenderingContext2D::drawImage):
+
 2011-12-16  Anders Carlsson  <[email protected]>
 
         Subpixel antialiasing not working in tiled mode

Modified: trunk/Source/WebCore/html/HTMLCanvasElement.cpp (103117 => 103118)


--- trunk/Source/WebCore/html/HTMLCanvasElement.cpp	2011-12-16 23:26:31 UTC (rev 103117)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.cpp	2011-12-16 23:29:12 UTC (rev 103118)
@@ -402,6 +402,13 @@
     return FloatSize(width, height);
 }
 
+FloatSize HTMLCanvasElement::convertDeviceToLogical(const FloatSize& deviceSize) const
+{
+    float width = ceilf(deviceSize.width() / m_deviceScaleFactor);
+    float height = ceilf(deviceSize.height() / m_deviceScaleFactor);
+    return FloatSize(width, height);
+}
+
 SecurityOrigin* HTMLCanvasElement::securityOrigin() const
 {
     return document()->securityOrigin();

Modified: trunk/Source/WebCore/html/HTMLCanvasElement.h (103117 => 103118)


--- trunk/Source/WebCore/html/HTMLCanvasElement.h	2011-12-16 23:26:31 UTC (rev 103117)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.h	2011-12-16 23:29:12 UTC (rev 103118)
@@ -115,6 +115,8 @@
     FloatRect convertLogicalToDevice(const FloatRect&) const;
     FloatSize convertLogicalToDevice(const FloatSize&) const;
 
+    FloatSize convertDeviceToLogical(const FloatSize&) const;
+
     SecurityOrigin* securityOrigin() const;
     void setOriginTainted() { m_originClean = false; }
     bool originClean() const { return m_originClean; }

Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (103117 => 103118)


--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2011-12-16 23:26:31 UTC (rev 103117)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp	2011-12-16 23:29:12 UTC (rev 103118)
@@ -1361,7 +1361,15 @@
         ec = TYPE_MISMATCH_ERR;
         return;
     }
-    drawImage(canvas, x, y, canvas->width(), canvas->height(), ec);
+
+    // In order to emulate drawing the result of toDataURL() into the canvas, we
+    // need to deflate the size of the source rectangle by the source canvas's
+    // backing store scale factor.
+    // See https://www.w3.org/Bugs/Public/show_bug.cgi?id=15041 for motivation.
+
+    FloatSize logicalSize = canvas->convertDeviceToLogical(canvas->size());
+
+    drawImage(canvas, 0, 0, logicalSize.width(), logicalSize.height(), x, y, canvas->width(), canvas->height(), ec);
 }
 
 void CanvasRenderingContext2D::drawImage(HTMLCanvasElement* canvas,
@@ -1430,18 +1438,21 @@
     sourceCanvas->makeRenderingResultsAvailable();
 #endif
 
+    // drawImageBuffer's srcRect is in buffer pixels (backing store pixels, in our case), dstRect is in canvas pixels.
+    FloatRect bufferSrcRect(sourceCanvas->convertLogicalToDevice(srcRect));
+
     if (rectContainsCanvas(dstRect)) {
-        c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, dstRect, srcRect, state().m_globalComposite);
+        c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, dstRect, bufferSrcRect, state().m_globalComposite);
         didDrawEntireCanvas();
     } else if (isFullCanvasCompositeMode(state().m_globalComposite)) {
-        fullCanvasCompositedDrawImage(buffer, ColorSpaceDeviceRGB, dstRect, srcRect, state().m_globalComposite);
+        fullCanvasCompositedDrawImage(buffer, ColorSpaceDeviceRGB, bufferSrcRect, srcRect, state().m_globalComposite);
         didDrawEntireCanvas();
     } else if (state().m_globalComposite == CompositeCopy) {
         clearCanvas();
-        c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, dstRect, srcRect, state().m_globalComposite);
+        c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, dstRect, bufferSrcRect, state().m_globalComposite);
         didDrawEntireCanvas();
     } else {
-        c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, dstRect, srcRect, state().m_globalComposite);
+        c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, dstRect, bufferSrcRect, state().m_globalComposite);
         didDraw(dstRect);
     }
 }
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to