<!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>[201629] trunk/Source</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/201629">201629</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2016-06-02 17:39:58 -0700 (Thu, 02 Jun 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>[iOS] PDFDocumentImage should not create a cached image larger than 4M pixels
https://bugs.webkit.org/show_bug.cgi?id=157857
Patch by Said Abou-Hallawa <sabouhallawa@apple,com> on 2016-06-02
Reviewed by Darin Adler.
Source/WebCore:
On iOS, if the scaled size of the PDFDocumentImage cached image will exceed
the 4M pixels limit and the system physical memory is 1GB or less, do not
create it. PDFDocumentImage::draw() falls back peacefully if the cached image
couldn't be created for any reason. The PDF will be drawn directly to the
GraphicsContext without having to go through the cached image. This means
the whole PDF will be drawn multiple times; one time for each tile. I think
this is okay for zooming a large PDFDocumentImage on a low end device.
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::drawTextInternal): Call the static function
ImageBuffer::createCompatibleBuffer() without having to go through the GraphicsContext.
* platform/graphics/BitmapImage.cpp:
(WebCore::BitmapImage::drawPattern): Ditto.
* platform/graphics/FloatSize.h:
(WebCore::FloatSize::area): A helper function similar to IntSize::area().
(WebCore::operator*): Scale a FloatSize by another FloatSize and return the result.
* platform/graphics/GradientImage.cpp:
(WebCore::GradientImage::drawPattern): Call ImageBuffer::createCompatibleBuffer().
* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::scaleFactor):: Return the scaling part of the current CTM.
(WebCore::scalesMatch): Deleted.
(WebCore::GraphicsContext::createCompatibleBuffer): Deleted.
(WebCore::GraphicsContext::isCompatibleWithBuffer): Deleted.
* platform/graphics/GraphicsContext.h:
Move these image buffer functions to ImageBuffer.
* platform/graphics/ImageBuffer.cpp:
(WebCore::ImageBuffer::createCompatibleBuffer): Make createCompatibleBuffer
a static function of the ImageBuffer. There is no need to go through the
GraphicsContext just to get the GraphicsContext scaleFactor.
(WebCore::ImageBuffer::compatibleBufferSize): Scale the size of the cachedImage
by the scaleFactor of the context.
(WebCore::ImageBuffer::isCompatibleWithContext): Returns true if the drawing
context and the ImageBuffer context have the same scaleFactor.
* platform/graphics/ImageBuffer.h:
* platform/graphics/NamedImageGeneratedImage.cpp:
(WebCore::NamedImageGeneratedImage::drawPattern): Call ImageBuffer::createCompatibleBuffer().
* platform/graphics/cg/PDFDocumentImage.cpp:
(WebCore::PDFDocumentImage::updateCachedImageIfNeeded): On iOS, if the
physical memory is less than 1GB, do not allocate more than 16MB for the
PDF cachedImage.
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::paintFillLayerExtended): Call ImageBuffer::createCompatibleBuffer().
* rendering/svg/SVGRenderingContext.cpp:
(WebCore::SVGRenderingContext::bufferForeground): Ditto.
Source/WTF:
* wtf/StdLibExtras.h: Add a constant value for GB (2^30).</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFwtfStdLibExtrash">trunk/Source/WTF/wtf/StdLibExtras.h</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorehtmlcanvasCanvasRenderingContext2Dcpp">trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsBitmapImagecpp">trunk/Source/WebCore/platform/graphics/BitmapImage.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsFloatSizeh">trunk/Source/WebCore/platform/graphics/FloatSize.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsGradientImagecpp">trunk/Source/WebCore/platform/graphics/GradientImage.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsGraphicsContextcpp">trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsGraphicsContexth">trunk/Source/WebCore/platform/graphics/GraphicsContext.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsImageBuffercpp">trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsImageBufferh">trunk/Source/WebCore/platform/graphics/ImageBuffer.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsNamedImageGeneratedImagecpp">trunk/Source/WebCore/platform/graphics/NamedImageGeneratedImage.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscgPDFDocumentImagecpp">trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderBoxModelObjectcpp">trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingsvgSVGRenderingContextcpp">trunk/Source/WebCore/rendering/svg/SVGRenderingContext.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (201628 => 201629)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2016-06-02 23:52:03 UTC (rev 201628)
+++ trunk/Source/WTF/ChangeLog        2016-06-03 00:39:58 UTC (rev 201629)
</span><span class="lines">@@ -1,3 +1,12 @@
</span><ins>+2016-06-02 Said Abou-Hallawa <sabouhallawa@apple,com>
+
+ [iOS] PDFDocumentImage should not create a cached image larger than 4M pixels
+ https://bugs.webkit.org/show_bug.cgi?id=157857
+
+ Reviewed by Darin Adler.
+
+ * wtf/StdLibExtras.h: Add a constant value for GB (2^30).
+
</ins><span class="cx"> 2016-06-02 Oliver Hunt <oliver@apple.com>
</span><span class="cx">
</span><span class="cx"> JS parser incorrectly handles invalid utf8 in error messages.
</span></span></pre></div>
<a id="trunkSourceWTFwtfStdLibExtrash"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/StdLibExtras.h (201628 => 201629)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/StdLibExtras.h        2016-06-02 23:52:03 UTC (rev 201628)
+++ trunk/Source/WTF/wtf/StdLibExtras.h        2016-06-03 00:39:58 UTC (rev 201629)
</span><span class="lines">@@ -121,6 +121,7 @@
</span><span class="cx">
</span><span class="cx"> static const size_t KB = 1024;
</span><span class="cx"> static const size_t MB = 1024 * 1024;
</span><ins>+static const size_t GB = 1024 * 1024 * 1024;
</ins><span class="cx">
</span><span class="cx"> inline bool isPointerAligned(void* p)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (201628 => 201629)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-06-02 23:52:03 UTC (rev 201628)
+++ trunk/Source/WebCore/ChangeLog        2016-06-03 00:39:58 UTC (rev 201629)
</span><span class="lines">@@ -1,3 +1,66 @@
</span><ins>+2016-06-02 Said Abou-Hallawa <sabouhallawa@apple,com>
+
+ [iOS] PDFDocumentImage should not create a cached image larger than 4M pixels
+ https://bugs.webkit.org/show_bug.cgi?id=157857
+
+ Reviewed by Darin Adler.
+
+ On iOS, if the scaled size of the PDFDocumentImage cached image will exceed
+ the 4M pixels limit and the system physical memory is 1GB or less, do not
+ create it. PDFDocumentImage::draw() falls back peacefully if the cached image
+ couldn't be created for any reason. The PDF will be drawn directly to the
+ GraphicsContext without having to go through the cached image. This means
+ the whole PDF will be drawn multiple times; one time for each tile. I think
+ this is okay for zooming a large PDFDocumentImage on a low end device.
+
+ * html/canvas/CanvasRenderingContext2D.cpp:
+ (WebCore::CanvasRenderingContext2D::drawTextInternal): Call the static function
+ ImageBuffer::createCompatibleBuffer() without having to go through the GraphicsContext.
+
+ * platform/graphics/BitmapImage.cpp:
+ (WebCore::BitmapImage::drawPattern): Ditto.
+
+ * platform/graphics/FloatSize.h:
+ (WebCore::FloatSize::area): A helper function similar to IntSize::area().
+ (WebCore::operator*): Scale a FloatSize by another FloatSize and return the result.
+
+ * platform/graphics/GradientImage.cpp:
+ (WebCore::GradientImage::drawPattern): Call ImageBuffer::createCompatibleBuffer().
+
+ * platform/graphics/GraphicsContext.cpp:
+ (WebCore::GraphicsContext::scaleFactor):: Return the scaling part of the current CTM.
+ (WebCore::scalesMatch): Deleted.
+ (WebCore::GraphicsContext::createCompatibleBuffer): Deleted.
+ (WebCore::GraphicsContext::isCompatibleWithBuffer): Deleted.
+ * platform/graphics/GraphicsContext.h:
+ Move these image buffer functions to ImageBuffer.
+
+ * platform/graphics/ImageBuffer.cpp:
+ (WebCore::ImageBuffer::createCompatibleBuffer): Make createCompatibleBuffer
+ a static function of the ImageBuffer. There is no need to go through the
+ GraphicsContext just to get the GraphicsContext scaleFactor.
+
+ (WebCore::ImageBuffer::compatibleBufferSize): Scale the size of the cachedImage
+ by the scaleFactor of the context.
+
+ (WebCore::ImageBuffer::isCompatibleWithContext): Returns true if the drawing
+ context and the ImageBuffer context have the same scaleFactor.
+
+ * platform/graphics/ImageBuffer.h:
+
+ * platform/graphics/NamedImageGeneratedImage.cpp:
+ (WebCore::NamedImageGeneratedImage::drawPattern): Call ImageBuffer::createCompatibleBuffer().
+
+ * platform/graphics/cg/PDFDocumentImage.cpp:
+ (WebCore::PDFDocumentImage::updateCachedImageIfNeeded): On iOS, if the
+ physical memory is less than 1GB, do not allocate more than 16MB for the
+ PDF cachedImage.
+
+ * rendering/RenderBoxModelObject.cpp:
+ (WebCore::RenderBoxModelObject::paintFillLayerExtended): Call ImageBuffer::createCompatibleBuffer().
+ * rendering/svg/SVGRenderingContext.cpp:
+ (WebCore::SVGRenderingContext::bufferForeground): Ditto.
+
</ins><span class="cx"> 2016-06-02 Chris Dumez <cdumez@apple.com>
</span><span class="cx">
</span><span class="cx"> [WebIDL] 'undefined' should be an acceptable value for nullable parameters
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlcanvasCanvasRenderingContext2Dcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp (201628 => 201629)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp        2016-06-02 23:52:03 UTC (rev 201628)
+++ trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp        2016-06-03 00:39:58 UTC (rev 201629)
</span><span class="lines">@@ -2448,7 +2448,7 @@
</span><span class="cx"> fontProxy.drawBidiText(*c, textRun, location + offset, FontCascade::UseFallbackIfFontNotReady);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- std::unique_ptr<ImageBuffer> maskImage = c->createCompatibleBuffer(maskRect.size());
</del><ins>+ auto maskImage = ImageBuffer::createCompatibleBuffer(maskRect.size(), *c);
</ins><span class="cx"> if (!maskImage)
</span><span class="cx"> return;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsBitmapImagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/BitmapImage.cpp (201628 => 201629)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/BitmapImage.cpp        2016-06-02 23:52:03 UTC (rev 201628)
+++ trunk/Source/WebCore/platform/graphics/BitmapImage.cpp        2016-06-03 00:39:58 UTC (rev 201629)
</span><span class="lines">@@ -606,7 +606,7 @@
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx"> if (!m_cachedImage) {
</span><del>- std::unique_ptr<ImageBuffer> buffer = ctxt.createCompatibleBuffer(expandedIntSize(tileRect.size()));
</del><ins>+ auto buffer = ImageBuffer::createCompatibleBuffer(expandedIntSize(tileRect.size()), ctxt);
</ins><span class="cx"> if (!buffer)
</span><span class="cx"> return;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsFloatSizeh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/FloatSize.h (201628 => 201629)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/FloatSize.h        2016-06-02 23:52:03 UTC (rev 201628)
+++ trunk/Source/WebCore/platform/graphics/FloatSize.h        2016-06-03 00:39:58 UTC (rev 201629)
</span><span class="lines">@@ -103,6 +103,11 @@
</span><span class="cx"> {
</span><span class="cx"> return m_width * m_width + m_height * m_height;
</span><span class="cx"> }
</span><ins>+
+ float area() const
+ {
+ return m_width * m_height;
+ }
</ins><span class="cx">
</span><span class="cx"> FloatSize transposedSize() const
</span><span class="cx"> {
</span><span class="lines">@@ -163,6 +168,11 @@
</span><span class="cx"> return FloatSize(a * b.width(), a * b.height());
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+inline FloatSize operator*(const FloatSize& a, const FloatSize& b)
+{
+ return FloatSize(a.width() * b.width(), a.height() * b.height());
+}
+
</ins><span class="cx"> inline FloatSize operator/(const FloatSize& a, float b)
</span><span class="cx"> {
</span><span class="cx"> return FloatSize(a.width() / b, a.height() / b);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGradientImagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/GradientImage.cpp (201628 => 201629)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/GradientImage.cpp        2016-06-02 23:52:03 UTC (rev 201628)
+++ trunk/Source/WebCore/platform/graphics/GradientImage.cpp        2016-06-03 00:39:58 UTC (rev 201629)
</span><span class="lines">@@ -74,8 +74,8 @@
</span><span class="cx">
</span><span class="cx"> unsigned generatorHash = m_gradient->hash();
</span><span class="cx">
</span><del>- if (!m_cachedImageBuffer || m_cachedGeneratorHash != generatorHash || m_cachedAdjustedSize != adjustedSize || !destContext.isCompatibleWithBuffer(*m_cachedImageBuffer)) {
- m_cachedImageBuffer = destContext.createCompatibleBuffer(adjustedSize, m_gradient->hasAlpha());
</del><ins>+ if (!m_cachedImageBuffer || m_cachedGeneratorHash != generatorHash || m_cachedAdjustedSize != adjustedSize || !m_cachedImageBuffer->isCompatibleWithContext(destContext)) {
+ m_cachedImageBuffer = ImageBuffer::createCompatibleBuffer(adjustedSize, destContext, m_gradient->hasAlpha());
</ins><span class="cx"> if (!m_cachedImageBuffer)
</span><span class="cx"> return;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGraphicsContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp (201628 => 201629)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp        2016-06-02 23:52:03 UTC (rev 201628)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp        2016-06-03 00:39:58 UTC (rev 201629)
</span><span class="lines">@@ -1012,36 +1012,6 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static bool scalesMatch(AffineTransform a, AffineTransform b)
-{
- return a.xScale() == b.xScale() && a.yScale() == b.yScale();
-}
-
-std::unique_ptr<ImageBuffer> GraphicsContext::createCompatibleBuffer(const FloatSize& size, bool hasAlpha) const
-{
- // Make the buffer larger if the context's transform is scaling it so we need a higher
- // resolution than one pixel per unit. Also set up a corresponding scale factor on the
- // graphics context.
-
- AffineTransform transform = getCTM(DefinitelyIncludeDeviceScale);
- FloatSize scaledSize(static_cast<int>(ceil(size.width() * transform.xScale())), static_cast<int>(ceil(size.height() * transform.yScale())));
-
- std::unique_ptr<ImageBuffer> buffer = ImageBuffer::createCompatibleBuffer(scaledSize, 1, ColorSpaceSRGB, *this, hasAlpha);
- if (!buffer)
- return nullptr;
-
- buffer->context().scale(FloatSize(scaledSize.width() / size.width(), scaledSize.height() / size.height()));
-
- return buffer;
-}
-
-bool GraphicsContext::isCompatibleWithBuffer(ImageBuffer& buffer) const
-{
- GraphicsContext& bufferContext = buffer.context();
-
- return scalesMatch(getCTM(), bufferContext.getCTM()) && isAcceleratedContext() == bufferContext.isAcceleratedContext();
-}
-
</del><span class="cx"> #if !USE(CG)
</span><span class="cx"> void GraphicsContext::platformApplyDeviceScaleFactor(float)
</span><span class="cx"> {
</span><span class="lines">@@ -1059,6 +1029,12 @@
</span><span class="cx">
</span><span class="cx"> platformApplyDeviceScaleFactor(deviceScaleFactor);
</span><span class="cx"> }
</span><ins>+
+FloatSize GraphicsContext::scaleFactor() const
+{
+ AffineTransform transform = getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
+ return FloatSize(transform.xScale(), transform.yScale());
+}
</ins><span class="cx">
</span><span class="cx"> void GraphicsContext::fillEllipse(const FloatRect& ellipse)
</span><span class="cx"> {
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGraphicsContexth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.h (201628 => 201629)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/GraphicsContext.h        2016-06-02 23:52:03 UTC (rev 201628)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.h        2016-06-03 00:39:58 UTC (rev 201629)
</span><span class="lines">@@ -476,15 +476,12 @@
</span><span class="cx"> void set3DTransform(const TransformationMatrix&);
</span><span class="cx"> TransformationMatrix get3DTransform() const;
</span><span class="cx"> #endif
</span><del>- // Create an image buffer compatible with this context, with suitable resolution
- // for drawing into the buffer and then into this context.
- std::unique_ptr<ImageBuffer> createCompatibleBuffer(const FloatSize&, bool hasAlpha = true) const;
- bool isCompatibleWithBuffer(ImageBuffer&) const;
</del><span class="cx">
</span><span class="cx"> // This function applies the device scale factor to the context, making the context capable of
</span><span class="cx"> // acting as a base-level context for a HiDPI environment.
</span><span class="cx"> WEBCORE_EXPORT void applyDeviceScaleFactor(float);
</span><span class="cx"> void platformApplyDeviceScaleFactor(float);
</span><ins>+ FloatSize scaleFactor() const;
</ins><span class="cx">
</span><span class="cx"> #if OS(WINDOWS)
</span><span class="cx"> HDC getWindowsContext(const IntRect&, bool supportAlphaBlend, bool mayCreateBitmap); // The passed in rect is used to create a bitmap for compositing inside transparency layers.
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsImageBuffercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp (201628 => 201629)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp        2016-06-02 23:52:03 UTC (rev 201628)
+++ trunk/Source/WebCore/platform/graphics/ImageBuffer.cpp        2016-06-03 00:39:58 UTC (rev 201629)
</span><span class="lines">@@ -164,9 +164,37 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+std::unique_ptr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const FloatSize& size, const GraphicsContext& context, bool hasAlpha)
+{
+ if (size.isEmpty())
+ return nullptr;
+
+ FloatSize scaledSize = ImageBuffer::compatibleBufferSize(size, context);
+
+ auto buffer = ImageBuffer::createCompatibleBuffer(expandedIntSize(scaledSize), 1, ColorSpaceSRGB, context, hasAlpha);
+ if (!buffer)
+ return nullptr;
+
+ // Set up a corresponding scale factor on the graphics context.
+ buffer->context().scale(context.scaleFactor());
+ return buffer;
+}
+
</ins><span class="cx"> std::unique_ptr<ImageBuffer> ImageBuffer::createCompatibleBuffer(const FloatSize& size, float resolutionScale, ColorSpace colorSpace, const GraphicsContext& context, bool)
</span><span class="cx"> {
</span><span class="cx"> return create(size, context.renderingMode(), resolutionScale, colorSpace);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+FloatSize ImageBuffer::compatibleBufferSize(const FloatSize& size, const GraphicsContext& context)
+{
+ // Enlarge the buffer size if the context's transform is scaling it so we need a higher
+ // resolution than one pixel per unit.
+ return size * context.scaleFactor();
</ins><span class="cx"> }
</span><ins>+
+bool ImageBuffer::isCompatibleWithContext(const GraphicsContext& context) const
+{
+ return areEssentiallyEqual(context.scaleFactor(), this->context().scaleFactor());
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsImageBufferh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/ImageBuffer.h (201628 => 201629)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/ImageBuffer.h        2016-06-02 23:52:03 UTC (rev 201628)
+++ trunk/Source/WebCore/platform/graphics/ImageBuffer.h        2016-06-03 00:39:58 UTC (rev 201629)
</span><span class="lines">@@ -79,8 +79,13 @@
</span><span class="cx"> return buffer;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ // Create an image buffer compatible with the context, with suitable resolution for drawing into the buffer and then into this context.
+ static std::unique_ptr<ImageBuffer> createCompatibleBuffer(const FloatSize&, const GraphicsContext&, bool hasAlpha = true);
</ins><span class="cx"> static std::unique_ptr<ImageBuffer> createCompatibleBuffer(const FloatSize&, float resolutionScale, ColorSpace, const GraphicsContext&, bool hasAlpha);
</span><span class="cx">
</span><ins>+ static FloatSize compatibleBufferSize(const FloatSize&, const GraphicsContext&);
+ bool isCompatibleWithContext(const GraphicsContext&) const;
+
</ins><span class="cx"> WEBCORE_EXPORT ~ImageBuffer();
</span><span class="cx">
</span><span class="cx"> // The actual resolution of the backing store
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsNamedImageGeneratedImagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/NamedImageGeneratedImage.cpp (201628 => 201629)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/NamedImageGeneratedImage.cpp        2016-06-02 23:52:03 UTC (rev 201628)
+++ trunk/Source/WebCore/platform/graphics/NamedImageGeneratedImage.cpp        2016-06-03 00:39:58 UTC (rev 201629)
</span><span class="lines">@@ -64,7 +64,7 @@
</span><span class="cx"> void NamedImageGeneratedImage::drawPattern(GraphicsContext& context, const FloatRect& srcRect, const AffineTransform& patternTransform, const FloatPoint& phase, const FloatSize& spacing, CompositeOperator compositeOp, const FloatRect& dstRect, BlendMode blendMode)
</span><span class="cx"> {
</span><span class="cx"> #if USE(NEW_THEME)
</span><del>- std::unique_ptr<ImageBuffer> imageBuffer = context.createCompatibleBuffer(size(), true);
</del><ins>+ auto imageBuffer = ImageBuffer::createCompatibleBuffer(size(), context, true);
</ins><span class="cx"> if (!imageBuffer)
</span><span class="cx"> return;
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscgPDFDocumentImagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp (201628 => 201629)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp        2016-06-02 23:52:03 UTC (rev 201628)
+++ trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp        2016-06-03 00:39:58 UTC (rev 201629)
</span><span class="lines">@@ -43,7 +43,9 @@
</span><span class="cx"> #include <CoreGraphics/CGContext.h>
</span><span class="cx"> #include <CoreGraphics/CGPDFDocument.h>
</span><span class="cx"> #include <wtf/MathExtras.h>
</span><ins>+#include <wtf/RAMSize.h>
</ins><span class="cx"> #include <wtf/RetainPtr.h>
</span><ins>+#include <wtf/StdLibExtras.h>
</ins><span class="cx">
</span><span class="cx"> #if !PLATFORM(COCOA)
</span><span class="cx"> #include "ImageSourceCG.h"
</span><span class="lines">@@ -143,6 +145,15 @@
</span><span class="cx"> void PDFDocumentImage::updateCachedImageIfNeeded(GraphicsContext& context, const FloatRect& dstRect, const FloatRect& srcRect)
</span><span class="cx"> {
</span><span class="cx"> #if PLATFORM(IOS)
</span><ins>+ // On iOS, if the physical memory is less than 1GB, do not allocate more than 16MB for the PDF cachedImage.
+ const size_t memoryThreshold = WTF::GB;
+ const size_t maxArea = 16 * WTF::MB / 4; // 16 MB maximum size, divided by a rough cost of 4 bytes per pixel of area.
+
+ if (ramSize() <= memoryThreshold && ImageBuffer::compatibleBufferSize(dstRect.size(), context).area() >= maxArea) {
+ m_cachedImageBuffer = nullptr;
+ return;
+ }
+
</ins><span class="cx"> // On iOS, some clients use low-quality image interpolation always, which throws off this optimization,
</span><span class="cx"> // as we never get the subsequent high-quality paint. Since live resize is rare on iOS, disable the optimization.
</span><span class="cx"> // FIXME (136593): It's also possible to do the wrong thing here if CSS specifies low-quality interpolation via the "image-rendering"
</span><span class="lines">@@ -156,26 +167,27 @@
</span><span class="cx"> bool repaintIfNecessary = interpolationQuality != InterpolationNone && interpolationQuality != InterpolationLow;
</span><span class="cx"> #endif
</span><span class="cx">
</span><del>- if (!m_cachedImageBuffer || (!cacheParametersMatch(context, dstRect, srcRect) && repaintIfNecessary)) {
- m_cachedImageBuffer = context.createCompatibleBuffer(FloatRect(enclosingIntRect(dstRect)).size());
- if (!m_cachedImageBuffer)
- return;
- GraphicsContext& bufferContext = m_cachedImageBuffer->context();
</del><ins>+ if (m_cachedImageBuffer && (!repaintIfNecessary || cacheParametersMatch(context, dstRect, srcRect)))
+ return;
+
+ m_cachedImageBuffer = ImageBuffer::createCompatibleBuffer(FloatRect(enclosingIntRect(dstRect)).size(), context);
+ if (!m_cachedImageBuffer)
+ return;
+ auto& bufferContext = m_cachedImageBuffer->context();
</ins><span class="cx">
</span><del>- transformContextForPainting(bufferContext, dstRect, srcRect);
- drawPDFPage(bufferContext);
</del><ins>+ transformContextForPainting(bufferContext, dstRect, srcRect);
+ drawPDFPage(bufferContext);
</ins><span class="cx">
</span><del>- m_cachedTransform = context.getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
- m_cachedDestinationSize = dstRect.size();
- m_cachedSourceRect = srcRect;
</del><ins>+ m_cachedTransform = context.getCTM(GraphicsContext::DefinitelyIncludeDeviceScale);
+ m_cachedDestinationSize = dstRect.size();
+ m_cachedSourceRect = srcRect;
</ins><span class="cx">
</span><del>- IntSize internalSize = m_cachedImageBuffer->internalSize();
- size_t oldCachedBytes = m_cachedBytes;
- m_cachedBytes = internalSize.width() * internalSize.height() * 4;
</del><ins>+ IntSize internalSize = m_cachedImageBuffer->internalSize();
+ size_t oldCachedBytes = m_cachedBytes;
+ m_cachedBytes = safeCast<size_t>(internalSize.width()) * internalSize.height() * 4;
</ins><span class="cx">
</span><del>- if (imageObserver())
- imageObserver()->decodedSizeChanged(this, safeCast<int>(m_cachedBytes) - safeCast<int>(oldCachedBytes));
- }
</del><ins>+ if (imageObserver())
+ imageObserver()->decodedSizeChanged(this, safeCast<int>(m_cachedBytes) - safeCast<int>(oldCachedBytes));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void PDFDocumentImage::draw(GraphicsContext& context, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator op, BlendMode, ImageOrientationDescription)
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderBoxModelObjectcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp (201628 => 201629)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp        2016-06-02 23:52:03 UTC (rev 201628)
+++ trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp        2016-06-03 00:39:58 UTC (rev 201629)
</span><span class="lines">@@ -756,7 +756,7 @@
</span><span class="cx"> maskRect.intersect(snappedIntRect(paintInfo.rect));
</span><span class="cx">
</span><span class="cx"> // Now create the mask.
</span><del>- maskImage = context.createCompatibleBuffer(maskRect.size());
</del><ins>+ maskImage = ImageBuffer::createCompatibleBuffer(maskRect.size(), context);
</ins><span class="cx"> if (!maskImage)
</span><span class="cx"> return;
</span><span class="cx"> paintMaskForTextFillBox(maskImage.get(), maskRect, box, scrolledPaintRect);
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingsvgSVGRenderingContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/svg/SVGRenderingContext.cpp (201628 => 201629)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/svg/SVGRenderingContext.cpp        2016-06-02 23:52:03 UTC (rev 201628)
+++ trunk/Source/WebCore/rendering/svg/SVGRenderingContext.cpp        2016-06-03 00:39:58 UTC (rev 201629)
</span><span class="lines">@@ -351,7 +351,7 @@
</span><span class="cx">
</span><span class="cx"> // Create a new buffer and paint the foreground into it.
</span><span class="cx"> if (!imageBuffer) {
</span><del>- if ((imageBuffer = m_paintInfo->context().createCompatibleBuffer(expandedIntSize(boundingBox.size()), true))) {
</del><ins>+ if ((imageBuffer = ImageBuffer::createCompatibleBuffer(expandedIntSize(boundingBox.size()), m_paintInfo->context(), true))) {
</ins><span class="cx"> GraphicsContext& bufferedRenderingContext = imageBuffer->context();
</span><span class="cx"> bufferedRenderingContext.translate(-boundingBox.x(), -boundingBox.y());
</span><span class="cx"> PaintInfo bufferedInfo(*m_paintInfo);
</span></span></pre>
</div>
</div>
</body>
</html>