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

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

Issue 16951017: convert pathops to use SkSTArray where possible. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: pathops use SkTArray Created 7 years, 6 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
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "SkOpEdgeBuilder.h" 7 #include "SkOpEdgeBuilder.h"
8 #include "SkReduceOrder.h" 8 #include "SkReduceOrder.h"
9 9
10 void SkOpEdgeBuilder::init() { 10 void SkOpEdgeBuilder::init() {
11 fCurrentContour = NULL; 11 fCurrentContour = NULL;
12 fOperand = false; 12 fOperand = false;
13 fXorMask[0] = fXorMask[1] = (fPath->getFillType() & 1) ? kEvenOdd_PathOpsMas k 13 fXorMask[0] = fXorMask[1] = (fPath->getFillType() & 1) ? kEvenOdd_PathOpsMas k
14 : kWinding_PathOpsMask; 14 : kWinding_PathOpsMask;
15 #if DEBUG_DUMP 15 #if DEBUG_DUMP
16 gContourID = 0; 16 gContourID = 0;
17 gSegmentID = 0; 17 gSegmentID = 0;
18 #endif 18 #endif
19 fUnparseable = false; 19 fUnparseable = false;
20 fSecondHalf = preFetch(); 20 fSecondHalf = preFetch();
21 } 21 }
22 22
23 void SkOpEdgeBuilder::addOperand(const SkPath& path) { 23 void SkOpEdgeBuilder::addOperand(const SkPath& path) {
24 SkASSERT(fPathVerbs.count() > 0 && fPathVerbs.end()[-1] == SkPath::kDone_Ver b); 24 SkASSERT(fPathVerbs.count() > 0 && fPathVerbs.end()[-1] == SkPath::kDone_Ver b);
25 fPathVerbs.pop(); 25 fPathVerbs.pop_back();
26 fPath = &path; 26 fPath = &path;
27 fXorMask[1] = (fPath->getFillType() & 1) ? kEvenOdd_PathOpsMask 27 fXorMask[1] = (fPath->getFillType() & 1) ? kEvenOdd_PathOpsMask
28 : kWinding_PathOpsMask; 28 : kWinding_PathOpsMask;
29 preFetch(); 29 preFetch();
30 } 30 }
31 31
32 bool SkOpEdgeBuilder::finish() { 32 bool SkOpEdgeBuilder::finish() {
33 if (fUnparseable || !walk()) { 33 if (fUnparseable || !walk()) {
34 return false; 34 return false;
35 } 35 }
(...skipping 29 matching lines...) Expand all
65 int SkOpEdgeBuilder::preFetch() { 65 int SkOpEdgeBuilder::preFetch() {
66 if (!fPath->isFinite()) { 66 if (!fPath->isFinite()) {
67 fUnparseable = true; 67 fUnparseable = true;
68 return 0; 68 return 0;
69 } 69 }
70 SkPath::RawIter iter(*fPath); 70 SkPath::RawIter iter(*fPath);
71 SkPoint pts[4]; 71 SkPoint pts[4];
72 SkPath::Verb verb; 72 SkPath::Verb verb;
73 do { 73 do {
74 verb = iter.next(pts); 74 verb = iter.next(pts);
75 *fPathVerbs.append() = verb; 75 fPathVerbs.push_back(verb);
76 if (verb == SkPath::kMove_Verb) { 76 if (verb == SkPath::kMove_Verb) {
77 *fPathPts.append() = pts[0]; 77 fPathPts.push_back(pts[0]);
78 } else if (verb >= SkPath::kLine_Verb && verb <= SkPath::kCubic_Verb) { 78 } else if (verb >= SkPath::kLine_Verb && verb <= SkPath::kCubic_Verb) {
79 fPathPts.append(SkPathOpsVerbToPoints(verb), &pts[1]); 79 fPathPts.push_back_n(SkPathOpsVerbToPoints(verb), &pts[1]);
80 } 80 }
81 } while (verb != SkPath::kDone_Verb); 81 } while (verb != SkPath::kDone_Verb);
82 return fPathVerbs.count() - 1; 82 return fPathVerbs.count() - 1;
83 } 83 }
84 84
85 bool SkOpEdgeBuilder::close() { 85 bool SkOpEdgeBuilder::close() {
86 if (fFinalCurveStart && fFinalCurveEnd && *fFinalCurveStart != *fFinalCurveE nd) { 86 if (fFinalCurveStart && fFinalCurveEnd && *fFinalCurveStart != *fFinalCurveE nd) {
87 *fReducePts.append() = *fFinalCurveStart; 87 fReducePts.push_back(*fFinalCurveStart);
88 *fReducePts.append() = *fFinalCurveEnd; 88 fReducePts.push_back(*fFinalCurveEnd);
89 const SkPoint* lineStart = fReducePts.end() - 2; 89 const SkPoint* lineStart = fReducePts.end() - 2;
90 *fExtra.append() = fCurrentContour->addLine(lineStart); 90 fExtra.push_back(fCurrentContour->addLine(lineStart));
91 } 91 }
92 complete(); 92 complete();
93 return true; 93 return true;
94 } 94 }
95 95
96 bool SkOpEdgeBuilder::walk() { 96 bool SkOpEdgeBuilder::walk() {
97 SkPath::Verb reducedVerb; 97 SkPath::Verb reducedVerb;
98 uint8_t* verbPtr = fPathVerbs.begin(); 98 uint8_t* verbPtr = fPathVerbs.begin();
99 uint8_t* endOfFirstHalf = &verbPtr[fSecondHalf]; 99 uint8_t* endOfFirstHalf = &verbPtr[fSecondHalf];
100 const SkPoint* pointsPtr = fPathPts.begin(); 100 const SkPoint* pointsPtr = fPathPts.begin();
(...skipping 11 matching lines...) Expand all
112 if (fAllowOpenContours) { 112 if (fAllowOpenContours) {
113 complete(); 113 complete();
114 } else if (!close()) { 114 } else if (!close()) {
115 return false; 115 return false;
116 } 116 }
117 } 117 }
118 if (!fCurrentContour) { 118 if (!fCurrentContour) {
119 fCurrentContour = fContours.push_back_n(1); 119 fCurrentContour = fContours.push_back_n(1);
120 fCurrentContour->setOperand(fOperand); 120 fCurrentContour->setOperand(fOperand);
121 fCurrentContour->setXor(fXorMask[fOperand] == kEvenOdd_PathO psMask); 121 fCurrentContour->setXor(fXorMask[fOperand] == kEvenOdd_PathO psMask);
122 *fExtra.append() = -1; // start new contour 122 fExtra.push_back(-1); // start new contour
123 } 123 }
124 fFinalCurveEnd = pointsPtr++; 124 fFinalCurveEnd = pointsPtr++;
125 continue; 125 continue;
126 case SkPath::kLine_Verb: { 126 case SkPath::kLine_Verb: {
127 const SkPoint& lineEnd = pointsPtr[0]; 127 const SkPoint& lineEnd = pointsPtr[0];
128 const SkPoint& lineStart = pointsPtr[-1]; 128 const SkPoint& lineStart = pointsPtr[-1];
129 // skip degenerate points 129 // skip degenerate points
130 if (lineStart.fX != lineEnd.fX || lineStart.fY != lineEnd.fY) { 130 if (lineStart.fX != lineEnd.fX || lineStart.fY != lineEnd.fY) {
131 fCurrentContour->addLine(&lineStart); 131 fCurrentContour->addLine(&lineStart);
132 } 132 }
133 } break; 133 } break;
134 case SkPath::kQuad_Verb: { 134 case SkPath::kQuad_Verb: {
135 const SkPoint* quadStart = &pointsPtr[-1]; 135 const SkPoint* quadStart = &pointsPtr[-1];
136 reducedVerb = SkReduceOrder::Quad(quadStart, &fReducePts); 136 reducedVerb = SkReduceOrder::Quad(quadStart, &fReducePts);
137 if (reducedVerb == 0) { 137 if (reducedVerb == 0) {
138 break; // skip degenerate points 138 break; // skip degenerate points
139 } 139 }
140 if (reducedVerb == SkPath::kLine_Verb) { 140 if (reducedVerb == SkPath::kLine_Verb) {
141 const SkPoint* lineStart = fReducePts.end() - 2; 141 const SkPoint* lineStart = fReducePts.end() - 2;
142 *fExtra.append() = fCurrentContour->addLine(lineStart); 142 fExtra.push_back(fCurrentContour->addLine(lineStart));
143 break; 143 break;
144 } 144 }
145 fCurrentContour->addQuad(quadStart); 145 fCurrentContour->addQuad(quadStart);
146 } break; 146 } break;
147 case SkPath::kCubic_Verb: { 147 case SkPath::kCubic_Verb: {
148 const SkPoint* cubicStart = &pointsPtr[-1]; 148 const SkPoint* cubicStart = &pointsPtr[-1];
149 reducedVerb = SkReduceOrder::Cubic(cubicStart, &fReducePts); 149 reducedVerb = SkReduceOrder::Cubic(cubicStart, &fReducePts);
150 if (reducedVerb == 0) { 150 if (reducedVerb == 0) {
151 break; // skip degenerate points 151 break; // skip degenerate points
152 } 152 }
153 if (reducedVerb == SkPath::kLine_Verb) { 153 if (reducedVerb == SkPath::kLine_Verb) {
154 const SkPoint* lineStart = fReducePts.end() - 2; 154 const SkPoint* lineStart = fReducePts.end() - 2;
155 *fExtra.append() = fCurrentContour->addLine(lineStart); 155 fExtra.push_back(fCurrentContour->addLine(lineStart));
156 break; 156 break;
157 } 157 }
158 if (reducedVerb == SkPath::kQuad_Verb) { 158 if (reducedVerb == SkPath::kQuad_Verb) {
159 const SkPoint* quadStart = fReducePts.end() - 3; 159 const SkPoint* quadStart = fReducePts.end() - 3;
160 *fExtra.append() = fCurrentContour->addQuad(quadStart); 160 fExtra.push_back(fCurrentContour->addQuad(quadStart));
161 break; 161 break;
162 } 162 }
163 fCurrentContour->addCubic(cubicStart); 163 fCurrentContour->addCubic(cubicStart);
164 } break; 164 } break;
165 case SkPath::kClose_Verb: 165 case SkPath::kClose_Verb:
166 SkASSERT(fCurrentContour); 166 SkASSERT(fCurrentContour);
167 if (!close()) { 167 if (!close()) {
168 return false; 168 return false;
169 } 169 }
170 continue; 170 continue;
171 default: 171 default:
172 SkDEBUGFAIL("bad verb"); 172 SkDEBUGFAIL("bad verb");
173 return false; 173 return false;
174 } 174 }
175 fFinalCurveStart = &pointsPtr[SkPathOpsVerbToPoints(verb) - 1]; 175 fFinalCurveStart = &pointsPtr[SkPathOpsVerbToPoints(verb) - 1];
176 pointsPtr += SkPathOpsVerbToPoints(verb); 176 pointsPtr += SkPathOpsVerbToPoints(verb);
177 SkASSERT(fCurrentContour); 177 SkASSERT(fCurrentContour);
178 } 178 }
179 if (fCurrentContour && !fAllowOpenContours && !close()) { 179 if (fCurrentContour && !fAllowOpenContours && !close()) {
180 return false; 180 return false;
181 } 181 }
182 return true; 182 return true;
183 } 183 }
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