Convert Path applier to use std::function
authorsimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Jul 2015 19:13:49 +0000 (19:13 +0000)
committersimon.fraser@apple.com <simon.fraser@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Jul 2015 19:13:49 +0000 (19:13 +0000)
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.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@187597 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
Source/WebCore/ChangeLog
Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm
Source/WebCore/inspector/InspectorOverlay.cpp
Source/WebCore/platform/graphics/Path.cpp
Source/WebCore/platform/graphics/Path.h
Source/WebCore/platform/graphics/cairo/FontCairo.cpp
Source/WebCore/platform/graphics/cairo/PathCairo.cpp
Source/WebCore/platform/graphics/cg/PathCG.cpp
Source/WebCore/rendering/svg/RenderSVGPath.cpp
Source/WebCore/rendering/svg/RenderSVGShape.cpp
Source/WebCore/rendering/svg/SVGMarkerData.h
Source/WebCore/rendering/svg/SVGSubpathData.h
Source/WebCore/svg/SVGPathUtilities.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebCoreArgumentCoders.cpp

index 80cba4d..a7b208e 100644 (file)
@@ -1,5 +1,47 @@
 2015-07-30  Simon Fraser  <simon.fraser@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.fraser@apple.com>
+
         Selecting in an iframe can cause main page scrolling
         https://bugs.webkit.org/show_bug.cgi?id=147431
         rdar://problem/19244589
index 830833c..2afc8bd 100644 (file)
@@ -247,11 +247,10 @@ struct PathConversionInfo {
     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 @@ static void ConvertPathToScreenSpaceFunction(void* info, const PathElement& elem
 - (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];
 }
 
index b8b5d74..b5e814a 100644 (file)
@@ -609,10 +609,8 @@ static void appendPathCommandAndPoints(PathApplyInfo& info, const String& comman
     }
 }
 
-// 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 @@ static RefPtr<Inspector::Protocol::OverlayTypes::ShapeOutsideData> buildObjectFo
         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 @@ static RefPtr<Inspector::Protocol::OverlayTypes::ShapeOutsideData> buildObjectFo
             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());
         }
index 5022b52..f088eff 100644 (file)
 
 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;
 }
index 17eba48..23640f3 100644 (file)
 
 #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 @@ namespace WebCore {
         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 @@ namespace WebCore {
         // 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);
index 64537c7..aa10c65 100644 (file)
@@ -174,9 +174,8 @@ static void updateX(GlyphIterationState& state, float x)
 // 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 @@ DashArray FontCascade::dashesForIntersectionsWithRect(const TextRun& run, const
         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());
index aa7b97f..dce36b1 100644 (file)
@@ -390,7 +390,7 @@ bool Path::strokeContains(StrokeStyleApplier* applier, const FloatPoint& point)
     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 @@ void Path::apply(void* info, PathApplierFunction function) const
         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;
         }
     }
index 3d9c31b..6d1543e 100644 (file)
@@ -375,14 +375,9 @@ FloatPoint Path::currentPoint() const
     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 @@ static void CGPathApplierToPathApplier(void *info, const CGPathElement* element)
     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);
 }
 
 }
index 4149552..8e40d8b 100644 (file)
@@ -155,7 +155,9 @@ void RenderSVGPath::updateZeroLengthSubpaths()
         return;
 
     SVGSubpathData subpathData(m_zeroLengthLinecapLocations);
-    path().apply(&subpathData, SVGSubpathData::updateFromPathElement);
+    path().apply([&subpathData](const PathElement& pathElement) {
+        SVGSubpathData::updateFromPathElement(subpathData, pathElement);
+    });
     subpathData.pathIsDone();
 }
 
index 7a1cac8..a19cdbb 100644 (file)
@@ -476,7 +476,9 @@ void RenderSVGShape::processMarkerPositions()
     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();
 }
 
index 1f1bb54..16b10eb 100644 (file)
@@ -54,22 +54,20 @@ public:
     {
     }
 
-    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()
index d7bc113..5ae2512 100644 (file)
@@ -29,51 +29,46 @@ class SVGSubpathData {
 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 @@ private:
     Vector<FloatPoint>& m_zeroLengthSubpathLocations;
     FloatPoint m_lastPoint;
     FloatPoint m_movePoint;
-    bool m_haveSeenMoveOnly;
-    bool m_pathIsZeroLength;
+    bool m_haveSeenMoveOnly { false };
+    bool m_pathIsZeroLength { false };
 };
 
 }
index 8ba8b45..8fa6280 100644 (file)
@@ -331,25 +331,23 @@ bool getPointAtLengthOfSVGPathByteStream(SVGPathByteStream* stream, float length
     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 @@ bool buildStringFromPath(const Path& path, String& string)
     // 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();
 
index e86102a..8eaea90 100644 (file)
@@ -1,3 +1,17 @@
+2015-07-30  Simon Fraser  <simon.fraser@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.park@samsung.com>
 
         [EFL] Enable IndexedDB based on DatabaseProcess
index 86141e5..1ce2f6c 100644 (file)
@@ -373,16 +373,8 @@ bool ArgumentCoder<IntSize>::decode(ArgumentDecoder& decoder, IntSize& intSize)
     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 @@ static void pathEncodeApplierFunction(void* info, const PathElement& element)
 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)