Bug 45252

Summary: Add local triangulation of cubic curve control points
Product: WebKit Reporter: Kenneth Russell <kbr>
Component: Layout and RenderingAssignee: Kenneth Russell <kbr>
Status: RESOLVED FIXED    
Severity: Normal CC: abarth, cmarrin, dglazkov, eric, fishd, jamesr, senorblanco, simon.fraser, webkit.review.bot
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 44729    
Attachments:
Description Flags
Patch
jamesr: review-, kbr: commit-queue-
Revised patch
kbr: commit-queue-
Revised patch jamesr: review+, kbr: commit-queue-

Description Kenneth Russell 2010-09-05 22:26:59 PDT
As part of the GPU accelerated path rendering algorithm in https://bugs.webkit.org/show_bug.cgi?id=44729 , a local triangulation algorithm is needed for the four points defining a cubic curve. This triangulator needs to support walking the interior edges of the shape in order to feed those edges to a more general triangulation algorithm which handles filling of the interior of the shape.
Comment 1 Kenneth Russell 2010-09-05 22:41:24 PDT
Created attachment 66611 [details]
Patch

From the ChangeLog:

Adding a localized triangulation algorithm which takes as input the four control points of a cubic curve segment and provides both triangles as well as the ability to walk the interior edges. The latter will be used later to fill the interior of shapes bounded by these cubic curves, quadratic curves and line segments.
Comment 2 James Robinson 2010-09-08 16:23:32 PDT
Comment on attachment 66611 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=66611&action=prettypatch

> WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp:35
> +using namespace LoopBlinnMathUtils;
explicitly 'using' the functions used in this cpp

> WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp:39
> +    for (int i = 0; i < 3; i++)
nit: could use indexForVertex()

> WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp:45
> +LoopBlinnLocalTriangulator::Vertex* LoopBlinnLocalTriangulator::Triangle::nextVertex(LoopBlinnLocalTriangulator::Vertex* cur, bool ccw)
rename params as in header

> WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp:101
> +    bool done = false;
instead of having a done flag, could the work in the first half of this function be a helper that early-returns?

> WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp:107
> +    for (int i = 0; i < 4 && !done; i++)
> +        for (int j = i + 1; j < 4 && !done; j++)
these need braces

> WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp:231
> +                    if (!next->marked()
> +                        && !isSharedEdge(v, next)
> +                        && (!next->interior() || next->end())) {
intentation looks funny. I think the predicate can go one line

> WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp:242
> +            // Something went wrong with the above algorithm; add the last
add a FIXME?

> WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.h:46
> +        Vertex()
initialize the flags in here

> WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.h:141
> +        Vertex* nextVertex(Vertex* cur, bool ccw);
cur -> current

ccw -> counterClockWise, or an enum { ClockWise, CounterClockWise }

> WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.h:165
> +        Vertex* m_vertices[3];
Add a comment indicating why these are raw pointers (that they point to data from the arena or something of that sort).

> WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.h:196
> +    void triangulate(bool computeInsideEdges,
> +                     bool fillRightSide);
these bool params should be enums so callsites look more like triangulage(ComputeInsideEdges, FillLeftSide);
Comment 3 Kenneth Russell 2010-09-09 13:02:45 PDT
Created attachment 67083 [details]
Revised patch

Revised patch addressing above code review comments.
Comment 4 Kenneth Russell 2010-09-09 13:04:05 PDT
(In reply to comment #2)
> (From update of attachment 66611 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=66611&action=prettypatch
> 
> > WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp:35
> > +using namespace LoopBlinnMathUtils;
> explicitly 'using' the functions used in this cpp

Done.

> > WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp:39
> > +    for (int i = 0; i < 3; i++)
> nit: could use indexForVertex()

Done.

> > WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp:45
> > +LoopBlinnLocalTriangulator::Vertex* LoopBlinnLocalTriangulator::Triangle::nextVertex(LoopBlinnLocalTriangulator::Vertex* cur, bool ccw)
> rename params as in header

Done.

> > WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp:101
> > +    bool done = false;
> instead of having a done flag, could the work in the first half of this function be a helper that early-returns?

Yes. Done; refactored first half into triangulateHelper.

> > WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp:107
> > +    for (int i = 0; i < 4 && !done; i++)
> > +        for (int j = i + 1; j < 4 && !done; j++)
> these need braces

Done.

> > WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp:231
> > +                    if (!next->marked()
> > +                        && !isSharedEdge(v, next)
> > +                        && (!next->interior() || next->end())) {
> intentation looks funny. I think the predicate can go one line

Done.

> > WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.cpp:242
> > +            // Something went wrong with the above algorithm; add the last
> add a FIXME?

Done.

> > WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.h:46
> > +        Vertex()
> initialize the flags in here

Done.

> > WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.h:141
> > +        Vertex* nextVertex(Vertex* cur, bool ccw);
> cur -> current
> 
> ccw -> counterClockWise, or an enum { ClockWise, CounterClockWise }

Done.

> > WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.h:165
> > +        Vertex* m_vertices[3];
> Add a comment indicating why these are raw pointers (that they point to data from the arena or something of that sort).

Done.

> > WebCore/platform/graphics/gpu/LoopBlinnLocalTriangulator.h:196
> > +    void triangulate(bool computeInsideEdges,
> > +                     bool fillRightSide);
> these bool params should be enums so callsites look more like triangulage(ComputeInsideEdges, FillLeftSide);

Done.
Comment 5 Kenneth Russell 2010-09-09 21:48:00 PDT
Created attachment 67149 [details]
Revised patch

Renamed numTriangles to numberOfTriangles and numInteriorVertices to numberOfInteriorVertices to avoid abbreviations.
Comment 6 James Robinson 2010-09-15 13:46:31 PDT
Comment on attachment 67149 [details]
Revised patch

View in context: https://bugs.webkit.org/attachment.cgi?id=67149&action=prettypatch

Looks good!
Comment 7 Kenneth Russell 2010-09-22 08:31:49 PDT
Committed r68045: <http://trac.webkit.org/changeset/68045>
Comment 8 Kenneth Russell 2010-09-27 16:08:06 PDT
Committed r68439: <http://trac.webkit.org/changeset/68439>
Comment 9 WebKit Review Bot 2010-09-27 16:43:47 PDT
http://trac.webkit.org/changeset/68439 might have broken Qt Linux Release
The following changes are on the blame list:
http://trac.webkit.org/changeset/68440
http://trac.webkit.org/changeset/68439