<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[171119] trunk/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/171119">171119</a></dd>
<dt>Author</dt> <dd>simon.fraser@apple.com</dd>
<dt>Date</dt> <dd>2014-07-15 15:25:50 -0700 (Tue, 15 Jul 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>[iOS] Fix issues drawing subsampled image elements and CSS images
https://bugs.webkit.org/show_bug.cgi?id=134944
&lt;rdar://problem/17634095&gt;

Reviewed by Dean Jackson.

After <a href="http://trac.webkit.org/projects/webkit/changeset/170675">r170675</a> 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):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsBitmapImagecpp">trunk/Source/WebCore/platform/graphics/BitmapImage.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsBitmapImageh">trunk/Source/WebCore/platform/graphics/BitmapImage.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsGraphicsContextcpp">trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsImagecpp">trunk/Source/WebCore/platform/graphics/Image.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsImageh">trunk/Source/WebCore/platform/graphics/Image.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscgBitmapImageCGcpp">trunk/Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscgGraphicsContext3DCGcpp">trunk/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscgImageCGcpp">trunk/Source/WebCore/platform/graphics/cg/ImageCG.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (171118 => 171119)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,40 @@
</span><ins>+2014-07-15  Simon Fraser  &lt;simon.fraser@apple.com&gt;
+
+        [iOS] Fix issues drawing subsampled image elements and CSS images
+        https://bugs.webkit.org/show_bug.cgi?id=134944
+        &lt;rdar://problem/17634095&gt;
+
+        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):
+
</ins><span class="cx"> 2014-07-15  Brent Fulgham  &lt;bfulgham@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Win] Unreviewed build fix after r171069.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsBitmapImagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.cpp (171118 => 171119)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -261,7 +261,7 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><del>-IntSize BitmapImage::originalSize() const
</del><ins>+FloatSize BitmapImage::originalSize() const
</ins><span class="cx"> {
</span><span class="cx">     updateSize();
</span><span class="cx">     return m_originalSize;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsBitmapImageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.h (171118 => 171119)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -138,7 +138,7 @@
</span><span class="cx">     virtual FloatSize size() const override;
</span><span class="cx">     IntSize sizeRespectingOrientation(ImageOrientationDescription = ImageOrientationDescription()) const;
</span><span class="cx"> #if PLATFORM(IOS)
</span><del>-    virtual IntSize originalSize() const;
</del><ins>+    virtual FloatSize originalSize() const override;
</ins><span class="cx">     IntSize originalSizeRespectingOrientation() const;
</span><span class="cx"> #endif
</span><span class="cx">     IntSize currentFrameSize() const;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGraphicsContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp (171118 => 171119)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -581,7 +581,14 @@
</span><span class="cx"> {
</span><span class="cx">     if (!image)
</span><span class="cx">         return;
</span><del>-    drawImage(image, colorSpace, destination, FloatRect(FloatPoint(), image-&gt;size()), imagePaintingOptions);
</del><ins>+    
+#if PLATFORM(IOS)
+    FloatRect srcRect(FloatPoint(), image-&gt;originalSize());
+#else
+    FloatRect srcRect(FloatPoint(), image-&gt;size());
+#endif
+        
+    drawImage(image, colorSpace, destination, srcRect, imagePaintingOptions);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void GraphicsContext::drawImage(Image* image, ColorSpace colorSpace, const FloatRect&amp; destination, const FloatRect&amp; source, const ImagePaintingOptions&amp; imagePaintingOptions)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsImagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Image.cpp (171118 => 171119)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -103,7 +103,11 @@
</span><span class="cx"> 
</span><span class="cx">     ASSERT(!isBitmapImage() || notSolidColor());
</span><span class="cx"> 
</span><ins>+#if PLATFORM(IOS)
+    FloatSize intrinsicTileSize = originalSize();
+#else
</ins><span class="cx">     FloatSize intrinsicTileSize = size();
</span><ins>+#endif
</ins><span class="cx">     if (hasRelativeWidth())
</span><span class="cx">         intrinsicTileSize.setWidth(scaledTileSize.width());
</span><span class="cx">     if (hasRelativeHeight())
</span><span class="lines">@@ -257,7 +261,11 @@
</span><span class="cx"> 
</span><span class="cx"> void Image::computeIntrinsicDimensions(Length&amp; intrinsicWidth, Length&amp; intrinsicHeight, FloatSize&amp; intrinsicRatio)
</span><span class="cx"> {
</span><ins>+#if PLATFORM(IOS)
+    intrinsicRatio = originalSize();
+#else
</ins><span class="cx">     intrinsicRatio = size();
</span><ins>+#endif
</ins><span class="cx">     intrinsicWidth = Length(intrinsicRatio.width(), Fixed);
</span><span class="cx">     intrinsicHeight = Length(intrinsicRatio.height(), Fixed);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsImageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Image.h (171118 => 171119)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -103,6 +103,10 @@
</span><span class="cx">     float height() const { return size().height(); }
</span><span class="cx">     virtual bool getHotSpot(IntPoint&amp;) const { return false; }
</span><span class="cx"> 
</span><ins>+#if PLATFORM(IOS)
+    virtual FloatSize originalSize() const { return size(); }
+#endif
+
</ins><span class="cx">     bool setData(PassRefPtr&lt;SharedBuffer&gt; data, bool allDataReceived);
</span><span class="cx">     virtual bool dataChanged(bool /*allDataReceived*/) { return false; }
</span><span class="cx">     
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscgBitmapImageCGcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cg/BitmapImageCG.cpp (171118 => 171119)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -101,11 +101,11 @@
</span><span class="cx"> 
</span><span class="cx">     // Since we don't have a decoder, we can't figure out the image orientation.
</span><span class="cx">     // Set m_sizeRespectingOrientation to be the same as m_size so it's not 0x0.
</span><del>-    m_sizeRespectingOrientation = IntSize(width, height);
</del><ins>+    m_sizeRespectingOrientation = m_size;
</ins><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><del>-    m_originalSize = IntSize(width, height);
-    m_originalSizeRespectingOrientation = IntSize(width, height);
</del><ins>+    m_originalSize = m_size;
+    m_originalSizeRespectingOrientation = m_size;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     m_frames.grow(1);
</span><span class="lines">@@ -202,7 +202,7 @@
</span><span class="cx">     FloatRect srcRectForCurrentFrame = srcRect;
</span><span class="cx"> 
</span><span class="cx"> #if PLATFORM(IOS)
</span><del>-    if (m_originalSize.width() &amp;&amp; m_originalSize.height())
</del><ins>+    if (m_originalSize != m_size &amp;&amp; !m_originalSize.isEmpty())
</ins><span class="cx">         srcRectForCurrentFrame.scale(m_size.width() / static_cast&lt;float&gt;(m_originalSize.width()), m_size.height() / static_cast&lt;float&gt;(m_originalSize.height()));
</span><span class="cx"> 
</span><span class="cx">     startAnimation(DoNotCatchUp);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscgGraphicsContext3DCGcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContext3DCG.cpp (171118 => 171119)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -335,9 +335,9 @@
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx">         float scaleHint = 1;
</span><span class="cx">         if (m_image-&gt;isBitmapImage()) {
</span><del>-            IntSize originalSize = toBitmapImage(m_image)-&gt;originalSize();
-            if (originalSize.width() &amp;&amp; originalSize.height())
-                scaleHint = std::min&lt;float&gt;(1.0f, std::max(m_image-&gt;size().width() / originalSize.width(), m_image-&gt;size().width() / originalSize.height()));
</del><ins>+            FloatSize originalSize = toBitmapImage(m_image)-&gt;originalSize();
+            if (!originalSize.isEmpty())
+                scaleHint = std::min&lt;float&gt;(1, std::max(m_image-&gt;size().width() / originalSize.width(), m_image-&gt;size().width() / originalSize.height()));
</ins><span class="cx">         }
</span><span class="cx">         m_decodedImage = adoptCF(decoder.createFrameAtIndex(0, &amp;scaleHint));
</span><span class="cx"> #else
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscgImageCGcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cg/ImageCG.cpp (171118 => 171119)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -116,7 +116,12 @@
</span><span class="cx">     float h = CGImageGetHeight(tileImage);
</span><span class="cx"> 
</span><span class="cx">     RetainPtr&lt;CGImageRef&gt; subImage;
</span><del>-    if (tileRect.size() == size())
</del><ins>+#if PLATFORM(IOS)
+    FloatSize imageSize = originalSize();
+#else
+    FloatSize imageSize = size();
+#endif
+    if (tileRect.size() == imageSize)
</ins><span class="cx">         subImage = tileImage;
</span><span class="cx">     else {
</span><span class="cx">         // Copying a sub-image out of a partially-decoded image stops the decoding of the original image. It should never happen
</span></span></pre>
</div>
</div>

</body>
</html>