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

Side by Side Diff: samplecode/SampleAAGeometry.cpp

Issue 2368993002: allow conic chop to fail (Closed)
Patch Set: address comment Created 4 years, 2 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 | « gm/beziereffects.cpp ('k') | src/core/SkGeometry.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 2015 Google Inc. 2 * Copyright 2015 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 "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkGeometry.h" 10 #include "SkGeometry.h"
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 case SkPath::kQuad_Verb: { 213 case SkPath::kQuad_Verb: {
214 SkPoint chop[5]; 214 SkPoint chop[5];
215 SkChopQuadAtHalf(pts, chop); 215 SkChopQuadAtHalf(pts, chop);
216 result.quadTo(chop[1], chop[2]); 216 result.quadTo(chop[1], chop[2]);
217 pts[1] = chop[3]; 217 pts[1] = chop[3];
218 } break; 218 } break;
219 case SkPath::kConic_Verb: { 219 case SkPath::kConic_Verb: {
220 SkConic chop[2]; 220 SkConic chop[2];
221 SkConic conic; 221 SkConic conic;
222 conic.set(pts, iter.conicWeight()); 222 conic.set(pts, iter.conicWeight());
223 conic.chopAt(0.5f, chop); 223 if (!conic.chopAt(0.5f, chop)) {
224 return;
225 }
224 result.conicTo(chop[0].fPts[1], chop[0].fPts[2], chop[0].fW) ; 226 result.conicTo(chop[0].fPts[1], chop[0].fPts[2], chop[0].fW) ;
225 pts[1] = chop[1].fPts[1]; 227 pts[1] = chop[1].fPts[1];
226 weight = chop[1].fW; 228 weight = chop[1].fW;
227 } break; 229 } break;
228 case SkPath::kCubic_Verb: { 230 case SkPath::kCubic_Verb: {
229 SkPoint chop[7]; 231 SkPoint chop[7];
230 SkChopCubicAtHalf(pts, chop); 232 SkChopCubicAtHalf(pts, chop);
231 result.cubicTo(chop[1], chop[2], chop[3]); 233 result.cubicTo(chop[1], chop[2], chop[3]);
232 pts[1] = chop[4]; 234 pts[1] = chop[4];
233 pts[2] = chop[5]; 235 pts[2] = chop[5];
(...skipping 1119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 1355
1354 void conic_coverage(SkPoint pts[3], SkScalar weight, uint8_t* distanceMap, i nt w, int h) { 1356 void conic_coverage(SkPoint pts[3], SkScalar weight, uint8_t* distanceMap, i nt w, int h) {
1355 SkScalar dist = pts[0].Distance(pts[0], pts[2]); 1357 SkScalar dist = pts[0].Distance(pts[0], pts[2]);
1356 if (dist < gCurveDistance) { 1358 if (dist < gCurveDistance) {
1357 (void) coverage(pts[0], pts[2], distanceMap, w, h); 1359 (void) coverage(pts[0], pts[2], distanceMap, w, h);
1358 return; 1360 return;
1359 } 1361 }
1360 SkConic split[2]; 1362 SkConic split[2];
1361 SkConic conic; 1363 SkConic conic;
1362 conic.set(pts, weight); 1364 conic.set(pts, weight);
1363 conic.chopAt(0.5f, split); 1365 if (conic.chopAt(0.5f, split)) {
1364 conic_coverage(split[0].fPts, split[0].fW, distanceMap, w, h); 1366 conic_coverage(split[0].fPts, split[0].fW, distanceMap, w, h);
1365 conic_coverage(split[1].fPts, split[1].fW, distanceMap, w, h); 1367 conic_coverage(split[1].fPts, split[1].fW, distanceMap, w, h);
1368 }
1366 } 1369 }
1367 1370
1368 void cubic_coverage(SkPoint pts[4], uint8_t* distanceMap, int w, int h) { 1371 void cubic_coverage(SkPoint pts[4], uint8_t* distanceMap, int w, int h) {
1369 SkScalar dist = pts[0].Distance(pts[0], pts[3]); 1372 SkScalar dist = pts[0].Distance(pts[0], pts[3]);
1370 if (dist < gCurveDistance) { 1373 if (dist < gCurveDistance) {
1371 (void) coverage(pts[0], pts[3], distanceMap, w, h); 1374 (void) coverage(pts[0], pts[3], distanceMap, w, h);
1372 return; 1375 return;
1373 } 1376 }
1374 SkPoint split[7]; 1377 SkPoint split[7];
1375 SkChopCubicAt(pts, split, 0.5f); 1378 SkChopCubicAt(pts, split, 0.5f);
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 (void) this->onClick(&click); 1863 (void) this->onClick(&click);
1861 return true; 1864 return true;
1862 } 1865 }
1863 } 1866 }
1864 } 1867 }
1865 } 1868 }
1866 return this->INHERITED::onQuery(evt); 1869 return this->INHERITED::onQuery(evt);
1867 } 1870 }
1868 1871
1869 DEF_SAMPLE( return new AAGeometryView; ) 1872 DEF_SAMPLE( return new AAGeometryView; )
OLDNEW
« no previous file with comments | « gm/beziereffects.cpp ('k') | src/core/SkGeometry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698