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

Side by Side Diff: src/core/SkEdgeBuilder.cpp

Issue 891613003: faster edge re-sort, drop trailing edges (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « src/core/SkEdgeBuilder.h ('k') | src/core/SkLineClipper.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkEdgeBuilder.h" 8 #include "SkEdgeBuilder.h"
9 #include "SkPath.h" 9 #include "SkPath.h"
10 #include "SkEdge.h" 10 #include "SkEdge.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 /////////////////////////////////////////////////////////////////////////////// 73 ///////////////////////////////////////////////////////////////////////////////
74 74
75 static void setShiftedClip(SkRect* dst, const SkIRect& src, int shift) { 75 static void setShiftedClip(SkRect* dst, const SkIRect& src, int shift) {
76 dst->set(SkIntToScalar(src.fLeft >> shift), 76 dst->set(SkIntToScalar(src.fLeft >> shift),
77 SkIntToScalar(src.fTop >> shift), 77 SkIntToScalar(src.fTop >> shift),
78 SkIntToScalar(src.fRight >> shift), 78 SkIntToScalar(src.fRight >> shift),
79 SkIntToScalar(src.fBottom >> shift)); 79 SkIntToScalar(src.fBottom >> shift));
80 } 80 }
81 81
82 int SkEdgeBuilder::buildPoly(const SkPath& path, const SkIRect* iclip, 82 int SkEdgeBuilder::buildPoly(const SkPath& path, const SkIRect* iclip, int shift Up,
83 int shiftUp) { 83 bool clipToTheRight) {
84 SkPath::Iter iter(path, true); 84 SkPath::Iter iter(path, true);
85 SkPoint pts[4]; 85 SkPoint pts[4];
86 SkPath::Verb verb; 86 SkPath::Verb verb;
87 87
88 int maxEdgeCount = path.countPoints(); 88 int maxEdgeCount = path.countPoints();
89 if (iclip) { 89 if (iclip) {
90 // clipping can turn 1 line into (up to) kMaxClippedLineSegments, since 90 // clipping can turn 1 line into (up to) kMaxClippedLineSegments, since
91 // we turn portions that are clipped out on the left/right into vertical 91 // we turn portions that are clipped out on the left/right into vertical
92 // segments. 92 // segments.
93 maxEdgeCount *= SkLineClipper::kMaxClippedLineSegments; 93 maxEdgeCount *= SkLineClipper::kMaxClippedLineSegments;
(...skipping 14 matching lines...) Expand all
108 108
109 while ((verb = iter.next(pts, false)) != SkPath::kDone_Verb) { 109 while ((verb = iter.next(pts, false)) != SkPath::kDone_Verb) {
110 switch (verb) { 110 switch (verb) {
111 case SkPath::kMove_Verb: 111 case SkPath::kMove_Verb:
112 case SkPath::kClose_Verb: 112 case SkPath::kClose_Verb:
113 // we ignore these, and just get the whole segment from 113 // we ignore these, and just get the whole segment from
114 // the corresponding line/quad/cubic verbs 114 // the corresponding line/quad/cubic verbs
115 break; 115 break;
116 case SkPath::kLine_Verb: { 116 case SkPath::kLine_Verb: {
117 SkPoint lines[SkLineClipper::kMaxPoints]; 117 SkPoint lines[SkLineClipper::kMaxPoints];
118 int lineCount = SkLineClipper::ClipLine(pts, clip, lines); 118 int lineCount = SkLineClipper::ClipLine(pts, clip, lines, cl ipToTheRight);
119 SkASSERT(lineCount <= SkLineClipper::kMaxClippedLineSegments ); 119 SkASSERT(lineCount <= SkLineClipper::kMaxClippedLineSegments );
120 for (int i = 0; i < lineCount; i++) { 120 for (int i = 0; i < lineCount; i++) {
121 if (edge->setLine(lines[i], lines[i + 1], shiftUp)) { 121 if (edge->setLine(lines[i], lines[i + 1], shiftUp)) {
122 *edgePtr++ = edge++; 122 *edgePtr++ = edge++;
123 } 123 }
124 } 124 }
125 break; 125 break;
126 } 126 }
127 default: 127 default:
128 SkDEBUGFAIL("unexpected verb"); 128 SkDEBUGFAIL("unexpected verb");
(...skipping 25 matching lines...) Expand all
154 } 154 }
155 155
156 static void handle_quad(SkEdgeBuilder* builder, const SkPoint pts[3]) { 156 static void handle_quad(SkEdgeBuilder* builder, const SkPoint pts[3]) {
157 SkPoint monoX[5]; 157 SkPoint monoX[5];
158 int n = SkChopQuadAtYExtrema(pts, monoX); 158 int n = SkChopQuadAtYExtrema(pts, monoX);
159 for (int i = 0; i <= n; i++) { 159 for (int i = 0; i <= n; i++) {
160 builder->addQuad(&monoX[i * 2]); 160 builder->addQuad(&monoX[i * 2]);
161 } 161 }
162 } 162 }
163 163
164 int SkEdgeBuilder::build(const SkPath& path, const SkIRect* iclip, 164 int SkEdgeBuilder::build(const SkPath& path, const SkIRect* iclip, int shiftUp,
165 int shiftUp) { 165 bool clipToTheRight) {
166 fAlloc.reset(); 166 fAlloc.reset();
167 fList.reset(); 167 fList.reset();
168 fShiftUp = shiftUp; 168 fShiftUp = shiftUp;
169 169
170 if (SkPath::kLine_SegmentMask == path.getSegmentMasks()) { 170 if (SkPath::kLine_SegmentMask == path.getSegmentMasks()) {
171 return this->buildPoly(path, iclip, shiftUp); 171 return this->buildPoly(path, iclip, shiftUp, clipToTheRight);
172 } 172 }
173 173
174 SkAutoConicToQuads quadder; 174 SkAutoConicToQuads quadder;
175 const SkScalar conicTol = SK_Scalar1 / 4; 175 const SkScalar conicTol = SK_Scalar1 / 4;
176 176
177 SkPath::Iter iter(path, true); 177 SkPath::Iter iter(path, true);
178 SkPoint pts[4]; 178 SkPoint pts[4];
179 SkPath::Verb verb; 179 SkPath::Verb verb;
180 180
181 if (iclip) { 181 if (iclip) {
182 SkRect clip; 182 SkRect clip;
183 setShiftedClip(&clip, *iclip, shiftUp); 183 setShiftedClip(&clip, *iclip, shiftUp);
184 SkEdgeClipper clipper; 184 SkEdgeClipper clipper;
185 185
186 while ((verb = iter.next(pts, false)) != SkPath::kDone_Verb) { 186 while ((verb = iter.next(pts, false)) != SkPath::kDone_Verb) {
187 switch (verb) { 187 switch (verb) {
188 case SkPath::kMove_Verb: 188 case SkPath::kMove_Verb:
189 case SkPath::kClose_Verb: 189 case SkPath::kClose_Verb:
190 // we ignore these, and just get the whole segment from 190 // we ignore these, and just get the whole segment from
191 // the corresponding line/quad/cubic verbs 191 // the corresponding line/quad/cubic verbs
192 break; 192 break;
193 case SkPath::kLine_Verb: { 193 case SkPath::kLine_Verb: {
194 SkPoint lines[SkLineClipper::kMaxPoints]; 194 SkPoint lines[SkLineClipper::kMaxPoints];
195 int lineCount = SkLineClipper::ClipLine(pts, clip, lines); 195 int lineCount = SkLineClipper::ClipLine(pts, clip, lines, cl ipToTheRight);
196 for (int i = 0; i < lineCount; i++) { 196 for (int i = 0; i < lineCount; i++) {
197 this->addLine(&lines[i]); 197 this->addLine(&lines[i]);
198 } 198 }
199 break; 199 break;
200 } 200 }
201 case SkPath::kQuad_Verb: 201 case SkPath::kQuad_Verb:
202 if (clipper.clipQuad(pts, clip)) { 202 if (clipper.clipQuad(pts, clip)) {
203 this->addClipper(&clipper); 203 this->addClipper(&clipper);
204 } 204 }
205 break; 205 break;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 } 256 }
257 default: 257 default:
258 SkDEBUGFAIL("unexpected verb"); 258 SkDEBUGFAIL("unexpected verb");
259 break; 259 break;
260 } 260 }
261 } 261 }
262 } 262 }
263 fEdgeList = fList.begin(); 263 fEdgeList = fList.begin();
264 return fList.count(); 264 return fList.count();
265 } 265 }
OLDNEW
« no previous file with comments | « src/core/SkEdgeBuilder.h ('k') | src/core/SkLineClipper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698