<!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>[238037] trunk/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/238037">238037</a></dd>
<dt>Author</dt> <dd>bfulgham@apple.com</dd>
<dt>Date</dt> <dd>2018-11-09 09:32:32 -0800 (Fri, 09 Nov 2018)</dd>
</dl>

<h3>Log Message</h3>
<pre>[Windows][DirectX] Be more rigors about BeginFigure/EndFigure and Close operations.
https://bugs.webkit.org/show_bug.cgi?id=191452
<rdar://problem/45933964>

Reviewed by Zalan Bujtas.

Do a better job of balancing the BeginFigure/EndFigure calls in
the PathDirect2D implementation. Failure to do so puts the Geometry sink
into an error state that prevents it from producing drawing output.

* platform/graphics/Path.h:
* platform/graphics/win/GraphicsContextDirect2D.cpp:
(WebCore::GraphicsContext::drawPath): Flush is needed here.
(WebCore::GraphicsContext::fillPath): Ditto.
(WebCore::GraphicsContext::strokePath): Ditto.
* platform/graphics/win/PathDirect2D.cpp:
(WebCore::Path::drawDidComplete):
(WebCore::Path::closeAnyOpenGeometries):
(WebCore::Path::transform):
(WebCore::Path::openFigureAtCurrentPointIfNecessary):
(WebCore::Path::moveTo):
(WebCore::Path::closeSubpath):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsPathh">trunk/Source/WebCore/platform/graphics/Path.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinGraphicsContextDirect2Dcpp">trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinPathDirect2Dcpp">trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (238036 => 238037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2018-11-09 17:27:34 UTC (rev 238036)
+++ trunk/Source/WebCore/ChangeLog      2018-11-09 17:32:32 UTC (rev 238037)
</span><span class="lines">@@ -1,3 +1,29 @@
</span><ins>+2018-11-09  Brent Fulgham  <bfulgham@apple.com>
+
+        [Windows][DirectX] Be more rigors about BeginFigure/EndFigure and Close operations. 
+        https://bugs.webkit.org/show_bug.cgi?id=191452
+        <rdar://problem/45933964>
+
+        Reviewed by Zalan Bujtas.
+
+        Do a better job of balancing the BeginFigure/EndFigure calls in
+        the PathDirect2D implementation. Failure to do so puts the Geometry sink
+        into an error state that prevents it from producing drawing output.
+      
+
+        * platform/graphics/Path.h:
+        * platform/graphics/win/GraphicsContextDirect2D.cpp:
+        (WebCore::GraphicsContext::drawPath): Flush is needed here.
+        (WebCore::GraphicsContext::fillPath): Ditto.
+        (WebCore::GraphicsContext::strokePath): Ditto.
+        * platform/graphics/win/PathDirect2D.cpp:
+        (WebCore::Path::drawDidComplete):
+        (WebCore::Path::closeAnyOpenGeometries):
+        (WebCore::Path::transform):
+        (WebCore::Path::openFigureAtCurrentPointIfNecessary):
+        (WebCore::Path::moveTo):
+        (WebCore::Path::closeSubpath):
+
</ins><span class="cx"> 2018-11-09  Jer Noble  <jer.noble@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [Cocoa] Fix failing imported/w3c/web-platform-tests/media-source/mediasource-changetype-play.html test
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsPathh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Path.h (238036 => 238037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Path.h    2018-11-09 17:27:34 UTC (rev 238036)
+++ trunk/Source/WebCore/platform/graphics/Path.h       2018-11-09 17:32:32 UTC (rev 238037)
</span><span class="lines">@@ -201,6 +201,7 @@
</span><span class="cx"> 
</span><span class="cx">         HRESULT initializePathState();
</span><span class="cx">         void openFigureAtCurrentPointIfNecessary();
</span><ins>+        void closeAnyOpenGeometries();
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #ifndef NDEBUG
</span><span class="lines">@@ -212,7 +213,7 @@
</span><span class="cx">         COMPtr<ID2D1GeometryGroup> m_path;
</span><span class="cx">         COMPtr<ID2D1PathGeometry> m_activePathGeometry;
</span><span class="cx">         COMPtr<ID2D1GeometrySink> m_activePath;
</span><del>-        bool m_doesHaveOpenFigure { false };
</del><ins>+        size_t m_openFigureCount { 0 };
</ins><span class="cx"> #else
</span><span class="cx">         PlatformPathPtr m_path { nullptr };
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinGraphicsContextDirect2Dcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp (238036 => 238037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp   2018-11-09 17:27:34 UTC (rev 238036)
+++ trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp      2018-11-09 17:32:32 UTC (rev 238037)
</span><span class="lines">@@ -940,6 +940,8 @@
</span><span class="cx">         auto brush = m_state.strokePattern ? patternStrokeBrush() : solidStrokeBrush();
</span><span class="cx">         renderTarget->DrawGeometry(path.platformPath(), brush, strokeThickness(), m_data->strokeStyle());
</span><span class="cx">     });
</span><ins>+
+    flush();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void GraphicsContext::drawWithoutShadow(const FloatRect& /*boundingRect*/, const WTF::Function<void(ID2D1RenderTarget*)>& drawCommands)
</span><span class="lines">@@ -1043,6 +1045,8 @@
</span><span class="cx">             drawWithShadow(boundingRect, drawFunction);
</span><span class="cx">         else
</span><span class="cx">             drawWithoutShadow(boundingRect, drawFunction);
</span><ins>+
+        flush();
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -1059,6 +1063,8 @@
</span><span class="cx">         auto brush = m_state.fillPattern ? patternFillBrush() : solidFillBrush();
</span><span class="cx">         renderTarget->FillGeometry(pathToFill.get(), brush);
</span><span class="cx">     });
</span><ins>+
+    flush();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void GraphicsContext::strokePath(const Path& path)
</span><span class="lines">@@ -1089,6 +1095,7 @@
</span><span class="cx">         else
</span><span class="cx">             drawWithoutShadow(boundingRect, drawFunction);
</span><span class="cx"> 
</span><ins>+        flush();
</ins><span class="cx">         return;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -1102,6 +1109,8 @@
</span><span class="cx">         auto brush = m_state.strokePattern ? patternStrokeBrush() : solidStrokeBrush();
</span><span class="cx">         renderTarget->DrawGeometry(path.platformPath(), brush, strokeThickness(), m_data->strokeStyle());
</span><span class="cx">     });
</span><ins>+
+    flush();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void GraphicsContext::fillRect(const FloatRect& rect)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinPathDirect2Dcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp (238036 => 238037)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp      2018-11-09 17:27:34 UTC (rev 238036)
+++ trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp 2018-11-09 17:32:32 UTC (rev 238037)
</span><span class="lines">@@ -224,7 +224,7 @@
</span><span class="cx">     m_activePath->SetFillMode(D2D1_FILL_MODE_WINDING);
</span><span class="cx"> 
</span><span class="cx">     m_activePath->BeginFigure(currentPoint, D2D1_FIGURE_BEGIN_FILLED);
</span><del>-    m_doesHaveOpenFigure = true;
</del><ins>+    ++m_openFigureCount;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool Path::contains(const FloatPoint& point, WindRule rule) const
</span><span class="lines">@@ -260,6 +260,22 @@
</span><span class="cx">     return containsPoint;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void Path::closeAnyOpenGeometries()
+{
+    ASSERT(m_activePath);
+
+    if (!m_openFigureCount)
+        return;
+
+    while (m_openFigureCount) {
+        m_activePath->EndFigure(D2D1_FIGURE_END_OPEN);
+        --m_openFigureCount;
+    }
+
+    HRESULT hr = m_activePath->Close();
+    ASSERT(SUCCEEDED(hr));
+}
+
</ins><span class="cx"> void Path::translate(const FloatSize& size)
</span><span class="cx"> {
</span><span class="cx">     transform(AffineTransform(1, 0, 0, 1, size.width(), size.height()));
</span><span class="lines">@@ -276,9 +292,7 @@
</span><span class="cx"> 
</span><span class="cx">     bool pathIsActive = false;
</span><span class="cx">     if (m_activePath) {
</span><del>-        m_activePath->EndFigure(D2D1_FIGURE_END_OPEN);
-        m_doesHaveOpenFigure = false;
-        m_activePath->Close();
</del><ins>+        closeAnyOpenGeometries();
</ins><span class="cx">         m_activePath = nullptr;
</span><span class="cx">         m_activePathGeometry = nullptr;
</span><span class="cx">         pathIsActive = true;
</span><span class="lines">@@ -311,7 +325,7 @@
</span><span class="cx"> 
</span><span class="cx">     auto transformedPoint = transform.mapPoint(currentPoint.value());
</span><span class="cx">     m_activePath->BeginFigure(transformedPoint, D2D1_FIGURE_BEGIN_FILLED);
</span><del>-    m_doesHaveOpenFigure = true;
</del><ins>+    m_openFigureCount = 1;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> FloatRect Path::boundingRect() const
</span><span class="lines">@@ -355,21 +369,20 @@
</span><span class="cx"> 
</span><span class="cx"> void Path::openFigureAtCurrentPointIfNecessary()
</span><span class="cx"> {
</span><del>-    if (m_doesHaveOpenFigure)
</del><ins>+    if (m_openFigureCount)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     m_activePath->SetFillMode(D2D1_FILL_MODE_WINDING);
</span><span class="cx">     m_activePath->BeginFigure(currentPoint(), D2D1_FIGURE_BEGIN_FILLED);
</span><del>-    m_doesHaveOpenFigure = true;
</del><ins>+    ++m_openFigureCount;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Path::moveTo(const FloatPoint& point)
</span><span class="cx"> {
</span><span class="cx">     if (m_activePath) {
</span><del>-        m_activePath->Close();
</del><ins>+        closeAnyOpenGeometries();
</ins><span class="cx">         m_activePath = nullptr;
</span><span class="cx">         m_activePathGeometry = nullptr;
</span><del>-        m_doesHaveOpenFigure = false;
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     GraphicsContext::systemFactory()->CreatePathGeometry(&m_activePathGeometry);
</span><span class="lines">@@ -381,7 +394,7 @@
</span><span class="cx"> 
</span><span class="cx">     m_activePath->SetFillMode(D2D1_FILL_MODE_WINDING);
</span><span class="cx">     m_activePath->BeginFigure(point, D2D1_FIGURE_BEGIN_FILLED);
</span><del>-    m_doesHaveOpenFigure = true;
</del><ins>+    m_openFigureCount = 1;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void Path::addLineTo(const FloatPoint& point)
</span><span class="lines">@@ -488,14 +501,24 @@
</span><span class="cx">     if (isNull())
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    if (m_activePath) {
-        m_activePath->EndFigure(D2D1_FIGURE_END_CLOSED);
-        m_activePath->Close();
-        m_activePath = nullptr;
-        m_activePathGeometry = nullptr;
</del><ins>+    if (!m_activePath) {
+        ASSERT(!m_openFigureCount);
+        ASSERT(!m_activePathGeometry);
+        return;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><del>-    m_doesHaveOpenFigure = false;
</del><ins>+    if (!m_openFigureCount)
+        return;
+
+    m_activePath->EndFigure(D2D1_FIGURE_END_CLOSED);
+    --m_openFigureCount;
+    if (m_openFigureCount > 0) {
+        ASSERT(m_activePathGeometry);
+        return;
+    }
+
+    HRESULT hr = m_activePath->Close();
+    ASSERT(SUCCEEDED(hr));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> static FloatPoint arcStart(const FloatPoint& center, float radius, float startAngle)
</span></span></pre>
</div>
</div>

</body>
</html>