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

Side by Side Diff: src/gpu/effects/GrConvexPolyEffect.cpp

Issue 2018613003: Filter out degenerate contours in GrConvexPolyEffect (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Added comments and assertions Created 4 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
« no previous file with comments | « no previous file | no next file » | 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 2014 Google Inc. 2 * Copyright 2014 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 7
8 #include "GrConvexPolyEffect.h" 8 #include "GrConvexPolyEffect.h"
9 #include "GrInvariantOutput.h" 9 #include "GrInvariantOutput.h"
10 #include "SkPathPriv.h" 10 #include "SkPathPriv.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType type, const SkPath& path, 240 GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType type, const SkPath& path,
241 const SkVector* offset) { 241 const SkVector* offset) {
242 if (kHairlineAA_GrProcessorEdgeType == type) { 242 if (kHairlineAA_GrProcessorEdgeType == type) {
243 return nullptr; 243 return nullptr;
244 } 244 }
245 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask || 245 if (path.getSegmentMasks() != SkPath::kLine_SegmentMask ||
246 !path.isConvex()) { 246 !path.isConvex()) {
247 return nullptr; 247 return nullptr;
248 } 248 }
249 249
250 if (path.countPoints() > kMaxEdges) {
251 return nullptr;
252 }
253
254 SkPoint pts[kMaxEdges];
255 SkScalar edges[3 * kMaxEdges];
256
257 SkPathPriv::FirstDirection dir; 250 SkPathPriv::FirstDirection dir;
258 // The only way this should fail is if the clip is effectively a infinitely thin line. In that 251 // The only way this should fail is if the clip is effectively a infinitely thin line. In that
259 // case nothing is inside the clip. It'd be nice to detect this at a higher level and either 252 // case nothing is inside the clip. It'd be nice to detect this at a higher level and either
260 // skip the draw or omit the clip element. 253 // skip the draw or omit the clip element.
261 if (!SkPathPriv::CheapComputeFirstDirection(path, &dir)) { 254 if (!SkPathPriv::CheapComputeFirstDirection(path, &dir)) {
262 if (GrProcessorEdgeTypeIsInverseFill(type)) { 255 if (GrProcessorEdgeTypeIsInverseFill(type)) {
263 return GrConstColorProcessor::Create(0xFFFFFFFF, 256 return GrConstColorProcessor::Create(0xFFFFFFFF,
264 GrConstColorProcessor::kModulat eRGBA_InputMode); 257 GrConstColorProcessor::kModulat eRGBA_InputMode);
265 } 258 }
266 return GrConstColorProcessor::Create(0, GrConstColorProcessor::kIgnore_I nputMode); 259 return GrConstColorProcessor::Create(0, GrConstColorProcessor::kIgnore_I nputMode);
267 } 260 }
268 261
269 SkVector t; 262 SkVector t;
270 if (nullptr == offset) { 263 if (nullptr == offset) {
271 t.set(0, 0); 264 t.set(0, 0);
272 } else { 265 } else {
273 t = *offset; 266 t = *offset;
274 } 267 }
275 268
276 int count = path.getPoints(pts, kMaxEdges); 269 SkScalar edges[3 * kMaxEdges];
270 SkPoint pts[4];
271 SkPath::Verb verb;
272 SkPath::Iter iter(path, true);
273
274 // SkPath considers itself convex so long as there is a convex contour withi n it,
275 // regardless of any degenerate contours such as a string of moveTos before it.
276 // Iterate here to consume any degenerate contours and only process the poin ts
277 // on the actual convex contour.
277 int n = 0; 278 int n = 0;
278 for (int lastPt = count - 1, i = 0; i < count; lastPt = i++) { 279 while ((verb = iter.next(pts, true, true)) != SkPath::kDone_Verb) {
279 if (pts[lastPt] != pts[i]) { 280 switch (verb) {
280 SkVector v = pts[i] - pts[lastPt]; 281 case SkPath::kMove_Verb:
281 v.normalize(); 282 SkASSERT(n == 0);
282 if (SkPathPriv::kCCW_FirstDirection == dir) { 283 case SkPath::kClose_Verb:
283 edges[3 * n] = v.fY; 284 break;
284 edges[3 * n + 1] = -v.fX; 285 case SkPath::kLine_Verb: {
285 } else { 286 if (n >= kMaxEdges) {
286 edges[3 * n] = -v.fY; 287 return nullptr;
287 edges[3 * n + 1] = v.fX; 288 }
289 SkVector v = pts[1] - pts[0];
290 v.normalize();
291 if (SkPathPriv::kCCW_FirstDirection == dir) {
292 edges[3 * n] = v.fY;
293 edges[3 * n + 1] = -v.fX;
294 } else {
295 edges[3 * n] = -v.fY;
296 edges[3 * n + 1] = v.fX;
297 }
298 SkPoint p = pts[1] + t;
299 edges[3 * n + 2] = -(edges[3 * n] * p.fX + edges[3 * n + 1] * p. fY);
300 ++n;
301 break;
288 } 302 }
289 SkPoint p = pts[i] + t; 303 default:
290 edges[3 * n + 2] = -(edges[3 * n] * p.fX + edges[3 * n + 1] * p.fY); 304 return nullptr;
291 ++n;
292 } 305 }
293 } 306 }
307
294 if (path.isInverseFillType()) { 308 if (path.isInverseFillType()) {
295 type = GrInvertProcessorEdgeType(type); 309 type = GrInvertProcessorEdgeType(type);
296 } 310 }
297 return Create(type, n, edges); 311 return Create(type, n, edges);
298 } 312 }
299 313
300 GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType edgeType, co nst SkRect& rect) { 314 GrFragmentProcessor* GrConvexPolyEffect::Create(GrPrimitiveEdgeType edgeType, co nst SkRect& rect) {
301 if (kHairlineAA_GrProcessorEdgeType == edgeType){ 315 if (kHairlineAA_GrProcessorEdgeType == edgeType){
302 return nullptr; 316 return nullptr;
303 } 317 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 } 367 }
354 368
355 GrFragmentProcessor* fp; 369 GrFragmentProcessor* fp;
356 do { 370 do {
357 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>( 371 GrPrimitiveEdgeType edgeType = static_cast<GrPrimitiveEdgeType>(
358 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt)); 372 d->fRandom->nextULessThan(kGrProcessorEdgeTypeCnt));
359 fp = GrConvexPolyEffect::Create(edgeType, count, edges); 373 fp = GrConvexPolyEffect::Create(edgeType, count, edges);
360 } while (nullptr == fp); 374 } while (nullptr == fp);
361 return fp; 375 return fp;
362 } 376 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698