Changeset 187597 in webkit
- Timestamp:
- Jul 30, 2015 12:13:49 PM (9 years ago)
- Location:
- trunk/Source
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r187593 r187597 1 2015-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 1 43 2015-07-30 Simon Fraser <simon.fraser@apple.com> 2 44 -
trunk/Source/WebCore/accessibility/mac/WebAccessibilityObjectWrapperBase.mm
r187492 r187597 248 248 }; 249 249 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; 250 static void convertPathToScreenSpaceFunction(PathConversionInfo& conversion, const PathElement& element) 251 { 252 WebAccessibilityObjectWrapperBase *wrapper = conversion.wrapper; 253 CGMutablePathRef newPath = conversion.path; 255 254 switch (element.type) { 256 255 case PathElementMoveToPoint: … … 292 291 { 293 292 PathConversionInfo conversion = { self, CGPathCreateMutable() }; 294 path.apply(&conversion, ConvertPathToScreenSpaceFunction); 293 path.apply([&conversion](const PathElement& pathElement) { 294 convertPathToScreenSpaceFunction(conversion, pathElement); 295 }); 295 296 return (CGPathRef)[(id)conversion.path autorelease]; 296 297 } -
trunk/Source/WebCore/inspector/InspectorOverlay.cpp
r187496 r187597 610 610 } 611 611 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); 612 static void appendPathSegment(PathApplyInfo& pathApplyInfo, const PathElement& pathElement) 613 { 616 614 FloatPoint point; 617 615 switch (pathElement.type) { … … 665 663 info.shapeOutsideInfo = shapeOutsideInfo; 666 664 667 paths.shape.apply(&info, &appendPathSegment); 665 paths.shape.apply([&info](const PathElement& pathElement) { 666 appendPathSegment(info, pathElement); 667 }); 668 668 669 669 shapeObject->setShape(shapePath.copyRef()); … … 673 673 info.pathArray = &marginShapePath.get(); 674 674 675 paths.marginShape.apply(&info, &appendPathSegment); 675 paths.marginShape.apply([&info](const PathElement& pathElement) { 676 appendPathSegment(info, pathElement); 677 }); 676 678 677 679 shapeObject->setMarginShape(marginShapePath.copyRef()); -
trunk/Source/WebCore/platform/graphics/Path.cpp
r187492 r187597 40 40 namespace WebCore { 41 41 42 static void pathLengthApplierFunction(void* info, const PathElement& element)43 {44 PathTraversalState& traversalState = *static_cast<PathTraversalState*>(info);45 traversalState.processPathElement(element);46 }47 48 42 float Path::length() const 49 43 { 50 44 PathTraversalState traversalState(PathTraversalState::Action::TotalLength); 51 apply(&traversalState, pathLengthApplierFunction); 45 46 apply([&traversalState](const PathElement& element) { 47 traversalState.processPathElement(element); 48 }); 49 52 50 return traversalState.totalLength(); 53 51 } … … 56 54 { 57 55 PathTraversalState traversalState(PathTraversalState::Action::VectorAtLength, length); 58 apply(&traversalState, pathLengthApplierFunction); 56 57 apply([&traversalState](const PathElement& element) { 58 traversalState.processPathElement(element); 59 }); 60 59 61 success = traversalState.success(); 60 62 return traversalState; -
trunk/Source/WebCore/platform/graphics/Path.h
r187492 r187597 31 31 #include "FloatRect.h" 32 32 #include "WindRule.h" 33 #include <functional> 33 34 #include <wtf/FastMalloc.h> 34 35 #include <wtf/Forward.h> 35 36 36 37 #if USE(CG) 38 37 39 #include <wtf/RetainPtr.h> 38 40 #include <CoreGraphics/CGPath.h> 39 41 typedef struct CGPath PlatformPath; 42 40 43 #elif USE(CAIRO) 44 41 45 namespace WebCore { 42 46 class CairoPath; 43 47 } 44 48 typedef WebCore::CairoPath PlatformPath; 49 45 50 #elif USE(WINGDI) 51 46 52 namespace WebCore { 47 53 class PlatformPath; 48 54 } 49 55 typedef WebCore::PlatformPath PlatformPath; 56 50 57 #else 58 51 59 typedef void PlatformPath; 60 52 61 #endif 53 62 … … 81 90 }; 82 91 83 typedef void (*PathApplierFunction)(void* info, const PathElement&);92 typedef std::function<void (const PathElement&)> PathApplierFunction; 84 93 85 94 class Path { … … 147 156 WEBCORE_EXPORT PlatformPathPtr ensurePlatformPath(); 148 157 149 WEBCORE_EXPORT void apply( void* info,PathApplierFunction) const;158 WEBCORE_EXPORT void apply(PathApplierFunction) const; 150 159 void transform(const AffineTransform&); 151 160 -
trunk/Source/WebCore/platform/graphics/cairo/FontCairo.cpp
r187492 r187597 175 175 // It keeps track of the leftmost and rightmost intersection in GlyphIterationState::minX and 176 176 // GlyphIterationState::maxX. 177 static void findPathIntersections(void* stateAsVoidPointer, const PathElement& element) 178 { 179 auto& state = *static_cast<GlyphIterationState*>(stateAsVoidPointer); 177 static void findPathIntersections(GlyphIterationState& state, const PathElement& element) 178 { 180 179 bool doIntersection = false; 181 180 FloatPoint point = FloatPoint(); … … 338 337 case GlyphToPathTranslator::GlyphUnderlineType::SkipDescenders: { 339 338 Path path = translator->path(); 340 path.apply(&info, &findPathIntersections); 339 path.apply([&info](const PathElement& pathElement) { 340 findPathIntersections(info, pathElement); 341 }); 341 342 if (info.minX < info.maxX) { 342 343 result.append(info.minX - lineExtents.x()); -
trunk/Source/WebCore/platform/graphics/cairo/PathCairo.cpp
r187498 r187597 391 391 } 392 392 393 void Path::apply( void* info,PathApplierFunction function) const393 void Path::apply(PathApplierFunction function) const 394 394 { 395 395 if (isNull()) … … 409 409 pelement.type = PathElementMoveToPoint; 410 410 pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y); 411 function( info,pelement);411 function(pelement); 412 412 break; 413 413 case CAIRO_PATH_LINE_TO: 414 414 pelement.type = PathElementAddLineToPoint; 415 415 pelement.points[0] = FloatPoint(data[1].point.x,data[1].point.y); 416 function( info,pelement);416 function(pelement); 417 417 break; 418 418 case CAIRO_PATH_CURVE_TO: … … 421 421 pelement.points[1] = FloatPoint(data[2].point.x,data[2].point.y); 422 422 pelement.points[2] = FloatPoint(data[3].point.x,data[3].point.y); 423 function( info,pelement);423 function(pelement); 424 424 break; 425 425 case CAIRO_PATH_CLOSE_PATH: 426 426 pelement.type = PathElementCloseSubpath; 427 function( info,pelement);427 function(pelement); 428 428 break; 429 429 } -
trunk/Source/WebCore/platform/graphics/cg/PathCG.cpp
r187492 r187597 376 376 } 377 377 378 struct PathApplierInfo {379 void* info;380 PathApplierFunction function;381 };382 383 378 static void CGPathApplierToPathApplier(void *info, const CGPathElement* element) 384 379 { 385 PathApplier Info* pinfo = (PathApplierInfo*)info;380 PathApplierFunction function = *(PathApplierFunction*)info; 386 381 FloatPoint points[3]; 387 382 PathElement pelement; … … 406 401 break; 407 402 } 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 406 void Path::apply(PathApplierFunction function) const 407 { 408 if (isNull()) 409 return; 410 411 CGPathApply(m_path, &function, CGPathApplierToPathApplier); 420 412 } 421 413 -
trunk/Source/WebCore/rendering/svg/RenderSVGPath.cpp
r177259 r187597 156 156 157 157 SVGSubpathData subpathData(m_zeroLengthLinecapLocations); 158 path().apply(&subpathData, SVGSubpathData::updateFromPathElement); 158 path().apply([&subpathData](const PathElement& pathElement) { 159 SVGSubpathData::updateFromPathElement(subpathData, pathElement); 160 }); 159 161 subpathData.pathIsDone(); 160 162 } -
trunk/Source/WebCore/rendering/svg/RenderSVGShape.cpp
r183065 r187597 477 477 478 478 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 }); 480 482 markerData.pathIsDone(); 481 483 } -
trunk/Source/WebCore/rendering/svg/SVGMarkerData.h
r187492 r187597 55 55 } 56 56 57 static void updateFromPathElement( void* info, const PathElement& element)57 static void updateFromPathElement(SVGMarkerData& markerData, const PathElement& element) 58 58 { 59 SVGMarkerData* markerData = static_cast<SVGMarkerData*>(info);60 61 59 // First update the outslope for the previous element. 62 markerData ->updateOutslope(element.points[0]);60 markerData.updateOutslope(element.points[0]); 63 61 64 62 // 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))); 68 66 } 69 67 70 68 // Update our marker data for this element. 71 markerData ->updateMarkerDataForPathElement(element);72 ++markerData ->m_elementIndex;69 markerData.updateMarkerDataForPathElement(element); 70 ++markerData.m_elementIndex; 73 71 } 74 72 -
trunk/Source/WebCore/rendering/svg/SVGSubpathData.h
r187492 r187597 30 30 SVGSubpathData(Vector<FloatPoint>& zeroLengthSubpathLocations) 31 31 : m_zeroLengthSubpathLocations(zeroLengthSubpathLocations) 32 , m_haveSeenMoveOnly(true)33 , m_pathIsZeroLength(true)34 32 { 35 m_lastPoint.set(0, 0);36 m_movePoint.set(0, 0);37 33 } 38 34 39 static void updateFromPathElement( void* info, const PathElement& element)35 static void updateFromPathElement(SVGSubpathData& subpathFinder, const PathElement& element) 40 36 { 41 SVGSubpathData* subpathFinder = static_cast<SVGSubpathData*>(info);42 37 switch (element.type) { 43 38 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; 49 44 break; 50 45 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]; 54 49 } 55 subpathFinder ->m_haveSeenMoveOnly = false;50 subpathFinder.m_haveSeenMoveOnly = false; 56 51 break; 57 52 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]; 61 56 } 62 subpathFinder ->m_haveSeenMoveOnly = false;57 subpathFinder.m_haveSeenMoveOnly = false; 63 58 break; 64 59 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]; 68 63 } 69 subpathFinder ->m_haveSeenMoveOnly = false;64 subpathFinder.m_haveSeenMoveOnly = false; 70 65 break; 71 66 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 element75 subpathFinder ->m_pathIsZeroLength = true; // A new sub-path also starts here76 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; 77 72 break; 78 73 } … … 89 84 FloatPoint m_lastPoint; 90 85 FloatPoint m_movePoint; 91 bool m_haveSeenMoveOnly ;92 bool m_pathIsZeroLength ;86 bool m_haveSeenMoveOnly { false }; 87 bool m_pathIsZeroLength { false }; 93 88 }; 94 89 -
trunk/Source/WebCore/svg/SVGPathUtilities.cpp
r187492 r187597 332 332 } 333 333 334 static void pathIteratorForBuildingString(void* info, const PathElement& pathElement) 335 { 336 SVGPathConsumer* consumer = static_cast<SVGPathConsumer*>(info); 337 334 static void pathIteratorForBuildingString(SVGPathConsumer& consumer, const PathElement& pathElement) 335 { 338 336 switch (pathElement.type) { 339 337 case PathElementMoveToPoint: 340 consumer ->moveTo(pathElement.points[0], false, AbsoluteCoordinates);338 consumer.moveTo(pathElement.points[0], false, AbsoluteCoordinates); 341 339 break; 342 340 case PathElementAddLineToPoint: 343 consumer ->lineTo(pathElement.points[0], AbsoluteCoordinates);341 consumer.lineTo(pathElement.points[0], AbsoluteCoordinates); 344 342 break; 345 343 case PathElementAddQuadCurveToPoint: 346 consumer ->curveToQuadratic(pathElement.points[0], pathElement.points[1], AbsoluteCoordinates);344 consumer.curveToQuadratic(pathElement.points[0], pathElement.points[1], AbsoluteCoordinates); 347 345 break; 348 346 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); 350 348 break; 351 349 case PathElementCloseSubpath: 352 consumer ->closePath();350 consumer.closePath(); 353 351 break; 354 352 … … 365 363 366 364 SVGPathStringBuilder* builder = globalSVGPathStringBuilder(); 367 path.apply(builder, &pathIteratorForBuildingString); 365 path.apply([builder](const PathElement& pathElement) { 366 pathIteratorForBuildingString(*builder, pathElement); 367 }); 368 368 string = builder->result(); 369 369 static_cast<SVGPathConsumer*>(builder)->cleanup(); -
trunk/Source/WebKit2/ChangeLog
r187596 r187597 1 2015-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 1 15 2015-07-30 Joonghun Park <jh718.park@samsung.com> 2 16 -
trunk/Source/WebKit2/Shared/WebCoreArgumentCoders.cpp
r187492 r187597 374 374 } 375 375 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 376 static void pathEncodeApplierFunction(ArgumentEncoder& encoder, const PathElement& element) 377 { 386 378 encoder.encodeEnum(element.type); 387 379 … … 410 402 { 411 403 uint64_t numPoints = 0; 412 path.apply(&numPoints, pathPointCountApplierFunction); 404 path.apply([&numPoints](const PathElement&) { 405 ++numPoints; 406 }); 413 407 414 408 encoder << numPoints; 415 409 416 path.apply(&encoder, pathEncodeApplierFunction); 410 path.apply([&encoder](const PathElement& pathElement) { 411 pathEncodeApplierFunction(encoder, pathElement); 412 }); 417 413 } 418 414
Note: See TracChangeset
for help on using the changeset viewer.