<!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>[192867] branches/safari-601.1.46-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/192867">192867</a></dd>
<dt>Author</dt> <dd>bshafiei@apple.com</dd>
<dt>Date</dt> <dd>2015-12-01 00:18:42 -0800 (Tue, 01 Dec 2015)</dd>
</dl>
<h3>Log Message</h3>
<pre>Merged <a href="http://trac.webkit.org/projects/webkit/changeset/190894">r190894</a>. rdar://problem/23691644</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari601146branchSourceWebCoreChangeLog">branches/safari-601.1.46-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari601146branchSourceWebCoreplatformgraphicscgGraphicsContextCGcpp">branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp</a></li>
<li><a href="#branchessafari601146branchSourceWebCoreplatformgraphicscgGraphicsContextCGh">branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari601146branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/ChangeLog (192866 => 192867)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/ChangeLog        2015-12-01 08:16:51 UTC (rev 192866)
+++ branches/safari-601.1.46-branch/Source/WebCore/ChangeLog        2015-12-01 08:18:42 UTC (rev 192867)
</span><span class="lines">@@ -1,5 +1,35 @@
</span><span class="cx"> 2015-12-01 Babak Shafiei <bshafiei@apple.com>
</span><span class="cx">
</span><ins>+ Merge r190894.
+
+ 2015-10-12 Simon Fraser <simon.fraser@apple.com>
+
+ Add a CGContextStateSaver and use it
+ https://bugs.webkit.org/show_bug.cgi?id=150049
+
+ Reviewed by Tim Horton.
+
+ Add a stack-based graphics state save/restore class for CGContext,
+ like the one we have for GraphicsContext, and use it in GraphicsContextCG.
+
+ * platform/graphics/cg/GraphicsContextCG.cpp:
+ (WebCore::GraphicsContext::drawNativeImage):
+ (WebCore::GraphicsContext::drawLine):
+ (WebCore::GraphicsContext::drawJoinedLines):
+ (WebCore::GraphicsContext::fillPath):
+ (WebCore::GraphicsContext::strokePath):
+ (WebCore::GraphicsContext::fillRect):
+ (WebCore::GraphicsContext::platformFillRoundedRect):
+ (WebCore::GraphicsContext::fillRectWithRoundedHole):
+ (WebCore::GraphicsContext::strokeRect):
+ * platform/graphics/cg/GraphicsContextCG.h:
+ (WebCore::CGContextStateSaver::CGContextStateSaver):
+ (WebCore::CGContextStateSaver::~CGContextStateSaver):
+ (WebCore::CGContextStateSaver::save):
+ (WebCore::CGContextStateSaver::restore):
+
+2015-12-01 Babak Shafiei <bshafiei@apple.com>
+
</ins><span class="cx"> Merge r190587.
</span><span class="cx">
</span><span class="cx"> 2015-10-05 Beth Dakin <bdakin@apple.com>
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCoreplatformgraphicscgGraphicsContextCGcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (192866 => 192867)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp        2015-12-01 08:16:51 UTC (rev 192866)
+++ branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp        2015-12-01 08:18:42 UTC (rev 192867)
</span><span class="lines">@@ -150,7 +150,7 @@
</span><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> CGContextRef context = platformContext();
</span><del>- CGContextSaveGState(context);
</del><ins>+ CGContextStateSaver stateSaver(context);
</ins><span class="cx">
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> // Anti-aliasing is on by default on the iPhone. Need to turn it off when drawing images.
</span><span class="lines">@@ -237,8 +237,6 @@
</span><span class="cx">
</span><span class="cx"> // Draw the image.
</span><span class="cx"> CGContextDrawImage(context, adjustedDestRect, image.get());
</span><del>-
- CGContextRestoreGState(context);
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> // Draws a filled rectangle with a stroked border.
</span><span class="lines">@@ -288,12 +286,13 @@
</span><span class="cx"> return;
</span><span class="cx">
</span><span class="cx"> CGContextRef context = platformContext();
</span><ins>+
</ins><span class="cx"> StrokeStyle strokeStyle = this->strokeStyle();
</span><span class="cx"> float cornerWidth = 0;
</span><span class="cx"> bool drawsDashedLine = strokeStyle == DottedStroke || strokeStyle == DashedStroke;
</span><span class="cx">
</span><ins>+ CGContextStateSaver stateSaver(context, drawsDashedLine);
</ins><span class="cx"> if (drawsDashedLine) {
</span><del>- CGContextSaveGState(context);
</del><span class="cx"> // Figure out end points to ensure we always paint corners.
</span><span class="cx"> cornerWidth = strokeStyle == DottedStroke ? thickness : std::min(2 * thickness, std::max(thickness, strokeWidth / 3));
</span><span class="cx"> setCGFillColor(context, strokeColor(), strokeColorSpace());
</span><span class="lines">@@ -307,10 +306,8 @@
</span><span class="cx"> strokeWidth -= 2 * cornerWidth;
</span><span class="cx"> float patternWidth = strokeStyle == DottedStroke ? thickness : std::min(3 * thickness, std::max(thickness, strokeWidth / 3));
</span><span class="cx"> // Check if corner drawing sufficiently covers the line.
</span><del>- if (strokeWidth <= patternWidth + 1) {
- CGContextRestoreGState(context);
</del><ins>+ if (strokeWidth <= patternWidth + 1)
</ins><span class="cx"> return;
</span><del>- }
</del><span class="cx">
</span><span class="cx"> // Pattern starts with full fill and ends with the empty fill.
</span><span class="cx"> // 1. Let's start with the empty phase after the corner.
</span><span class="lines">@@ -358,8 +355,6 @@
</span><span class="cx"> CGContextMoveToPoint(context, p1.x(), p1.y());
</span><span class="cx"> CGContextAddLineToPoint(context, p2.x(), p2.y());
</span><span class="cx"> CGContextStrokePath(context);
</span><del>- if (drawsDashedLine)
- CGContextRestoreGState(context);
</del><span class="cx"> if (shouldAntialias())
</span><span class="cx"> CGContextSetShouldAntialias(context, true);
</span><span class="cx"> }
</span><span class="lines">@@ -373,24 +368,18 @@
</span><span class="cx"> CGContextRef context = platformContext();
</span><span class="cx"> float width = CGContextGetLineWidth(context);
</span><span class="cx">
</span><del>- CGContextSaveGState(context);
</del><ins>+ CGContextStateSaver stateSaver(context);
</ins><span class="cx">
</span><span class="cx"> CGContextSetShouldAntialias(context, antialias);
</span><del>-
</del><span class="cx"> CGContextSetLineWidth(context, width < 1 ? 1 : width);
</span><del>-
</del><span class="cx"> CGContextBeginPath(context);
</span><del>-
</del><span class="cx"> CGContextSetLineCap(context, lineCap);
</span><del>-
</del><span class="cx"> CGContextMoveToPoint(context, points[0].x, points[0].y);
</span><span class="cx">
</span><span class="cx"> for (unsigned i = 1; i < count; ++i)
</span><span class="cx"> CGContextAddLineToPoint(context, points[i].x, points[i].y);
</span><span class="cx">
</span><span class="cx"> CGContextStrokePath(context);
</span><del>-
- CGContextRestoreGState(context);
</del><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx">
</span><span class="lines">@@ -584,7 +573,7 @@
</span><span class="cx"> } else {
</span><span class="cx"> CGContextBeginPath(context);
</span><span class="cx"> CGContextAddPath(context, path.platformPath());
</span><del>- CGContextSaveGState(context);
</del><ins>+ CGContextStateSaver stateSaver(context);
</ins><span class="cx"> CGContextConcatCTM(context, m_state.fillGradient->gradientSpaceTransform());
</span><span class="cx">
</span><span class="cx"> if (fillRule() == RULE_EVENODD)
</span><span class="lines">@@ -593,7 +582,6 @@
</span><span class="cx"> CGContextClip(context);
</span><span class="cx">
</span><span class="cx"> m_state.fillGradient->paint(this);
</span><del>- CGContextRestoreGState(context);
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> return;
</span><span class="lines">@@ -650,12 +638,11 @@
</span><span class="cx"> CGContextDrawLayerInRect(context, CGRectMake(destinationX, destinationY, adjustedWidth, adjustedHeight), layer);
</span><span class="cx"> CGLayerRelease(layer);
</span><span class="cx"> } else {
</span><del>- CGContextSaveGState(context);
</del><ins>+ CGContextStateSaver stateSaver(context);
</ins><span class="cx"> CGContextReplacePathWithStrokedPath(context);
</span><span class="cx"> CGContextClip(context);
</span><span class="cx"> CGContextConcatCTM(context, m_state.strokeGradient->gradientSpaceTransform());
</span><span class="cx"> m_state.strokeGradient->paint(this);
</span><del>- CGContextRestoreGState(context);
</del><span class="cx"> }
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="lines">@@ -673,7 +660,7 @@
</span><span class="cx"> CGContextRef context = platformContext();
</span><span class="cx">
</span><span class="cx"> if (m_state.fillGradient) {
</span><del>- CGContextSaveGState(context);
</del><ins>+ CGContextStateSaver stateSaver(context);
</ins><span class="cx"> if (hasShadow()) {
</span><span class="cx"> FloatSize layerSize = getCTM().mapSize(rect.size());
</span><span class="cx">
</span><span class="lines">@@ -694,7 +681,6 @@
</span><span class="cx"> CGContextConcatCTM(context, m_state.fillGradient->gradientSpaceTransform());
</span><span class="cx"> m_state.fillGradient->paint(this);
</span><span class="cx"> }
</span><del>- CGContextRestoreGState(context);
</del><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -702,9 +688,9 @@
</span><span class="cx"> applyFillPattern();
</span><span class="cx">
</span><span class="cx"> bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow() && !m_state.shadowsIgnoreTransforms; // Don't use ShadowBlur for canvas yet.
</span><ins>+ CGContextStateSaver stateSaver(context, drawOwnShadow);
</ins><span class="cx"> if (drawOwnShadow) {
</span><span class="cx"> // Turn off CG shadows.
</span><del>- CGContextSaveGState(context);
</del><span class="cx"> CGContextSetShadowWithColor(platformContext(), CGSizeZero, 0, 0);
</span><span class="cx">
</span><span class="cx"> ShadowBlur contextShadow(m_state);
</span><span class="lines">@@ -712,9 +698,6 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> CGContextFillRect(context, rect);
</span><del>-
- if (drawOwnShadow)
- CGContextRestoreGState(context);
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void GraphicsContext::fillRect(const FloatRect& rect, const Color& color, ColorSpace colorSpace)
</span><span class="lines">@@ -730,9 +713,9 @@
</span><span class="cx"> setCGFillColor(context, color, colorSpace);
</span><span class="cx">
</span><span class="cx"> bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow() && !m_state.shadowsIgnoreTransforms; // Don't use ShadowBlur for canvas yet.
</span><ins>+ CGContextStateSaver stateSaver(context, drawOwnShadow);
</ins><span class="cx"> if (drawOwnShadow) {
</span><span class="cx"> // Turn off CG shadows.
</span><del>- CGContextSaveGState(context);
</del><span class="cx"> CGContextSetShadowWithColor(platformContext(), CGSizeZero, 0, 0);
</span><span class="cx">
</span><span class="cx"> ShadowBlur contextShadow(m_state);
</span><span class="lines">@@ -742,7 +725,7 @@
</span><span class="cx"> CGContextFillRect(context, rect);
</span><span class="cx">
</span><span class="cx"> if (drawOwnShadow)
</span><del>- CGContextRestoreGState(context);
</del><ins>+ stateSaver.restore();
</ins><span class="cx">
</span><span class="cx"> if (oldFillColor != color || oldColorSpace != colorSpace)
</span><span class="cx"> setCGFillColor(context, oldFillColor, oldColorSpace);
</span><span class="lines">@@ -761,9 +744,9 @@
</span><span class="cx"> setCGFillColor(context, color, colorSpace);
</span><span class="cx">
</span><span class="cx"> bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow() && !m_state.shadowsIgnoreTransforms; // Don't use ShadowBlur for canvas yet.
</span><ins>+ CGContextStateSaver stateSaver(context, drawOwnShadow);
</ins><span class="cx"> if (drawOwnShadow) {
</span><span class="cx"> // Turn off CG shadows.
</span><del>- CGContextSaveGState(context);
</del><span class="cx"> CGContextSetShadowWithColor(platformContext(), CGSizeZero, 0, 0);
</span><span class="cx">
</span><span class="cx"> ShadowBlur contextShadow(m_state);
</span><span class="lines">@@ -784,7 +767,7 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> if (drawOwnShadow)
</span><del>- CGContextRestoreGState(context);
</del><ins>+ stateSaver.restore();
</ins><span class="cx">
</span><span class="cx"> if (oldFillColor != color || oldColorSpace != colorSpace)
</span><span class="cx"> setCGFillColor(context, oldFillColor, oldColorSpace);
</span><span class="lines">@@ -814,9 +797,9 @@
</span><span class="cx">
</span><span class="cx"> // fillRectWithRoundedHole() assumes that the edges of rect are clipped out, so we only care about shadows cast around inside the hole.
</span><span class="cx"> bool drawOwnShadow = !isAcceleratedContext() && hasBlurredShadow() && !m_state.shadowsIgnoreTransforms;
</span><ins>+ CGContextStateSaver stateSaver(context, drawOwnShadow);
</ins><span class="cx"> if (drawOwnShadow) {
</span><span class="cx"> // Turn off CG shadows.
</span><del>- CGContextSaveGState(context);
</del><span class="cx"> CGContextSetShadowWithColor(platformContext(), CGSizeZero, 0, 0);
</span><span class="cx">
</span><span class="cx"> ShadowBlur contextShadow(m_state);
</span><span class="lines">@@ -826,7 +809,7 @@
</span><span class="cx"> fillPath(path);
</span><span class="cx">
</span><span class="cx"> if (drawOwnShadow)
</span><del>- CGContextRestoreGState(context);
</del><ins>+ stateSaver.restore();
</ins><span class="cx">
</span><span class="cx"> setFillRule(oldFillRule);
</span><span class="cx"> setFillColor(oldFillColor, oldFillColorSpace);
</span><span class="lines">@@ -1042,14 +1025,13 @@
</span><span class="cx"> CGContextDrawLayerInRect(context, CGRectMake(destinationX, destinationY, adjustedWidth, adjustedHeight), layer);
</span><span class="cx"> CGLayerRelease(layer);
</span><span class="cx"> } else {
</span><del>- CGContextSaveGState(context);
</del><ins>+ CGContextStateSaver stateSaver(context);
</ins><span class="cx"> setStrokeThickness(lineWidth);
</span><span class="cx"> CGContextAddRect(context, rect);
</span><span class="cx"> CGContextReplacePathWithStrokedPath(context);
</span><span class="cx"> CGContextClip(context);
</span><span class="cx"> CGContextConcatCTM(context, m_state.strokeGradient->gradientSpaceTransform());
</span><span class="cx"> m_state.strokeGradient->paint(this);
</span><del>- CGContextRestoreGState(context);
</del><span class="cx"> }
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="lines">@@ -1062,13 +1044,11 @@
</span><span class="cx"> // The convenience functions currently (in at least OSX 10.9.4) fail to
</span><span class="cx"> // apply some attributes of the graphics state in certain cases
</span><span class="cx"> // (as identified in https://bugs.webkit.org/show_bug.cgi?id=132948)
</span><del>- CGContextSaveGState(context);
</del><ins>+ CGContextStateSaver stateSaver(context);
</ins><span class="cx"> setStrokeThickness(lineWidth);
</span><span class="cx">
</span><span class="cx"> CGContextAddRect(context, rect);
</span><span class="cx"> CGContextStrokePath(context);
</span><del>-
- CGContextRestoreGState(context);
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void GraphicsContext::setLineCap(LineCap cap)
</span></span></pre></div>
<a id="branchessafari601146branchSourceWebCoreplatformgraphicscgGraphicsContextCGh"></a>
<div class="modfile"><h4>Modified: branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h (192866 => 192867)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h        2015-12-01 08:16:51 UTC (rev 192866)
+++ branches/safari-601.1.46-branch/Source/WebCore/platform/graphics/cg/GraphicsContextCG.h        2015-12-01 08:18:42 UTC (rev 192867)
</span><span class="lines">@@ -50,6 +50,41 @@
</span><span class="cx"> return deviceRGBColorSpaceRef();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+class CGContextStateSaver {
+public:
+ CGContextStateSaver(CGContextRef context, bool saveAndRestore = true)
+ : m_context(context)
+ , m_saveAndRestore(saveAndRestore)
+ {
+ if (m_saveAndRestore)
+ CGContextSaveGState(m_context);
+ }
+
+ ~CGContextStateSaver()
+ {
+ if (m_saveAndRestore)
+ CGContextRestoreGState(m_context);
+ }
+
+ void save()
+ {
+ ASSERT(!m_saveAndRestore);
+ CGContextSaveGState(m_context);
+ m_saveAndRestore = true;
+ }
+
+ void restore()
+ {
+ ASSERT(m_saveAndRestore);
+ CGContextRestoreGState(m_context);
+ m_saveAndRestore = false;
+ }
+
+private:
+ CGContextRef m_context;
+ bool m_saveAndRestore;
+};
+
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> #endif
</span></span></pre>
</div>
</div>
</body>
</html>