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

Side by Side Diff: src/gpu/GrPath.cpp

Issue 1473973003: Obtain conic weights for GrPath cache keys from SkPathRef Base URL: https://skia.googlesource.com/skia.git@path-cache-fix-conic-weights
Patch Set: Created 5 years 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/core/SkPath.h ('k') | 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 2012 Google Inc. 2 * Copyright 2012 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 "GrPath.h" 8 #include "GrPath.h"
9 9
10 namespace { 10 namespace {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 memcpy(&builder[1], &rect, sizeof(rect)); 51 memcpy(&builder[1], &rect, sizeof(rect));
52 if (strokeDataCnt > 0) { 52 if (strokeDataCnt > 0) {
53 stroke.asUniqueKeyFragment(&builder[kBaseData32Cnt]); 53 stroke.asUniqueKeyFragment(&builder[kBaseData32Cnt]);
54 } 54 }
55 return true; 55 return true;
56 } 56 }
57 57
58 // Encodes the full path data to the unique key for very small, volatile paths. This is typically 58 // Encodes the full path data to the unique key for very small, volatile paths. This is typically
59 // hit when clipping stencils the clip stack. Intention is that this handles rec ts too, since 59 // hit when clipping stencils the clip stack. Intention is that this handles rec ts too, since
60 // SkPath::isRect seems to do non-trivial amount of work. 60 // SkPath::isRect seems to do non-trivial amount of work.
61 inline static bool compute_key_for_simple_path(const SkPath& path, const GrStrok eInfo& stroke, 61 inline static bool compute_key_for_simple_path(const SkPath& path, const SkPathR ef* pathRef,
62 GrUniqueKey* key) { 62 const GrStrokeInfo& stroke, GrUni queKey* key) {
63 if (!path.isVolatile()) { 63 if (!path.isVolatile()) {
64 return false; 64 return false;
65 } 65 }
66 // The check below should take care of negative values casted positive. 66 // The check below should take care of negative values casted positive.
67 const int verbCnt = path.countVerbs(); 67 const int verbCnt = path.countVerbs();
68 if (verbCnt > kSimpleVolatilePathVerbLimit) { 68 if (verbCnt > kSimpleVolatilePathVerbLimit) {
69 return false; 69 return false;
70 } 70 }
71 71
72 // If somebody goes wild with the constant, it might cause an overflow. 72 // If somebody goes wild with the constant, it might cause an overflow.
73 static_assert(kSimpleVolatilePathVerbLimit <= 100, 73 static_assert(kSimpleVolatilePathVerbLimit <= 100,
74 "big_simple_volatile_path_verb_limit_may_cause_overflow"); 74 "big_simple_volatile_path_verb_limit_may_cause_overflow");
75 75
76 const int pointCnt = path.countPoints(); 76 const int pointCnt = path.countPoints();
77 if (pointCnt < 0) { 77 if (pointCnt < 0) {
reed1 2015/11/30 15:36:39 Same question here: why this check? (tho I know it
78 SkASSERT(false); 78 SkASSERT(false);
79 return false; 79 return false;
80 } 80 }
81 SkSTArray<16, SkScalar, true> conicWeights(16); 81
82 if ((path.getSegmentMasks() & SkPath::kConic_SegmentMask) != 0) { 82 const int conicWeightCnt = pathRef ? pathRef->countWeights() : 0;
83 SkPath::RawIter iter(path); 83 if (conicWeightCnt < 0) {
reed1 2015/11/30 15:36:39 Why this check?
Kimmo Kinnunen 2015/12/01 06:35:14 Because it's an int and used as a thing below that
reed1 2015/12/01 14:37:21 Yes, but can it ever be negative? This is an inter
84 SkPath::Verb verb; 84 SkASSERT(false);
85 SkPoint points[4]; 85 return false;
86 while ((verb = iter.next(points)) != SkPath::kDone_Verb) {
87 if (verb == SkPath::kConic_Verb) {
88 conicWeights.push_back(iter.conicWeight());
89 }
90 }
91 } 86 }
92 87
93 const int conicWeightCnt = conicWeights.count();
94
95 // Construct counts that align as uint32_t counts. 88 // Construct counts that align as uint32_t counts.
96 #define ARRAY_DATA32_COUNT(array_type, count) \ 89 #define ARRAY_DATA32_COUNT(array_type, count) \
97 static_cast<int>((((count) * sizeof(array_type) + sizeof(uint32_t) - 1) / si zeof(uint32_t))) 90 static_cast<int>((((count) * sizeof(array_type) + sizeof(uint32_t) - 1) / si zeof(uint32_t)))
98 91
99 const int verbData32Cnt = ARRAY_DATA32_COUNT(uint8_t, verbCnt); 92 const int verbData32Cnt = ARRAY_DATA32_COUNT(uint8_t, verbCnt);
100 const int pointData32Cnt = ARRAY_DATA32_COUNT(SkPoint, pointCnt); 93 const int pointData32Cnt = ARRAY_DATA32_COUNT(SkPoint, pointCnt);
101 const int conicWeightData32Cnt = ARRAY_DATA32_COUNT(SkScalar, conicWeightCnt ); 94 const int conicWeightData32Cnt = ARRAY_DATA32_COUNT(SkScalar, conicWeightCnt );
102 95
103 #undef ARRAY_DATA32_COUNT 96 #undef ARRAY_DATA32_COUNT
104 97
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 135
143 // Here we assume getPoints does a memcpy, so that we do not need to worry a bout the alignment. 136 // Here we assume getPoints does a memcpy, so that we do not need to worry a bout the alignment.
144 path.getPoints(reinterpret_cast<SkPoint*>(&builder[i]), pointCnt); 137 path.getPoints(reinterpret_cast<SkPoint*>(&builder[i]), pointCnt);
145 i += pointData32Cnt; 138 i += pointData32Cnt;
146 139
147 if (conicWeightCnt > 0) { 140 if (conicWeightCnt > 0) {
148 if (conicWeightData32Cnt != static_cast<int>( 141 if (conicWeightData32Cnt != static_cast<int>(
149 (conicWeightCnt * sizeof(SkScalar) / sizeof(uint32_t)))) { 142 (conicWeightCnt * sizeof(SkScalar) / sizeof(uint32_t)))) {
150 builder[i + conicWeightData32Cnt - 1] = 0; 143 builder[i + conicWeightData32Cnt - 1] = 0;
151 } 144 }
152 memcpy(&builder[i], conicWeights.begin(), conicWeightCnt * sizeof(SkScal ar)); 145 memcpy(&builder[i], pathRef->conicWeights(), conicWeightCnt * sizeof(SkS calar));
153 SkDEBUGCODE(i += conicWeightData32Cnt); 146 SkDEBUGCODE(i += conicWeightData32Cnt);
154 } 147 }
155 SkASSERT(i == baseData32Cnt); 148 SkASSERT(i == baseData32Cnt);
156 if (strokeDataCnt > 0) { 149 if (strokeDataCnt > 0) {
157 stroke.asUniqueKeyFragment(&builder[baseData32Cnt]); 150 stroke.asUniqueKeyFragment(&builder[baseData32Cnt]);
158 } 151 }
159 return true; 152 return true;
160 } 153 }
161 154
162 inline static void compute_key_for_general_path(const SkPath& path, const GrStro keInfo& stroke, 155 inline static void compute_key_for_general_path(const SkPath& path, const GrStro keInfo& stroke,
(...skipping 16 matching lines...) Expand all
179 if (compute_key_for_line_path(path, stroke, key)) { 172 if (compute_key_for_line_path(path, stroke, key)) {
180 *outIsVolatile = false; 173 *outIsVolatile = false;
181 return; 174 return;
182 } 175 }
183 176
184 if (compute_key_for_oval_path(path, stroke, key)) { 177 if (compute_key_for_oval_path(path, stroke, key)) {
185 *outIsVolatile = false; 178 *outIsVolatile = false;
186 return; 179 return;
187 } 180 }
188 181
189 if (compute_key_for_simple_path(path, stroke, key)) { 182 if (compute_key_for_simple_path(path, path.fPathRef, stroke, key)) {
190 *outIsVolatile = false; 183 *outIsVolatile = false;
191 return; 184 return;
192 } 185 }
193 186
194 compute_key_for_general_path(path, stroke, key); 187 compute_key_for_general_path(path, stroke, key);
195 *outIsVolatile = path.isVolatile(); 188 *outIsVolatile = path.isVolatile();
196 } 189 }
197 190
198 #ifdef SK_DEBUG 191 #ifdef SK_DEBUG
199 bool GrPath::isEqualTo(const SkPath& path, const GrStrokeInfo& stroke) const { 192 bool GrPath::isEqualTo(const SkPath& path, const GrStrokeInfo& stroke) const {
200 if (!fStroke.hasEqualEffect(stroke)) { 193 if (!fStroke.hasEqualEffect(stroke)) {
201 return false; 194 return false;
202 } 195 }
203 196
204 // We treat same-rect ovals as identical - but only when not dashing. 197 // We treat same-rect ovals as identical - but only when not dashing.
205 SkRect ovalBounds; 198 SkRect ovalBounds;
206 if (!fStroke.isDashed() && fSkPath.isOval(&ovalBounds)) { 199 if (!fStroke.isDashed() && fSkPath.isOval(&ovalBounds)) {
207 SkRect otherOvalBounds; 200 SkRect otherOvalBounds;
208 return path.isOval(&otherOvalBounds) && ovalBounds == otherOvalBounds; 201 return path.isOval(&otherOvalBounds) && ovalBounds == otherOvalBounds;
209 } 202 }
210 203
211 return fSkPath == path; 204 return fSkPath == path;
212 } 205 }
213 #endif 206 #endif
214 207
OLDNEW
« no previous file with comments | « include/core/SkPath.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698