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

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

Issue 1608353002: resolution dependent path measure (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add comment Created 4 years, 11 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/SkDraw.cpp ('k') | src/gpu/GrBlurUtils.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 /* 2 /*
3 * Copyright 2008 The Android Open Source Project 3 * Copyright 2008 The Android Open Source Project
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 8
9 9
10 #include "SkPathMeasure.h" 10 #include "SkPathMeasure.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 static inline int tspan_big_enough(int tspan) { 54 static inline int tspan_big_enough(int tspan) {
55 SkASSERT((unsigned)tspan <= kMaxTValue); 55 SkASSERT((unsigned)tspan <= kMaxTValue);
56 return tspan >> 10; 56 return tspan >> 10;
57 } 57 }
58 58
59 // can't use tangents, since we need [0..1..................2] to be seen 59 // can't use tangents, since we need [0..1..................2] to be seen
60 // as definitely not a line (it is when drawn, but not parametrically) 60 // as definitely not a line (it is when drawn, but not parametrically)
61 // so we compare midpoints 61 // so we compare midpoints
62 #define CHEAP_DIST_LIMIT (SK_Scalar1/2) // just made this value up 62 #define CHEAP_DIST_LIMIT (SK_Scalar1/2) // just made this value up
63 63
64 static bool quad_too_curvy(const SkPoint pts[3]) { 64 bool SkPathMeasure::quad_too_curvy(const SkPoint pts[3]) {
65 // diff = (a/4 + b/2 + c/4) - (a/2 + c/2) 65 // diff = (a/4 + b/2 + c/4) - (a/2 + c/2)
66 // diff = -a/4 + b/2 - c/4 66 // diff = -a/4 + b/2 - c/4
67 SkScalar dx = SkScalarHalf(pts[1].fX) - 67 SkScalar dx = SkScalarHalf(pts[1].fX) -
68 SkScalarHalf(SkScalarHalf(pts[0].fX + pts[2].fX)); 68 SkScalarHalf(SkScalarHalf(pts[0].fX + pts[2].fX));
69 SkScalar dy = SkScalarHalf(pts[1].fY) - 69 SkScalar dy = SkScalarHalf(pts[1].fY) -
70 SkScalarHalf(SkScalarHalf(pts[0].fY + pts[2].fY)); 70 SkScalarHalf(SkScalarHalf(pts[0].fY + pts[2].fY));
71 71
72 SkScalar dist = SkMaxScalar(SkScalarAbs(dx), SkScalarAbs(dy)); 72 SkScalar dist = SkMaxScalar(SkScalarAbs(dx), SkScalarAbs(dy));
73 return dist > CHEAP_DIST_LIMIT; 73 return dist > fTolerance;
74 } 74 }
75 75
76 #ifndef SK_SUPPORT_LEGACY_CONIC_MEASURE 76 #ifndef SK_SUPPORT_LEGACY_CONIC_MEASURE
77 static bool conic_too_curvy(const SkPoint& firstPt, const SkPoint& midTPt, 77 bool SkPathMeasure::conic_too_curvy(const SkPoint& firstPt, const SkPoint& midTP t,
78 const SkPoint& lastPt) { 78 const SkPoint& lastPt) {
79 SkPoint midEnds = firstPt + lastPt; 79 SkPoint midEnds = firstPt + lastPt;
80 midEnds *= 0.5f; 80 midEnds *= 0.5f;
81 SkVector dxy = midTPt - midEnds; 81 SkVector dxy = midTPt - midEnds;
82 SkScalar dist = SkMaxScalar(SkScalarAbs(dxy.fX), SkScalarAbs(dxy.fY)); 82 SkScalar dist = SkMaxScalar(SkScalarAbs(dxy.fX), SkScalarAbs(dxy.fY));
83 return dist > CHEAP_DIST_LIMIT; 83 return dist > fTolerance;
84 } 84 }
85 #endif 85 #endif
86 86
87 static bool cheap_dist_exceeds_limit(const SkPoint& pt, 87 bool SkPathMeasure::cheap_dist_exceeds_limit(const SkPoint& pt,
88 SkScalar x, SkScalar y) { 88 SkScalar x, SkScalar y) {
89 SkScalar dist = SkMaxScalar(SkScalarAbs(x - pt.fX), SkScalarAbs(y - pt.fY)); 89 SkScalar dist = SkMaxScalar(SkScalarAbs(x - pt.fX), SkScalarAbs(y - pt.fY));
90 // just made up the 1/2 90 // just made up the 1/2
91 return dist > CHEAP_DIST_LIMIT; 91 return dist > fTolerance;
92 } 92 }
93 93
94 static bool cubic_too_curvy(const SkPoint pts[4]) { 94 bool SkPathMeasure::cubic_too_curvy(const SkPoint pts[4]) {
95 return cheap_dist_exceeds_limit(pts[1], 95 return cheap_dist_exceeds_limit(pts[1],
96 SkScalarInterp(pts[0].fX, pts[3].fX, SK_Scalar1/3), 96 SkScalarInterp(pts[0].fX, pts[3].fX, SK_Scalar1/3),
97 SkScalarInterp(pts[0].fY, pts[3].fY, SK_Scalar1/3)) 97 SkScalarInterp(pts[0].fY, pts[3].fY, SK_Scalar1/3))
98 || 98 ||
99 cheap_dist_exceeds_limit(pts[2], 99 cheap_dist_exceeds_limit(pts[2],
100 SkScalarInterp(pts[0].fX, pts[3].fX, SK_Scalar1*2/3), 100 SkScalarInterp(pts[0].fX, pts[3].fX, SK_Scalar1*2/3),
101 SkScalarInterp(pts[0].fY, pts[3].fY, SK_Scalar1*2/3)); 101 SkScalarInterp(pts[0].fY, pts[3].fY, SK_Scalar1*2/3));
102 } 102 }
103 103
104 static SkScalar quad_folded_len(const SkPoint pts[3]) { 104 static SkScalar quad_folded_len(const SkPoint pts[3]) {
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 SkDEBUGFAIL("unknown segType"); 522 SkDEBUGFAIL("unknown segType");
523 sk_throw(); 523 sk_throw();
524 } 524 }
525 } 525 }
526 526
527 //////////////////////////////////////////////////////////////////////////////// 527 ////////////////////////////////////////////////////////////////////////////////
528 //////////////////////////////////////////////////////////////////////////////// 528 ////////////////////////////////////////////////////////////////////////////////
529 529
530 SkPathMeasure::SkPathMeasure() { 530 SkPathMeasure::SkPathMeasure() {
531 fPath = nullptr; 531 fPath = nullptr;
532 fTolerance = CHEAP_DIST_LIMIT;
532 fLength = -1; // signal we need to compute it 533 fLength = -1; // signal we need to compute it
533 fForceClosed = false; 534 fForceClosed = false;
534 fFirstPtIndex = -1; 535 fFirstPtIndex = -1;
535 } 536 }
536 537
537 SkPathMeasure::SkPathMeasure(const SkPath& path, bool forceClosed) { 538 SkPathMeasure::SkPathMeasure(const SkPath& path, bool forceClosed, SkScalar resS cale) {
538 fPath = &path; 539 fPath = &path;
540 #ifdef SK_SUPPORT_LEGACY_DASH_MEASURE
541 fTolerance = CHEAP_DIST_LIMIT;
542 #else
543 fTolerance = CHEAP_DIST_LIMIT * SkScalarInvert(resScale);
544 #endif
539 fLength = -1; // signal we need to compute it 545 fLength = -1; // signal we need to compute it
540 fForceClosed = forceClosed; 546 fForceClosed = forceClosed;
541 fFirstPtIndex = -1; 547 fFirstPtIndex = -1;
542 548
543 fIter.setPath(path, forceClosed); 549 fIter.setPath(path, forceClosed);
544 } 550 }
545 551
546 SkPathMeasure::~SkPathMeasure() {} 552 SkPathMeasure::~SkPathMeasure() {}
547 553
548 /** Assign a new path, or null to have none. 554 /** Assign a new path, or null to have none.
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 756
751 for (int i = 0; i < fSegments.count(); i++) { 757 for (int i = 0; i < fSegments.count(); i++) {
752 const Segment* seg = &fSegments[i]; 758 const Segment* seg = &fSegments[i];
753 SkDebugf("pathmeas: seg[%d] distance=%g, point=%d, t=%g, type=%d\n", 759 SkDebugf("pathmeas: seg[%d] distance=%g, point=%d, t=%g, type=%d\n",
754 i, seg->fDistance, seg->fPtIndex, seg->getScalarT(), 760 i, seg->fDistance, seg->fPtIndex, seg->getScalarT(),
755 seg->fType); 761 seg->fType);
756 } 762 }
757 } 763 }
758 764
759 #endif 765 #endif
OLDNEW
« no previous file with comments | « src/core/SkDraw.cpp ('k') | src/gpu/GrBlurUtils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698