<!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 <sabouhallawa@apple.com> 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 "PDFImageCachingBelowMemoryLimit"
option to be available on a;; platforms. The "PDFImageCachingClipBoundsOnly"
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 <sabouhallawa@apple.com>
+
+ 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 <ryanhaddad@apple.com>
</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>+<style>
+ img {
+ width: 200px;
+ height: 200px;
+ }
+</style>
+<img src="resources/green_rectangle.pdf">
+<script>
+ if (window.testRunner && window.internals)
+ window.internals.settings.setPDFImageCachingPolicy("enabled");
+</script>
</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>+<style>
+ img {
+ width: 200px;
+ height: 200px;
+ }
+</style>
+<img src="resources/green_rectangle.pdf">
+<script>
+ if (window.testRunner && window.internals)
+ window.internals.settings.setPDFImageCachingPolicy("clipBoundsOnly");
+</script>
</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"> <body>
</span><span class="cx"> <script>
</span><span class="cx"> if (window.testRunner && window.internals)
</span><del>- window.internals.settings.setCachedPDFImageEnabled(false);
</del><ins>+ window.internals.settings.setPDFImageCachingPolicy("disabled");
</ins><span class="cx"> </script>
</span><span class="cx"> <img src="resources/green_rectangle.pdf">
</span><span class="cx"> <img src="resources/green_rectangle.pdf">
</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 <sabouhallawa@apple.com>
+
+ 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 "PDFImageCachingBelowMemoryLimit"
+ option to be available on a;; platforms. The "PDFImageCachingClipBoundsOnly"
+ 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 <zalan@apple.com>
</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<Settings> {
</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& context, const FloatRect& dstRect, const FloatRect& 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& context, const FloatRect& 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()->decodedSizeChanged(this, -safeCast<int>(m_cachedBytes) + newCachedBytes);
</span><span class="cx">
</span><del>-#if PLATFORM(IOS)
</del><span class="cx"> ASSERT(s_allDecodedDataSize >= 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 && interpolationQuality != InterpolationLow;
</span><span class="cx"> #endif
</span><span class="cx">
</span><del>- if (!m_isCachedPDFImageEnabled || (m_cachedImageBuffer && (!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 && (!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<size_t>(scaledSize.width()) * scaledSize.height() * 4 - m_cachedBytes > s_maxDecodedDataSize) {
- destroyDecodedData();
- return;
</del><ins>+ if (m_pdfImageCachingPolicy == PDFImageCachingBelowMemoryLimit) {
+ IntSize scaledSize = ImageBuffer::compatibleBufferSize(cachedImageSize, context);
+ if (s_allDecodedDataSize + safeCast<size_t>(scaledSize.width()) * scaledSize.height() * 4 - m_cachedBytes > 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& bufferContext = m_cachedImageBuffer->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 "FloatRect.h"
</span><span class="cx"> #include "GraphicsTypes.h"
</span><span class="cx"> #include "Image.h"
</span><ins>+#include "Settings.h"
</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&, const FloatRect& dstRect, const FloatRect& srcRect);
</span><span class="cx"> bool cacheParametersMatch(GraphicsContext&, const FloatRect& dstRect, const FloatRect& 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<PDFDocument> 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<PDFDocumentImage>(image))
</span><del>- downcast<PDFDocumentImage>(*image).setCachedPDFImageEnabled(frame().settings().isCachedPDFImageEnabled());
</del><ins>+ downcast<PDFDocumentImage>(*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()->setImagesEnabled(enabled);
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void InternalSettings::setCachedPDFImageEnabled(bool enabled, ExceptionCode& ec)
</del><ins>+void InternalSettings::setPDFImageCachingPolicy(const String& policy, ExceptionCode& ec)
</ins><span class="cx"> {
</span><span class="cx"> InternalSettingsGuardForSettings();
</span><del>- settings()->setCachedPDFImageEnabled(enabled);
</del><ins>+ if (equalLettersIgnoringASCIICase(policy, "disabled"))
+ settings()->setPdfImageCachingPolicy(PDFImageCachingDisabled);
+ else if (equalLettersIgnoringASCIICase(policy, "belowmemorylimit"))
+ settings()->setPdfImageCachingPolicy(PDFImageCachingBelowMemoryLimit);
+ else if (equalLettersIgnoringASCIICase(policy, "clipboundsonly"))
+ settings()->setPdfImageCachingPolicy(PDFImageCachingClipBoundsOnly);
+ else if (equalLettersIgnoringASCIICase(policy, "enabled"))
+ settings()->setPdfImageCachingPolicy(PDFImageCachingEnabled);
+ else
+ ec = SYNTAX_ERR;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void InternalSettings::setMinimumTimerInterval(double intervalInSeconds, ExceptionCode& 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<InternalSettings> 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&, ExceptionCode&);
</span><span class="cx"> void setPreferMIMETypeForImages(bool, ExceptionCode&);
</span><del>- void setCachedPDFImageEnabled(bool, ExceptionCode&);
</del><ins>+ void setPDFImageCachingPolicy(const String&, ExceptionCode&);
</ins><span class="cx"> void setShouldDisplayTrackKind(const String& kind, bool enabled, ExceptionCode&);
</span><span class="cx"> bool shouldDisplayTrackKind(const String& kind, ExceptionCode&);
</span><span class="cx"> void setStorageBlockingPolicy(const String&, ExceptionCode&);
</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>