Title: [141303] trunk
Revision
141303
Author
[email protected]
Date
2013-01-30 13:09:52 -0800 (Wed, 30 Jan 2013)

Log Message

Track scale and zoom together when drawing SVG images
https://bugs.webkit.org/show_bug.cgi?id=108108

Reviewed by Tim Horton.

Source/WebCore:

This patch refactors SVGImage::drawSVGToImageBuffer to take a single zoomAndScale parameter
and removes two messy calls to setPageZoomFactor. This patch makes progress towards an
SVG image cache keyed on just container size and scale.

This refactoring is covered by existing tests.

* loader/cache/CachedImage.cpp:
(WebCore::CachedImage::setContainerSizeForRenderer):
(WebCore::CachedImage::imageSizeForRenderer):

    This complex logic has been refactored out of CachedImage and into SVGImageCache.
    In addition to the code move, we no longer divide by the zoom factor because the
    container size is stored without zoom.

* svg/graphics/SVGImage.cpp:
(WebCore::SVGImage::drawSVGToImageBuffer):

    This method signature has changed to take a FloatSize for the container size and
    a combined zoom and scale parameter (zoomAndScale). A FloatSize is needed for the
    container size because we now store the container size unzoomed, and in this process
    we do not want to lose precision.

    The messy setPageZoomFactor calls have also been removed which cleans this function up.

* svg/graphics/SVGImage.h:
* svg/graphics/SVGImageCache.cpp:
(WebCore::SVGImageCache::setContainerSizeForRenderer):

    This function now stores the container size unzoomed. The container size was changed
    to a FloatSize so that precision is not lost.

(WebCore::SVGImageCache::imageSizeForRenderer):

    Note that the ImageBuffer size will stay the same. We now store the size as:
        containerSize (without zoom) * zoom * scale
    Previously this was:
        containerSize (with zoom) * scale

(WebCore::SVGImageCache::redraw):
(WebCore::SVGImageCache::lookupOrCreateBitmapImageForRenderer):
* svg/graphics/SVGImageCache.h:
(WebCore::SVGImageCache::SizeAndScales::SizeAndScales):
(SizeAndScales):
(SVGImageCache):

LayoutTests:

* platform/chromium/TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (141302 => 141303)


--- trunk/LayoutTests/ChangeLog	2013-01-30 21:03:48 UTC (rev 141302)
+++ trunk/LayoutTests/ChangeLog	2013-01-30 21:09:52 UTC (rev 141303)
@@ -1,3 +1,12 @@
+2013-01-30  Philip Rogers  <[email protected]>
+
+        Track scale and zoom together when drawing SVG images
+        https://bugs.webkit.org/show_bug.cgi?id=108108
+
+        Reviewed by Tim Horton.
+
+        * platform/chromium/TestExpectations:
+
 2013-01-30  Zan Dobersek  <[email protected]>
 
         [GTK] http/tests/w3c/webperf/submission/Intel/user-timing/test_user_timing_entry_type.html is failing

Modified: trunk/LayoutTests/platform/chromium/TestExpectations (141302 => 141303)


--- trunk/LayoutTests/platform/chromium/TestExpectations	2013-01-30 21:03:48 UTC (rev 141302)
+++ trunk/LayoutTests/platform/chromium/TestExpectations	2013-01-30 21:09:52 UTC (rev 141303)
@@ -3653,6 +3653,12 @@
 webkit.org/b/94002 [ Win7 Debug ] inspector/debugger [ Pass Timeout ]
 webkit.org/b/94002 [ Win7 Debug ] inspector/debugger/event-listener-breakpoints.html [ Pass Timeout Failure ]
 
+# Requires a rebasline after webkit.org/b/108108
+webkit.org/b/108108 svg/zoom/page/zoom-background-images.html [ ImageOnlyFailure Pass ]
+webkit.org/b/108108 svg/zoom/page/zoom-img-preserveAspectRatio-support-1.html [ ImageOnlyFailure Pass ]
+webkit.org/b/108108 svg/zoom/page/zoom-svg-as-background-with-relative-size.html [ ImageOnlyFailure Pass ]
+webkit.org/b/108108 fast/backgrounds/size/contain-and-cover-zoomed.html [ ImageOnlyFailure Pass ]
+
 # Flaky
 webkit.org/b/99389 [ Win ] inspector/debugger/xhr-breakpoints.html [ Pass Failure ]
 

Modified: trunk/Source/WebCore/ChangeLog (141302 => 141303)


--- trunk/Source/WebCore/ChangeLog	2013-01-30 21:03:48 UTC (rev 141302)
+++ trunk/Source/WebCore/ChangeLog	2013-01-30 21:09:52 UTC (rev 141303)
@@ -1,3 +1,55 @@
+2013-01-30  Philip Rogers  <[email protected]>
+
+        Track scale and zoom together when drawing SVG images
+        https://bugs.webkit.org/show_bug.cgi?id=108108
+
+        Reviewed by Tim Horton.
+
+        This patch refactors SVGImage::drawSVGToImageBuffer to take a single zoomAndScale parameter
+        and removes two messy calls to setPageZoomFactor. This patch makes progress towards an
+        SVG image cache keyed on just container size and scale.
+
+        This refactoring is covered by existing tests.
+
+        * loader/cache/CachedImage.cpp:
+        (WebCore::CachedImage::setContainerSizeForRenderer):
+        (WebCore::CachedImage::imageSizeForRenderer):
+
+            This complex logic has been refactored out of CachedImage and into SVGImageCache.
+            In addition to the code move, we no longer divide by the zoom factor because the
+            container size is stored without zoom.
+
+        * svg/graphics/SVGImage.cpp:
+        (WebCore::SVGImage::drawSVGToImageBuffer):
+
+            This method signature has changed to take a FloatSize for the container size and
+            a combined zoom and scale parameter (zoomAndScale). A FloatSize is needed for the
+            container size because we now store the container size unzoomed, and in this process
+            we do not want to lose precision.
+
+            The messy setPageZoomFactor calls have also been removed which cleans this function up.
+
+        * svg/graphics/SVGImage.h:
+        * svg/graphics/SVGImageCache.cpp:
+        (WebCore::SVGImageCache::setContainerSizeForRenderer):
+
+            This function now stores the container size unzoomed. The container size was changed
+            to a FloatSize so that precision is not lost.
+
+        (WebCore::SVGImageCache::imageSizeForRenderer):
+
+            Note that the ImageBuffer size will stay the same. We now store the size as:
+                containerSize (without zoom) * zoom * scale
+            Previously this was:
+                containerSize (with zoom) * scale
+
+        (WebCore::SVGImageCache::redraw):
+        (WebCore::SVGImageCache::lookupOrCreateBitmapImageForRenderer):
+        * svg/graphics/SVGImageCache.h:
+        (WebCore::SVGImageCache::SizeAndScales::SizeAndScales):
+        (SizeAndScales):
+        (SVGImageCache):
+
 2013-01-30  Benjamin Poulain  <[email protected]>
 
         Do not convert to String->AtomicString for NamedNodeMap

Modified: trunk/Source/WebCore/loader/cache/CachedImage.cpp (141302 => 141303)


--- trunk/Source/WebCore/loader/cache/CachedImage.cpp	2013-01-30 21:03:48 UTC (rev 141302)
+++ trunk/Source/WebCore/loader/cache/CachedImage.cpp	2013-01-30 21:09:52 UTC (rev 141303)
@@ -225,7 +225,7 @@
         return;
     }
 
-    m_svgImageCache->setRequestedSizeAndScales(renderer, SVGImageCache::SizeAndScales(containerSize, containerZoom));
+    m_svgImageCache->setContainerSizeForRenderer(renderer, containerSize, containerZoom);
 #else
     UNUSED_PARAM(containerZoom);
     m_image->setContainerSize(containerSize);
@@ -267,24 +267,13 @@
 
     if (m_image->isBitmapImage() && (renderer && renderer->shouldRespectImageOrientation() == RespectImageOrientation))
         imageSize = static_cast<BitmapImage*>(m_image.get())->sizeRespectingOrientation();
-    else
-        imageSize = m_image->size();
-
 #if ENABLE(SVG)
-    if (m_image->isSVGImage()) {
-        SVGImageCache::SizeAndScales sizeAndScales = m_svgImageCache->requestedSizeAndScales(renderer);
-        if (!sizeAndScales.size.isEmpty()) {
-            float scale = sizeAndScales.scale;
-            if (!scale) {
-                Page* page = renderer->document()->page();
-                scale = page->deviceScaleFactor() * page->pageScaleFactor();
-            }
-
-            imageSize.setWidth(scale * sizeAndScales.size.width() / sizeAndScales.zoom);
-            imageSize.setHeight(scale * sizeAndScales.size.height() / sizeAndScales.zoom);
-        }
+    else if (m_image->isSVGImage()) {
+        imageSize = m_svgImageCache->imageSizeForRenderer(renderer);
     }
 #endif
+    else
+        imageSize = m_image->size();
 
     if (multiplier == 1.0f)
         return imageSize;

Modified: trunk/Source/WebCore/svg/graphics/SVGImage.cpp (141302 => 141303)


--- trunk/Source/WebCore/svg/graphics/SVGImage.cpp	2013-01-30 21:03:48 UTC (rev 141302)
+++ trunk/Source/WebCore/svg/graphics/SVGImage.cpp	2013-01-30 21:09:52 UTC (rev 141303)
@@ -99,7 +99,7 @@
     return IntSize(300, 150);
 }
 
-void SVGImage::drawSVGToImageBuffer(ImageBuffer* buffer, const IntSize& size, float zoom, float scale, ShouldClearBuffer shouldClear)
+void SVGImage::drawSVGToImageBuffer(ImageBuffer* buffer, const FloatSize& size, float zoomAndScale, 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
@@ -130,35 +130,19 @@
     // Disable repainting; we don't want deferred repaints to schedule any timers due to this relayout.
     frame->view()->beginDisableRepaints();
 
-    renderer->setContainerSize(size);
+    IntSize containerSize = roundedIntSize(size);
+    renderer->setContainerSize(containerSize);
     frame->view()->resize(this->size());
 
-    if (zoom != 1)
-        frame->setPageZoomFactor(zoom);
-
-    // Eventually clear image buffer.
-    IntRect rect(IntPoint(), size);
-
-    FloatRect scaledRect(rect);
-    scaledRect.scale(scale);
-
+    FloatSize scaledContainerSize(size);
+    scaledContainerSize.scale(zoomAndScale);
+    IntRect destRect = IntRect(IntPoint(), expandedIntSize(scaledContainerSize));
     if (shouldClear == ClearImageBuffer)
-        buffer->context()->clearRect(enclosingIntRect(scaledRect));
+        buffer->context()->clearRect(destRect);
 
     // Draw SVG on top of ImageBuffer.
-    draw(buffer->context(), enclosingIntRect(scaledRect), rect, ColorSpaceDeviceRGB, CompositeSourceOver, BlendModeNormal);
+    draw(buffer->context(), destRect, IntRect(IntPoint(), containerSize), ColorSpaceDeviceRGB, CompositeSourceOver, BlendModeNormal);
 
-    // Reset container size & zoom to initial state. Otherwhise the size() of this
-    // image would return whatever last size was set by drawSVGToImageBuffer().
-    if (zoom != 1)
-        frame->setPageZoomFactor(1);
-
-    // Renderer may have been recreated by frame->setPageZoomFactor(zoom). So fetch it again.
-    renderer = toRenderSVGRoot(rootElement->renderer());
-    if (renderer)
-        renderer->setContainerSize(IntSize());
-
-    frame->view()->resize(this->size());
     if (frame->view()->needsLayout())
         frame->view()->layout();
 

Modified: trunk/Source/WebCore/svg/graphics/SVGImage.h (141302 => 141303)


--- trunk/Source/WebCore/svg/graphics/SVGImage.h	2013-01-30 21:03:48 UTC (rev 141302)
+++ trunk/Source/WebCore/svg/graphics/SVGImage.h	2013-01-30 21:09:52 UTC (rev 141303)
@@ -51,7 +51,7 @@
         DontClearImageBuffer
     };
 
-    void drawSVGToImageBuffer(ImageBuffer*, const IntSize&, float zoom, float scale, ShouldClearBuffer);
+    void drawSVGToImageBuffer(ImageBuffer*, const FloatSize&, float, ShouldClearBuffer);
     RenderBox* embeddedContentBox() const;
     FrameView* frameView() const;
 

Modified: trunk/Source/WebCore/svg/graphics/SVGImageCache.cpp (141302 => 141303)


--- trunk/Source/WebCore/svg/graphics/SVGImageCache.cpp	2013-01-30 21:03:48 UTC (rev 141302)
+++ trunk/Source/WebCore/svg/graphics/SVGImageCache.cpp	2013-01-30 21:09:52 UTC (rev 141303)
@@ -75,21 +75,38 @@
     m_imageDataMap.remove(it);
 }
 
-void SVGImageCache::setRequestedSizeAndScales(const CachedImageClient* client, const SizeAndScales& sizeAndScales)
+void SVGImageCache::setContainerSizeForRenderer(const CachedImageClient* client, const IntSize& containerSize, float containerZoom)
 {
     ASSERT(client);
-    ASSERT(!sizeAndScales.size.isEmpty());
-    m_sizeAndScalesMap.set(client, sizeAndScales);
+    ASSERT(!containerSize.isEmpty());
+
+    FloatSize containerSizeWithoutZoom(containerSize);
+    containerSizeWithoutZoom.scale(1 / containerZoom);
+    m_sizeAndScalesMap.set(client, SizeAndScales(containerSizeWithoutZoom, containerZoom));
 }
 
-SVGImageCache::SizeAndScales SVGImageCache::requestedSizeAndScales(const CachedImageClient* client) const
+IntSize SVGImageCache::imageSizeForRenderer(const RenderObject* renderer) const
 {
-    if (!client)
-        return SizeAndScales();
-    SizeAndScalesMap::const_iterator it = m_sizeAndScalesMap.find(client);
+    IntSize imageSize = m_svgImage->size();
+
+    if (!renderer)
+        return imageSize;
+    SizeAndScalesMap::const_iterator it = m_sizeAndScalesMap.find(renderer);
     if (it == m_sizeAndScalesMap.end())
-        return SizeAndScales();
-    return it->value;
+        return imageSize;
+
+    SizeAndScales sizeAndScales = it->value;
+    if (!sizeAndScales.size.isEmpty()) {
+        float scale = sizeAndScales.scale;
+        if (!scale) {
+            Page* page = renderer->document()->page();
+            scale = page->deviceScaleFactor() * page->pageScaleFactor();
+        }
+
+        imageSize.setWidth(scale * sizeAndScales.size.width());
+        imageSize.setHeight(scale * sizeAndScales.size.height());
+    }
+    return imageSize;
 }
 
 void SVGImageCache::imageContentChanged()
@@ -113,7 +130,7 @@
         // If the content changed we redraw using our existing ImageBuffer.
         ASSERT(data.buffer);
         ASSERT(data.image);
-        m_svgImage->drawSVGToImageBuffer(data.buffer, data.sizeAndScales.size, data.sizeAndScales.zoom, data.sizeAndScales.scale, 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;
     }
@@ -150,7 +167,7 @@
     if (sizeIt == m_sizeAndScalesMap.end())
         return Image::nullImage();
 
-    IntSize size = sizeIt->value.size;
+    FloatSize size = sizeIt->value.size;
     float zoom = sizeIt->value.zoom;
     float scale = sizeIt->value.scale;
 
@@ -179,14 +196,14 @@
     }
 
     FloatSize scaledSize(size);
-    scaledSize.scale(scale);
+    scaledSize.scale(scale * zoom);
 
     // Create and cache new image and image buffer at requested size.
     OwnPtr<ImageBuffer> newBuffer = ImageBuffer::create(expandedIntSize(scaledSize), 1);
     if (!newBuffer)
         return Image::nullImage();
 
-    m_svgImage->drawSVGToImageBuffer(newBuffer.get(), size, zoom, scale, SVGImage::DontClearImageBuffer);
+    m_svgImage->drawSVGToImageBuffer(newBuffer.get(), size, scale * zoom, SVGImage::DontClearImageBuffer);
 
     RefPtr<Image> newImage = newBuffer->copyImage(CopyBackingStore);
     Image* newImagePtr = newImage.get();

Modified: trunk/Source/WebCore/svg/graphics/SVGImageCache.h (141302 => 141303)


--- trunk/Source/WebCore/svg/graphics/SVGImageCache.h	2013-01-30 21:03:48 UTC (rev 141302)
+++ trunk/Source/WebCore/svg/graphics/SVGImageCache.h	2013-01-30 21:09:52 UTC (rev 141303)
@@ -21,6 +21,7 @@
 #define SVGImageCache_h
 
 #if ENABLE(SVG)
+#include "FloatSize.h"
 #include "Image.h"
 #include "IntSize.h"
 #include "Timer.h"
@@ -53,29 +54,29 @@
         {
         }
 
-        SizeAndScales(const IntSize& newSize, float newZoom, float newScale)
+        SizeAndScales(const FloatSize& newSize, float newZoom, float newScale)
             : size(newSize)
             , zoom(newZoom)
             , scale(newScale)
         {
         }
 
-        SizeAndScales(const IntSize& newSize, float newZoom)
+        SizeAndScales(const FloatSize& newSize, float newZoom)
             : size(newSize)
             , zoom(newZoom)
             , scale(0)
         {
         }
 
-        IntSize size;
+        FloatSize size; // This is the container size without zoom.
         float zoom;
         float scale; // A scale of 0 indicates that the default scale should be used.
     };
 
     void removeClientFromCache(const CachedImageClient*);
 
-    void setRequestedSizeAndScales(const CachedImageClient*, const SizeAndScales&);
-    SizeAndScales requestedSizeAndScales(const CachedImageClient*) const;
+    void setContainerSizeForRenderer(const CachedImageClient*, const IntSize&, float);
+    IntSize imageSizeForRenderer(const RenderObject*) const;
 
     Image* lookupOrCreateBitmapImageForRenderer(const RenderObject*);
     void imageContentChanged();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to