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/core/SkPath.cpp

Issue 2481463002: use reversePathTo in place of addPathReverse (Closed)
Patch Set: fix nanobench; stop after one contour Created 4 years, 1 month 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 | « include/pathops/SkPathOps.h ('k') | src/pathops/SkOpBuilder.cpp » ('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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 <cmath> 8 #include <cmath>
9 #include "SkBuffer.h" 9 #include "SkBuffer.h"
10 #include "SkCubicClipper.h" 10 #include "SkCubicClipper.h"
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after
1560 0, // kClose 1560 0, // kClose
1561 0 // kDone 1561 0 // kDone
1562 }; 1562 };
1563 1563
1564 SkASSERT(verb < SK_ARRAY_COUNT(gPtsInVerb)); 1564 SkASSERT(verb < SK_ARRAY_COUNT(gPtsInVerb));
1565 return gPtsInVerb[verb]; 1565 return gPtsInVerb[verb];
1566 } 1566 }
1567 1567
1568 // ignore the last point of the 1st contour 1568 // ignore the last point of the 1st contour
1569 void SkPath::reversePathTo(const SkPath& path) { 1569 void SkPath::reversePathTo(const SkPath& path) {
1570 int i, vcount = path.fPathRef->countVerbs(); 1570 const uint8_t* verbs = path.fPathRef->verbsMemBegin(); // points at the last verb
1571 // exit early if the path is empty, or just has a moveTo. 1571 if (!verbs) { // empty path returns nullptr
1572 if (vcount < 2) {
1573 return; 1572 return;
1574 } 1573 }
1574 const uint8_t* verbsEnd = path.fPathRef->verbs() - 1; // points just past th e first verb
1575 SkASSERT(verbsEnd[0] == kMove_Verb);
1576 const SkPoint* pts = path.fPathRef->pointsEnd() - 1;
1577 const SkScalar* conicWeights = path.fPathRef->conicWeightsEnd();
1575 1578
1576 SkPathRef::Editor(&fPathRef, vcount, path.countPoints()); 1579 while (verbs < verbsEnd) {
1577 1580 uint8_t v = *verbs++;
1578 const uint8_t* verbs = path.fPathRef->verbs(); 1581 pts -= pts_in_verb(v);
1579 const SkPoint* pts = path.fPathRef->points(); 1582 switch (v) {
1580 const SkScalar* conicWeights = path.fPathRef->conicWeights(); 1583 case kMove_Verb:
1581 1584 // if the path has multiple contours, stop after reversing the l ast
1582 SkASSERT(verbs[~0] == kMove_Verb); 1585 return;
1583 for (i = 1; i < vcount; ++i) {
1584 unsigned v = verbs[~i];
1585 int n = pts_in_verb(v);
1586 if (n == 0) {
1587 break;
1588 }
1589 pts += n;
1590 conicWeights += (SkPath::kConic_Verb == v);
1591 }
1592
1593 while (--i > 0) {
1594 switch (verbs[~i]) {
1595 case kLine_Verb: 1586 case kLine_Verb:
1596 this->lineTo(pts[-1].fX, pts[-1].fY); 1587 this->lineTo(pts[0]);
1597 break; 1588 break;
1598 case kQuad_Verb: 1589 case kQuad_Verb:
1599 this->quadTo(pts[-1].fX, pts[-1].fY, pts[-2].fX, pts[-2].fY); 1590 this->quadTo(pts[1], pts[0]);
1600 break; 1591 break;
1601 case kConic_Verb: 1592 case kConic_Verb:
1602 this->conicTo(pts[-1], pts[-2], *--conicWeights); 1593 this->conicTo(pts[1], pts[0], *--conicWeights);
1603 break; 1594 break;
1604 case kCubic_Verb: 1595 case kCubic_Verb:
1605 this->cubicTo(pts[-1].fX, pts[-1].fY, pts[-2].fX, pts[-2].fY, 1596 this->cubicTo(pts[2], pts[1], pts[0]);
1606 pts[-3].fX, pts[-3].fY); 1597 break;
1598 case kClose_Verb:
1599 SkASSERT(verbs - path.fPathRef->verbsMemBegin() == 1);
1607 break; 1600 break;
1608 default: 1601 default:
1609 SkDEBUGFAIL("bad verb"); 1602 SkDEBUGFAIL("bad verb");
1610 break; 1603 break;
1611 } 1604 }
1612 pts -= pts_in_verb(verbs[~i]);
1613 } 1605 }
1614 } 1606 }
1615 1607
1616 void SkPath::reverseAddPath(const SkPath& src) { 1608 void SkPath::reverseAddPath(const SkPath& src) {
1617 SkPathRef::Editor ed(&fPathRef, src.fPathRef->countPoints(), src.fPathRef->c ountVerbs()); 1609 SkPathRef::Editor ed(&fPathRef, src.fPathRef->countPoints(), src.fPathRef->c ountVerbs());
1618 1610
1619 const SkPoint* pts = src.fPathRef->pointsEnd(); 1611 const SkPoint* pts = src.fPathRef->pointsEnd();
1620 // we will iterator through src's verbs backwards 1612 // we will iterator through src's verbs backwards
1621 const uint8_t* verbs = src.fPathRef->verbsMemBegin(); // points at the last verb 1613 const uint8_t* verbs = src.fPathRef->verbsMemBegin(); // points at the last verb
1622 const uint8_t* verbsEnd = src.fPathRef->verbs(); // points just past the fir st verb 1614 const uint8_t* verbsEnd = src.fPathRef->verbs(); // points just past the fir st verb
(...skipping 1768 matching lines...) Expand 10 before | Expand all | Expand 10 after
3391 path->arcTo(oval, startAngle, 180.f, false); 3383 path->arcTo(oval, startAngle, 180.f, false);
3392 startAngle += 180.f; 3384 startAngle += 180.f;
3393 forceMoveTo = false; 3385 forceMoveTo = false;
3394 sweepAngle -= 360.f; 3386 sweepAngle -= 360.f;
3395 } 3387 }
3396 path->arcTo(oval, startAngle, sweepAngle, forceMoveTo); 3388 path->arcTo(oval, startAngle, sweepAngle, forceMoveTo);
3397 if (useCenter) { 3389 if (useCenter) {
3398 path->close(); 3390 path->close();
3399 } 3391 }
3400 } 3392 }
OLDNEW
« no previous file with comments | « include/pathops/SkPathOps.h ('k') | src/pathops/SkOpBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698