Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(238)

Side by Side Diff: src/pathops/SkOpEdgeBuilder.cpp

Issue 13094010: Add implementation of path ops (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/pathops/SkOpEdgeBuilder.h ('k') | src/pathops/SkOpSegment.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7 #include "SkOpEdgeBuilder.h"
8 #include "SkReduceOrder.h"
9
10 void SkOpEdgeBuilder::init() {
11 fCurrentContour = NULL;
12 fOperand = false;
13 fXorMask[0] = fXorMask[1] = (fPath->getFillType() & 1) ? kEvenOdd_PathOpsMas k
14 : kWinding_PathOpsMask;
15 #if DEBUG_DUMP
16 gContourID = 0;
17 gSegmentID = 0;
18 #endif
19 fSecondHalf = preFetch();
20 }
21
22 void SkOpEdgeBuilder::addOperand(const SkPath& path) {
23 SkASSERT(fPathVerbs.count() > 0 && fPathVerbs.end()[-1] == SkPath::kDone_Ver b);
24 fPathVerbs.pop();
25 fPath = &path;
26 fXorMask[1] = (fPath->getFillType() & 1) ? kEvenOdd_PathOpsMask
27 : kWinding_PathOpsMask;
28 preFetch();
29 }
30
31 void SkOpEdgeBuilder::finish() {
32 walk();
33 complete();
34 if (fCurrentContour && !fCurrentContour->segments().count()) {
35 fContours.pop_back();
36 }
37 // correct pointers in contours since fReducePts may have moved as it grew
38 int cIndex = 0;
39 int extraCount = fExtra.count();
40 SkASSERT(extraCount == 0 || fExtra[0] == -1);
41 int eIndex = 0;
42 int rIndex = 0;
43 while (++eIndex < extraCount) {
44 int offset = fExtra[eIndex];
45 if (offset < 0) {
46 ++cIndex;
47 continue;
48 }
49 fCurrentContour = &fContours[cIndex];
50 rIndex += fCurrentContour->updateSegment(offset - 1,
51 &fReducePts[rIndex]);
52 }
53 fExtra.reset(); // we're done with this
54 }
55
56 // FIXME:remove once we can access path pts directly
57 int SkOpEdgeBuilder::preFetch() {
58 SkPath::RawIter iter(*fPath); // FIXME: access path directly when allowed
59 SkPoint pts[4];
60 SkPath::Verb verb;
61 do {
62 verb = iter.next(pts);
63 *fPathVerbs.append() = verb;
64 if (verb == SkPath::kMove_Verb) {
65 *fPathPts.append() = pts[0];
66 } else if (verb >= SkPath::kLine_Verb && verb <= SkPath::kCubic_Verb) {
67 fPathPts.append(verb, &pts[1]);
68 }
69 } while (verb != SkPath::kDone_Verb);
70 return fPathVerbs.count() - 1;
71 }
72
73 void SkOpEdgeBuilder::walk() {
74 SkPath::Verb reducedVerb;
75 uint8_t* verbPtr = fPathVerbs.begin();
76 uint8_t* endOfFirstHalf = &verbPtr[fSecondHalf];
77 const SkPoint* pointsPtr = fPathPts.begin();
78 const SkPoint* finalCurveStart = NULL;
79 const SkPoint* finalCurveEnd = NULL;
80 SkPath::Verb verb;
81 while ((verb = (SkPath::Verb) *verbPtr++) != SkPath::kDone_Verb) {
82 switch (verb) {
83 case SkPath::kMove_Verb:
84 complete();
85 if (!fCurrentContour) {
86 fCurrentContour = fContours.push_back_n(1);
87 fCurrentContour->setOperand(fOperand);
88 fCurrentContour->setXor(fXorMask[fOperand] == kEvenOdd_PathO psMask);
89 *fExtra.append() = -1; // start new contour
90 }
91 finalCurveEnd = pointsPtr++;
92 goto nextVerb;
93 case SkPath::kLine_Verb:
94 // skip degenerate points
95 if (pointsPtr[-1].fX != pointsPtr[0].fX || pointsPtr[-1].fY != p ointsPtr[0].fY) {
96 fCurrentContour->addLine(&pointsPtr[-1]);
97 }
98 break;
99 case SkPath::kQuad_Verb:
100 reducedVerb = SkReduceOrder::Quad(&pointsPtr[-1], &fReducePts);
101 if (reducedVerb == 0) {
102 break; // skip degenerate points
103 }
104 if (reducedVerb == 1) {
105 *fExtra.append() =
106 fCurrentContour->addLine(fReducePts.end() - 2);
107 break;
108 }
109 fCurrentContour->addQuad(&pointsPtr[-1]);
110 break;
111 case SkPath::kCubic_Verb:
112 reducedVerb = SkReduceOrder::Cubic(&pointsPtr[-1], &fReducePts);
113 if (reducedVerb == 0) {
114 break; // skip degenerate points
115 }
116 if (reducedVerb == 1) {
117 *fExtra.append() = fCurrentContour->addLine(fReducePts.end() - 2);
118 break;
119 }
120 if (reducedVerb == 2) {
121 *fExtra.append() = fCurrentContour->addQuad(fReducePts.end() - 3);
122 break;
123 }
124 fCurrentContour->addCubic(&pointsPtr[-1]);
125 break;
126 case SkPath::kClose_Verb:
127 SkASSERT(fCurrentContour);
128 if (finalCurveStart && finalCurveEnd
129 && *finalCurveStart != *finalCurveEnd) {
130 *fReducePts.append() = *finalCurveStart;
131 *fReducePts.append() = *finalCurveEnd;
132 *fExtra.append() = fCurrentContour->addLine(fReducePts.end() - 2);
133 }
134 complete();
135 goto nextVerb;
136 default:
137 SkDEBUGFAIL("bad verb");
138 return;
139 }
140 finalCurveStart = &pointsPtr[verb - 1];
141 pointsPtr += verb;
142 SkASSERT(fCurrentContour);
143 nextVerb:
144 if (verbPtr == endOfFirstHalf) {
145 fOperand = true;
146 }
147 }
148 }
OLDNEW
« no previous file with comments | « src/pathops/SkOpEdgeBuilder.h ('k') | src/pathops/SkOpSegment.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698