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

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

Issue 1472733002: Include conic weights in GrPath cache kSimpleVolatilePathDomain keys (Closed) Base URL: https://skia.googlesource.com/skia.git@commandbuffer-as-api-02-other-tests-refactor
Patch Set: rebase 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 | « no previous file | tests/GpuDrawPathTest.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 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
78 SkASSERT(false); 78 SkASSERT(false);
79 return false; 79 return false;
80 } 80 }
81 SkSTArray<16, SkScalar, true> conicWeights(16);
82 if ((path.getSegmentMasks() & SkPath::kConic_SegmentMask) != 0) {
83 SkPath::RawIter iter(path);
84 SkPath::Verb verb;
85 SkPoint points[4];
86 while ((verb = iter.next(points)) != SkPath::kDone_Verb) {
87 if (verb == SkPath::kConic_Verb) {
88 conicWeights.push_back(iter.conicWeight());
89 }
90 }
91 }
92
93 const int conicWeightCnt = conicWeights.count();
81 94
82 // Construct counts that align as uint32_t counts. 95 // Construct counts that align as uint32_t counts.
83 #define ARRAY_DATA32_COUNT(array_type, count) \ 96 #define ARRAY_DATA32_COUNT(array_type, count) \
84 static_cast<int>((((count) * sizeof(array_type) + sizeof(uint32_t) - 1) / si zeof(uint32_t))) 97 static_cast<int>((((count) * sizeof(array_type) + sizeof(uint32_t) - 1) / si zeof(uint32_t)))
85 98
86 const int verbData32Cnt = ARRAY_DATA32_COUNT(uint8_t, verbCnt); 99 const int verbData32Cnt = ARRAY_DATA32_COUNT(uint8_t, verbCnt);
87 const int pointData32Cnt = ARRAY_DATA32_COUNT(SkPoint, pointCnt); 100 const int pointData32Cnt = ARRAY_DATA32_COUNT(SkPoint, pointCnt);
101 const int conicWeightData32Cnt = ARRAY_DATA32_COUNT(SkScalar, conicWeightCnt );
88 102
89 #undef ARRAY_DATA32_COUNT 103 #undef ARRAY_DATA32_COUNT
90 104
91 // The unique key data is a "message" with following fragments: 105 // The unique key data is a "message" with following fragments:
92 // 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
93 // (fragment 0, fixed size) 107 // (fragment 0, fixed size)
94 // 1) verb and point data (varying size) 108 // 1) verb, point data and conic weights (varying size)
95 // 2) stroke data (varying size) 109 // 2) stroke data (varying size)
96 110
97 const int baseData32Cnt = 2 + verbData32Cnt + pointData32Cnt; 111 const int baseData32Cnt = 2 + verbData32Cnt + pointData32Cnt + conicWeightDa ta32Cnt;
98 const int strokeDataCnt = stroke.computeUniqueKeyFragmentData32Cnt(); 112 const int strokeDataCnt = stroke.computeUniqueKeyFragmentData32Cnt();
99 static const GrUniqueKey::Domain kSimpleVolatilePathDomain = GrUniqueKey::Ge nerateDomain(); 113 static const GrUniqueKey::Domain kSimpleVolatilePathDomain = GrUniqueKey::Ge nerateDomain();
100 GrUniqueKey::Builder builder(key, kSimpleVolatilePathDomain, baseData32Cnt + strokeDataCnt); 114 GrUniqueKey::Builder builder(key, kSimpleVolatilePathDomain, baseData32Cnt + strokeDataCnt);
101 int i = 0; 115 int i = 0;
102 builder[i++] = path.getFillType(); 116 builder[i++] = path.getFillType();
103 117
104 // Serialize the verbCnt to make the whole message unambiguous. 118 // Serialize the verbCnt to make the whole message unambiguous.
105 // We serialize two variable length fragments to the message: 119 // We serialize two variable length fragments to the message:
106 // * verb and point data (fragment 1) 120 // * verbs, point data and conic weights (fragment 1)
107 // * stroke data (fragment 2) 121 // * stroke data (fragment 2)
108 // "Proof:" 122 // "Proof:"
109 // Verb count establishes unambiguous verb data. 123 // Verb count establishes unambiguous verb data.
110 // Unambiguous verb data establishes unambiguous point data, making fragment 1 unambiguous. 124 // Verbs encode also point data size and conic weight size.
125 // Thus the fragment 1 is unambiguous.
111 // Unambiguous fragment 1 establishes unambiguous fragment 2, since the leng th of the message 126 // Unambiguous fragment 1 establishes unambiguous fragment 2, since the leng th of the message
112 // has been established. 127 // has been established.
113 128
114 builder[i++] = SkToU32(verbCnt); // The path limit is compile-asserted above , so the cast is ok. 129 builder[i++] = SkToU32(verbCnt); // The path limit is compile-asserted above , so the cast is ok.
115 130
116 // Fill the last uint32_t with 0 first, since the last uint8_ts of the uint3 2_t may be 131 // Fill the last uint32_t with 0 first, since the last uint8_ts of the uint3 2_t may be
117 // uninitialized. This does not produce ambiguous verb data, since we have s erialized the exact 132 // uninitialized. This does not produce ambiguous verb data, since we have s erialized the exact
118 // verb count. 133 // verb count.
119 if (verbData32Cnt != static_cast<int>((verbCnt * sizeof(uint8_t) / sizeof(ui nt32_t)))) { 134 if (verbData32Cnt != static_cast<int>((verbCnt * sizeof(uint8_t) / sizeof(ui nt32_t)))) {
120 builder[i + verbData32Cnt - 1] = 0; 135 builder[i + verbData32Cnt - 1] = 0;
121 } 136 }
122 path.getVerbs(reinterpret_cast<uint8_t*>(&builder[i]), verbCnt); 137 path.getVerbs(reinterpret_cast<uint8_t*>(&builder[i]), verbCnt);
123 i += verbData32Cnt; 138 i += verbData32Cnt;
124 139
125 static_assert(((sizeof(SkPoint) % sizeof(uint32_t)) == 0) && sizeof(SkPoint) > sizeof(uint32_t), 140 static_assert(((sizeof(SkPoint) % sizeof(uint32_t)) == 0) && sizeof(SkPoint) > sizeof(uint32_t),
126 "skpoint_array_needs_padding"); 141 "skpoint_array_needs_padding");
127 142
128 // Here we assume getPoints does a memcpy, so that we do not need to worry a bout the alignment. 143 // Here we assume getPoints does a memcpy, so that we do not need to worry a bout the alignment.
129 path.getPoints(reinterpret_cast<SkPoint*>(&builder[i]), pointCnt); 144 path.getPoints(reinterpret_cast<SkPoint*>(&builder[i]), pointCnt);
130 SkDEBUGCODE(i += pointData32Cnt); 145 i += pointData32Cnt;
131 146
147 if (conicWeightCnt > 0) {
148 if (conicWeightData32Cnt != static_cast<int>(
149 (conicWeightCnt * sizeof(SkScalar) / sizeof(uint32_t)))) {
150 builder[i + conicWeightData32Cnt - 1] = 0;
151 }
152 memcpy(&builder[i], conicWeights.begin(), conicWeightCnt * sizeof(SkScal ar));
153 SkDEBUGCODE(i += conicWeightData32Cnt);
154 }
132 SkASSERT(i == baseData32Cnt); 155 SkASSERT(i == baseData32Cnt);
133 if (strokeDataCnt > 0) { 156 if (strokeDataCnt > 0) {
134 stroke.asUniqueKeyFragment(&builder[baseData32Cnt]); 157 stroke.asUniqueKeyFragment(&builder[baseData32Cnt]);
135 } 158 }
136 return true; 159 return true;
137 } 160 }
138 161
139 inline static void compute_key_for_general_path(const SkPath& path, const GrStro keInfo& stroke, 162 inline static void compute_key_for_general_path(const SkPath& path, const GrStro keInfo& stroke,
140 GrUniqueKey* key) { 163 GrUniqueKey* key) {
141 const int kBaseData32Cnt = 2; 164 const int kBaseData32Cnt = 2;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 SkRect ovalBounds; 205 SkRect ovalBounds;
183 if (!fStroke.isDashed() && fSkPath.isOval(&ovalBounds)) { 206 if (!fStroke.isDashed() && fSkPath.isOval(&ovalBounds)) {
184 SkRect otherOvalBounds; 207 SkRect otherOvalBounds;
185 return path.isOval(&otherOvalBounds) && ovalBounds == otherOvalBounds; 208 return path.isOval(&otherOvalBounds) && ovalBounds == otherOvalBounds;
186 } 209 }
187 210
188 return fSkPath == path; 211 return fSkPath == path;
189 } 212 }
190 #endif 213 #endif
191 214
OLDNEW
« no previous file with comments | « no previous file | tests/GpuDrawPathTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698