Title: [171119] trunk/Source/WebCore
Revision
171119
Author
simon.fra...@apple.com
Date
2014-07-15 15:25:50 -0700 (Tue, 15 Jul 2014)

Log Message

[iOS] Fix issues drawing subsampled image elements and CSS images
https://bugs.webkit.org/show_bug.cgi?id=134944
<rdar://problem/17634095>

Reviewed by Dean Jackson.

After r170675 it is important for BitmapImage::draw() to be given a srcRect computed
using the original size of the image, not the subsampled size.

So fix various code paths that end up in image drawing to use the originalSize(),
which requires giving Image a virtual function that just returns size(), and hence has
a FloatSize return value.

Tested by setting a very low subsampling threshold and browsing various sites.

A better longterm fix will happen via bug 134916.

* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::originalSize):
* platform/graphics/BitmapImage.h:
* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::drawImage):
* platform/graphics/Image.cpp:
(WebCore::Image::drawTiled):
(WebCore::Image::computeIntrinsicDimensions):
* platform/graphics/Image.h:
(WebCore::Image::originalSize):
* platform/graphics/cg/BitmapImageCG.cpp:
(WebCore::BitmapImage::BitmapImage): Just use m_size for initializing the other members.
(WebCore::BitmapImage::draw):
* platform/graphics/cg/GraphicsContext3DCG.cpp:
(WebCore::GraphicsContext3D::ImageExtractor::extractImage):
* platform/graphics/cg/ImageCG.cpp:
(WebCore::Image::drawPattern):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (171118 => 171119)


--- trunk/Source/WebCore/ChangeLog	2014-07-15 21:32:20 UTC (rev 171118)
+++ trunk/Source/WebCore/ChangeLog	2014-07-15 22:25:50 UTC (rev 171119)
@@ -1,3 +1,40 @@
+2014-07-15  Simon Fraser  <simon.fra...@apple.com>
+
+        [iOS] Fix issues drawing subsampled image elements and CSS images
+        https://bugs.webkit.org/show_bug.cgi?id=134944
+        <rdar://problem/17634095>
+
+        Reviewed by Dean Jackson.
+
+        After r170675 it is important for BitmapImage::draw() to be given a srcRect computed
+        using the original size of the image, not the subsampled size.
+        
+        So fix various code paths that end up in image drawing to use the originalSize(),
+        which requires giving Image a virtual function that just returns size(), and hence has
+        a FloatSize return value.
+        
+        Tested by setting a very low subsampling threshold and browsing various sites.
+        
+        A better longterm fix will happen via bug 134916.
+
+        * platform/graphics/BitmapImage.cpp:
+        (WebCore::BitmapImage::originalSize):
+        * platform/graphics/BitmapImage.h:
+        * platform/graphics/GraphicsContext.cpp:
+        (WebCore::GraphicsContext::drawImage):
+        * platform/graphics/Image.cpp:
+        (WebCore::Image::drawTiled):
+        (WebCore::Image::computeIntrinsicDimensions):
+        * platform/graphics/Image.h:
+        (WebCore::Image::originalSize):
+        * platform/graphics/cg/BitmapImageCG.cpp:
+        (WebCore::BitmapImage::BitmapImage): Just use m_size for initializing the other members.
+        (WebCore::BitmapImage::draw):
+        * platform/graphics/cg/GraphicsContext3DCG.cpp:
+        (WebCore::GraphicsContext3D::ImageExtractor::extractImage):
+        * platform/graphics/cg/ImageCG.cpp:
+        (WebCore::Image::drawPattern):
+
 2014-07-15  Brent Fulgham  <bfulg...@apple.com>
 
         [Win] Unreviewed build fix after r171069.

Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.cpp (171118 => 171119)


--- trunk/Source/WebCore/platform/graphics/BitmapImage.cpp	2014-07-15 21:32:20 UTC (rev 171118)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.cpp	2014-07-15 22:25:50 UTC (rev 171119)
@@ -261,7 +261,7 @@
 }
 
 #if PLATFORM(IOS)
-IntSize BitmapImage::originalSize() const
+FloatSize BitmapImage::originalSize() const
 {
     updateSize();
     return m_originalSize;

Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.h (171118 => 171119)


--- trunk/Source/WebCore/platform/graphics/BitmapImage.h	2014-07-15 21:32:20 UTC (rev 171118)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.h	2014-07-15 22:25:50 UTC (rev 171119)
@@ -138,7 +138,7 @@
     virtual FloatSize size() const override;
     IntSize sizeRespectingOrientation(ImageOrientationDescription = ImageOrientationDescription()) const;
 #if PLATFORM(IOS)
-    virtual IntSize originalSize() const;
+    virtual FloatSize originalSize() const override;
     IntSize originalSizeRespectingOrientation() const;
 #endif
     IntSize currentFrameSize() const;

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp (171118 => 171119)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp	2014-07-15 21:32:20 UTC (rev 171118)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp	2014-07-15 22:25:50 UTC (rev 171119)
@@ -581,7 +581,14 @@
 {
     if (!image)
         return;
-    drawImage(image, colorSpace, destination, FloatRect(FloatPoint(), image->size()), imagePaintingOptions);
+    
+#if PLATFORM(IOS)
+    FloatRect srcRect(FloatPoint(), image->originalSize());
+#else
+    FloatRect srcRect(FloatPoint(), image->size());
+#endif
+        
+    drawImage(image, colorSpace, destination, srcRect, imagePaintingOptions);
 }
 
 void GraphicsContext::drawImage(Image* image, ColorSpace colorSpace, const FloatRect& destination, const FloatRect& source, const ImagePaintingOptions& imagePaintingOptions)

Modified: trunk/Source/WebCore/platform/graphics/Image.cpp (171118 => 171119)


--- trunk/Source/WebCore/platform/graphics/Image.cpp	2014-07-15 21:32:20 UTC (rev 171118)
+++ trunk/Source/WebCore/platform/graphics/Image.cpp	2014-07-15 22:25:50 UTC (rev 171119)
@@ -103,7 +103,11 @@
 
     ASSERT(!isBitmapImage() || notSolidColor());
 
+#if PLATFORM(IOS)
+    FloatSize intrinsicTileSize = originalSize();
+#else
     FloatSize intrinsicTileSize = size();
+#endif
     if (hasRelativeWidth())
         intrinsicTileSize.setWidth(scaledTileSize.width());
     if (hasRelativeHeight())
@@ -257,7 +261,11 @@
 
 void Image::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
 {
+#if PLATFORM(IOS)
+    intrinsicRatio = originalSize();
+#else
     intrinsicRatio = size();
+#endif
     intrinsicWidth = Length(intrinsicRatio.width(), Fixed);
     intrinsicHeight = Length(intrinsicRatio.height(), Fixed);
 }

Modified: trunk/Source/WebCore/platform/graphics/Image.h (171118 => 171119)


--- trunk/Source/WebCore/platform/graphics/Image.h	2014-07-15 21:32:20 UTC (rev 171118)
+++ trunk/Source/WebCore/platform/graphics/Image.h	2014-07-15 22:25:50 UTC (rev 171119)
@@ -103,6 +103,10 @@
     float height() const { return size().height(); }
     virtual bool getHotSpot(IntPoint&) const { return false; }
 
+#if PLATFORM(IOS)
+    virtual FloatSize originalSize() const { return size(); }
+#endif
+
     bool setData(PassRefPtr<SharedBuffer> data, bool allDataReceived);
     virtual bool dataChanged(bool /*allDataReceived*/) { return false; }
     

Modified: trunk/Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp (171118 => 171119)


--- trunk/Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp	2014-07-15 21:32:20 UTC (rev 171118)
+++ trunk/Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp	2014-07-15 22:25:50 UTC (rev 171119)
@@ -101,11 +101,11 @@
 
     // Since we don't have a decoder, we can't figure out the image orientation.
     // Set m_sizeRespectingOrientation to be the same as m_size so it's not 0x0.
-    m_sizeRespectingOrientation = IntSize(width, height);
+    m_sizeRespectingOrientation = m_size;
 
 #if PLATFORM(IOS)
-    m_originalSize = IntSize(width, height);
-    m_originalSizeRespectingOrientation = IntSize(width, height);
+    m_originalSize = m_size;
+    m_originalSizeRespectingOrientation = m_size;
 #endif
 
     m_frames.grow(1);
@@ -202,7 +202,7 @@
     FloatRect srcRectForCurrentFrame = srcRect;
 
 #if PLATFORM(IOS)
-    if (m_originalSize.width() && m_originalSize.height())
+    if (m_originalSize != m_size && !m_originalSize.isEmpty())
         srcRectForCurrentFrame.scale(m_size.width() / static_cast<float>(m_originalSize.width()), m_size.height() / static_cast<float>(m_originalSize.height()));
 
     startAnimation(DoNotCatchUp);

Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp (171118 => 171119)


--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp	2014-07-15 21:32:20 UTC (rev 171118)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp	2014-07-15 22:25:50 UTC (rev 171119)
@@ -335,9 +335,9 @@
 #if PLATFORM(IOS)
         float scaleHint = 1;
         if (m_image->isBitmapImage()) {
-            IntSize originalSize = toBitmapImage(m_image)->originalSize();
-            if (originalSize.width() && originalSize.height())
-                scaleHint = std::min<float>(1.0f, std::max(m_image->size().width() / originalSize.width(), m_image->size().width() / originalSize.height()));
+            FloatSize originalSize = toBitmapImage(m_image)->originalSize();
+            if (!originalSize.isEmpty())
+                scaleHint = std::min<float>(1, std::max(m_image->size().width() / originalSize.width(), m_image->size().width() / originalSize.height()));
         }
         m_decodedImage = adoptCF(decoder.createFrameAtIndex(0, &scaleHint));
 #else

Modified: trunk/Source/WebCore/platform/graphics/cg/ImageCG.cpp (171118 => 171119)


--- trunk/Source/WebCore/platform/graphics/cg/ImageCG.cpp	2014-07-15 21:32:20 UTC (rev 171118)
+++ trunk/Source/WebCore/platform/graphics/cg/ImageCG.cpp	2014-07-15 22:25:50 UTC (rev 171119)
@@ -116,7 +116,12 @@
     float h = CGImageGetHeight(tileImage);
 
     RetainPtr<CGImageRef> subImage;
-    if (tileRect.size() == size())
+#if PLATFORM(IOS)
+    FloatSize imageSize = originalSize();
+#else
+    FloatSize imageSize = size();
+#endif
+    if (tileRect.size() == imageSize)
         subImage = tileImage;
     else {
         // Copying a sub-image out of a partially-decoded image stops the decoding of the original image. It should never happen
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to