Title: [238037] trunk/Source/WebCore
Revision
238037
Author
bfulg...@apple.com
Date
2018-11-09 09:32:32 -0800 (Fri, 09 Nov 2018)

Log Message

[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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (238036 => 238037)


--- 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)
@@ -1,3 +1,29 @@
+2018-11-09  Brent Fulgham  <bfulg...@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):
+
 2018-11-09  Jer Noble  <jer.no...@apple.com>
 
         [Cocoa] Fix failing imported/w3c/web-platform-tests/media-source/mediasource-changetype-play.html test

Modified: trunk/Source/WebCore/platform/graphics/Path.h (238036 => 238037)


--- 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)
@@ -201,6 +201,7 @@
 
         HRESULT initializePathState();
         void openFigureAtCurrentPointIfNecessary();
+        void closeAnyOpenGeometries();
 #endif
 
 #ifndef NDEBUG
@@ -212,7 +213,7 @@
         COMPtr<ID2D1GeometryGroup> m_path;
         COMPtr<ID2D1PathGeometry> m_activePathGeometry;
         COMPtr<ID2D1GeometrySink> m_activePath;
-        bool m_doesHaveOpenFigure { false };
+        size_t m_openFigureCount { 0 };
 #else
         PlatformPathPtr m_path { nullptr };
 #endif

Modified: trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp (238036 => 238037)


--- 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)
@@ -940,6 +940,8 @@
         auto brush = m_state.strokePattern ? patternStrokeBrush() : solidStrokeBrush();
         renderTarget->DrawGeometry(path.platformPath(), brush, strokeThickness(), m_data->strokeStyle());
     });
+
+    flush();
 }
 
 void GraphicsContext::drawWithoutShadow(const FloatRect& /*boundingRect*/, const WTF::Function<void(ID2D1RenderTarget*)>& drawCommands)
@@ -1043,6 +1045,8 @@
             drawWithShadow(boundingRect, drawFunction);
         else
             drawWithoutShadow(boundingRect, drawFunction);
+
+        flush();
         return;
     }
 
@@ -1059,6 +1063,8 @@
         auto brush = m_state.fillPattern ? patternFillBrush() : solidFillBrush();
         renderTarget->FillGeometry(pathToFill.get(), brush);
     });
+
+    flush();
 }
 
 void GraphicsContext::strokePath(const Path& path)
@@ -1089,6 +1095,7 @@
         else
             drawWithoutShadow(boundingRect, drawFunction);
 
+        flush();
         return;
     }
 
@@ -1102,6 +1109,8 @@
         auto brush = m_state.strokePattern ? patternStrokeBrush() : solidStrokeBrush();
         renderTarget->DrawGeometry(path.platformPath(), brush, strokeThickness(), m_data->strokeStyle());
     });
+
+    flush();
 }
 
 void GraphicsContext::fillRect(const FloatRect& rect)

Modified: trunk/Source/WebCore/platform/graphics/win/PathDirect2D.cpp (238036 => 238037)


--- 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)
@@ -224,7 +224,7 @@
     m_activePath->SetFillMode(D2D1_FILL_MODE_WINDING);
 
     m_activePath->BeginFigure(currentPoint, D2D1_FIGURE_BEGIN_FILLED);
-    m_doesHaveOpenFigure = true;
+    ++m_openFigureCount;
 }
 
 bool Path::contains(const FloatPoint& point, WindRule rule) const
@@ -260,6 +260,22 @@
     return containsPoint;
 }
 
+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));
+}
+
 void Path::translate(const FloatSize& size)
 {
     transform(AffineTransform(1, 0, 0, 1, size.width(), size.height()));
@@ -276,9 +292,7 @@
 
     bool pathIsActive = false;
     if (m_activePath) {
-        m_activePath->EndFigure(D2D1_FIGURE_END_OPEN);
-        m_doesHaveOpenFigure = false;
-        m_activePath->Close();
+        closeAnyOpenGeometries();
         m_activePath = nullptr;
         m_activePathGeometry = nullptr;
         pathIsActive = true;
@@ -311,7 +325,7 @@
 
     auto transformedPoint = transform.mapPoint(currentPoint.value());
     m_activePath->BeginFigure(transformedPoint, D2D1_FIGURE_BEGIN_FILLED);
-    m_doesHaveOpenFigure = true;
+    m_openFigureCount = 1;
 }
 
 FloatRect Path::boundingRect() const
@@ -355,21 +369,20 @@
 
 void Path::openFigureAtCurrentPointIfNecessary()
 {
-    if (m_doesHaveOpenFigure)
+    if (m_openFigureCount)
         return;
 
     m_activePath->SetFillMode(D2D1_FILL_MODE_WINDING);
     m_activePath->BeginFigure(currentPoint(), D2D1_FIGURE_BEGIN_FILLED);
-    m_doesHaveOpenFigure = true;
+    ++m_openFigureCount;
 }
 
 void Path::moveTo(const FloatPoint& point)
 {
     if (m_activePath) {
-        m_activePath->Close();
+        closeAnyOpenGeometries();
         m_activePath = nullptr;
         m_activePathGeometry = nullptr;
-        m_doesHaveOpenFigure = false;
     }
 
     GraphicsContext::systemFactory()->CreatePathGeometry(&m_activePathGeometry);
@@ -381,7 +394,7 @@
 
     m_activePath->SetFillMode(D2D1_FILL_MODE_WINDING);
     m_activePath->BeginFigure(point, D2D1_FIGURE_BEGIN_FILLED);
-    m_doesHaveOpenFigure = true;
+    m_openFigureCount = 1;
 }
 
 void Path::addLineTo(const FloatPoint& point)
@@ -488,14 +501,24 @@
     if (isNull())
         return;
 
-    if (m_activePath) {
-        m_activePath->EndFigure(D2D1_FIGURE_END_CLOSED);
-        m_activePath->Close();
-        m_activePath = nullptr;
-        m_activePathGeometry = nullptr;
+    if (!m_activePath) {
+        ASSERT(!m_openFigureCount);
+        ASSERT(!m_activePathGeometry);
+        return;
     }
 
-    m_doesHaveOpenFigure = false;
+    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));
 }
 
 static FloatPoint arcStart(const FloatPoint& center, float radius, float startAngle)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to