- Revision
- 134099
- Author
- timo...@apple.com
- Date
- 2012-11-09 12:39:22 -0800 (Fri, 09 Nov 2012)
Log Message
Source/WebCore: Reset the canvas backing store pixel ratio when the buffer resizes.
The backing store was not being recreated using the current page pixel ratio
when a resize occurred.
https://bugs.webkit.org/show_bug.cgi?id=100608
Reviewed by Darin Adler.
Test: fast/canvas/canvas-resize-reset-pixelRatio.html
* html/HTMLCanvasElement.cpp:
(WebCore::HTMLCanvasElement::HTMLCanvasElement): Use targetDeviceScaleFactor.
(WebCore::HTMLCanvasElement::reset): Do a clear only if the pixel ratios also
match. Store the new pixel ratio in m_deviceScaleFactor.
(WebCore::HTMLCanvasElement::targetDeviceScaleFactor): Added.
* html/HTMLCanvasElement.h:
(WebCore::HTMLCanvasElement::setSize): Return early only if the sizes and
pixel ratios match.
LayoutTests: Test the canvas backing store pixel ratio when the buffer resizes.
https://bugs.webkit.org/show_bug.cgi?id=100608
Reviewed by Darin Adler.
* fast/canvas/canvas-resize-reset-pixelRatio-expected.txt: Added.
* fast/canvas/canvas-resize-reset-pixelRatio.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (134098 => 134099)
--- trunk/LayoutTests/ChangeLog 2012-11-09 20:30:08 UTC (rev 134098)
+++ trunk/LayoutTests/ChangeLog 2012-11-09 20:39:22 UTC (rev 134099)
@@ -1,3 +1,14 @@
+2012-10-28 Timothy Hatcher <timo...@apple.com>
+
+ Test the canvas backing store pixel ratio when the buffer resizes.
+
+ https://bugs.webkit.org/show_bug.cgi?id=100608
+
+ Reviewed by Darin Adler.
+
+ * fast/canvas/canvas-resize-reset-pixelRatio-expected.txt: Added.
+ * fast/canvas/canvas-resize-reset-pixelRatio.html: Added.
+
2012-11-08 Ryosuke Niwa <rn...@webkit.org>
RemoveFormat command doesn't remove background color
Added: trunk/LayoutTests/fast/canvas/canvas-resize-reset-pixelRatio-expected.txt (0 => 134099)
--- trunk/LayoutTests/fast/canvas/canvas-resize-reset-pixelRatio-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-resize-reset-pixelRatio-expected.txt 2012-11-09 20:39:22 UTC (rev 134099)
@@ -0,0 +1,6 @@
+Testing webkitBackingStorePixelRatio after resize
+PASS: webkitBackingStorePixelRatio is 1.
+PASS: webkitBackingStorePixelRatio is 2.
+PASS: webkitBackingStorePixelRatio is 1.
+PASS: webkitBackingStorePixelRatio is 2.
+
Added: trunk/LayoutTests/fast/canvas/canvas-resize-reset-pixelRatio.html (0 => 134099)
--- trunk/LayoutTests/fast/canvas/canvas-resize-reset-pixelRatio.html (rev 0)
+++ trunk/LayoutTests/fast/canvas/canvas-resize-reset-pixelRatio.html 2012-11-09 20:39:22 UTC (rev 134099)
@@ -0,0 +1,56 @@
+<pre id="console"></pre>
+<script>
+ function log(message)
+ {
+ document.getElementById("console").appendChild(document.createTextNode(message + "\n"));
+ }
+
+ if (!window.testRunner)
+ log("This test requires WebKitTestRunner or DumpRenderTree.");
+
+ testRunner.dumpAsText();
+ testRunner.waitUntilDone();
+
+ var canvas = document.createElement("canvas");
+ canvas.width = 8;
+ canvas.height = 8;
+
+ var context = canvas.getContext("2d");
+ var cssContext = document.getCSSCanvasContext("2d", "test", 8, 8);
+
+ if (context.webkitBackingStorePixelRatio !== 1)
+ log("FAIL: expected webkitBackingStorePixelRatio of 1, was " + context.webkitBackingStorePixelRatio + ".");
+
+ testRunner.setBackingScaleFactor(2, function() {
+ var testCanvas = document.createElement("canvas");
+ var testContext = testCanvas.getContext("2d");
+
+ if (testContext.webkitBackingStorePixelRatio === 2) {
+ log("Testing webkitBackingStorePixelRatio after resize");
+
+ function assertPixelRatio(context, expected)
+ {
+ if (context.webkitBackingStorePixelRatio === expected)
+ log("PASS: webkitBackingStorePixelRatio is " + expected + ".");
+ else
+ log("FAIL: webkitBackingStorePixelRatio is " + context.webkitBackingStorePixelRatio + ", expected " + expected + ".");
+ }
+
+ assertPixelRatio(context, 1);
+
+ canvas.width = 8;
+ canvas.height = 8;
+
+ assertPixelRatio(context, 2);
+
+ assertPixelRatio(cssContext, 1);
+
+ cssContext = document.getCSSCanvasContext("2d", "test", 8, 8);
+
+ assertPixelRatio(cssContext, 2);
+ } else
+ log("High-DPI canvas is not enabled.");
+
+ testRunner.notifyDone();
+ });
+</script>
Modified: trunk/Source/WebCore/ChangeLog (134098 => 134099)
--- trunk/Source/WebCore/ChangeLog 2012-11-09 20:30:08 UTC (rev 134098)
+++ trunk/Source/WebCore/ChangeLog 2012-11-09 20:39:22 UTC (rev 134099)
@@ -1,3 +1,25 @@
+2012-10-28 Timothy Hatcher <timo...@apple.com>
+
+ Reset the canvas backing store pixel ratio when the buffer resizes.
+
+ The backing store was not being recreated using the current page pixel ratio
+ when a resize occurred.
+
+ https://bugs.webkit.org/show_bug.cgi?id=100608
+
+ Reviewed by Darin Adler.
+
+ Test: fast/canvas/canvas-resize-reset-pixelRatio.html
+
+ * html/HTMLCanvasElement.cpp:
+ (WebCore::HTMLCanvasElement::HTMLCanvasElement): Use targetDeviceScaleFactor.
+ (WebCore::HTMLCanvasElement::reset): Do a clear only if the pixel ratios also
+ match. Store the new pixel ratio in m_deviceScaleFactor.
+ (WebCore::HTMLCanvasElement::targetDeviceScaleFactor): Added.
+ * html/HTMLCanvasElement.h:
+ (WebCore::HTMLCanvasElement::setSize): Return early only if the sizes and
+ pixel ratios match.
+
2012-11-08 Ryosuke Niwa <rn...@webkit.org>
RemoveFormat command doesn't remove background color
Modified: trunk/Source/WebCore/html/HTMLCanvasElement.cpp (134098 => 134099)
--- trunk/Source/WebCore/html/HTMLCanvasElement.cpp 2012-11-09 20:30:08 UTC (rev 134098)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.cpp 2012-11-09 20:39:22 UTC (rev 134099)
@@ -84,13 +84,7 @@
, m_size(DefaultWidth, DefaultHeight)
, m_rendererIsCanvas(false)
, m_ignoreReset(false)
-#if ENABLE(HIGH_DPI_CANVAS)
- // NOTE: High-DPI canvas requires the platform-specific ImageBuffer implementation to respect
- // the resolutionScale parameter.
- , m_deviceScaleFactor(document->frame() ? document->frame()->page()->deviceScaleFactor() : 1)
-#else
- , m_deviceScaleFactor(1)
-#endif
+ , m_deviceScaleFactor(targetDeviceScaleFactor())
, m_originClean(true)
, m_hasCreatedImageBuffer(false)
, m_didClearImageBuffer(false)
@@ -247,9 +241,11 @@
bool ok;
bool hadImageBuffer = hasCreatedImageBuffer();
+
int w = getAttribute(widthAttr).toInt(&ok);
if (!ok || w < 0)
w = DefaultWidth;
+
int h = getAttribute(heightAttr).toInt(&ok);
if (!ok || h < 0)
h = DefaultHeight;
@@ -266,15 +262,21 @@
}
IntSize oldSize = size();
+ IntSize newSize(w, h);
+ float newDeviceScaleFactor = targetDeviceScaleFactor();
+
// If the size of an existing buffer matches, we can just clear it instead of reallocating.
// This optimization is only done for 2D canvases for now.
- if (m_hasCreatedImageBuffer && oldSize == IntSize(w, h) && m_context && m_context->is2d()) {
+ if (m_hasCreatedImageBuffer && oldSize == newSize && m_deviceScaleFactor == newDeviceScaleFactor && m_context && m_context->is2d()) {
if (!m_didClearImageBuffer)
clearImageBuffer();
return;
}
- setSurfaceSize(IntSize(w, h));
+ m_deviceScaleFactor = newDeviceScaleFactor;
+
+ setSurfaceSize(newSize);
+
#if ENABLE(WEBGL)
if (m_context && m_context->is3d() && oldSize != size())
static_cast<WebGLRenderingContext*>(m_context.get())->reshape(width(), height());
@@ -299,6 +301,15 @@
(*it)->canvasResized(this);
}
+float HTMLCanvasElement::targetDeviceScaleFactor() const
+{
+#if ENABLE(HIGH_DPI_CANVAS)
+ return document()->frame() ? document()->frame()->page()->deviceScaleFactor() : 1;
+#else
+ return 1;
+#endif
+}
+
bool HTMLCanvasElement::paintsIntoCanvasBuffer() const
{
ASSERT(m_context);
Modified: trunk/Source/WebCore/html/HTMLCanvasElement.h (134098 => 134099)
--- trunk/Source/WebCore/html/HTMLCanvasElement.h 2012-11-09 20:30:08 UTC (rev 134098)
+++ trunk/Source/WebCore/html/HTMLCanvasElement.h 2012-11-09 20:39:22 UTC (rev 134099)
@@ -82,7 +82,7 @@
void setSize(const IntSize& newSize)
{
- if (newSize == size())
+ if (newSize == size() && targetDeviceScaleFactor() == m_deviceScaleFactor)
return;
m_ignoreReset = true;
setWidth(newSize.width());
@@ -150,6 +150,8 @@
void reset();
+ float targetDeviceScaleFactor() const;
+
void createImageBuffer() const;
void clearImageBuffer() const;