REGRESSION(99539): SVG <img> disregards page scale and device scale
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 May 2012 20:25:57 +0000 (20:25 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 May 2012 20:25:57 +0000 (20:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77237
<rdar://problem/10767413>

Reviewed by Simon Fraser.

Rename SVGImageCache::SizeAndZoom to SVGImageCache::SizeAndScales, as it carries more than just zoom now.

Pass the product of the device and page scales through everything that takes a SVGImageCache::SizeAndScales,
using it to inflate the size of the buffer created in lookupOrCreateBitmapImageForRenderer,
and to inflate the destination rectangle passed to SVGImage::draw, which will cause a transformation
on the context being drawn into.

Invalidate the SVGImageCache entry on device/page scale changes in addition to zoom changes.

This patch does not cause SVGImageCache to take into account scale caused by CSS transforms; that is tracked
separately by https://bugs.webkit.org/show_bug.cgi?id=85335.

Tests: svg/as-image/image-respects-deviceScaleFactor.html
       svg/as-image/image-respects-pageScaleFactor.html

* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::setContainerSizeForRenderer):
(WebCore::CachedImage::imageSizeForRenderer):
* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::drawSVGToImageBuffer):
* svg/graphics/SVGImage.h:
* svg/graphics/SVGImageCache.cpp:
(WebCore::SVGImageCache::~SVGImageCache):
(WebCore::SVGImageCache::removeRendererFromCache):
(WebCore::SVGImageCache::setRequestedSizeAndScales):
(WebCore::SVGImageCache::requestedSizeAndScales):
(WebCore::SVGImageCache::redraw):
(WebCore::SVGImageCache::lookupOrCreateBitmapImageForRenderer):
* svg/graphics/SVGImageCache.h:
(WebCore::SVGImageCache::SizeAndScales::SizeAndScales):
(SizeAndScales):
(SVGImageCache):
(WebCore::SVGImageCache::ImageData::ImageData):
(ImageData):

Add tests ensuring that SVG used via <img> respects deviceScaleFactor and pageScaleFactor.

* platform/chromium-linux/svg/as-image/image-respects-pageScaleFactor-expected.txt: Added.
* platform/chromium-linux/svg/as-image/image-respects-pageScaleFactor-expected.png: Added.
* platform/chromium/test_expectations.txt:
* platform/qt/Skipped:
* platform/mac/svg/as-image/image-respects-deviceScaleFactor-expected.png: Added.
* platform/mac/svg/as-image/image-respects-deviceScaleFactor-expected.txt: Added.
* platform/mac/svg/as-image/image-respects-pageScaleFactor-expected.png: Added.
* platform/mac/svg/as-image/image-respects-pageScaleFactor-expected.txt: Added.
* platform/efl/Skipped:
* svg/as-image/image-respects-deviceScaleFactor.html: Added.
* svg/as-image/image-respects-pageScaleFactor.html: Added.

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

18 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/chromium-linux/svg/as-image/image-respects-pageScaleFactor-expected.png [new file with mode: 0644]
LayoutTests/platform/chromium-linux/svg/as-image/image-respects-pageScaleFactor-expected.txt [new file with mode: 0644]
LayoutTests/platform/chromium/test_expectations.txt
LayoutTests/platform/efl/Skipped
LayoutTests/platform/mac/svg/as-image/image-respects-deviceScaleFactor-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/svg/as-image/image-respects-deviceScaleFactor-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac/svg/as-image/image-respects-pageScaleFactor-expected.png [new file with mode: 0644]
LayoutTests/platform/mac/svg/as-image/image-respects-pageScaleFactor-expected.txt [new file with mode: 0644]
LayoutTests/platform/qt/Skipped
LayoutTests/svg/as-image/image-respects-deviceScaleFactor.html [new file with mode: 0644]
LayoutTests/svg/as-image/image-respects-pageScaleFactor.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/loader/cache/CachedImage.cpp
Source/WebCore/svg/graphics/SVGImage.cpp
Source/WebCore/svg/graphics/SVGImage.h
Source/WebCore/svg/graphics/SVGImageCache.cpp
Source/WebCore/svg/graphics/SVGImageCache.h

index 10f9c60..b53eb6f 100644 (file)
@@ -1,3 +1,25 @@
+2012-05-03  Tim Horton  <timothy_horton@apple.com>
+
+        REGRESSION(99539): SVG <img> disregards page scale and device scale
+        https://bugs.webkit.org/show_bug.cgi?id=77237
+        <rdar://problem/10767413>
+
+        Reviewed by Simon Fraser.
+
+        Add tests ensuring that SVG used via <img> respects deviceScaleFactor and pageScaleFactor.
+
+        * platform/chromium-linux/svg/as-image/image-respects-pageScaleFactor-expected.txt: Added.
+        * platform/chromium-linux/svg/as-image/image-respects-pageScaleFactor-expected.png: Added.
+        * platform/chromium/test_expectations.txt:
+        * platform/qt/Skipped:
+        * platform/mac/svg/as-image/image-respects-deviceScaleFactor-expected.png: Added.
+        * platform/mac/svg/as-image/image-respects-deviceScaleFactor-expected.txt: Added.
+        * platform/mac/svg/as-image/image-respects-pageScaleFactor-expected.png: Added.
+        * platform/mac/svg/as-image/image-respects-pageScaleFactor-expected.txt: Added.
+        * platform/efl/Skipped:
+        * svg/as-image/image-respects-deviceScaleFactor.html: Added.
+        * svg/as-image/image-respects-pageScaleFactor.html: Added.
+
 2012-05-03  Joshua Bell  <jsbell@chromium.org>
 
         IndexedDB: Handle generated keys up to 2^53
diff --git a/LayoutTests/platform/chromium-linux/svg/as-image/image-respects-pageScaleFactor-expected.png b/LayoutTests/platform/chromium-linux/svg/as-image/image-respects-pageScaleFactor-expected.png
new file mode 100644 (file)
index 0000000..154427a
Binary files /dev/null and b/LayoutTests/platform/chromium-linux/svg/as-image/image-respects-pageScaleFactor-expected.png differ
diff --git a/LayoutTests/platform/chromium-linux/svg/as-image/image-respects-pageScaleFactor-expected.txt b/LayoutTests/platform/chromium-linux/svg/as-image/image-respects-pageScaleFactor-expected.txt
new file mode 100644 (file)
index 0000000..41dff8a
--- /dev/null
@@ -0,0 +1,17 @@
+layer at (0,0) size 785x585
+  RenderView at (0,0) size 785x585
+layer at (0,0) size 785x585
+  RenderBlock {HTML} at (0,0) size 785x585
+    RenderBody {BODY} at (8,8) size 769x569
+      RenderBlock {P} at (0,0) size 769x20
+        RenderText {#text} at (0,0) size 328x19
+          text run at (0,0) width 328: "This test passes if both of the circles have sharp edges."
+      RenderBlock {P} at (0,36) size 769x20
+        RenderText {#text} at (0,0) size 418x19
+          text run at (0,0) width 418: "To run manually, use full-page zoom to increase the page scale factor."
+      RenderBlock (anonymous) at (0,72) size 769x133
+        RenderImage {IMG} at (0,0) size 128x128
+        RenderText {#text} at (128,113) size 4x19
+          text run at (128,113) width 4: " "
+        RenderImage {IMG} at (132,0) size 128x128
+        RenderText {#text} at (0,0) size 0x0
index b4962d8..108b998 100644 (file)
@@ -2963,6 +2963,7 @@ BUGWK70210 : fast/js/stack-overflow-arrity-catch.html = TEXT
 
 // These all will timeout, because we are lacking a hook that signals test completion.
 BUGWK70066 SKIP : fast/hidpi = TIMEOUT
+BUGWK70066 SKIP : svg/as-image/image-respects-deviceScaleFactor.html = TIMEOUT
 
 // Flaky tests from ~r97647
 BUGWK70298 : fast/images/pdf-as-background.html = FAIL TIMEOUT PASS
index 7d6d86e..6824012 100644 (file)
@@ -1482,6 +1482,7 @@ gamepad/
 
 # HiDPI tests require test infrastructure enhancements
 fast/hidpi
+svg/as-image/image-respects-deviceScaleFactor.html
 
 # Skipped until new WebSocket protocol is implemented. http://webkit.org/b/50099
 http/tests/websocket/tests/hybi/
diff --git a/LayoutTests/platform/mac/svg/as-image/image-respects-deviceScaleFactor-expected.png b/LayoutTests/platform/mac/svg/as-image/image-respects-deviceScaleFactor-expected.png
new file mode 100644 (file)
index 0000000..bf35ac0
Binary files /dev/null and b/LayoutTests/platform/mac/svg/as-image/image-respects-deviceScaleFactor-expected.png differ
diff --git a/LayoutTests/platform/mac/svg/as-image/image-respects-deviceScaleFactor-expected.txt b/LayoutTests/platform/mac/svg/as-image/image-respects-deviceScaleFactor-expected.txt
new file mode 100644 (file)
index 0000000..cbf94f2
--- /dev/null
@@ -0,0 +1,14 @@
+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
+      RenderBlock {P} at (0,0) size 784x18
+        RenderText {#text} at (0,0) size 517x18
+          text run at (0,0) width 517: "This test passes if both of the circles have sharp edges when deviceScaleFactor=2."
+      RenderBlock (anonymous) at (0,34) size 784x132
+        RenderImage {IMG} at (0,0) size 128x128
+        RenderText {#text} at (128,114) size 4x18
+          text run at (128,114) width 4: " "
+        RenderImage {IMG} at (132,0) size 128x128
+        RenderText {#text} at (0,0) size 0x0
diff --git a/LayoutTests/platform/mac/svg/as-image/image-respects-pageScaleFactor-expected.png b/LayoutTests/platform/mac/svg/as-image/image-respects-pageScaleFactor-expected.png
new file mode 100644 (file)
index 0000000..1689eb8
Binary files /dev/null and b/LayoutTests/platform/mac/svg/as-image/image-respects-pageScaleFactor-expected.png differ
diff --git a/LayoutTests/platform/mac/svg/as-image/image-respects-pageScaleFactor-expected.txt b/LayoutTests/platform/mac/svg/as-image/image-respects-pageScaleFactor-expected.txt
new file mode 100644 (file)
index 0000000..7f234d4
--- /dev/null
@@ -0,0 +1,17 @@
+layer at (0,0) size 785x585
+  RenderView at (0,0) size 785x585
+layer at (0,0) size 785x585
+  RenderBlock {HTML} at (0,0) size 785x585
+    RenderBody {BODY} at (8,8) size 769x569
+      RenderBlock {P} at (0,0) size 769x18
+        RenderText {#text} at (0,0) size 342x18
+          text run at (0,0) width 342: "This test passes if both of the circles have sharp edges."
+      RenderBlock {P} at (0,34) size 769x18
+        RenderText {#text} at (0,0) size 440x18
+          text run at (0,0) width 440: "To run manually, use full-page zoom to increase the page scale factor."
+      RenderBlock (anonymous) at (0,68) size 769x132
+        RenderImage {IMG} at (0,0) size 128x128
+        RenderText {#text} at (128,114) size 4x18
+          text run at (128,114) width 4: " "
+        RenderImage {IMG} at (132,0) size 128x128
+        RenderText {#text} at (0,0) size 0x0
index 398d193..7d95741 100644 (file)
@@ -351,6 +351,7 @@ http/tests/multipart
 
 # HiDPI tests require test infrastructure enhancements
 fast/hidpi
+svg/as-image/image-respects-deviceScaleFactor.html
 
 # [Qt] QtWebKit needs fullscreen api support
 # <https://bugs.webkit.org/show_bug.cgi?id=70132>
diff --git a/LayoutTests/svg/as-image/image-respects-deviceScaleFactor.html b/LayoutTests/svg/as-image/image-respects-deviceScaleFactor.html
new file mode 100644 (file)
index 0000000..0654699
--- /dev/null
@@ -0,0 +1,17 @@
+<html>
+<head>
+    <script>
+    function init() {
+        if (!window.layoutTestController)
+            return;
+
+        layoutTestController.waitUntilDone();
+        layoutTestController.setBackingScaleFactor(2, function () { layoutTestController.notifyDone(); });
+    }
+    window.onload = init;
+    </script>
+</head>
+<p>This test passes if both of the circles have sharp edges when deviceScaleFactor=2.</p>
+<img style="width: 128px;" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4Ij4KPGNpcmNsZSBmaWxsPSJibGFjayIgY3g9IjY0IiBjeT0iNjQiIHI9IjY0IiAvPgo8L3N2Zz4K">
+<img style="width: 128px;" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgoJPGNpcmNsZSBmaWxsPSJibGFjayIgY3g9IjY0IiBjeT0iNjQiIHI9IjY0IiAvPgo8L3N2Zz4=">
+</html>
diff --git a/LayoutTests/svg/as-image/image-respects-pageScaleFactor.html b/LayoutTests/svg/as-image/image-respects-pageScaleFactor.html
new file mode 100644 (file)
index 0000000..4d6ba94
--- /dev/null
@@ -0,0 +1,18 @@
+<html>
+<head>
+    <script>
+    function init() {
+        if (!window.internals)
+            return;
+
+        window.internals.settings.setPageScaleFactor(2, 0, 0);
+    }
+    window.onload = init;
+    </script>
+</head>
+<p>This test passes if both of the circles have sharp edges.</p>
+<p>To run manually, use full-page zoom to increase the page scale factor.</p>
+<img style="width: 128px;" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMjgiIGhlaWdodD0iMTI4Ij4KPGNpcmNsZSBmaWxsPSJibGFjayIgY3g9IjY0IiBjeT0iNjQiIHI9IjY0IiAvPgo8L3N2Zz4K">
+<img style="width: 128px;" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgoJPGNpcmNsZSBmaWxsPSJibGFjayIgY3g9IjY0IiBjeT0iNjQiIHI9IjY0IiAvPgo8L3N2Zz4=">
+
+</html>
index 715f713..f13b9fe 100644 (file)
@@ -1,3 +1,46 @@
+2012-05-03  Tim Horton  <timothy_horton@apple.com>
+
+        REGRESSION(99539): SVG <img> disregards page scale and device scale
+        https://bugs.webkit.org/show_bug.cgi?id=77237
+        <rdar://problem/10767413>
+
+        Reviewed by Simon Fraser.
+
+        Rename SVGImageCache::SizeAndZoom to SVGImageCache::SizeAndScales, as it carries more than just zoom now.
+
+        Pass the product of the device and page scales through everything that takes a SVGImageCache::SizeAndScales,
+        using it to inflate the size of the buffer created in lookupOrCreateBitmapImageForRenderer,
+        and to inflate the destination rectangle passed to SVGImage::draw, which will cause a transformation
+        on the context being drawn into.
+
+        Invalidate the SVGImageCache entry on device/page scale changes in addition to zoom changes.
+
+        This patch does not cause SVGImageCache to take into account scale caused by CSS transforms; that is tracked
+        separately by https://bugs.webkit.org/show_bug.cgi?id=85335.
+
+        Tests: svg/as-image/image-respects-deviceScaleFactor.html
+               svg/as-image/image-respects-pageScaleFactor.html
+
+        * loader/cache/CachedImage.cpp:
+        (WebCore::CachedImage::setContainerSizeForRenderer):
+        (WebCore::CachedImage::imageSizeForRenderer):
+        * svg/graphics/SVGImage.cpp:
+        (WebCore::SVGImage::drawSVGToImageBuffer):
+        * svg/graphics/SVGImage.h:
+        * svg/graphics/SVGImageCache.cpp:
+        (WebCore::SVGImageCache::~SVGImageCache):
+        (WebCore::SVGImageCache::removeRendererFromCache):
+        (WebCore::SVGImageCache::setRequestedSizeAndScales):
+        (WebCore::SVGImageCache::requestedSizeAndScales):
+        (WebCore::SVGImageCache::redraw):
+        (WebCore::SVGImageCache::lookupOrCreateBitmapImageForRenderer):
+        * svg/graphics/SVGImageCache.h:
+        (WebCore::SVGImageCache::SizeAndScales::SizeAndScales):
+        (SizeAndScales):
+        (SVGImageCache):
+        (WebCore::SVGImageCache::ImageData::ImageData):
+        (ImageData):
+
 2012-05-03  Fady Samuel  <fsamuel@chromium.org>
 
         Removing line in computeViewportAttributes that enforces a minimum scale factor to never allow zooming out more than viewport
index a6d99eb..33a4015 100644 (file)
@@ -33,6 +33,7 @@
 #include "FrameLoaderClient.h"
 #include "FrameLoaderTypes.h"
 #include "FrameView.h"
+#include "Page.h"
 #include "RenderObject.h"
 #include "Settings.h"
 #include "SharedBuffer.h"
@@ -202,7 +203,11 @@ void CachedImage::setContainerSizeForRenderer(const RenderObject* renderer, cons
         m_image->setContainerSize(containerSize);
         return;
     }
-    m_svgImageCache->setRequestedSizeAndZoom(renderer, SVGImageCache::SizeAndZoom(containerSize, containerZoom));
+
+    // FIXME (85335): This needs to take CSS transform scale into account as well.
+    float containerScale = renderer->document()->page()->deviceScaleFactor() * renderer->document()->page()->pageScaleFactor();
+
+    m_svgImageCache->setRequestedSizeAndScales(renderer, SVGImageCache::SizeAndScales(containerSize, containerZoom, containerScale));
 #else
     UNUSED_PARAM(renderer);
     UNUSED_PARAM(containerZoom);
@@ -250,10 +255,10 @@ IntSize CachedImage::imageSizeForRenderer(const RenderObject* renderer, float mu
 
 #if ENABLE(SVG)
     if (m_image->isSVGImage()) {
-        SVGImageCache::SizeAndZoom sizeAndZoom = m_svgImageCache->requestedSizeAndZoom(renderer);
-        if (!sizeAndZoom.size.isEmpty()) {
-            imageSize.setWidth(sizeAndZoom.size.width() / sizeAndZoom.zoom);
-            imageSize.setHeight(sizeAndZoom.size.height() / sizeAndZoom.zoom);
+        SVGImageCache::SizeAndScales sizeAndScales = m_svgImageCache->requestedSizeAndScales(renderer);
+        if (!sizeAndScales.size.isEmpty()) {
+            imageSize.setWidth(sizeAndScales.size.width() / sizeAndScales.zoom);
+            imageSize.setHeight(sizeAndScales.size.height() / sizeAndScales.zoom);
         }
     }
 #endif
index 8c2bf19..b59af4b 100644 (file)
@@ -140,7 +140,7 @@ IntSize SVGImage::size() const
     return IntSize(300, 150);
 }
 
-void SVGImage::drawSVGToImageBuffer(ImageBuffer* buffer, const IntSize& size, float zoom, ShouldClearBuffer shouldClear)
+void SVGImage::drawSVGToImageBuffer(ImageBuffer* buffer, const IntSize& size, float zoom, float scale, ShouldClearBuffer shouldClear)
 {
     // FIXME: This doesn't work correctly with animations. If an image contains animations, that say run for 2 seconds,
     // and we currently have one <img> that displays us. If we open another document referencing the same SVGImage it
@@ -182,8 +182,11 @@ void SVGImage::drawSVGToImageBuffer(ImageBuffer* buffer, const IntSize& size, fl
     if (shouldClear == ClearImageBuffer)
         buffer->context()->clearRect(rect);
 
+    FloatRect scaledRect(rect);
+    scaledRect.scale(scale);
+
     // Draw SVG on top of ImageBuffer.
-    draw(buffer->context(), rect, rect, ColorSpaceDeviceRGB, CompositeSourceOver);
+    draw(buffer->context(), enclosingIntRect(scaledRect), rect, ColorSpaceDeviceRGB, CompositeSourceOver);
 
     // Reset container size & zoom to initial state. Otherwhise the size() of this
     // image would return whatever last size was set by drawSVGToImageBuffer().
index af8cf7d..e63d641 100644 (file)
@@ -52,7 +52,7 @@ public:
         DontClearImageBuffer
     };
 
-    void drawSVGToImageBuffer(ImageBuffer*, const IntSize&, float zoom, ShouldClearBuffer);
+    void drawSVGToImageBuffer(ImageBuffer*, const IntSize&, float zoom, float scale, ShouldClearBuffer);
     RenderBox* embeddedContentBox() const;
     FrameView* frameView() const;
 
index 2869f61..e560293 100644 (file)
@@ -38,7 +38,7 @@ SVGImageCache::SVGImageCache(SVGImage* svgImage)
 
 SVGImageCache::~SVGImageCache()
 {
-    m_sizeAndZoomMap.clear();
+    m_sizeAndScalesMap.clear();
 
     ImageDataMap::iterator end = m_imageDataMap.end();
     for (ImageDataMap::iterator it = m_imageDataMap.begin(); it != end; ++it)
@@ -50,7 +50,7 @@ SVGImageCache::~SVGImageCache()
 void SVGImageCache::removeRendererFromCache(const RenderObject* renderer)
 {
     ASSERT(renderer);
-    m_sizeAndZoomMap.remove(renderer);
+    m_sizeAndScalesMap.remove(renderer);
 
     ImageDataMap::iterator it = m_imageDataMap.find(renderer);
     if (it == m_imageDataMap.end())
@@ -60,19 +60,19 @@ void SVGImageCache::removeRendererFromCache(const RenderObject* renderer)
     m_imageDataMap.remove(it);
 }
 
-void SVGImageCache::setRequestedSizeAndZoom(const RenderObject* renderer, const SizeAndZoom& sizeAndZoom)
+void SVGImageCache::setRequestedSizeAndScales(const RenderObject* renderer, const SizeAndScales& sizeAndScales)
 {
     ASSERT(renderer);
-    ASSERT(!sizeAndZoom.size.isEmpty());
-    m_sizeAndZoomMap.set(renderer, sizeAndZoom);
+    ASSERT(!sizeAndScales.size.isEmpty());
+    m_sizeAndScalesMap.set(renderer, sizeAndScales);
 }
 
-SVGImageCache::SizeAndZoom SVGImageCache::requestedSizeAndZoom(const RenderObject* renderer) const
+SVGImageCache::SizeAndScales SVGImageCache::requestedSizeAndScales(const RenderObject* renderer) const
 {
     ASSERT(renderer);
-    SizeAndZoomMap::const_iterator it = m_sizeAndZoomMap.find(renderer);
-    if (it == m_sizeAndZoomMap.end())
-        return SizeAndZoom();
+    SizeAndScalesMap::const_iterator it = m_sizeAndScalesMap.find(renderer);
+    if (it == m_sizeAndScalesMap.end())
+        return SizeAndScales();
     return it->second;
 }
 
@@ -102,7 +102,7 @@ void SVGImageCache::redraw()
         // If the content changed we redraw using our existing ImageBuffer.
         ASSERT(data.buffer);
         ASSERT(data.image);
-        m_svgImage->drawSVGToImageBuffer(data.buffer, data.sizeAndZoom.size, data.sizeAndZoom.zoom, SVGImage::ClearImageBuffer);
+        m_svgImage->drawSVGToImageBuffer(data.buffer, data.sizeAndScales.size, data.sizeAndScales.zoom, data.sizeAndScales.scale, SVGImage::ClearImageBuffer);
         data.image = data.buffer->copyImage(CopyBackingStore);
         data.imageNeedsUpdate = false;
     }
@@ -127,12 +127,13 @@ Image* SVGImageCache::lookupOrCreateBitmapImageForRenderer(const RenderObject* r
     ASSERT(renderer);
 
     // The cache needs to know the size of the renderer before querying an image for it.
-    SizeAndZoomMap::iterator sizeIt = m_sizeAndZoomMap.find(renderer);
-    if (sizeIt == m_sizeAndZoomMap.end())
+    SizeAndScalesMap::iterator sizeIt = m_sizeAndScalesMap.find(renderer);
+    if (sizeIt == m_sizeAndScalesMap.end())
         return Image::nullImage();
 
     IntSize size = sizeIt->second.size;
     float zoom = sizeIt->second.zoom;
+    float scale = sizeIt->second.scale;
     ASSERT(!size.isEmpty());
 
     // Lookup image for renderer in cache and eventually update it.
@@ -141,7 +142,7 @@ Image* SVGImageCache::lookupOrCreateBitmapImageForRenderer(const RenderObject* r
         ImageData& data = it->second;
 
         // Common case: image size & zoom remained the same.
-        if (data.sizeAndZoom.size == size && data.sizeAndZoom.zoom == zoom)
+        if (data.sizeAndScales.size == size && data.sizeAndScales.zoom == zoom && data.sizeAndScales.scale == scale)
             return data.image.get();
 
         // If the image size for the renderer changed, we have to delete the buffer, remove the item from the cache and recreate it.
@@ -149,12 +150,15 @@ Image* SVGImageCache::lookupOrCreateBitmapImageForRenderer(const RenderObject* r
         m_imageDataMap.remove(it);
     }
 
+    FloatSize scaledSize(size);
+    scaledSize.scale(scale);
+
     // Create and cache new image and image buffer at requested size.
-    OwnPtr<ImageBuffer> newBuffer = ImageBuffer::create(size, 1);
+    OwnPtr<ImageBuffer> newBuffer = ImageBuffer::create(expandedIntSize(scaledSize), 1);
     if (!newBuffer)
         return Image::nullImage();
 
-    m_svgImage->drawSVGToImageBuffer(newBuffer.get(), size, zoom, SVGImage::DontClearImageBuffer);
+    m_svgImage->drawSVGToImageBuffer(newBuffer.get(), size, zoom, scale, SVGImage::DontClearImageBuffer);
 
     RefPtr<Image> newImage = newBuffer->copyImage(CopyBackingStore);
     Image* newImagePtr = newImage.get();
index 46b7093..7f42f46 100644 (file)
@@ -44,26 +44,29 @@ public:
         return adoptPtr(new SVGImageCache(image));
     }
 
-    struct SizeAndZoom {
-        SizeAndZoom()
+    struct SizeAndScales {
+        SizeAndScales()
             : zoom(1)
+            , scale(1)
         {
         }
 
-        SizeAndZoom(const IntSize& newSize, float newZoom)
+        SizeAndScales(const IntSize& newSize, float newZoom, float newScale)
             : size(newSize)
             , zoom(newZoom)
+            , scale(newScale)
         {
         }
 
         IntSize size;
         float zoom;
+        float scale;
     };
 
     void removeRendererFromCache(const RenderObject*);
 
-    void setRequestedSizeAndZoom(const RenderObject*, const SizeAndZoom&);
-    SizeAndZoom requestedSizeAndZoom(const RenderObject*) const;
+    void setRequestedSizeAndScales(const RenderObject*, const SizeAndScales&);
+    SizeAndScales requestedSizeAndScales(const RenderObject*) const;
 
     Image* lookupOrCreateBitmapImageForRenderer(const RenderObject*);
     void imageContentChanged();
@@ -80,26 +83,26 @@ private:
         {
         }
 
-        ImageData(ImageBuffer* newBuffer, PassRefPtr<Image> newImage, const SizeAndZoom& newSizeAndZoom)
+        ImageData(ImageBuffer* newBuffer, PassRefPtr<Image> newImage, const SizeAndScales& newSizeAndScales)
             : imageNeedsUpdate(false)
-            , sizeAndZoom(newSizeAndZoom)
+            , sizeAndScales(newSizeAndScales)
             , buffer(newBuffer)
             , image(newImage)
         {
         }
 
         bool imageNeedsUpdate;
-        SizeAndZoom sizeAndZoom;
+        SizeAndScales sizeAndScales;
 
         ImageBuffer* buffer;
         RefPtr<Image> image;
     };
 
-    typedef HashMap<const RenderObject*, SizeAndZoom> SizeAndZoomMap;
+    typedef HashMap<const RenderObject*, SizeAndScales> SizeAndScalesMap;
     typedef HashMap<const RenderObject*, ImageData> ImageDataMap;
 
     SVGImage* m_svgImage;
-    SizeAndZoomMap m_sizeAndZoomMap;
+    SizeAndScalesMap m_sizeAndScalesMap;
     ImageDataMap m_imageDataMap;
     Timer<SVGImageCache> m_redrawTimer;
 };