<!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>[161580] branches/safari-537.74-branch/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/161580">161580</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2014-01-09 13:31:38 -0800 (Thu, 09 Jan 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/161568">r161568</a>: <rdar://problem/15784802></pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari53774branchSourceWebCoreChangeLog">branches/safari-537.74-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari53774branchSourceWebCoreplatformgraphicscgPDFDocumentImagecpp">branches/safari-537.74-branch/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp</a></li>
<li><a href="#branchessafari53774branchSourceWebCoreplatformgraphicscgPDFDocumentImageh">branches/safari-537.74-branch/Source/WebCore/platform/graphics/cg/PDFDocumentImage.h</a></li>
<li><a href="#branchessafari53774branchSourceWebCoreplatformgraphicsmacPDFDocumentImageMacmm">branches/safari-537.74-branch/Source/WebCore/platform/graphics/mac/PDFDocumentImageMac.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari53774branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-537.74-branch/Source/WebCore/ChangeLog (161579 => 161580)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-537.74-branch/Source/WebCore/ChangeLog        2014-01-09 21:26:54 UTC (rev 161579)
+++ branches/safari-537.74-branch/Source/WebCore/ChangeLog        2014-01-09 21:31:38 UTC (rev 161580)
</span><span class="lines">@@ -1,3 +1,35 @@
</span><ins>+2014-01-09 Matthew Hanson <matthew_hanson@apple.com>
+
+ Merge r161568: <rdar://problem/15784802>
+
+ 2014-01-09 Tim Horton <timothy_horton@apple.com>
+
+ PDFDocumentImage can be very slow to do the initial paint
+ https://bugs.webkit.org/show_bug.cgi?id=126633
+ <rdar://problem/15770980>
+
+ Reviewed by Simon Fraser.
+
+ * platform/graphics/cg/PDFDocumentImage.cpp:
+ (WebCore::PDFDocumentImage::PDFDocumentImage):
+ (WebCore::PDFDocumentImage::size):
+ (WebCore::transformContextForPainting):
+ (WebCore::PDFDocumentImage::computeBoundsForCurrentPage):
+ (WebCore::applyRotationForPainting):
+ (WebCore::PDFDocumentImage::drawPDFPage):
+ * platform/graphics/cg/PDFDocumentImage.h:
+ * platform/graphics/mac/PDFDocumentImageMac.mm:
+ (WebCore::PDFDocumentImage::computeBoundsForCurrentPage):
+ Store rotation from the PDF in degrees, since it can
+ only be 0, 90, 180, or 270, and don't do any trig to
+ perform the rotation, to avoid introducing minor rounding
+ issues in the size.
+
+ Once we're going to paint, if the difference between the
+ computed scale for each axis is due only to integer rounding
+ of the image size, use the same scale for both axes, to avoid
+ a CG slow-path which occurs whenever the scale is nonuniform.
+
</ins><span class="cx"> 2014-01-07 Lucas Forschler <lforschler@apple.com>
</span><span class="cx">
</span><span class="cx"> Merge r160479
</span></span></pre></div>
<a id="branchessafari53774branchSourceWebCoreplatformgraphicscgPDFDocumentImagecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-537.74-branch/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp (161579 => 161580)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-537.74-branch/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp        2014-01-09 21:26:54 UTC (rev 161579)
+++ branches/safari-537.74-branch/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp        2014-01-09 21:31:38 UTC (rev 161580)
</span><span class="lines">@@ -48,7 +48,7 @@
</span><span class="cx"> PDFDocumentImage::PDFDocumentImage(ImageObserver* observer)
</span><span class="cx"> : Image(observer)
</span><span class="cx"> , m_cachedBytes(0)
</span><del>- , m_rotation(0.0f)
</del><ins>+ , m_rotationDegrees(0)
</ins><span class="cx"> , m_hasPage(false)
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="lines">@@ -64,14 +64,11 @@
</span><span class="cx">
</span><span class="cx"> IntSize PDFDocumentImage::size() const
</span><span class="cx"> {
</span><del>- const float sina = sinf(-m_rotation);
- const float cosa = cosf(-m_rotation);
- const float width = m_mediaBox.size().width();
- const float height = m_mediaBox.size().height();
- const float rotWidth = fabsf(width * cosa - height * sina);
- const float rotHeight = fabsf(width * sina + height * cosa);
-
- return expandedIntSize(FloatSize(rotWidth, rotHeight));
</del><ins>+ IntSize expandedCropBoxSize = expandedIntSize(m_cropBox.size());
+
+ if (m_rotationDegrees == 90 || m_rotationDegrees == 270)
+ return expandedCropBoxSize.transposedSize();
+ return expandedCropBoxSize;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void PDFDocumentImage::computeIntrinsicDimensions(Length& intrinsicWidth, Length& intrinsicHeight, FloatSize& intrinsicRatio)
</span><span class="lines">@@ -95,26 +92,6 @@
</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::applyRotationForPainting(GraphicsContext* context) const
-{
- // Rotate the crop box and calculate bounding box.
- float sina = sinf(-m_rotation);
- float cosa = cosf(-m_rotation);
- float width = m_cropBox.width();
- float height = m_cropBox.height();
-
- // Calculate rotated x and y edges of the crop box. If they're negative, it means part of the image has
- // been rotated outside of the bounds and we need to shift over the image so it lies inside the bounds again.
- CGPoint rx = CGPointMake(width * cosa, width * sina);
- CGPoint ry = CGPointMake(-height * sina, height * cosa);
-
- // Adjust so we are at the crop box origin.
- const CGFloat zero = 0;
- context->translate(floorf(-std::min(zero, std::min(rx.x, ry.x))), floorf(-std::min(zero, std::min(rx.y, ry.y))));
-
- context->rotate(-m_rotation);
-}
-
</del><span class="cx"> bool PDFDocumentImage::cacheParametersMatch(GraphicsContext* context, const FloatRect& dstRect, const FloatRect& srcRect) const
</span><span class="cx"> {
</span><span class="cx"> if (dstRect.size() != m_cachedDestinationSize)
</span><span class="lines">@@ -138,6 +115,17 @@
</span><span class="cx"> {
</span><span class="cx"> float hScale = dstRect.width() / srcRect.width();
</span><span class="cx"> float vScale = dstRect.height() / srcRect.height();
</span><ins>+
+ float minimumScale = std::max((dstRect.width() - 0.5) / srcRect.width(), (dstRect.height() - 0.5) / srcRect.height());
+ float maximumScale = std::min((dstRect.width() + 0.5) / srcRect.width(), (dstRect.height() + 0.5) / srcRect.height());
+
+ // If the difference between the two scales is due to integer rounding of image sizes,
+ // use the average scale for both axes.
+ if (minimumScale <= maximumScale) {
+ hScale = (maximumScale + minimumScale) / 2;
+ vScale = hScale;
+ }
+
</ins><span class="cx"> context->translate(srcRect.x() * hScale, srcRect.y() * vScale);
</span><span class="cx"> context->scale(FloatSize(hScale, -vScale));
</span><span class="cx"> context->translate(0, -srcRect.height());
</span><span class="lines">@@ -238,7 +226,7 @@
</span><span class="cx"> else
</span><span class="cx"> m_cropBox = m_mediaBox;
</span><span class="cx">
</span><del>- m_rotation = deg2rad(static_cast<float>(CGPDFPageGetRotationAngle(cgPage)));
</del><ins>+ m_rotationDegrees = CGPDFPageGetRotationAngle(cgPage);
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> unsigned PDFDocumentImage::pageCount() const
</span><span class="lines">@@ -246,9 +234,21 @@
</span><span class="cx"> return CGPDFDocumentGetNumberOfPages(m_document.get());
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+static void applyRotationForPainting(GraphicsContext* context, IntSize size, int rotationDegrees)
+{
+ if (rotationDegrees == 90)
+ context->translate(0, size.height());
+ else if (rotationDegrees == 180)
+ context->translate(size.width(), size.height());
+ else if (rotationDegrees == 270)
+ context->translate(size.width(), 0);
+
+ context->rotate(-deg2rad(static_cast<float>(rotationDegrees)));
+}
+
</ins><span class="cx"> void PDFDocumentImage::drawPDFPage(GraphicsContext* context)
</span><span class="cx"> {
</span><del>- applyRotationForPainting(context);
</del><ins>+ applyRotationForPainting(context, size(), m_rotationDegrees);
</ins><span class="cx">
</span><span class="cx"> context->translate(-m_cropBox.x(), -m_cropBox.y());
</span><span class="cx">
</span></span></pre></div>
<a id="branchessafari53774branchSourceWebCoreplatformgraphicscgPDFDocumentImageh"></a>
<div class="modfile"><h4>Modified: branches/safari-537.74-branch/Source/WebCore/platform/graphics/cg/PDFDocumentImage.h (161579 => 161580)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-537.74-branch/Source/WebCore/platform/graphics/cg/PDFDocumentImage.h        2014-01-09 21:26:54 UTC (rev 161579)
+++ branches/safari-537.74-branch/Source/WebCore/platform/graphics/cg/PDFDocumentImage.h        2014-01-09 21:31:38 UTC (rev 161580)
</span><span class="lines">@@ -75,8 +75,6 @@
</span><span class="cx"> // FIXME: Implement this to be less conservative.
</span><span class="cx"> virtual bool currentFrameKnownToBeOpaque() OVERRIDE { return false; }
</span><span class="cx">
</span><del>- void applyRotationForPainting(GraphicsContext*) const;
-
</del><span class="cx"> void createPDFDocument();
</span><span class="cx"> void computeBoundsForCurrentPage();
</span><span class="cx"> unsigned pageCount() const;
</span><span class="lines">@@ -99,7 +97,7 @@
</span><span class="cx">
</span><span class="cx"> FloatRect m_mediaBox;
</span><span class="cx"> FloatRect m_cropBox;
</span><del>- float m_rotation;
</del><ins>+ int m_rotationDegrees; // Can only be 0, 90, 180, or 270 degrees.
</ins><span class="cx"> bool m_hasPage;
</span><span class="cx"> };
</span><span class="cx">
</span></span></pre></div>
<a id="branchessafari53774branchSourceWebCoreplatformgraphicsmacPDFDocumentImageMacmm"></a>
<div class="modfile"><h4>Modified: branches/safari-537.74-branch/Source/WebCore/platform/graphics/mac/PDFDocumentImageMac.mm (161579 => 161580)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-537.74-branch/Source/WebCore/platform/graphics/mac/PDFDocumentImageMac.mm        2014-01-09 21:26:54 UTC (rev 161579)
+++ branches/safari-537.74-branch/Source/WebCore/platform/graphics/mac/PDFDocumentImageMac.mm        2014-01-09 21:31:38 UTC (rev 161580)
</span><span class="lines">@@ -63,7 +63,7 @@
</span><span class="cx"> m_mediaBox = [pdfPage boundsForBox:kPDFDisplayBoxMediaBox];
</span><span class="cx"> m_cropBox = [pdfPage boundsForBox:kPDFDisplayBoxCropBox];
</span><span class="cx">
</span><del>- m_rotation = deg2rad(static_cast<float>([pdfPage rotation]));
</del><ins>+ m_rotationDegrees = [pdfPage rotation];
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> unsigned PDFDocumentImage::pageCount() const
</span></span></pre>
</div>
</div>
</body>
</html>