Title: [187597] trunk/Source
Revision
187597
Author
simon.fra...@apple.com
Date
2015-07-30 12:13:49 -0700 (Thu, 30 Jul 2015)

Log Message

Convert Path applier to use std::function
https://bugs.webkit.org/show_bug.cgi?id=147368

Reviewed by Sam Weinig.

Use std::function for Path::apply().

Source/WebCore:

* accessibility/mac/WebAccessibilityObjectWrapperBase.mm:
(convertPathToScreenSpaceFunction):
(-[WebAccessibilityObjectWrapperBase convertPathToScreenSpace:]):
(ConvertPathToScreenSpaceFunction): Deleted.
* inspector/InspectorOverlay.cpp:
(WebCore::appendPathSegment):
(WebCore::buildObjectForShapeOutside):
* platform/graphics/Path.cpp:
(WebCore::Path::length):
(WebCore::Path::traversalStateAtLength):
(WebCore::pathLengthApplierFunction): Deleted.
* platform/graphics/Path.h:
* platform/graphics/cairo/FontCairo.cpp:
(WebCore::findPathIntersections):
(WebCore::FontCascade::dashesForIntersectionsWithRect):
* platform/graphics/cairo/PathCairo.cpp:
(WebCore::Path::apply):
* platform/graphics/cg/PathCG.cpp:
(WebCore::CGPathApplierToPathApplier):
(WebCore::Path::apply):
* rendering/svg/RenderSVGPath.cpp:
(WebCore::RenderSVGPath::updateZeroLengthSubpaths):
* rendering/svg/RenderSVGShape.cpp:
(WebCore::RenderSVGShape::processMarkerPositions):
* rendering/svg/SVGMarkerData.h:
(WebCore::SVGMarkerData::updateFromPathElement):
* rendering/svg/SVGSubpathData.h:
(WebCore::SVGSubpathData::updateFromPathElement):
(WebCore::SVGSubpathData::SVGSubpathData): Deleted.
* svg/SVGPathUtilities.cpp:
(WebCore::pathIteratorForBuildingString):
(WebCore::buildStringFromPath):

Source/WebKit2:

* Shared/WebCoreArgumentCoders.cpp:
(IPC::pathEncodeApplierFunction):
(IPC::ArgumentCoder<Path>::encode):
(IPC::pathPointCountApplierFunction): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (187596 => 187597)


--- trunk/Source/WebCore/ChangeLog	2015-07-30 18:47:37 UTC (rev 187596)
+++ trunk/Source/WebCore/ChangeLog	2015-07-30 19:13:49 UTC (rev 187597)
@@ -1,5 +1,47 @@
 2015-07-30  Simon Fraser  <simon.fra...@apple.com>
 
+        Convert Path applier to use std::function
+        https://bugs.webkit.org/show_bug.cgi?id=147368
+
+        Reviewed by Sam Weinig.
+
+        Use std::function for Path::apply().
+
+        * accessibility/mac/WebAccessibilityObjectWrapperBase.mm:
+        (convertPathToScreenSpaceFunction):
+        (-[WebAccessibilityObjectWrapperBase convertPathToScreenSpace:]):
+        (ConvertPathToScreenSpaceFunction): Deleted.
+        * inspector/InspectorOverlay.cpp:
+        (WebCore::appendPathSegment):
+        (WebCore::buildObjectForShapeOutside):
+        * platform/graphics/Path.cpp:
+        (WebCore::Path::length):
+        (WebCore::Path::traversalStateAtLength):
+        (WebCore::pathLengthApplierFunction): Deleted.
+        * platform/graphics/Path.h:
+        * platform/graphics/cairo/FontCairo.cpp:
+        (WebCore::findPathIntersections):
+        (WebCore::FontCascade::dashesForIntersectionsWithRect):
+        * platform/graphics/cairo/PathCairo.cpp:
+        (WebCore::Path::apply):
+        * platform/graphics/cg/PathCG.cpp:
+        (WebCore::CGPathApplierToPathApplier):
+        (WebCore::Path::apply):
+        * rendering/svg/RenderSVGPath.cpp:
+        (WebCore::RenderSVGPath::updateZeroLengthSubpaths):
+        * rendering/svg/RenderSVGShape.cpp:
+        (WebCore::RenderSVGShape::processMarkerPositions):
+        * rendering/svg/SVGMarkerData.h:
+        (WebCore::SVGMarkerData::updateFromPathElement):
+        * rendering/svg/SVGSubpathData.h:
+        (WebCore::SVGSubpathData::updateFromPathElement):
+        (WebCore::SVGSubpathData::SVGSubpathData): Deleted.
+        * svg/SVGPathUtilities.cpp:
+        (WebCore::pathIteratorForBuildingString):
+        (WebCore::buildStringFromPath):
+
+2015-07-30  Simon Fraser  <simon.fra...@apple.com>
+
         Selecting in an iframe can cause main page scrolling
         https://bugs.webkit.org/show_bug.cgi?id=147431
         rdar://problem/19244589

Modified: trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm (187596 => 187597)


--- trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm	2015-07-30 18:47:37 UTC (rev 187596)
+++ trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm	2015-07-30 19:13:49 UTC (rev 187597)
@@ -247,11 +247,10 @@
     CGMutablePathRef path;
 };
 
-static void ConvertPathToScreenSpaceFunction(void* info, const PathElement& element)
+static void convertPathToScreenSpaceFunction(PathConversionInfo& conversion, const PathElement& element)
 {
-    PathConversionInfo* conversion = (PathConversionInfo*)info;
-    WebAccessibilityObjectWrapperBase *wrapper = conversion->wrapper;
-    CGMutablePathRef newPath = conversion->path;
+    WebAccessibilityObjectWrapperBase *wrapper = conversion.wrapper;
+    CGMutablePathRef newPath = conversion.path;
     switch (element.type) {
     case PathElementMoveToPoint:
     {
@@ -291,7 +290,9 @@
 - (CGPathRef)convertPathToScreenSpace:(Path &)path
 {
     PathConversionInfo conversion = { self, CGPathCreateMutable() };
-    path.apply(&conversion, ConvertPathToScreenSpaceFunction);    
+    path.apply([&conversion](const PathElement& pathElement) {
+        convertPathToScreenSpaceFunction(conversion, pathElement);
+    });
     return (CGPathRef)[(id)conversion.path autorelease];
 }
 

Modified: trunk/Source/WebCore/inspector/InspectorOverlay.cpp (187596 => 187597)


--- trunk/Source/WebCore/inspector/InspectorOverlay.cpp	2015-07-30 18:47:37 UTC (rev 187596)
+++ trunk/Source/WebCore/inspector/InspectorOverlay.cpp	2015-07-30 19:13:49 UTC (rev 187597)
@@ -609,10 +609,8 @@
     }
 }
 
-// Used as a functor for Shape::apply, which has not been cleaned up to use modern C++.
-static void appendPathSegment(void* info, const PathElement& pathElement)
+static void appendPathSegment(PathApplyInfo& pathApplyInfo, const PathElement& pathElement)
 {
-    PathApplyInfo& pathApplyInfo = *static_cast<PathApplyInfo*>(info);
     FloatPoint point;
     switch (pathElement.type) {
     // The points member will contain 1 value.
@@ -664,7 +662,9 @@
         info.renderer = renderer;
         info.shapeOutsideInfo = shapeOutsideInfo;
 
-        paths.shape.apply(&info, &appendPathSegment);
+        paths.shape.apply([&info](const PathElement& pathElement) {
+            appendPathSegment(info, pathElement);
+        });
 
         shapeObject->setShape(shapePath.copyRef());
 
@@ -672,7 +672,9 @@
             auto marginShapePath = Inspector::Protocol::OverlayTypes::DisplayPath::create();
             info.pathArray = &marginShapePath.get();
 
-            paths.marginShape.apply(&info, &appendPathSegment);
+            paths.marginShape.apply([&info](const PathElement& pathElement) {
+                appendPathSegment(info, pathElement);
+            });
 
             shapeObject->setMarginShape(marginShapePath.copyRef());
         }

Modified: trunk/Source/WebCore/platform/graphics/Path.cpp (187596 => 187597)


--- trunk/Source/WebCore/platform/graphics/Path.cpp	2015-07-30 18:47:37 UTC (rev 187596)
+++ trunk/Source/WebCore/platform/graphics/Path.cpp	2015-07-30 19:13:49 UTC (rev 187597)
@@ -39,23 +39,25 @@
 
 namespace WebCore {
 
-static void pathLengthApplierFunction(void* info, const PathElement& element)
-{
-    PathTraversalState& traversalState = *static_cast<PathTraversalState*>(info);
-    traversalState.processPathElement(element);
-}
-
 float Path::length() const
 {
     PathTraversalState traversalState(PathTraversalState::Action::TotalLength);
-    apply(&traversalState, pathLengthApplierFunction);
+
+    apply([&traversalState](const PathElement& element) {
+        traversalState.processPathElement(element);
+    });
+
     return traversalState.totalLength();
 }
 
 PathTraversalState Path::traversalStateAtLength(float length, bool& success) const
 {
     PathTraversalState traversalState(PathTraversalState::Action::VectorAtLength, length);
-    apply(&traversalState, pathLengthApplierFunction);
+
+    apply([&traversalState](const PathElement& element) {
+        traversalState.processPathElement(element);
+    });
+
     success = traversalState.success();
     return traversalState;
 }

Modified: trunk/Source/WebCore/platform/graphics/Path.h (187596 => 187597)


--- trunk/Source/WebCore/platform/graphics/Path.h	2015-07-30 18:47:37 UTC (rev 187596)
+++ trunk/Source/WebCore/platform/graphics/Path.h	2015-07-30 19:13:49 UTC (rev 187597)
@@ -30,25 +30,34 @@
 
 #include "FloatRect.h"
 #include "WindRule.h"
+#include <functional>
 #include <wtf/FastMalloc.h>
 #include <wtf/Forward.h>
 
 #if USE(CG)
+
 #include <wtf/RetainPtr.h>
 #include <CoreGraphics/CGPath.h>
 typedef struct CGPath PlatformPath;
+
 #elif USE(CAIRO)
+
 namespace WebCore {
 class CairoPath;
 }
 typedef WebCore::CairoPath PlatformPath;
+
 #elif USE(WINGDI)
+
 namespace WebCore {
     class PlatformPath;
 }
 typedef WebCore::PlatformPath PlatformPath;
+
 #else
+
 typedef void PlatformPath;
+
 #endif
 
 typedef PlatformPath* PlatformPathPtr;
@@ -80,7 +89,7 @@
         FloatPoint* points;
     };
 
-    typedef void (*PathApplierFunction)(void* info, const PathElement&);
+    typedef std::function<void (const PathElement&)> PathApplierFunction;
 
     class Path {
         WTF_MAKE_FAST_ALLOCATED;
@@ -146,7 +155,7 @@
         // ensurePlatformPath() will allocate a PlatformPath if it has not yet been and will never return null.
         WEBCORE_EXPORT PlatformPathPtr ensurePlatformPath();
 
-        WEBCORE_EXPORT void apply(void* info, PathApplierFunction) const;
+        WEBCORE_EXPORT void apply(PathApplierFunction) const;
         void transform(const AffineTransform&);
 
         void addBeziersForRoundedRect(const FloatRect&, const FloatSize& topLeftRadius, const FloatSize& topRightRadius, const FloatSize& bottomLeftRadius, const FloatSize& bottomRightRadius);

Modified: trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp (187596 => 187597)


--- trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp	2015-07-30 18:47:37 UTC (rev 187596)
+++ trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp	2015-07-30 19:13:49 UTC (rev 187597)
@@ -174,9 +174,8 @@
 // pseudo-contour and the vertical center of the underline found in GlyphIterationState::centerOfLine.
 // It keeps track of the leftmost and rightmost intersection in  GlyphIterationState::minX and 
 // GlyphIterationState::maxX.
-static void findPathIntersections(void* stateAsVoidPointer, const PathElement& element)
+static void findPathIntersections(GlyphIterationState& state, const PathElement& element)
 {
-    auto& state = *static_cast<GlyphIterationState*>(stateAsVoidPointer);
     bool doIntersection = false;
     FloatPoint point = FloatPoint();
     switch (element.type) {
@@ -337,7 +336,9 @@
         switch (translator->underlineType()) {
         case GlyphToPathTranslator::GlyphUnderlineType::SkipDescenders: {
             Path path = translator->path();
-            path.apply(&info, &findPathIntersections);
+            path.apply([&info](const PathElement& pathElement) {
+                findPathIntersections(info, pathElement);
+            });
             if (info.minX < info.maxX) {
                 result.append(info.minX - lineExtents.x());
                 result.append(info.maxX - lineExtents.x());

Modified: trunk/Source/WebCore/platform/graphics/cairo/PathCairo.cpp (187596 => 187597)


--- trunk/Source/WebCore/platform/graphics/cairo/PathCairo.cpp	2015-07-30 18:47:37 UTC (rev 187596)
+++ trunk/Source/WebCore/platform/graphics/cairo/PathCairo.cpp	2015-07-30 19:13:49 UTC (rev 187597)
@@ -390,7 +390,7 @@
     return cairo_in_stroke(cr, point.x(), point.y());
 }
 
-void Path::apply(void* info, PathApplierFunction function) const
+void Path::apply(PathApplierFunction function) const
 {
     if (isNull())
         return;
@@ -408,23 +408,23 @@
         case CAIRO_PATH_MOVE_TO:
             pelement.type = PathElementMoveToPoint;
             pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y);
-            function(info, pelement);
+            function(pelement);
             break;
         case CAIRO_PATH_LINE_TO:
             pelement.type = PathElementAddLineToPoint;
             pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y);
-            function(info, pelement);
+            function(pelement);
             break;
         case CAIRO_PATH_CURVE_TO:
             pelement.type = PathElementAddCurveToPoint;
             pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y);
             pelement.points[1] = FloatPoint(data[2].point.x,data[2].point.y);
             pelement.points[2] = FloatPoint(data[3].point.x,data[3].point.y);
-            function(info, pelement);
+            function(pelement);
             break;
         case CAIRO_PATH_CLOSE_PATH:
             pelement.type = PathElementCloseSubpath;
-            function(info, pelement);
+            function(pelement);
             break;
         }
     }

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


--- trunk/Source/WebCore/platform/graphics/cg/PathCG.cpp	2015-07-30 18:47:37 UTC (rev 187596)
+++ trunk/Source/WebCore/platform/graphics/cg/PathCG.cpp	2015-07-30 19:13:49 UTC (rev 187597)
@@ -375,14 +375,9 @@
     return CGPathGetCurrentPoint(m_path);
 }
 
-struct PathApplierInfo {
-    void* info;
-    PathApplierFunction function;
-};
-
 static void CGPathApplierToPathApplier(void *info, const CGPathElement* element)
 {
-    PathApplierInfo* pinfo = (PathApplierInfo*)info;
+    PathApplierFunction function = *(PathApplierFunction*)info;
     FloatPoint points[3];
     PathElement pelement;
     pelement.type = (PathElementType)element->type;
@@ -405,18 +400,15 @@
     case kCGPathElementCloseSubpath:
         break;
     }
-    pinfo->function(pinfo->info, pelement);
+    function(pelement);
 }
 
-void Path::apply(void* info, PathApplierFunction function) const
+void Path::apply(PathApplierFunction function) const
 {
     if (isNull())
         return;
 
-    PathApplierInfo pinfo;
-    pinfo.info = info;
-    pinfo.function = function;
-    CGPathApply(m_path, &pinfo, CGPathApplierToPathApplier);
+    CGPathApply(m_path, &function, CGPathApplierToPathApplier);
 }
 
 }

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGPath.cpp (187596 => 187597)


--- trunk/Source/WebCore/rendering/svg/RenderSVGPath.cpp	2015-07-30 18:47:37 UTC (rev 187596)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGPath.cpp	2015-07-30 19:13:49 UTC (rev 187597)
@@ -155,7 +155,9 @@
         return;
 
     SVGSubpathData subpathData(m_zeroLengthLinecapLocations);
-    path().apply(&subpathData, SVGSubpathData::updateFromPathElement);
+    path().apply([&subpathData](const PathElement& pathElement) {
+        SVGSubpathData::updateFromPathElement(subpathData, pathElement);
+    });
     subpathData.pathIsDone();
 }
 

Modified: trunk/Source/WebCore/rendering/svg/RenderSVGShape.cpp (187596 => 187597)


--- trunk/Source/WebCore/rendering/svg/RenderSVGShape.cpp	2015-07-30 18:47:37 UTC (rev 187596)
+++ trunk/Source/WebCore/rendering/svg/RenderSVGShape.cpp	2015-07-30 19:13:49 UTC (rev 187597)
@@ -476,7 +476,9 @@
     ASSERT(m_path);
 
     SVGMarkerData markerData(m_markerPositions);
-    m_path->apply(&markerData, SVGMarkerData::updateFromPathElement);
+    m_path->apply([&markerData](const PathElement& pathElement) {
+        SVGMarkerData::updateFromPathElement(markerData, pathElement);
+    });
     markerData.pathIsDone();
 }
 

Modified: trunk/Source/WebCore/rendering/svg/SVGMarkerData.h (187596 => 187597)


--- trunk/Source/WebCore/rendering/svg/SVGMarkerData.h	2015-07-30 18:47:37 UTC (rev 187596)
+++ trunk/Source/WebCore/rendering/svg/SVGMarkerData.h	2015-07-30 19:13:49 UTC (rev 187597)
@@ -54,22 +54,20 @@
     {
     }
 
-    static void updateFromPathElement(void* info, const PathElement& element)
+    static void updateFromPathElement(SVGMarkerData& markerData, const PathElement& element)
     {
-        SVGMarkerData* markerData = static_cast<SVGMarkerData*>(info);
-
         // First update the outslope for the previous element.
-        markerData->updateOutslope(element.points[0]);
+        markerData.updateOutslope(element.points[0]);
 
         // Record the marker for the previous element.
-        if (markerData->m_elementIndex > 0) {
-            SVGMarkerType markerType = markerData->m_elementIndex == 1 ? StartMarker : MidMarker;
-            markerData->m_positions.append(MarkerPosition(markerType, markerData->m_origin, markerData->currentAngle(markerType)));
+        if (markerData.m_elementIndex > 0) {
+            SVGMarkerType markerType = markerData.m_elementIndex == 1 ? StartMarker : MidMarker;
+            markerData.m_positions.append(MarkerPosition(markerType, markerData.m_origin, markerData.currentAngle(markerType)));
         }
 
         // Update our marker data for this element.
-        markerData->updateMarkerDataForPathElement(element);
-        ++markerData->m_elementIndex;
+        markerData.updateMarkerDataForPathElement(element);
+        ++markerData.m_elementIndex;
     }
 
     void pathIsDone()

Modified: trunk/Source/WebCore/rendering/svg/SVGSubpathData.h (187596 => 187597)


--- trunk/Source/WebCore/rendering/svg/SVGSubpathData.h	2015-07-30 18:47:37 UTC (rev 187596)
+++ trunk/Source/WebCore/rendering/svg/SVGSubpathData.h	2015-07-30 19:13:49 UTC (rev 187597)
@@ -29,51 +29,46 @@
 public:
     SVGSubpathData(Vector<FloatPoint>& zeroLengthSubpathLocations)
         : m_zeroLengthSubpathLocations(zeroLengthSubpathLocations)
-        , m_haveSeenMoveOnly(true)
-        , m_pathIsZeroLength(true)
     {
-        m_lastPoint.set(0, 0);
-        m_movePoint.set(0, 0);
     }
 
-    static void updateFromPathElement(void* info, const PathElement& element)
+    static void updateFromPathElement(SVGSubpathData& subpathFinder, const PathElement& element)
     {
-        SVGSubpathData* subpathFinder = static_cast<SVGSubpathData*>(info);
         switch (element.type) {
         case PathElementMoveToPoint:
-            if (subpathFinder->m_pathIsZeroLength && !subpathFinder->m_haveSeenMoveOnly)
-                subpathFinder->m_zeroLengthSubpathLocations.append(subpathFinder->m_lastPoint);
-            subpathFinder->m_lastPoint = subpathFinder->m_movePoint = element.points[0];
-            subpathFinder->m_haveSeenMoveOnly = true;
-            subpathFinder->m_pathIsZeroLength = true;
+            if (subpathFinder.m_pathIsZeroLength && !subpathFinder.m_haveSeenMoveOnly)
+                subpathFinder.m_zeroLengthSubpathLocations.append(subpathFinder.m_lastPoint);
+            subpathFinder.m_lastPoint = subpathFinder.m_movePoint = element.points[0];
+            subpathFinder.m_haveSeenMoveOnly = true;
+            subpathFinder.m_pathIsZeroLength = true;
             break;
         case PathElementAddLineToPoint:
-            if (subpathFinder->m_lastPoint != element.points[0]) {
-                subpathFinder->m_pathIsZeroLength = false;
-                subpathFinder->m_lastPoint = element.points[0];
+            if (subpathFinder.m_lastPoint != element.points[0]) {
+                subpathFinder.m_pathIsZeroLength = false;
+                subpathFinder.m_lastPoint = element.points[0];
             }
-            subpathFinder->m_haveSeenMoveOnly = false;
+            subpathFinder.m_haveSeenMoveOnly = false;
             break;
         case PathElementAddQuadCurveToPoint:
-            if (subpathFinder->m_lastPoint != element.points[0] || element.points[0] != element.points[1]) {
-                subpathFinder->m_pathIsZeroLength = false;
-                subpathFinder->m_lastPoint = element.points[1];
+            if (subpathFinder.m_lastPoint != element.points[0] || element.points[0] != element.points[1]) {
+                subpathFinder.m_pathIsZeroLength = false;
+                subpathFinder.m_lastPoint = element.points[1];
             }
-            subpathFinder->m_haveSeenMoveOnly = false;
+            subpathFinder.m_haveSeenMoveOnly = false;
             break;
         case PathElementAddCurveToPoint:
-            if (subpathFinder->m_lastPoint != element.points[0] || element.points[0] != element.points[1] || element.points[1] != element.points[2]) {
-                subpathFinder->m_pathIsZeroLength = false;
-                subpathFinder->m_lastPoint = element.points[2];
+            if (subpathFinder.m_lastPoint != element.points[0] || element.points[0] != element.points[1] || element.points[1] != element.points[2]) {
+                subpathFinder.m_pathIsZeroLength = false;
+                subpathFinder.m_lastPoint = element.points[2];
             }
-            subpathFinder->m_haveSeenMoveOnly = false;
+            subpathFinder.m_haveSeenMoveOnly = false;
             break;
         case PathElementCloseSubpath:
-            if (subpathFinder->m_pathIsZeroLength)
-                subpathFinder->m_zeroLengthSubpathLocations.append(subpathFinder->m_lastPoint);
-            subpathFinder->m_haveSeenMoveOnly = true; // This is an implicit move for the next element
-            subpathFinder->m_pathIsZeroLength = true; // A new sub-path also starts here
-            subpathFinder->m_lastPoint = subpathFinder->m_movePoint;
+            if (subpathFinder.m_pathIsZeroLength)
+                subpathFinder.m_zeroLengthSubpathLocations.append(subpathFinder.m_lastPoint);
+            subpathFinder.m_haveSeenMoveOnly = true; // This is an implicit move for the next element
+            subpathFinder.m_pathIsZeroLength = true; // A new sub-path also starts here
+            subpathFinder.m_lastPoint = subpathFinder.m_movePoint;
             break;
         }
     }
@@ -88,8 +83,8 @@
     Vector<FloatPoint>& m_zeroLengthSubpathLocations;
     FloatPoint m_lastPoint;
     FloatPoint m_movePoint;
-    bool m_haveSeenMoveOnly;
-    bool m_pathIsZeroLength;
+    bool m_haveSeenMoveOnly { false };
+    bool m_pathIsZeroLength { false };
 };
 
 }

Modified: trunk/Source/WebCore/svg/SVGPathUtilities.cpp (187596 => 187597)


--- trunk/Source/WebCore/svg/SVGPathUtilities.cpp	2015-07-30 18:47:37 UTC (rev 187596)
+++ trunk/Source/WebCore/svg/SVGPathUtilities.cpp	2015-07-30 19:13:49 UTC (rev 187597)
@@ -331,25 +331,23 @@
     return ok;
 }
 
-static void pathIteratorForBuildingString(void* info, const PathElement& pathElement)
+static void pathIteratorForBuildingString(SVGPathConsumer& consumer, const PathElement& pathElement)
 {
-    SVGPathConsumer* consumer = static_cast<SVGPathConsumer*>(info);
-
     switch (pathElement.type) {
     case PathElementMoveToPoint:
-        consumer->moveTo(pathElement.points[0], false, AbsoluteCoordinates);
+        consumer.moveTo(pathElement.points[0], false, AbsoluteCoordinates);
         break;
     case PathElementAddLineToPoint:
-        consumer->lineTo(pathElement.points[0], AbsoluteCoordinates);
+        consumer.lineTo(pathElement.points[0], AbsoluteCoordinates);
         break;
     case PathElementAddQuadCurveToPoint:
-        consumer->curveToQuadratic(pathElement.points[0], pathElement.points[1], AbsoluteCoordinates);
+        consumer.curveToQuadratic(pathElement.points[0], pathElement.points[1], AbsoluteCoordinates);
         break;
     case PathElementAddCurveToPoint:
-        consumer->curveToCubic(pathElement.points[0], pathElement.points[1], pathElement.points[2], AbsoluteCoordinates);
+        consumer.curveToCubic(pathElement.points[0], pathElement.points[1], pathElement.points[2], AbsoluteCoordinates);
         break;
     case PathElementCloseSubpath:
-        consumer->closePath();
+        consumer.closePath();
         break;
 
     default:
@@ -364,7 +362,9 @@
     // a path, only apply a function to all path elements at once.
 
     SVGPathStringBuilder* builder = globalSVGPathStringBuilder();
-    path.apply(builder, &pathIteratorForBuildingString);
+    path.apply([builder](const PathElement& pathElement) {
+        pathIteratorForBuildingString(*builder, pathElement);
+    });
     string = builder->result();
     static_cast<SVGPathConsumer*>(builder)->cleanup();
 

Modified: trunk/Source/WebKit2/ChangeLog (187596 => 187597)


--- trunk/Source/WebKit2/ChangeLog	2015-07-30 18:47:37 UTC (rev 187596)
+++ trunk/Source/WebKit2/ChangeLog	2015-07-30 19:13:49 UTC (rev 187597)
@@ -1,3 +1,17 @@
+2015-07-30  Simon Fraser  <simon.fra...@apple.com>
+
+        Convert Path applier to use std::function
+        https://bugs.webkit.org/show_bug.cgi?id=147368
+
+        Reviewed by Sam Weinig.
+
+        Use std::function for Path::apply().
+
+        * Shared/WebCoreArgumentCoders.cpp:
+        (IPC::pathEncodeApplierFunction):
+        (IPC::ArgumentCoder<Path>::encode):
+        (IPC::pathPointCountApplierFunction): Deleted.
+
 2015-07-30  Joonghun Park  <jh718.p...@samsung.com>
 
         [EFL] Enable IndexedDB based on DatabaseProcess

Modified: trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp (187596 => 187597)


--- trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp	2015-07-30 18:47:37 UTC (rev 187596)
+++ trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp	2015-07-30 19:13:49 UTC (rev 187597)
@@ -373,16 +373,8 @@
     return SimpleArgumentCoder<IntSize>::decode(decoder, intSize);
 }
 
-static void pathPointCountApplierFunction(void* info, const PathElement&)
+static void pathEncodeApplierFunction(ArgumentEncoder& encoder, const PathElement& element)
 {
-    uint64_t* pointCount = static_cast<uint64_t*>(info);
-    ++*pointCount;
-}
-
-static void pathEncodeApplierFunction(void* info, const PathElement& element)
-{
-    ArgumentEncoder& encoder = *static_cast<ArgumentEncoder*>(info);
-
     encoder.encodeEnum(element.type);
 
     switch (element.type) {
@@ -409,11 +401,15 @@
 void ArgumentCoder<Path>::encode(ArgumentEncoder& encoder, const Path& path)
 {
     uint64_t numPoints = 0;
-    path.apply(&numPoints, pathPointCountApplierFunction);
+    path.apply([&numPoints](const PathElement&) {
+        ++numPoints;
+    });
 
     encoder << numPoints;
 
-    path.apply(&encoder, pathEncodeApplierFunction);
+    path.apply([&encoder](const PathElement& pathElement) {
+        pathEncodeApplierFunction(encoder, pathElement);
+    });
 }
 
 bool ArgumentCoder<Path>::decode(ArgumentDecoder& decoder, Path& path)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to