Title: [224527] trunk/Source/WebCore
Revision
224527
Author
[email protected]
Date
2017-11-06 18:28:45 -0800 (Mon, 06 Nov 2017)

Log Message

[CG] Adopt CGContextDrawPathDirect()
https://bugs.webkit.org/show_bug.cgi?id=179339
<rdar://problem/26283575>

Patch by Said Abou-Hallawa <[email protected]> on 2017-11-06
Reviewed by Simon Fraser.

Source/WebCore:

Adopt this function on macOS >= 10.12 and iOS >= 10.0. Instead of clearing
the current path and creating a new one by calling CGContextBeginPath()
and then adding a CGPath by calling CGContextAddPath() and then calling
one of the drawing path functions, we just call CGContextDrawPathDirect().

* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::drawPath):
(WebCore::GraphicsContext::fillPath):
(WebCore::GraphicsContext::strokePath): Don't call CGContextBeginPath()
and CGContextAddPath() for the drawing CGContext in the case of gradient
shadow because we add the CGPath to the layerContext and at the end we
draw this CGLayer into the drawing context.

Source/WebCore/PAL:

Add CGContextDrawPathDirect() as a new CoreGraphics SPI.

* pal/spi/cg/CoreGraphicsSPI.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (224526 => 224527)


--- trunk/Source/WebCore/ChangeLog	2017-11-07 01:27:35 UTC (rev 224526)
+++ trunk/Source/WebCore/ChangeLog	2017-11-07 02:28:45 UTC (rev 224527)
@@ -1,3 +1,24 @@
+2017-11-06  Said Abou-Hallawa  <[email protected]>
+
+        [CG] Adopt CGContextDrawPathDirect()
+        https://bugs.webkit.org/show_bug.cgi?id=179339
+        <rdar://problem/26283575>
+
+        Reviewed by Simon Fraser.
+
+        Adopt this function on macOS >= 10.12 and iOS >= 10.0. Instead of clearing
+        the current path and creating a new one by calling CGContextBeginPath()
+        and then adding a CGPath by calling CGContextAddPath() and then calling 
+        one of the drawing path functions, we just call CGContextDrawPathDirect().
+
+        * platform/graphics/cg/GraphicsContextCG.cpp:
+        (WebCore::GraphicsContext::drawPath):
+        (WebCore::GraphicsContext::fillPath):
+        (WebCore::GraphicsContext::strokePath): Don't call CGContextBeginPath()
+        and CGContextAddPath() for the drawing CGContext in the case of gradient
+        shadow because we add the CGPath to the layerContext and at the end we
+        draw this CGLayer into the drawing context.
+
 2017-11-06  Alex Christensen  <[email protected]>
 
         Make ResourceLoader::willSendRequestInternal asynchronous

Modified: trunk/Source/WebCore/PAL/ChangeLog (224526 => 224527)


--- trunk/Source/WebCore/PAL/ChangeLog	2017-11-07 01:27:35 UTC (rev 224526)
+++ trunk/Source/WebCore/PAL/ChangeLog	2017-11-07 02:28:45 UTC (rev 224527)
@@ -1,3 +1,15 @@
+2017-11-06  Said Abou-Hallawa  <[email protected]>
+
+        [CG] Adopt CGContextDrawPathDirect()
+        https://bugs.webkit.org/show_bug.cgi?id=179339
+        <rdar://problem/26283575>
+
+        Reviewed by Simon Fraser.
+
+        Add CGContextDrawPathDirect() as a new CoreGraphics SPI.
+
+        * pal/spi/cg/CoreGraphicsSPI.h:
+
 2017-11-02  Ryan Haddad  <[email protected]>
 
         Unreviewed, rolling out r224353.

Modified: trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h (224526 => 224527)


--- trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h	2017-11-07 01:27:35 UTC (rev 224526)
+++ trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h	2017-11-07 02:28:45 UTC (rev 224527)
@@ -254,6 +254,7 @@
 typedef struct CGPDFAnnotation *CGPDFAnnotationRef;
 typedef bool (^CGPDFAnnotationDrawCallbackType)(CGContextRef context, CGPDFPageRef page, CGPDFAnnotationRef annotation);
 void CGContextDrawPDFPageWithAnnotations(CGContextRef, CGPDFPageRef, CGPDFAnnotationDrawCallbackType);
+void CGContextDrawPathDirect(CGContextRef, CGPathDrawingMode, CGPathRef, const CGRect* boundingBox);
 #endif
 
 #if USE(IOSURFACE)

Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (224526 => 224527)


--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2017-11-07 01:27:35 UTC (rev 224526)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp	2017-11-07 02:28:45 UTC (rev 224527)
@@ -52,6 +52,8 @@
 #include <WebKitSystemInterface/WebKitSystemInterface.h>
 #endif
 
+#define USE_DRAW_PATH_DIRECT (PLATFORM(IOS) || (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200))
+
 // FIXME: The following using declaration should be in <wtf/HashFunctions.h>.
 using WTF::pairIntHash;
 
@@ -713,9 +715,6 @@
         return;
     }
 
-    CGContextBeginPath(context);
-    CGContextAddPath(context, path.platformPath());
-
     if (state.fillPattern)
         applyFillPattern();
     if (state.strokePattern)
@@ -722,8 +721,15 @@
         applyStrokePattern();
 
     CGPathDrawingMode drawingMode;
-    if (calculateDrawingMode(state, drawingMode))
+    if (calculateDrawingMode(state, drawingMode)) {
+#if USE_DRAW_PATH_DIRECT
+        CGContextDrawPathDirect(context, drawingMode, path.platformPath(), nullptr);
+#else
+        CGContextBeginPath(context);
+        CGContextAddPath(context, path.platformPath());
         CGContextDrawPath(context, drawingMode);
+#endif
+    }
 }
 
 void GraphicsContext::fillPath(const Path& path)
@@ -777,16 +783,18 @@
         return;
     }
 
+    if (m_state.fillPattern)
+        applyFillPattern();
+#if USE_DRAW_PATH_DIRECT
+    CGContextDrawPathDirect(context, fillRule() == RULE_EVENODD ? kCGPathEOFill : kCGPathFill, path.platformPath(), nullptr);
+#else
     CGContextBeginPath(context);
     CGContextAddPath(context, path.platformPath());
-
-    if (m_state.fillPattern)
-        applyFillPattern();
-
     if (fillRule() == RULE_EVENODD)
         CGContextEOFillPath(context);
     else
         CGContextFillPath(context);
+#endif
 }
 
 void GraphicsContext::strokePath(const Path& path)
@@ -801,9 +809,6 @@
 
     CGContextRef context = platformContext();
 
-    CGContextBeginPath(context);
-    CGContextAddPath(context, path.platformPath());
-
     if (m_state.strokeGradient) {
         if (hasShadow()) {
             FloatRect rect = path.fastBoundingRect();
@@ -838,6 +843,8 @@
             CGLayerRelease(layer);
         } else {
             CGContextStateSaver stateSaver(context);
+            CGContextBeginPath(context);
+            CGContextAddPath(context, path.platformPath());
             CGContextReplacePathWithStrokedPath(context);
             CGContextClip(context);
             CGContextConcatCTM(context, m_state.strokeGradient->gradientSpaceTransform());
@@ -848,7 +855,13 @@
 
     if (m_state.strokePattern)
         applyStrokePattern();
+#if USE_DRAW_PATH_DIRECT
+    CGContextDrawPathDirect(context, kCGPathStroke, path.platformPath(), nullptr);
+#else
+    CGContextBeginPath(context);
+    CGContextAddPath(context, path.platformPath());
     CGContextStrokePath(context);
+#endif
 }
 
 void GraphicsContext::fillRect(const FloatRect& rect)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to