Modified: branches/safari-534.54-branch/Source/WebCore/ChangeLog (105180 => 105181)
--- branches/safari-534.54-branch/Source/WebCore/ChangeLog 2012-01-17 19:37:56 UTC (rev 105180)
+++ branches/safari-534.54-branch/Source/WebCore/ChangeLog 2012-01-17 19:59:27 UTC (rev 105181)
@@ -1,5 +1,28 @@
2012-01-17 Mark Rowe <[email protected]>
+ Merge r103118.
+
+ 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):
+
+2012-01-17 Mark Rowe <[email protected]>
+
Merge r104669.
2012-01-10 Jer Noble <[email protected]>
Modified: branches/safari-534.54-branch/Source/WebCore/html/HTMLCanvasElement.cpp (105180 => 105181)
--- branches/safari-534.54-branch/Source/WebCore/html/HTMLCanvasElement.cpp 2012-01-17 19:37:56 UTC (rev 105180)
+++ branches/safari-534.54-branch/Source/WebCore/html/HTMLCanvasElement.cpp 2012-01-17 19:59:27 UTC (rev 105181)
@@ -395,6 +395,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);
+}
+
const SecurityOrigin& HTMLCanvasElement::securityOrigin() const
{
return *document()->securityOrigin();
Modified: branches/safari-534.54-branch/Source/WebCore/html/HTMLCanvasElement.h (105180 => 105181)
--- branches/safari-534.54-branch/Source/WebCore/html/HTMLCanvasElement.h 2012-01-17 19:37:56 UTC (rev 105180)
+++ branches/safari-534.54-branch/Source/WebCore/html/HTMLCanvasElement.h 2012-01-17 19:59:27 UTC (rev 105181)
@@ -114,6 +114,8 @@
FloatRect convertLogicalToDevice(const FloatRect&) const;
FloatSize convertLogicalToDevice(const FloatSize&) const;
+ FloatSize convertDeviceToLogical(const FloatSize&) const;
+
const SecurityOrigin& securityOrigin() const;
void setOriginTainted() { m_originClean = false; }
bool originClean() const { return m_originClean; }
Modified: branches/safari-534.54-branch/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (105180 => 105181)
--- branches/safari-534.54-branch/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2012-01-17 19:37:56 UTC (rev 105180)
+++ branches/safari-534.54-branch/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp 2012-01-17 19:59:27 UTC (rev 105181)
@@ -1326,7 +1326,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,
@@ -1395,7 +1403,10 @@
sourceCanvas->makeRenderingResultsAvailable();
#endif
- c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, dstRect, srcRect, state().m_globalComposite);
+ // drawImageBuffer's srcRect is in buffer pixels (backing store pixels, in our case), dstRect is in canvas pixels.
+ FloatRect bufferSrcRect(sourceCanvas->convertLogicalToDevice(srcRect));
+
+ c->drawImageBuffer(buffer, ColorSpaceDeviceRGB, dstRect, bufferSrcRect, state().m_globalComposite);
didDraw(dstRect);
}