Changeset 187597 in webkit


Ignore:
Timestamp:
Jul 30, 2015 12:13:49 PM (9 years ago)
Author:
Simon Fraser
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.

Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r187593 r187597  
     12015-07-30  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Convert Path applier to use std::function
     4        https://bugs.webkit.org/show_bug.cgi?id=147368
     5
     6        Reviewed by Sam Weinig.
     7
     8        Use std::function for Path::apply().
     9
     10        * accessibility/mac/WebAccessibilityObjectWrapperBase.mm:
     11        (convertPathToScreenSpaceFunction):
     12        (-[WebAccessibilityObjectWrapperBase convertPathToScreenSpace:]):
     13        (ConvertPathToScreenSpaceFunction): Deleted.
     14        * inspector/InspectorOverlay.cpp:
     15        (WebCore::appendPathSegment):
     16        (WebCore::buildObjectForShapeOutside):
     17        * platform/graphics/Path.cpp:
     18        (WebCore::Path::length):
     19        (WebCore::Path::traversalStateAtLength):
     20        (WebCore::pathLengthApplierFunction): Deleted.
     21        * platform/graphics/Path.h:
     22        * platform/graphics/cairo/FontCairo.cpp:
     23        (WebCore::findPathIntersections):
     24        (WebCore::FontCascade::dashesForIntersectionsWithRect):
     25        * platform/graphics/cairo/PathCairo.cpp:
     26        (WebCore::Path::apply):
     27        * platform/graphics/cg/PathCG.cpp:
     28        (WebCore::CGPathApplierToPathApplier):
     29        (WebCore::Path::apply):
     30        * rendering/svg/RenderSVGPath.cpp:
     31        (WebCore::RenderSVGPath::updateZeroLengthSubpaths):
     32        * rendering/svg/RenderSVGShape.cpp:
     33        (WebCore::RenderSVGShape::processMarkerPositions):
     34        * rendering/svg/SVGMarkerData.h:
     35        (WebCore::SVGMarkerData::updateFromPathElement):
     36        * rendering/svg/SVGSubpathData.h:
     37        (WebCore::SVGSubpathData::updateFromPathElement):
     38        (WebCore::SVGSubpathData::SVGSubpathData): Deleted.
     39        * svg/SVGPathUtilities.cpp:
     40        (WebCore::pathIteratorForBuildingString):
     41        (WebCore::buildStringFromPath):
     42
    1432015-07-30  Simon Fraser  <simon.fraser@apple.com>
    244
  • trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm

    r187492 r187597  
    248248};
    249249
    250 static void ConvertPathToScreenSpaceFunction(void* info, const PathElement& element)
    251 {
    252     PathConversionInfo* conversion = (PathConversionInfo*)info;
    253     WebAccessibilityObjectWrapperBase *wrapper = conversion->wrapper;
    254     CGMutablePathRef newPath = conversion->path;
     250static void convertPathToScreenSpaceFunction(PathConversionInfo& conversion, const PathElement& element)
     251{
     252    WebAccessibilityObjectWrapperBase *wrapper = conversion.wrapper;
     253    CGMutablePathRef newPath = conversion.path;
    255254    switch (element.type) {
    256255    case PathElementMoveToPoint:
     
    292291{
    293292    PathConversionInfo conversion = { self, CGPathCreateMutable() };
    294     path.apply(&conversion, ConvertPathToScreenSpaceFunction);   
     293    path.apply([&conversion](const PathElement& pathElement) {
     294        convertPathToScreenSpaceFunction(conversion, pathElement);
     295    });
    295296    return (CGPathRef)[(id)conversion.path autorelease];
    296297}
  • trunk/Source/WebCore/inspector/InspectorOverlay.cpp

    r187496 r187597  
    610610}
    611611
    612 // Used as a functor for Shape::apply, which has not been cleaned up to use modern C++.
    613 static void appendPathSegment(void* info, const PathElement& pathElement)
    614 {
    615     PathApplyInfo& pathApplyInfo = *static_cast<PathApplyInfo*>(info);
     612static void appendPathSegment(PathApplyInfo& pathApplyInfo, const PathElement& pathElement)
     613{
    616614    FloatPoint point;
    617615    switch (pathElement.type) {
     
    665663        info.shapeOutsideInfo = shapeOutsideInfo;
    666664
    667         paths.shape.apply(&info, &appendPathSegment);
     665        paths.shape.apply([&info](const PathElement& pathElement) {
     666            appendPathSegment(info, pathElement);
     667        });
    668668
    669669        shapeObject->setShape(shapePath.copyRef());
     
    673673            info.pathArray = &marginShapePath.get();
    674674
    675             paths.marginShape.apply(&info, &appendPathSegment);
     675            paths.marginShape.apply([&info](const PathElement& pathElement) {
     676                appendPathSegment(info, pathElement);
     677            });
    676678
    677679            shapeObject->setMarginShape(marginShapePath.copyRef());
  • trunk/Source/WebCore/platform/graphics/Path.cpp

    r187492 r187597  
    4040namespace WebCore {
    4141
    42 static void pathLengthApplierFunction(void* info, const PathElement& element)
    43 {
    44     PathTraversalState& traversalState = *static_cast<PathTraversalState*>(info);
    45     traversalState.processPathElement(element);
    46 }
    47 
    4842float Path::length() const
    4943{
    5044    PathTraversalState traversalState(PathTraversalState::Action::TotalLength);
    51     apply(&traversalState, pathLengthApplierFunction);
     45
     46    apply([&traversalState](const PathElement& element) {
     47        traversalState.processPathElement(element);
     48    });
     49
    5250    return traversalState.totalLength();
    5351}
     
    5654{
    5755    PathTraversalState traversalState(PathTraversalState::Action::VectorAtLength, length);
    58     apply(&traversalState, pathLengthApplierFunction);
     56
     57    apply([&traversalState](const PathElement& element) {
     58        traversalState.processPathElement(element);
     59    });
     60
    5961    success = traversalState.success();
    6062    return traversalState;
  • trunk/Source/WebCore/platform/graphics/Path.h

    r187492 r187597  
    3131#include "FloatRect.h"
    3232#include "WindRule.h"
     33#include <functional>
    3334#include <wtf/FastMalloc.h>
    3435#include <wtf/Forward.h>
    3536
    3637#if USE(CG)
     38
    3739#include <wtf/RetainPtr.h>
    3840#include <CoreGraphics/CGPath.h>
    3941typedef struct CGPath PlatformPath;
     42
    4043#elif USE(CAIRO)
     44
    4145namespace WebCore {
    4246class CairoPath;
    4347}
    4448typedef WebCore::CairoPath PlatformPath;
     49
    4550#elif USE(WINGDI)
     51
    4652namespace WebCore {
    4753    class PlatformPath;
    4854}
    4955typedef WebCore::PlatformPath PlatformPath;
     56
    5057#else
     58
    5159typedef void PlatformPath;
     60
    5261#endif
    5362
     
    8190    };
    8291
    83     typedef void (*PathApplierFunction)(void* info, const PathElement&);
     92    typedef std::function<void (const PathElement&)> PathApplierFunction;
    8493
    8594    class Path {
     
    147156        WEBCORE_EXPORT PlatformPathPtr ensurePlatformPath();
    148157
    149         WEBCORE_EXPORT void apply(void* info, PathApplierFunction) const;
     158        WEBCORE_EXPORT void apply(PathApplierFunction) const;
    150159        void transform(const AffineTransform&);
    151160
  • trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp

    r187492 r187597  
    175175// It keeps track of the leftmost and rightmost intersection in  GlyphIterationState::minX and
    176176// GlyphIterationState::maxX.
    177 static void findPathIntersections(void* stateAsVoidPointer, const PathElement& element)
    178 {
    179     auto& state = *static_cast<GlyphIterationState*>(stateAsVoidPointer);
     177static void findPathIntersections(GlyphIterationState& state, const PathElement& element)
     178{
    180179    bool doIntersection = false;
    181180    FloatPoint point = FloatPoint();
     
    338337        case GlyphToPathTranslator::GlyphUnderlineType::SkipDescenders: {
    339338            Path path = translator->path();
    340             path.apply(&info, &findPathIntersections);
     339            path.apply([&info](const PathElement& pathElement) {
     340                findPathIntersections(info, pathElement);
     341            });
    341342            if (info.minX < info.maxX) {
    342343                result.append(info.minX - lineExtents.x());
  • trunk/Source/WebCore/platform/graphics/cairo/PathCairo.cpp

    r187498 r187597  
    391391}
    392392
    393 void Path::apply(void* info, PathApplierFunction function) const
     393void Path::apply(PathApplierFunction function) const
    394394{
    395395    if (isNull())
     
    409409            pelement.type = PathElementMoveToPoint;
    410410            pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y);
    411             function(info, pelement);
     411            function(pelement);
    412412            break;
    413413        case CAIRO_PATH_LINE_TO:
    414414            pelement.type = PathElementAddLineToPoint;
    415415            pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y);
    416             function(info, pelement);
     416            function(pelement);
    417417            break;
    418418        case CAIRO_PATH_CURVE_TO:
     
    421421            pelement.points[1] = FloatPoint(data[2].point.x,data[2].point.y);
    422422            pelement.points[2] = FloatPoint(data[3].point.x,data[3].point.y);
    423             function(info, pelement);
     423            function(pelement);
    424424            break;
    425425        case CAIRO_PATH_CLOSE_PATH:
    426426            pelement.type = PathElementCloseSubpath;
    427             function(info, pelement);
     427            function(pelement);
    428428            break;
    429429        }
  • trunk/Source/WebCore/platform/graphics/cg/PathCG.cpp

    r187492 r187597  
    376376}
    377377
    378 struct PathApplierInfo {
    379     void* info;
    380     PathApplierFunction function;
    381 };
    382 
    383378static void CGPathApplierToPathApplier(void *info, const CGPathElement* element)
    384379{
    385     PathApplierInfo* pinfo = (PathApplierInfo*)info;
     380    PathApplierFunction function = *(PathApplierFunction*)info;
    386381    FloatPoint points[3];
    387382    PathElement pelement;
     
    406401        break;
    407402    }
    408     pinfo->function(pinfo->info, pelement);
    409 }
    410 
    411 void Path::apply(void* info, PathApplierFunction function) const
    412 {
    413     if (isNull())
    414         return;
    415 
    416     PathApplierInfo pinfo;
    417     pinfo.info = info;
    418     pinfo.function = function;
    419     CGPathApply(m_path, &pinfo, CGPathApplierToPathApplier);
     403    function(pelement);
     404}
     405
     406void Path::apply(PathApplierFunction function) const
     407{
     408    if (isNull())
     409        return;
     410
     411    CGPathApply(m_path, &function, CGPathApplierToPathApplier);
    420412}
    421413
  • trunk/Source/WebCore/rendering/svg/RenderSVGPath.cpp

    r177259 r187597  
    156156
    157157    SVGSubpathData subpathData(m_zeroLengthLinecapLocations);
    158     path().apply(&subpathData, SVGSubpathData::updateFromPathElement);
     158    path().apply([&subpathData](const PathElement& pathElement) {
     159        SVGSubpathData::updateFromPathElement(subpathData, pathElement);
     160    });
    159161    subpathData.pathIsDone();
    160162}
  • trunk/Source/WebCore/rendering/svg/RenderSVGShape.cpp

    r183065 r187597  
    477477
    478478    SVGMarkerData markerData(m_markerPositions);
    479     m_path->apply(&markerData, SVGMarkerData::updateFromPathElement);
     479    m_path->apply([&markerData](const PathElement& pathElement) {
     480        SVGMarkerData::updateFromPathElement(markerData, pathElement);
     481    });
    480482    markerData.pathIsDone();
    481483}
  • trunk/Source/WebCore/rendering/svg/SVGMarkerData.h

    r187492 r187597  
    5555    }
    5656
    57     static void updateFromPathElement(void* info, const PathElement& element)
     57    static void updateFromPathElement(SVGMarkerData& markerData, const PathElement& element)
    5858    {
    59         SVGMarkerData* markerData = static_cast<SVGMarkerData*>(info);
    60 
    6159        // First update the outslope for the previous element.
    62         markerData->updateOutslope(element.points[0]);
     60        markerData.updateOutslope(element.points[0]);
    6361
    6462        // Record the marker for the previous element.
    65         if (markerData->m_elementIndex > 0) {
    66             SVGMarkerType markerType = markerData->m_elementIndex == 1 ? StartMarker : MidMarker;
    67             markerData->m_positions.append(MarkerPosition(markerType, markerData->m_origin, markerData->currentAngle(markerType)));
     63        if (markerData.m_elementIndex > 0) {
     64            SVGMarkerType markerType = markerData.m_elementIndex == 1 ? StartMarker : MidMarker;
     65            markerData.m_positions.append(MarkerPosition(markerType, markerData.m_origin, markerData.currentAngle(markerType)));
    6866        }
    6967
    7068        // Update our marker data for this element.
    71         markerData->updateMarkerDataForPathElement(element);
    72         ++markerData->m_elementIndex;
     69        markerData.updateMarkerDataForPathElement(element);
     70        ++markerData.m_elementIndex;
    7371    }
    7472
  • trunk/Source/WebCore/rendering/svg/SVGSubpathData.h

    r187492 r187597  
    3030    SVGSubpathData(Vector<FloatPoint>& zeroLengthSubpathLocations)
    3131        : m_zeroLengthSubpathLocations(zeroLengthSubpathLocations)
    32         , m_haveSeenMoveOnly(true)
    33         , m_pathIsZeroLength(true)
    3432    {
    35         m_lastPoint.set(0, 0);
    36         m_movePoint.set(0, 0);
    3733    }
    3834
    39     static void updateFromPathElement(void* info, const PathElement& element)
     35    static void updateFromPathElement(SVGSubpathData& subpathFinder, const PathElement& element)
    4036    {
    41         SVGSubpathData* subpathFinder = static_cast<SVGSubpathData*>(info);
    4237        switch (element.type) {
    4338        case PathElementMoveToPoint:
    44             if (subpathFinder->m_pathIsZeroLength && !subpathFinder->m_haveSeenMoveOnly)
    45                 subpathFinder->m_zeroLengthSubpathLocations.append(subpathFinder->m_lastPoint);
    46             subpathFinder->m_lastPoint = subpathFinder->m_movePoint = element.points[0];
    47             subpathFinder->m_haveSeenMoveOnly = true;
    48             subpathFinder->m_pathIsZeroLength = true;
     39            if (subpathFinder.m_pathIsZeroLength && !subpathFinder.m_haveSeenMoveOnly)
     40                subpathFinder.m_zeroLengthSubpathLocations.append(subpathFinder.m_lastPoint);
     41            subpathFinder.m_lastPoint = subpathFinder.m_movePoint = element.points[0];
     42            subpathFinder.m_haveSeenMoveOnly = true;
     43            subpathFinder.m_pathIsZeroLength = true;
    4944            break;
    5045        case PathElementAddLineToPoint:
    51             if (subpathFinder->m_lastPoint != element.points[0]) {
    52                 subpathFinder->m_pathIsZeroLength = false;
    53                 subpathFinder->m_lastPoint = element.points[0];
     46            if (subpathFinder.m_lastPoint != element.points[0]) {
     47                subpathFinder.m_pathIsZeroLength = false;
     48                subpathFinder.m_lastPoint = element.points[0];
    5449            }
    55             subpathFinder->m_haveSeenMoveOnly = false;
     50            subpathFinder.m_haveSeenMoveOnly = false;
    5651            break;
    5752        case PathElementAddQuadCurveToPoint:
    58             if (subpathFinder->m_lastPoint != element.points[0] || element.points[0] != element.points[1]) {
    59                 subpathFinder->m_pathIsZeroLength = false;
    60                 subpathFinder->m_lastPoint = element.points[1];
     53            if (subpathFinder.m_lastPoint != element.points[0] || element.points[0] != element.points[1]) {
     54                subpathFinder.m_pathIsZeroLength = false;
     55                subpathFinder.m_lastPoint = element.points[1];
    6156            }
    62             subpathFinder->m_haveSeenMoveOnly = false;
     57            subpathFinder.m_haveSeenMoveOnly = false;
    6358            break;
    6459        case PathElementAddCurveToPoint:
    65             if (subpathFinder->m_lastPoint != element.points[0] || element.points[0] != element.points[1] || element.points[1] != element.points[2]) {
    66                 subpathFinder->m_pathIsZeroLength = false;
    67                 subpathFinder->m_lastPoint = element.points[2];
     60            if (subpathFinder.m_lastPoint != element.points[0] || element.points[0] != element.points[1] || element.points[1] != element.points[2]) {
     61                subpathFinder.m_pathIsZeroLength = false;
     62                subpathFinder.m_lastPoint = element.points[2];
    6863            }
    69             subpathFinder->m_haveSeenMoveOnly = false;
     64            subpathFinder.m_haveSeenMoveOnly = false;
    7065            break;
    7166        case PathElementCloseSubpath:
    72             if (subpathFinder->m_pathIsZeroLength)
    73                 subpathFinder->m_zeroLengthSubpathLocations.append(subpathFinder->m_lastPoint);
    74             subpathFinder->m_haveSeenMoveOnly = true; // This is an implicit move for the next element
    75             subpathFinder->m_pathIsZeroLength = true; // A new sub-path also starts here
    76             subpathFinder->m_lastPoint = subpathFinder->m_movePoint;
     67            if (subpathFinder.m_pathIsZeroLength)
     68                subpathFinder.m_zeroLengthSubpathLocations.append(subpathFinder.m_lastPoint);
     69            subpathFinder.m_haveSeenMoveOnly = true; // This is an implicit move for the next element
     70            subpathFinder.m_pathIsZeroLength = true; // A new sub-path also starts here
     71            subpathFinder.m_lastPoint = subpathFinder.m_movePoint;
    7772            break;
    7873        }
     
    8984    FloatPoint m_lastPoint;
    9085    FloatPoint m_movePoint;
    91     bool m_haveSeenMoveOnly;
    92     bool m_pathIsZeroLength;
     86    bool m_haveSeenMoveOnly { false };
     87    bool m_pathIsZeroLength { false };
    9388};
    9489
  • trunk/Source/WebCore/svg/SVGPathUtilities.cpp

    r187492 r187597  
    332332}
    333333
    334 static void pathIteratorForBuildingString(void* info, const PathElement& pathElement)
    335 {
    336     SVGPathConsumer* consumer = static_cast<SVGPathConsumer*>(info);
    337 
     334static void pathIteratorForBuildingString(SVGPathConsumer& consumer, const PathElement& pathElement)
     335{
    338336    switch (pathElement.type) {
    339337    case PathElementMoveToPoint:
    340         consumer->moveTo(pathElement.points[0], false, AbsoluteCoordinates);
     338        consumer.moveTo(pathElement.points[0], false, AbsoluteCoordinates);
    341339        break;
    342340    case PathElementAddLineToPoint:
    343         consumer->lineTo(pathElement.points[0], AbsoluteCoordinates);
     341        consumer.lineTo(pathElement.points[0], AbsoluteCoordinates);
    344342        break;
    345343    case PathElementAddQuadCurveToPoint:
    346         consumer->curveToQuadratic(pathElement.points[0], pathElement.points[1], AbsoluteCoordinates);
     344        consumer.curveToQuadratic(pathElement.points[0], pathElement.points[1], AbsoluteCoordinates);
    347345        break;
    348346    case PathElementAddCurveToPoint:
    349         consumer->curveToCubic(pathElement.points[0], pathElement.points[1], pathElement.points[2], AbsoluteCoordinates);
     347        consumer.curveToCubic(pathElement.points[0], pathElement.points[1], pathElement.points[2], AbsoluteCoordinates);
    350348        break;
    351349    case PathElementCloseSubpath:
    352         consumer->closePath();
     350        consumer.closePath();
    353351        break;
    354352
     
    365363
    366364    SVGPathStringBuilder* builder = globalSVGPathStringBuilder();
    367     path.apply(builder, &pathIteratorForBuildingString);
     365    path.apply([builder](const PathElement& pathElement) {
     366        pathIteratorForBuildingString(*builder, pathElement);
     367    });
    368368    string = builder->result();
    369369    static_cast<SVGPathConsumer*>(builder)->cleanup();
  • trunk/Source/WebKit2/ChangeLog

    r187596 r187597  
     12015-07-30  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Convert Path applier to use std::function
     4        https://bugs.webkit.org/show_bug.cgi?id=147368
     5
     6        Reviewed by Sam Weinig.
     7
     8        Use std::function for Path::apply().
     9
     10        * Shared/WebCoreArgumentCoders.cpp:
     11        (IPC::pathEncodeApplierFunction):
     12        (IPC::ArgumentCoder<Path>::encode):
     13        (IPC::pathPointCountApplierFunction): Deleted.
     14
    1152015-07-30  Joonghun Park  <jh718.park@samsung.com>
    216
  • trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp

    r187492 r187597  
    374374}
    375375
    376 static void pathPointCountApplierFunction(void* info, const PathElement&)
    377 {
    378     uint64_t* pointCount = static_cast<uint64_t*>(info);
    379     ++*pointCount;
    380 }
    381 
    382 static void pathEncodeApplierFunction(void* info, const PathElement& element)
    383 {
    384     ArgumentEncoder& encoder = *static_cast<ArgumentEncoder*>(info);
    385 
     376static void pathEncodeApplierFunction(ArgumentEncoder& encoder, const PathElement& element)
     377{
    386378    encoder.encodeEnum(element.type);
    387379
     
    410402{
    411403    uint64_t numPoints = 0;
    412     path.apply(&numPoints, pathPointCountApplierFunction);
     404    path.apply([&numPoints](const PathElement&) {
     405        ++numPoints;
     406    });
    413407
    414408    encoder << numPoints;
    415409
    416     path.apply(&encoder, pathEncodeApplierFunction);
     410    path.apply([&encoder](const PathElement& pathElement) {
     411        pathEncodeApplierFunction(encoder, pathElement);
     412    });
    417413}
    418414
Note: See TracChangeset for help on using the changeset viewer.