Title: [257918] trunk/Source/WebCore
Revision
257918
Author
wenson_hs...@apple.com
Date
2020-03-05 08:13:57 -0800 (Thu, 05 Mar 2020)

Log Message

Optimize Path::encode on platforms that support CGPathGetNumberOfElements
https://bugs.webkit.org/show_bug.cgi?id=208266

Reviewed by Darin Adler and Simon Fraser.

Source/WebCore:

When encoding Path objects, we currently first encode the number of elements in the path by iterating over each
path element and incrementing a counter; then, we iterate over each element again, and encode information
(points, angles, etc.) for each path element.

However, on platforms that have the fix for <rdar://problem/59828724>, the first call to CGPathApply can be
skipped, since CoreGraphics can (in constant time, for the most part) simply tell us how many elements are in
the CGPath. See comments below for more details.

There should be no change in behavior.

* platform/graphics/Path.cpp:
* platform/graphics/Path.h:

Add an `elementCount` method on Path, which returns the count of elements in the path. On platforms where
CGPathGetNumberOfElements exists (and the fix for <rdar://problem/59828724> is also present), we return the
result of calling this SPI. Otherwise, fall back to mapping over each path element and incrementing a count.

(WebCore::Path::encode const):

Use the new `elementCount` method when encoding a WebCore::Path.

* platform/graphics/cg/PathCG.cpp:
(WebCore::Path::elementCount const):

Source/WebCore/PAL:

Add an SPI declaration for CGPathGetNumberOfElements.

* pal/spi/cg/CoreGraphicsSPI.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (257917 => 257918)


--- trunk/Source/WebCore/ChangeLog	2020-03-05 16:04:12 UTC (rev 257917)
+++ trunk/Source/WebCore/ChangeLog	2020-03-05 16:13:57 UTC (rev 257918)
@@ -1,3 +1,34 @@
+2020-03-05  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Optimize Path::encode on platforms that support CGPathGetNumberOfElements
+        https://bugs.webkit.org/show_bug.cgi?id=208266
+
+        Reviewed by Darin Adler and Simon Fraser.
+
+        When encoding Path objects, we currently first encode the number of elements in the path by iterating over each
+        path element and incrementing a counter; then, we iterate over each element again, and encode information
+        (points, angles, etc.) for each path element.
+
+        However, on platforms that have the fix for <rdar://problem/59828724>, the first call to CGPathApply can be
+        skipped, since CoreGraphics can (in constant time, for the most part) simply tell us how many elements are in
+        the CGPath. See comments below for more details.
+
+        There should be no change in behavior.
+
+        * platform/graphics/Path.cpp:
+        * platform/graphics/Path.h:
+
+        Add an `elementCount` method on Path, which returns the count of elements in the path. On platforms where
+        CGPathGetNumberOfElements exists (and the fix for <rdar://problem/59828724> is also present), we return the
+        result of calling this SPI. Otherwise, fall back to mapping over each path element and incrementing a count.
+
+        (WebCore::Path::encode const):
+
+        Use the new `elementCount` method when encoding a WebCore::Path.
+
+        * platform/graphics/cg/PathCG.cpp:
+        (WebCore::Path::elementCount const):
+
 2020-03-05  Zalan Bujtas  <za...@apple.com>
 
         [LFC][Invalidation] Incoming image data should invalidate layout tree content

Modified: trunk/Source/WebCore/PAL/ChangeLog (257917 => 257918)


--- trunk/Source/WebCore/PAL/ChangeLog	2020-03-05 16:04:12 UTC (rev 257917)
+++ trunk/Source/WebCore/PAL/ChangeLog	2020-03-05 16:13:57 UTC (rev 257918)
@@ -1,3 +1,14 @@
+2020-03-05  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Optimize Path::encode on platforms that support CGPathGetNumberOfElements
+        https://bugs.webkit.org/show_bug.cgi?id=208266
+
+        Reviewed by Darin Adler and Simon Fraser.
+
+        Add an SPI declaration for CGPathGetNumberOfElements.
+
+        * pal/spi/cg/CoreGraphicsSPI.h:
+
 2020-03-04  Chris Dumez  <cdu...@apple.com>
 
         Adopt new and improved CFNetwork SPI for cookie change notifications

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


--- trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h	2020-03-05 16:04:12 UTC (rev 257917)
+++ trunk/Source/WebCore/PAL/pal/spi/cg/CoreGraphicsSPI.h	2020-03-05 16:13:57 UTC (rev 257918)
@@ -42,6 +42,7 @@
 #include <ColorSync/ColorSyncPriv.h>
 #endif
 #include <CoreGraphics/CGFontCache.h>
+#include <CoreGraphics/CGPathPrivate.h>
 #include <CoreGraphics/CoreGraphicsPrivate.h>
 
 #else
@@ -249,6 +250,10 @@
 bool CGContextDrawsWithCorrectShadowOffsets(CGContextRef);
 CGPatternRef CGPatternCreateWithImage2(CGImageRef, CGAffineTransform, CGPatternTiling);
 
+#if HAVE(CGPATH_GET_NUMBER_OF_ELEMENTS)
+size_t CGPathGetNumberOfElements(CGPathRef);
+#endif
+
 #if HAVE(IOSURFACE)
 CGContextRef CGIOSurfaceContextCreate(IOSurfaceRef, size_t, size_t, size_t, size_t, CGColorSpaceRef, CGBitmapInfo);
 CGImageRef CGIOSurfaceContextCreateImage(CGContextRef);

Modified: trunk/Source/WebCore/platform/graphics/Path.cpp (257917 => 257918)


--- trunk/Source/WebCore/platform/graphics/Path.cpp	2020-03-05 16:04:12 UTC (rev 257917)
+++ trunk/Source/WebCore/platform/graphics/Path.cpp	2020-03-05 16:13:57 UTC (rev 257918)
@@ -53,6 +53,19 @@
 }
 #endif
 
+#if !HAVE(CGPATH_GET_NUMBER_OF_ELEMENTS)
+
+size_t Path::elementCount() const
+{
+    size_t numPoints = 0;
+    apply([&numPoints](auto&) {
+        ++numPoints;
+    });
+    return numPoints;
+}
+
+#endif // !HAVE(CGPATH_GET_NUMBER_OF_ELEMENTS)
+
 PathTraversalState Path::traversalStateAtLength(float length) const
 {
     PathTraversalState traversalState(PathTraversalState::Action::VectorAtLength, length);

Modified: trunk/Source/WebCore/platform/graphics/Path.h (257917 => 257918)


--- trunk/Source/WebCore/platform/graphics/Path.h	2020-03-05 16:04:12 UTC (rev 257917)
+++ trunk/Source/WebCore/platform/graphics/Path.h	2020-03-05 16:13:57 UTC (rev 257918)
@@ -141,6 +141,7 @@
     WEBCORE_EXPORT FloatRect fastBoundingRect() const;
     FloatRect strokeBoundingRect(StrokeStyleApplier* = 0) const;
 
+    WEBCORE_EXPORT size_t elementCount() const;
     float length() const;
     PathTraversalState traversalStateAtLength(float length) const;
     FloatPoint pointAtLength(float length) const;
@@ -245,13 +246,8 @@
 
 template<class Encoder> void Path::encode(Encoder& encoder) const
 {
-    uint64_t numPoints = 0;
-    apply([&numPoints](const PathElement&) {
-        ++numPoints;
-    });
+    encoder << static_cast<uint64_t>(elementCount());
 
-    encoder << numPoints;
-
     apply([&](auto& element) {
         encoder.encodeEnum(element.type);
 

Modified: trunk/Source/WebCore/platform/graphics/cg/PathCG.cpp (257917 => 257918)


--- trunk/Source/WebCore/platform/graphics/cg/PathCG.cpp	2020-03-05 16:04:12 UTC (rev 257917)
+++ trunk/Source/WebCore/platform/graphics/cg/PathCG.cpp	2020-03-05 16:13:57 UTC (rev 257918)
@@ -34,7 +34,6 @@
 #include "GraphicsContext.h"
 #include "IntRect.h"
 #include "StrokeStyleApplier.h"
-#include <CoreGraphics/CoreGraphics.h>
 #include <pal/spi/cg/CoreGraphicsSPI.h>
 #include <wtf/MathExtras.h>
 #include <wtf/RetainPtr.h>
@@ -458,6 +457,15 @@
     CGPathApply(m_path.get(), (void*)&function, CGPathApplierToPathApplier);
 }
 
+#if HAVE(CGPATH_GET_NUMBER_OF_ELEMENTS)
+
+size_t Path::elementCount() const
+{
+    return CGPathGetNumberOfElements(m_path);
 }
 
+#endif // HAVE(CGPATH_GET_NUMBER_OF_ELEMENTS)
+
+}
+
 #endif // USE(CG)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to