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

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

Issue 1967513002: Revert of Replace GrStrokeInfo with GrStyle. (Closed) Base URL: https://chromium.googlesource.com/skia.git@resscale
Patch Set: Created 4 years, 7 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/gpu/GrPath.h ('k') | src/gpu/GrPathRenderer.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 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 #include "GrStyle.h"
10 9
11 namespace { 10 namespace {
12 // Verb count limit for generating path key from content of a volatile path. 11 // Verb count limit for generating path key from content of a volatile path.
13 // The value should accomodate at least simple rects and rrects. 12 // The value should accomodate at least simple rects and rrects.
14 static const int kSimpleVolatilePathVerbLimit = 10; 13 static const int kSimpleVolatilePathVerbLimit = 10;
15 14
16 static inline int style_data_cnt(const GrStyle& style) { 15 inline static bool compute_key_for_line_path(const SkPath& path, const GrStrokeI nfo& stroke,
17 int cnt = GrStyle::KeySize(style, GrStyle::Apply::kPathEffectAndStrokeRec);
18 // This should only fail for an arbitrary path effect, and we should not hav e gotten
19 // here with anything other than a dash path effect.
20 SkASSERT(cnt >= 0);
21 return cnt;
22 }
23
24 static inline void write_style_key(uint32_t* dst, const GrStyle& style) {
25 // Pass 1 for the scale since the GPU will apply the style not GrStyle::appl yToPath().
26 GrStyle::WriteKey(dst, style, GrStyle::Apply::kPathEffectAndStrokeRec, SK_Sc alar1);
27 }
28
29
30 inline static bool compute_key_for_line_path(const SkPath& path, const GrStyle& style,
31 GrUniqueKey* key) { 16 GrUniqueKey* key) {
32 SkPoint pts[2]; 17 SkPoint pts[2];
33 if (!path.isLine(pts)) { 18 if (!path.isLine(pts)) {
34 return false; 19 return false;
35 } 20 }
36 static_assert((sizeof(pts) % sizeof(uint32_t)) == 0 && sizeof(pts) > sizeof( uint32_t), 21 static_assert((sizeof(pts) % sizeof(uint32_t)) == 0 && sizeof(pts) > sizeof( uint32_t),
37 "pts_needs_padding"); 22 "pts_needs_padding");
38 int styleDataCnt = style_data_cnt(style);
39 23
40 const int kBaseData32Cnt = 1 + sizeof(pts) / sizeof(uint32_t); 24 const int kBaseData32Cnt = 1 + sizeof(pts) / sizeof(uint32_t);
25 int strokeDataCnt = stroke.computeUniqueKeyFragmentData32Cnt();
41 static const GrUniqueKey::Domain kOvalPathDomain = GrUniqueKey::GenerateDoma in(); 26 static const GrUniqueKey::Domain kOvalPathDomain = GrUniqueKey::GenerateDoma in();
42 GrUniqueKey::Builder builder(key, kOvalPathDomain, kBaseData32Cnt + styleDat aCnt); 27 GrUniqueKey::Builder builder(key, kOvalPathDomain, kBaseData32Cnt + strokeDa taCnt);
43 builder[0] = path.getFillType(); 28 builder[0] = path.getFillType();
44 memcpy(&builder[1], &pts, sizeof(pts)); 29 memcpy(&builder[1], &pts, sizeof(pts));
45 if (styleDataCnt > 0) { 30 if (strokeDataCnt > 0) {
46 write_style_key(&builder[kBaseData32Cnt], style); 31 stroke.asUniqueKeyFragment(&builder[kBaseData32Cnt]);
47 } 32 }
48 return true; 33 return true;
49 } 34 }
50 35
51 inline static bool compute_key_for_oval_path(const SkPath& path, const GrStyle& style, 36 inline static bool compute_key_for_oval_path(const SkPath& path, const GrStrokeI nfo& stroke,
52 GrUniqueKey* key) { 37 GrUniqueKey* key) {
53 SkRect rect; 38 SkRect rect;
54 // Point order is significant when dashing, so we cannot devolve to a rect k ey. 39 // Point order is significant when dashing, so we cannot devolve to a rect k ey.
55 if (style.pathEffect() || !path.isOval(&rect)) { 40 if (stroke.isDashed() || !path.isOval(&rect)) {
56 return false; 41 return false;
57 } 42 }
58 static_assert((sizeof(rect) % sizeof(uint32_t)) == 0 && sizeof(rect) > sizeo f(uint32_t), 43 static_assert((sizeof(rect) % sizeof(uint32_t)) == 0 && sizeof(rect) > sizeo f(uint32_t),
59 "rect_needs_padding"); 44 "rect_needs_padding");
60 45
61 const int kBaseData32Cnt = 1 + sizeof(rect) / sizeof(uint32_t); 46 const int kBaseData32Cnt = 1 + sizeof(rect) / sizeof(uint32_t);
62 int styleDataCnt = style_data_cnt(style); 47 int strokeDataCnt = stroke.computeUniqueKeyFragmentData32Cnt();
63 static const GrUniqueKey::Domain kOvalPathDomain = GrUniqueKey::GenerateDoma in(); 48 static const GrUniqueKey::Domain kOvalPathDomain = GrUniqueKey::GenerateDoma in();
64 GrUniqueKey::Builder builder(key, kOvalPathDomain, kBaseData32Cnt + styleDat aCnt); 49 GrUniqueKey::Builder builder(key, kOvalPathDomain, kBaseData32Cnt + strokeDa taCnt);
65 builder[0] = path.getFillType(); 50 builder[0] = path.getFillType();
66 memcpy(&builder[1], &rect, sizeof(rect)); 51 memcpy(&builder[1], &rect, sizeof(rect));
67 if (styleDataCnt > 0) { 52 if (strokeDataCnt > 0) {
68 write_style_key(&builder[kBaseData32Cnt], style); 53 stroke.asUniqueKeyFragment(&builder[kBaseData32Cnt]);
69 } 54 }
70 return true; 55 return true;
71 } 56 }
72 57
73 // 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
74 // 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
75 // SkPath::isRect seems to do non-trivial amount of work. 60 // SkPath::isRect seems to do non-trivial amount of work.
76 inline static bool compute_key_for_simple_path(const SkPath& path, const GrStyle & style, 61 inline static bool compute_key_for_simple_path(const SkPath& path, const GrStrok eInfo& stroke,
77 GrUniqueKey* key) { 62 GrUniqueKey* key) {
78 if (!path.isVolatile()) { 63 if (!path.isVolatile()) {
79 return false; 64 return false;
80 } 65 }
81 // The check below should take care of negative values casted positive. 66 // The check below should take care of negative values casted positive.
82 const int verbCnt = path.countVerbs(); 67 const int verbCnt = path.countVerbs();
83 if (verbCnt > kSimpleVolatilePathVerbLimit) { 68 if (verbCnt > kSimpleVolatilePathVerbLimit) {
84 return false; 69 return false;
85 } 70 }
86 71
(...skipping 30 matching lines...) Expand all
117 102
118 #undef ARRAY_DATA32_COUNT 103 #undef ARRAY_DATA32_COUNT
119 104
120 // The unique key data is a "message" with following fragments: 105 // The unique key data is a "message" with following fragments:
121 // 0) domain, key length, uint32_t for fill type and uint32_t for verbCnt 106 // 0) domain, key length, uint32_t for fill type and uint32_t for verbCnt
122 // (fragment 0, fixed size) 107 // (fragment 0, fixed size)
123 // 1) verb, point data and conic weights (varying size) 108 // 1) verb, point data and conic weights (varying size)
124 // 2) stroke data (varying size) 109 // 2) stroke data (varying size)
125 110
126 const int baseData32Cnt = 2 + verbData32Cnt + pointData32Cnt + conicWeightDa ta32Cnt; 111 const int baseData32Cnt = 2 + verbData32Cnt + pointData32Cnt + conicWeightDa ta32Cnt;
127 const int styleDataCnt = style_data_cnt(style); 112 const int strokeDataCnt = stroke.computeUniqueKeyFragmentData32Cnt();
128 static const GrUniqueKey::Domain kSimpleVolatilePathDomain = GrUniqueKey::Ge nerateDomain(); 113 static const GrUniqueKey::Domain kSimpleVolatilePathDomain = GrUniqueKey::Ge nerateDomain();
129 GrUniqueKey::Builder builder(key, kSimpleVolatilePathDomain, baseData32Cnt + styleDataCnt); 114 GrUniqueKey::Builder builder(key, kSimpleVolatilePathDomain, baseData32Cnt + strokeDataCnt);
130 int i = 0; 115 int i = 0;
131 builder[i++] = path.getFillType(); 116 builder[i++] = path.getFillType();
132 117
133 // Serialize the verbCnt to make the whole message unambiguous. 118 // Serialize the verbCnt to make the whole message unambiguous.
134 // We serialize two variable length fragments to the message: 119 // We serialize two variable length fragments to the message:
135 // * verbs, point data and conic weights (fragment 1) 120 // * verbs, point data and conic weights (fragment 1)
136 // * stroke data (fragment 2) 121 // * stroke data (fragment 2)
137 // "Proof:" 122 // "Proof:"
138 // Verb count establishes unambiguous verb data. 123 // Verb count establishes unambiguous verb data.
139 // Verbs encode also point data size and conic weight size. 124 // Verbs encode also point data size and conic weight size.
(...skipping 21 matching lines...) Expand all
161 146
162 if (conicWeightCnt > 0) { 147 if (conicWeightCnt > 0) {
163 if (conicWeightData32Cnt != static_cast<int>( 148 if (conicWeightData32Cnt != static_cast<int>(
164 (conicWeightCnt * sizeof(SkScalar) / sizeof(uint32_t)))) { 149 (conicWeightCnt * sizeof(SkScalar) / sizeof(uint32_t)))) {
165 builder[i + conicWeightData32Cnt - 1] = 0; 150 builder[i + conicWeightData32Cnt - 1] = 0;
166 } 151 }
167 memcpy(&builder[i], conicWeights.begin(), conicWeightCnt * sizeof(SkScal ar)); 152 memcpy(&builder[i], conicWeights.begin(), conicWeightCnt * sizeof(SkScal ar));
168 SkDEBUGCODE(i += conicWeightData32Cnt); 153 SkDEBUGCODE(i += conicWeightData32Cnt);
169 } 154 }
170 SkASSERT(i == baseData32Cnt); 155 SkASSERT(i == baseData32Cnt);
171 if (styleDataCnt > 0) { 156 if (strokeDataCnt > 0) {
172 write_style_key(&builder[baseData32Cnt], style); 157 stroke.asUniqueKeyFragment(&builder[baseData32Cnt]);
173 } 158 }
174 return true; 159 return true;
175 } 160 }
176 161
177 inline static void compute_key_for_general_path(const SkPath& path, const GrStyl e& style, 162 inline static void compute_key_for_general_path(const SkPath& path, const GrStro keInfo& stroke,
178 GrUniqueKey* key) { 163 GrUniqueKey* key) {
179 const int kBaseData32Cnt = 2; 164 const int kBaseData32Cnt = 2;
180 int styleDataCnt = style_data_cnt(style); 165 int strokeDataCnt = stroke.computeUniqueKeyFragmentData32Cnt();
181 static const GrUniqueKey::Domain kGeneralPathDomain = GrUniqueKey::GenerateD omain(); 166 static const GrUniqueKey::Domain kGeneralPathDomain = GrUniqueKey::GenerateD omain();
182 GrUniqueKey::Builder builder(key, kGeneralPathDomain, kBaseData32Cnt + style DataCnt); 167 GrUniqueKey::Builder builder(key, kGeneralPathDomain, kBaseData32Cnt + strok eDataCnt);
183 builder[0] = path.getGenerationID(); 168 builder[0] = path.getGenerationID();
184 builder[1] = path.getFillType(); 169 builder[1] = path.getFillType();
185 if (styleDataCnt > 0) { 170 if (strokeDataCnt > 0) {
186 write_style_key(&builder[kBaseData32Cnt], style); 171 stroke.asUniqueKeyFragment(&builder[kBaseData32Cnt]);
187 } 172 }
188 } 173 }
189 174
190 } 175 }
191 176
192 void GrPath::ComputeKey(const SkPath& path, const GrStyle& style, GrUniqueKey* k ey, 177 void GrPath::ComputeKey(const SkPath& path, const GrStrokeInfo& stroke, GrUnique Key* key,
193 bool* outIsVolatile) { 178 bool* outIsVolatile) {
194 if (compute_key_for_line_path(path, style, key)) { 179 if (compute_key_for_line_path(path, stroke, key)) {
195 *outIsVolatile = false; 180 *outIsVolatile = false;
196 return; 181 return;
197 } 182 }
198 183
199 if (compute_key_for_oval_path(path, style, key)) { 184 if (compute_key_for_oval_path(path, stroke, key)) {
200 *outIsVolatile = false; 185 *outIsVolatile = false;
201 return; 186 return;
202 } 187 }
203 188
204 if (compute_key_for_simple_path(path, style, key)) { 189 if (compute_key_for_simple_path(path, stroke, key)) {
205 *outIsVolatile = false; 190 *outIsVolatile = false;
206 return; 191 return;
207 } 192 }
208 193
209 compute_key_for_general_path(path, style, key); 194 compute_key_for_general_path(path, stroke, key);
210 *outIsVolatile = path.isVolatile(); 195 *outIsVolatile = path.isVolatile();
211 } 196 }
212 197
213 #ifdef SK_DEBUG 198 #ifdef SK_DEBUG
214 bool GrPath::isEqualTo(const SkPath& path, const GrStyle& style) const { 199 bool GrPath::isEqualTo(const SkPath& path, const GrStrokeInfo& stroke) const {
215 // Since this is only called in debug we don't care about performance. 200 if (!fStroke.hasEqualEffect(stroke)) {
216 int cnt0 = GrStyle::KeySize(fStyle, GrStyle::Apply::kPathEffectAndStrokeRec) ;
217 int cnt1 = GrStyle::KeySize(style, GrStyle::Apply::kPathEffectAndStrokeRec);
218 if (cnt0 < 0 || cnt1 < 0 || cnt0 != cnt1) {
219 return false; 201 return false;
220 } 202 }
221 if (cnt0) { 203
222 SkAutoTArray<uint32_t> key0(cnt0);
223 SkAutoTArray<uint32_t> key1(cnt0);
224 write_style_key(key0.get(), fStyle);
225 write_style_key(key1.get(), style);
226 if (0 != memcmp(key0.get(), key1.get(), cnt0)) {
227 return false;
228 }
229 }
230 // We treat same-rect ovals as identical - but only when not dashing. 204 // We treat same-rect ovals as identical - but only when not dashing.
231 SkRect ovalBounds; 205 SkRect ovalBounds;
232 if (!fStyle.isDashed() && fSkPath.isOval(&ovalBounds)) { 206 if (!fStroke.isDashed() && fSkPath.isOval(&ovalBounds)) {
233 SkRect otherOvalBounds; 207 SkRect otherOvalBounds;
234 return path.isOval(&otherOvalBounds) && ovalBounds == otherOvalBounds; 208 return path.isOval(&otherOvalBounds) && ovalBounds == otherOvalBounds;
235 } 209 }
236 210
237 return fSkPath == path; 211 return fSkPath == path;
238 } 212 }
239 #endif 213 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrPath.h ('k') | src/gpu/GrPathRenderer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698