<!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>[204983] trunk</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/204983">204983</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-08-25 12:18:29 -0700 (Thu, 25 Aug 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>REGRESSION (<a href="http://trac.webkit.org/projects/webkit/changeset/203378">r203378</a>): [iOS] The PDF image is rendered stretched if a sub image of it is cached first
https://bugs.webkit.org/show_bug.cgi?id=160617

Patch by Said Abou-Hallawa &lt;sabouhallawa@apple.com&gt; on 2016-08-25
Reviewed by Tim Horton.

Source/WebCore:

When caching only a sub-image of the PDF ensure the source rectangle starts
at the top-left of the cached sub-image rectangle. When drawing the cached
sub-image to the destination context ensure the destination rectangle is the
sub-image rectangle so no stretching or shrinking happens.

Test: fast/images/cached-clipped-pdf.html

* page/Settings.cpp:
(WebCore::Settings::Settings):
(WebCore::Settings::setCachedPDFImageEnabled): Deleted.
* page/Settings.h:
(WebCore::Settings::isCachedPDFImageEnabled): Deleted.
* page/Settings.in:
Change the boolean setting CachedPDFImageEnabled to be enum property and
rename it PDFImageCachingPolicy. Allow the &quot;PDFImageCachingBelowMemoryLimit&quot;
option to be available on a;; platforms. The &quot;PDFImageCachingClipBoundsOnly&quot;
option is added for testing purpose. If forces recaching the PDF with each
draw and it sets the cached image rectangle to the clipping rectangle.

* platform/graphics/cg/PDFDocumentImage.cpp:
(WebCore::PDFDocumentImage::setPdfImageCachingPolicy): Take an enum instead of boolean.
(WebCore::cachedImageRect):
(WebCore::PDFDocumentImage::decodedSizeChanged): Enable PDFImageCachingBelowMemoryLimit
on all platforms.
(WebCore::PDFDocumentImage::updateCachedImageIfNeeded): Fix the source rectangle
when caching a sub-image of the PDF.
(WebCore::PDFDocumentImage::draw): Fix the destination rectangle when drawing
a sub-image to the destination context.
(WebCore::PDFDocumentImage::setCachedPDFImageEnabled): Deleted.
* platform/graphics/cg/PDFDocumentImage.h:

* rendering/RenderImage.cpp:
(WebCore::RenderImage::paintIntoRect):

* testing/InternalSettings.cpp:
(WebCore::InternalSettings::Backup::Backup):
(WebCore::InternalSettings::Backup::restoreTo):
(WebCore::InternalSettings::setPDFImageCachingPolicy):
(WebCore::InternalSettings::setCachedPDFImageEnabled): Deleted.
* testing/InternalSettings.h:
* testing/InternalSettings.idl:
Change the internal setting CachedPDFImageEnabled to PDFImageCachingPolicy.

LayoutTests:

* fast/images/cached-clipped-pdf-expected.html: Added.
* fast/images/cached-clipped-pdf.html: Added.
* fast/images/displaced-non-cached-pdf.html:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsfastimagesdisplacednoncachedpdfhtml">trunk/LayoutTests/fast/images/displaced-non-cached-pdf.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorepageSettingscpp">trunk/Source/WebCore/page/Settings.cpp</a></li>
<li><a href="#trunkSourceWebCorepageSettingsh">trunk/Source/WebCore/page/Settings.h</a></li>
<li><a href="#trunkSourceWebCorepageSettingsin">trunk/Source/WebCore/page/Settings.in</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscgPDFDocumentImagecpp">trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscgPDFDocumentImageh">trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderImagecpp">trunk/Source/WebCore/rendering/RenderImage.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalSettingscpp">trunk/Source/WebCore/testing/InternalSettings.cpp</a></li>
<li><a href="#trunkSourceWebCoretestingInternalSettingsh">trunk/Source/WebCore/testing/InternalSettings.h</a></li>
<li><a href="#trunkSourceWebCoretestingInternalSettingsidl">trunk/Source/WebCore/testing/InternalSettings.idl</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsfastimagescachedclippedpdfexpectedhtml">trunk/LayoutTests/fast/images/cached-clipped-pdf-expected.html</a></li>
<li><a href="#trunkLayoutTestsfastimagescachedclippedpdfhtml">trunk/LayoutTests/fast/images/cached-clipped-pdf.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (204982 => 204983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-08-25 19:02:10 UTC (rev 204982)
+++ trunk/LayoutTests/ChangeLog        2016-08-25 19:18:29 UTC (rev 204983)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2016-08-25  Said Abou-Hallawa  &lt;sabouhallawa@apple.com&gt;
+
+        REGRESSION (r203378): [iOS] The PDF image is rendered stretched if a sub image of it is cached first
+        https://bugs.webkit.org/show_bug.cgi?id=160617
+
+        Reviewed by Tim Horton.
+
+        * fast/images/cached-clipped-pdf-expected.html: Added.
+        * fast/images/cached-clipped-pdf.html: Added.
+        * fast/images/displaced-non-cached-pdf.html:
+
</ins><span class="cx"> 2016-08-25  Ryan Haddad  &lt;ryanhaddad@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Skipping imported/w3c/web-platform-tests/url/url-setters.html because it asserts.
</span></span></pre></div>
<a id="trunkLayoutTestsfastimagescachedclippedpdfexpectedhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/images/cached-clipped-pdf-expected.html (0 => 204983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/images/cached-clipped-pdf-expected.html                                (rev 0)
+++ trunk/LayoutTests/fast/images/cached-clipped-pdf-expected.html        2016-08-25 19:18:29 UTC (rev 204983)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+&lt;style&gt;
+    img {
+        width: 200px;
+        height: 200px;
+    }
+&lt;/style&gt;
+&lt;img src=&quot;resources/green_rectangle.pdf&quot;&gt;
+&lt;script&gt;
+    if (window.testRunner &amp;&amp; window.internals)
+        window.internals.settings.setPDFImageCachingPolicy(&quot;enabled&quot;);
+&lt;/script&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastimagescachedclippedpdfhtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/images/cached-clipped-pdf.html (0 => 204983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/images/cached-clipped-pdf.html                                (rev 0)
+++ trunk/LayoutTests/fast/images/cached-clipped-pdf.html        2016-08-25 19:18:29 UTC (rev 204983)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+&lt;style&gt;
+    img {
+        width: 200px;
+        height: 200px;
+    }
+&lt;/style&gt;
+&lt;img src=&quot;resources/green_rectangle.pdf&quot;&gt;
+&lt;script&gt;
+    if (window.testRunner &amp;&amp; window.internals)
+        window.internals.settings.setPDFImageCachingPolicy(&quot;clipBoundsOnly&quot;);
+&lt;/script&gt;
</ins></span></pre></div>
<a id="trunkLayoutTestsfastimagesdisplacednoncachedpdfhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/fast/images/displaced-non-cached-pdf.html (204982 => 204983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/images/displaced-non-cached-pdf.html        2016-08-25 19:02:10 UTC (rev 204982)
+++ trunk/LayoutTests/fast/images/displaced-non-cached-pdf.html        2016-08-25 19:18:29 UTC (rev 204983)
</span><span class="lines">@@ -3,7 +3,7 @@
</span><span class="cx"> &lt;body&gt;
</span><span class="cx">     &lt;script&gt;
</span><span class="cx">         if (window.testRunner &amp;&amp; window.internals)
</span><del>-            window.internals.settings.setCachedPDFImageEnabled(false);
</del><ins>+            window.internals.settings.setPDFImageCachingPolicy(&quot;disabled&quot;);
</ins><span class="cx">     &lt;/script&gt;
</span><span class="cx">     &lt;img src=&quot;resources/green_rectangle.pdf&quot;&gt;
</span><span class="cx">     &lt;img src=&quot;resources/green_rectangle.pdf&quot;&gt;
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (204982 => 204983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-08-25 19:02:10 UTC (rev 204982)
+++ trunk/Source/WebCore/ChangeLog        2016-08-25 19:18:29 UTC (rev 204983)
</span><span class="lines">@@ -1,3 +1,53 @@
</span><ins>+2016-08-25  Said Abou-Hallawa  &lt;sabouhallawa@apple.com&gt;
+
+        REGRESSION (r203378): [iOS] The PDF image is rendered stretched if a sub image of it is cached first
+        https://bugs.webkit.org/show_bug.cgi?id=160617
+
+        Reviewed by Tim Horton.
+
+        When caching only a sub-image of the PDF ensure the source rectangle starts
+        at the top-left of the cached sub-image rectangle. When drawing the cached 
+        sub-image to the destination context ensure the destination rectangle is the
+        sub-image rectangle so no stretching or shrinking happens.
+
+        Test: fast/images/cached-clipped-pdf.html
+
+        * page/Settings.cpp:
+        (WebCore::Settings::Settings):
+        (WebCore::Settings::setCachedPDFImageEnabled): Deleted.
+        * page/Settings.h:
+        (WebCore::Settings::isCachedPDFImageEnabled): Deleted.
+        * page/Settings.in:
+        Change the boolean setting CachedPDFImageEnabled to be enum property and
+        rename it PDFImageCachingPolicy. Allow the &quot;PDFImageCachingBelowMemoryLimit&quot;
+        option to be available on a;; platforms. The &quot;PDFImageCachingClipBoundsOnly&quot;
+        option is added for testing purpose. If forces recaching the PDF with each
+        draw and it sets the cached image rectangle to the clipping rectangle.
+        
+        * platform/graphics/cg/PDFDocumentImage.cpp:
+        (WebCore::PDFDocumentImage::setPdfImageCachingPolicy): Take an enum instead of boolean.
+        (WebCore::cachedImageRect): 
+        (WebCore::PDFDocumentImage::decodedSizeChanged): Enable PDFImageCachingBelowMemoryLimit
+        on all platforms.
+        (WebCore::PDFDocumentImage::updateCachedImageIfNeeded): Fix the source rectangle
+        when caching a sub-image of the PDF.
+        (WebCore::PDFDocumentImage::draw): Fix the destination rectangle when drawing
+        a sub-image to the destination context.
+        (WebCore::PDFDocumentImage::setCachedPDFImageEnabled): Deleted.
+        * platform/graphics/cg/PDFDocumentImage.h:
+        
+        * rendering/RenderImage.cpp:
+        (WebCore::RenderImage::paintIntoRect):
+        
+        * testing/InternalSettings.cpp:
+        (WebCore::InternalSettings::Backup::Backup):
+        (WebCore::InternalSettings::Backup::restoreTo):
+        (WebCore::InternalSettings::setPDFImageCachingPolicy):
+        (WebCore::InternalSettings::setCachedPDFImageEnabled): Deleted.
+        * testing/InternalSettings.h:
+        * testing/InternalSettings.idl:
+        Change the internal setting CachedPDFImageEnabled to PDFImageCachingPolicy.
+
</ins><span class="cx"> 2016-08-25  Zalan Bujtas  &lt;zalan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Infinite recursion crash in WebCore::RenderBlockFlow::layoutBlock
</span></span></pre></div>
<a id="trunkSourceWebCorepageSettingscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Settings.cpp (204982 => 204983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Settings.cpp        2016-08-25 19:02:10 UTC (rev 204982)
+++ trunk/Source/WebCore/page/Settings.cpp        2016-08-25 19:18:29 UTC (rev 204983)
</span><span class="lines">@@ -192,7 +192,6 @@
</span><span class="cx">     , m_loadsImagesAutomatically(false)
</span><span class="cx">     , m_areImagesEnabled(true)
</span><span class="cx">     , m_preferMIMETypeForImages(false)
</span><del>-    , m_isCachedPDFImageEnabled(true)
</del><span class="cx">     , m_arePluginsEnabled(false)
</span><span class="cx">     , m_isScriptEnabled(false)
</span><span class="cx">     , m_needsAdobeFrameReloadingQuirk(false)
</span><span class="lines">@@ -425,11 +424,6 @@
</span><span class="cx">     m_preferMIMETypeForImages = preferMIMETypeForImages;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void Settings::setCachedPDFImageEnabled(bool isCachedPDFImageEnabled)
-{
-    m_isCachedPDFImageEnabled = isCachedPDFImageEnabled;
-}
-
</del><span class="cx"> void Settings::setForcePendingWebGLPolicy(bool forced)
</span><span class="cx"> {
</span><span class="cx">     m_forcePendingWebGLPolicy = forced;
</span></span></pre></div>
<a id="trunkSourceWebCorepageSettingsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Settings.h (204982 => 204983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Settings.h        2016-08-25 19:02:10 UTC (rev 204982)
+++ trunk/Source/WebCore/page/Settings.h        2016-08-25 19:18:29 UTC (rev 204983)
</span><span class="lines">@@ -76,6 +76,18 @@
</span><span class="cx">     System
</span><span class="cx"> };
</span><span class="cx"> 
</span><ins>+enum PDFImageCachingPolicy {
+    PDFImageCachingEnabled,
+    PDFImageCachingBelowMemoryLimit,
+    PDFImageCachingDisabled,
+    PDFImageCachingClipBoundsOnly,
+#if PLATFORM(IOS)
+    PDFImageCachingDefault = PDFImageCachingBelowMemoryLimit
+#else
+    PDFImageCachingDefault = PDFImageCachingEnabled
+#endif
+};
+
</ins><span class="cx"> typedef unsigned DebugOverlayRegions;
</span><span class="cx"> 
</span><span class="cx"> class Settings : public RefCounted&lt;Settings&gt; {
</span><span class="lines">@@ -145,9 +157,6 @@
</span><span class="cx">     WEBCORE_EXPORT void setPreferMIMETypeForImages(bool);
</span><span class="cx">     bool preferMIMETypeForImages() const { return m_preferMIMETypeForImages; }
</span><span class="cx"> 
</span><del>-    WEBCORE_EXPORT void setCachedPDFImageEnabled(bool);
-    bool isCachedPDFImageEnabled() const { return m_isCachedPDFImageEnabled; }
-
</del><span class="cx">     WEBCORE_EXPORT void setPluginsEnabled(bool);
</span><span class="cx">     bool arePluginsEnabled() const { return m_arePluginsEnabled; }
</span><span class="cx"> 
</span><span class="lines">@@ -327,7 +336,6 @@
</span><span class="cx">     bool m_loadsImagesAutomatically : 1;
</span><span class="cx">     bool m_areImagesEnabled : 1;
</span><span class="cx">     bool m_preferMIMETypeForImages : 1;
</span><del>-    bool m_isCachedPDFImageEnabled : 1;
</del><span class="cx">     bool m_arePluginsEnabled : 1;
</span><span class="cx">     bool m_isScriptEnabled : 1;
</span><span class="cx">     bool m_needsAdobeFrameReloadingQuirk : 1;
</span></span></pre></div>
<a id="trunkSourceWebCorepageSettingsin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/Settings.in (204982 => 204983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/Settings.in        2016-08-25 19:02:10 UTC (rev 204982)
+++ trunk/Source/WebCore/page/Settings.in        2016-08-25 19:18:29 UTC (rev 204983)
</span><span class="lines">@@ -6,6 +6,7 @@
</span><span class="cx"> localStorageDatabasePath type=String
</span><span class="cx"> editableLinkBehavior type=EditableLinkBehavior, initial=EditableLinkDefaultBehavior
</span><span class="cx"> textDirectionSubmenuInclusionBehavior type=TextDirectionSubmenuInclusionBehavior, initial=TextDirectionSubmenuAutomaticallyIncluded
</span><ins>+pdfImageCachingPolicy type=PDFImageCachingPolicy, initial = PDFImageCachingDefault
</ins><span class="cx"> passwordEchoDurationInSeconds type=double, initial=1
</span><span class="cx"> 
</span><span class="cx"> # Sets the magnification value for validation message timer.  If the
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscgPDFDocumentImagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp (204982 => 204983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp        2016-08-25 19:02:10 UTC (rev 204982)
+++ trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp        2016-08-25 19:18:29 UTC (rev 204983)
</span><span class="lines">@@ -100,13 +100,13 @@
</span><span class="cx">     return m_document; // Return true if size is available.
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void PDFDocumentImage::setCachedPDFImageEnabled(bool enabled)
</del><ins>+void PDFDocumentImage::setPdfImageCachingPolicy(PDFImageCachingPolicy pdfImageCachingPolicy)
</ins><span class="cx"> {
</span><del>-    if (m_isCachedPDFImageEnabled == enabled)
</del><ins>+    if (m_pdfImageCachingPolicy == pdfImageCachingPolicy)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (!(m_isCachedPDFImageEnabled = enabled))
-        destroyDecodedData();
</del><ins>+    m_pdfImageCachingPolicy = pdfImageCachingPolicy;
+    destroyDecodedData();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool PDFDocumentImage::cacheParametersMatch(GraphicsContext&amp; context, const FloatRect&amp; dstRect, const FloatRect&amp; srcRect) const
</span><span class="lines">@@ -157,7 +157,6 @@
</span><span class="cx">     context.translate(0, -srcRect.height());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if PLATFORM(IOS)
</del><span class="cx"> // To avoid the jetsam on iOS, we are going to limit the size of all the PDF cachedImages to be 64MB.
</span><span class="cx"> static const size_t s_maxCachedImageSide = 4 * 1024;
</span><span class="cx"> static const size_t s_maxCachedImageArea = s_maxCachedImageSide * s_maxCachedImageSide;
</span><span class="lines">@@ -167,19 +166,15 @@
</span><span class="cx"> 
</span><span class="cx"> static FloatRect cachedImageRect(GraphicsContext&amp; context, const FloatRect&amp; dstRect)
</span><span class="cx"> {
</span><ins>+    FloatRect dirtyRect = context.clipBounds();
+
+    // Calculate the maximum rectangle we can cache around the center of the clipping bounds.
</ins><span class="cx">     FloatSize maxSize = s_maxCachedImageSide / context.scaleFactor();
</span><ins>+    FloatPoint minLocation = FloatPoint(dirtyRect.center() - maxSize / 2);
</ins><span class="cx"> 
</span><del>-    // Expand from the center of the dirty rectangle.
-    FloatRect rect = context.clipBounds();
-    rect.setX(std::max(rect.center().x() - maxSize.width() / 2, dstRect.x()));
-    rect.setY(std::max(rect.center().y() - maxSize.height() / 2, dstRect.y()));
-
-    // Cover as much as we could from the dstRect.
-    rect.setWidth(std::min(maxSize.width(), dstRect.width()));
-    rect.setHeight(std::min(maxSize.height(), dstRect.height()));
-    return rect;
</del><ins>+    // Ensure the clipping bounds are all included but within the bounds of the dstRect
+    return intersection(unionRect(dirtyRect, FloatRect(minLocation, maxSize)), dstRect);
</ins><span class="cx"> }
</span><del>-#endif
</del><span class="cx"> 
</span><span class="cx"> void PDFDocumentImage::decodedSizeChanged(size_t newCachedBytes)
</span><span class="cx"> {
</span><span class="lines">@@ -189,12 +184,10 @@
</span><span class="cx">     if (imageObserver())
</span><span class="cx">         imageObserver()-&gt;decodedSizeChanged(this, -safeCast&lt;int&gt;(m_cachedBytes) + newCachedBytes);
</span><span class="cx"> 
</span><del>-#if PLATFORM(IOS)
</del><span class="cx">     ASSERT(s_allDecodedDataSize &gt;= m_cachedBytes);
</span><span class="cx">     // Update with the difference in two steps to avoid unsigned underflow subtraction.
</span><span class="cx">     s_allDecodedDataSize -= m_cachedBytes;
</span><span class="cx">     s_allDecodedDataSize += newCachedBytes;
</span><del>-#endif
</del><span class="cx"> 
</span><span class="cx">     m_cachedBytes = newCachedBytes;
</span><span class="cx"> }
</span><span class="lines">@@ -215,28 +208,38 @@
</span><span class="cx">     bool repaintIfNecessary = interpolationQuality != InterpolationNone &amp;&amp; interpolationQuality != InterpolationLow;
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    if (!m_isCachedPDFImageEnabled || (m_cachedImageBuffer &amp;&amp; (!repaintIfNecessary || cacheParametersMatch(context, dstRect, srcRect))))
</del><ins>+    // Clipped option is for testing only. Force recaching the PDF with each draw.
+    if (m_pdfImageCachingPolicy != PDFImageCachingClipBoundsOnly) {
+        if (m_cachedImageBuffer &amp;&amp; (!repaintIfNecessary || cacheParametersMatch(context, dstRect, srcRect)))
+            return;
+    }
+
+    switch (m_pdfImageCachingPolicy) {
+    case PDFImageCachingDisabled:
</ins><span class="cx">         return;
</span><ins>+    case PDFImageCachingBelowMemoryLimit:
+        // Keep the memory used by the cached image below some threshold, otherwise WebKit process
+        // will jetsam if it exceeds its memory limit. Only a rectangle from the PDF may be cached.
+        m_cachedImageRect = cachedImageRect(context, dstRect);
+        break;
+    case PDFImageCachingClipBoundsOnly:
+        m_cachedImageRect = context.clipBounds();
+        break;
+    case PDFImageCachingEnabled:
+        m_cachedImageRect = dstRect;
+        break;
+    }
</ins><span class="cx"> 
</span><del>-#if PLATFORM(IOS)
-    // Keep the memory used by the cached image below some threshold, otherwise WebKit process
-    // will jetsam if it exceeds its memory limit. Only a rectangle from the PDF may be cached.
-    m_cachedImageRect = cachedImageRect(context, dstRect);
-#else
-    m_cachedImageRect = dstRect;
-#endif
-
</del><span class="cx">     FloatSize cachedImageSize = FloatRect(enclosingIntRect(m_cachedImageRect)).size();
</span><span class="cx"> 
</span><del>-#if PLATFORM(IOS)
-    IntSize scaledSize = ImageBuffer::compatibleBufferSize(cachedImageSize, context);
-
</del><span class="cx">     // Cache the PDF image only if the size of the new image won't exceed the cache threshold.
</span><del>-    if (s_allDecodedDataSize + safeCast&lt;size_t&gt;(scaledSize.width()) * scaledSize.height() * 4 - m_cachedBytes &gt; s_maxDecodedDataSize) {
-        destroyDecodedData();
-        return;
</del><ins>+    if (m_pdfImageCachingPolicy == PDFImageCachingBelowMemoryLimit) {
+        IntSize scaledSize = ImageBuffer::compatibleBufferSize(cachedImageSize, context);
+        if (s_allDecodedDataSize + safeCast&lt;size_t&gt;(scaledSize.width()) * scaledSize.height() * 4 - m_cachedBytes &gt; s_maxDecodedDataSize) {
+            destroyDecodedData();
+            return;
+        }
</ins><span class="cx">     }
</span><del>-#endif
</del><span class="cx"> 
</span><span class="cx">     m_cachedImageBuffer = ImageBuffer::createCompatibleBuffer(cachedImageSize, context);
</span><span class="cx">     if (!m_cachedImageBuffer) {
</span><span class="lines">@@ -245,8 +248,10 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     auto&amp; bufferContext = m_cachedImageBuffer-&gt;context();
</span><del>-    // The PDF cachedImage should be drawn at (0, 0) always.
-    transformContextForPainting(bufferContext, FloatRect({ }, dstRect.size()), srcRect);
</del><ins>+    // We need to transform the coordinate system such that top-left of m_cachedImageRect will be mapped to the
+    // top-left of dstRect. Although only m_cachedImageRect.size() of the image copied, the sizes of srcRect
+    // and dstRect should be passed to this function because they are used to calculate the image scaling.
+    transformContextForPainting(bufferContext, dstRect, FloatRect(m_cachedImageRect.location(), srcRect.size()));
</ins><span class="cx">     drawPDFPage(bufferContext);
</span><span class="cx"> 
</span><span class="cx">     m_cachedTransform = context.getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
</span><span class="lines">@@ -268,8 +273,13 @@
</span><span class="cx">         GraphicsContextStateSaver stateSaver(context);
</span><span class="cx">         context.setCompositeOperation(op);
</span><span class="cx"> 
</span><del>-        if (m_cachedImageBuffer)
-            context.drawImageBuffer(*m_cachedImageBuffer, dstRect);
</del><ins>+        if (m_cachedImageBuffer) {
+            // Draw the ImageBuffer 'm_cachedImageBuffer' to the rectangle 'm_cachedImageRect'
+            // on the destination context. Since the pixels of the rectangle 'm_cachedImageRect'
+            // of the source PDF was copied to 'm_cachedImageBuffer', the sizes of the source
+            // and the destination rectangles will be equal and no scaling will be needed here.
+            context.drawImageBuffer(*m_cachedImageBuffer, m_cachedImageRect);
+        }
</ins><span class="cx">         else {
</span><span class="cx">             transformContextForPainting(context, dstRect, srcRect);
</span><span class="cx">             drawPDFPage(context);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscgPDFDocumentImageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.h (204982 => 204983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.h        2016-08-25 19:02:10 UTC (rev 204982)
+++ trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.h        2016-08-25 19:18:29 UTC (rev 204983)
</span><span class="lines">@@ -30,6 +30,7 @@
</span><span class="cx"> #include &quot;FloatRect.h&quot;
</span><span class="cx"> #include &quot;GraphicsTypes.h&quot;
</span><span class="cx"> #include &quot;Image.h&quot;
</span><ins>+#include &quot;Settings.h&quot;
</ins><span class="cx"> 
</span><span class="cx"> #if USE(CG)
</span><span class="cx"> 
</span><span class="lines">@@ -52,7 +53,7 @@
</span><span class="cx">         return adoptRef(new PDFDocumentImage(observer));
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    void setCachedPDFImageEnabled(bool);
</del><ins>+    void setPdfImageCachingPolicy(PDFImageCachingPolicy);
</ins><span class="cx"> 
</span><span class="cx"> private:
</span><span class="cx">     PDFDocumentImage(ImageObserver*);
</span><span class="lines">@@ -87,7 +88,7 @@
</span><span class="cx">     void updateCachedImageIfNeeded(GraphicsContext&amp;, const FloatRect&amp; dstRect, const FloatRect&amp; srcRect);
</span><span class="cx">     bool cacheParametersMatch(GraphicsContext&amp;, const FloatRect&amp; dstRect, const FloatRect&amp; srcRect) const;
</span><span class="cx"> 
</span><del>-    bool m_isCachedPDFImageEnabled { true };
</del><ins>+    PDFImageCachingPolicy m_pdfImageCachingPolicy { PDFImageCachingDefault };
</ins><span class="cx"> 
</span><span class="cx"> #if USE(PDFKIT_FOR_PDFDOCUMENTIMAGE)
</span><span class="cx">     RetainPtr&lt;PDFDocument&gt; m_document;
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderImagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderImage.cpp (204982 => 204983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderImage.cpp        2016-08-25 19:02:10 UTC (rev 204982)
+++ trunk/Source/WebCore/rendering/RenderImage.cpp        2016-08-25 19:18:29 UTC (rev 204983)
</span><span class="lines">@@ -552,7 +552,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if USE(CG)
</span><span class="cx">     if (is&lt;PDFDocumentImage&gt;(image))
</span><del>-        downcast&lt;PDFDocumentImage&gt;(*image).setCachedPDFImageEnabled(frame().settings().isCachedPDFImageEnabled());
</del><ins>+        downcast&lt;PDFDocumentImage&gt;(*image).setPdfImageCachingPolicy(frame().settings().pdfImageCachingPolicy());
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     ImageOrientationDescription orientationDescription(shouldRespectImageOrientation(), style().imageOrientation());
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalSettingscpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/InternalSettings.cpp (204982 => 204983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/InternalSettings.cpp        2016-08-25 19:02:10 UTC (rev 204982)
+++ trunk/Source/WebCore/testing/InternalSettings.cpp        2016-08-25 19:18:29 UTC (rev 204983)
</span><span class="lines">@@ -80,7 +80,6 @@
</span><span class="cx">     , m_langAttributeAwareFormControlUIEnabled(RuntimeEnabledFeatures::sharedFeatures().langAttributeAwareFormControlUIEnabled())
</span><span class="cx">     , m_imagesEnabled(settings.areImagesEnabled())
</span><span class="cx">     , m_preferMIMETypeForImages(settings.preferMIMETypeForImages())
</span><del>-    , m_cachedPDFImageEnabled(settings.isCachedPDFImageEnabled())
</del><span class="cx">     , m_minimumTimerInterval(settings.minimumDOMTimerInterval())
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx">     , m_shouldDisplaySubtitles(settings.shouldDisplaySubtitles())
</span><span class="lines">@@ -113,6 +112,7 @@
</span><span class="cx"> #endif
</span><span class="cx">     , m_userInterfaceDirectionPolicy(settings.userInterfaceDirectionPolicy())
</span><span class="cx">     , m_systemLayoutDirection(settings.systemLayoutDirection())
</span><ins>+    , m_pdfImageCachingPolicy(settings.pdfImageCachingPolicy())
</ins><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -160,7 +160,6 @@
</span><span class="cx">     RuntimeEnabledFeatures::sharedFeatures().setLangAttributeAwareFormControlUIEnabled(m_langAttributeAwareFormControlUIEnabled);
</span><span class="cx">     settings.setImagesEnabled(m_imagesEnabled);
</span><span class="cx">     settings.setPreferMIMETypeForImages(m_preferMIMETypeForImages);
</span><del>-    settings.setCachedPDFImageEnabled(m_cachedPDFImageEnabled);
</del><span class="cx">     settings.setMinimumDOMTimerInterval(m_minimumTimerInterval);
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx">     settings.setShouldDisplaySubtitles(m_shouldDisplaySubtitles);
</span><span class="lines">@@ -190,6 +189,7 @@
</span><span class="cx"> #endif
</span><span class="cx">     settings.setUserInterfaceDirectionPolicy(m_userInterfaceDirectionPolicy);
</span><span class="cx">     settings.setSystemLayoutDirection(m_systemLayoutDirection);
</span><ins>+    settings.setPdfImageCachingPolicy(m_pdfImageCachingPolicy);
</ins><span class="cx">     Settings::setAllowsAnySSLCertificate(false);
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -485,10 +485,19 @@
</span><span class="cx">     settings()-&gt;setImagesEnabled(enabled);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void InternalSettings::setCachedPDFImageEnabled(bool enabled, ExceptionCode&amp; ec)
</del><ins>+void InternalSettings::setPDFImageCachingPolicy(const String&amp; policy, ExceptionCode&amp; ec)
</ins><span class="cx"> {
</span><span class="cx">     InternalSettingsGuardForSettings();
</span><del>-    settings()-&gt;setCachedPDFImageEnabled(enabled);
</del><ins>+    if (equalLettersIgnoringASCIICase(policy, &quot;disabled&quot;))
+        settings()-&gt;setPdfImageCachingPolicy(PDFImageCachingDisabled);
+    else if (equalLettersIgnoringASCIICase(policy, &quot;belowmemorylimit&quot;))
+        settings()-&gt;setPdfImageCachingPolicy(PDFImageCachingBelowMemoryLimit);
+    else if (equalLettersIgnoringASCIICase(policy, &quot;clipboundsonly&quot;))
+        settings()-&gt;setPdfImageCachingPolicy(PDFImageCachingClipBoundsOnly);
+    else if (equalLettersIgnoringASCIICase(policy, &quot;enabled&quot;))
+        settings()-&gt;setPdfImageCachingPolicy(PDFImageCachingEnabled);
+    else
+        ec = SYNTAX_ERR;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void InternalSettings::setMinimumTimerInterval(double intervalInSeconds, ExceptionCode&amp; ec)
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalSettingsh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/InternalSettings.h (204982 => 204983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/InternalSettings.h        2016-08-25 19:02:10 UTC (rev 204982)
+++ trunk/Source/WebCore/testing/InternalSettings.h        2016-08-25 19:18:29 UTC (rev 204983)
</span><span class="lines">@@ -80,7 +80,6 @@
</span><span class="cx">         bool m_langAttributeAwareFormControlUIEnabled;
</span><span class="cx">         bool m_imagesEnabled;
</span><span class="cx">         bool m_preferMIMETypeForImages;
</span><del>-        bool m_cachedPDFImageEnabled;
</del><span class="cx">         std::chrono::milliseconds m_minimumTimerInterval;
</span><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx">         bool m_shouldDisplaySubtitles;
</span><span class="lines">@@ -113,6 +112,7 @@
</span><span class="cx"> #endif
</span><span class="cx">         UserInterfaceDirectionPolicy m_userInterfaceDirectionPolicy;
</span><span class="cx">         TextDirection m_systemLayoutDirection;
</span><ins>+        PDFImageCachingPolicy m_pdfImageCachingPolicy;
</ins><span class="cx">     };
</span><span class="cx"> 
</span><span class="cx">     static Ref&lt;InternalSettings&gt; create(Page* page)
</span><span class="lines">@@ -142,7 +142,7 @@
</span><span class="cx">     void setAllowsAirPlayForMediaPlayback(bool);
</span><span class="cx">     void setEditingBehavior(const String&amp;, ExceptionCode&amp;);
</span><span class="cx">     void setPreferMIMETypeForImages(bool, ExceptionCode&amp;);
</span><del>-    void setCachedPDFImageEnabled(bool, ExceptionCode&amp;);
</del><ins>+    void setPDFImageCachingPolicy(const String&amp;, ExceptionCode&amp;);
</ins><span class="cx">     void setShouldDisplayTrackKind(const String&amp; kind, bool enabled, ExceptionCode&amp;);
</span><span class="cx">     bool shouldDisplayTrackKind(const String&amp; kind, ExceptionCode&amp;);
</span><span class="cx">     void setStorageBlockingPolicy(const String&amp;, ExceptionCode&amp;);
</span></span></pre></div>
<a id="trunkSourceWebCoretestingInternalSettingsidl"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/testing/InternalSettings.idl (204982 => 204983)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/testing/InternalSettings.idl        2016-08-25 19:02:10 UTC (rev 204982)
+++ trunk/Source/WebCore/testing/InternalSettings.idl        2016-08-25 19:18:29 UTC (rev 204983)
</span><span class="lines">@@ -68,7 +68,7 @@
</span><span class="cx">     // Other switches
</span><span class="cx">     [RaisesException] void setStorageBlockingPolicy(DOMString policy);
</span><span class="cx">     [RaisesException] void setImagesEnabled(boolean enabled);
</span><del>-    [RaisesException] void setCachedPDFImageEnabled(boolean enabled);
</del><ins>+    [RaisesException] void setPDFImageCachingPolicy(DOMString policy);
</ins><span class="cx">     [RaisesException] void setUseLegacyBackgroundSizeShorthandBehavior(boolean enabled);
</span><span class="cx">     [RaisesException] void setAutoscrollForDragAndDropEnabled(boolean enabled);
</span><span class="cx">     [RaisesException] void setBackgroundShouldExtendBeyondPage(boolean hasExtendedBackground);
</span></span></pre>
</div>
</div>

</body>
</html>