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/gpu/GrShape.h

Issue 1929643002: Detect empty (r)rects in GrShape. (Closed) Base URL: https://chromium.googlesource.com/skia.git@volatileshape
Patch Set: a->an 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 | « no previous file | tests/GrShapeTest.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 2016 Google Inc. 2 * Copyright 2016 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 #ifndef GrShape_DEFINED 8 #ifndef GrShape_DEFINED
9 #define GrShape_DEFINED 9 #define GrShape_DEFINED
10 10
(...skipping 15 matching lines...) Expand all
26 * to geometric information and is included in the new shape's key. When the sam e style is applied 26 * to geometric information and is included in the new shape's key. When the sam e style is applied
27 * to two shapes that reflect the same underlying geometry the computed keys of the stylized shapes 27 * to two shapes that reflect the same underlying geometry the computed keys of the stylized shapes
28 * will be the same. 28 * will be the same.
29 * 29 *
30 * Currently this can only be constructed from a rrect, though it can become a p ath by applying 30 * Currently this can only be constructed from a rrect, though it can become a p ath by applying
31 * style to the geometry. The idea is to expand this to cover most or all of the geometries that 31 * style to the geometry. The idea is to expand this to cover most or all of the geometries that
32 * have SkCanvas::draw APIs. 32 * have SkCanvas::draw APIs.
33 */ 33 */
34 class GrShape { 34 class GrShape {
35 public: 35 public:
36 GrShape(const SkPath& path) 36 GrShape() : fType(Type::kEmpty) {}
37
38 explicit GrShape(const SkPath& path)
37 : fType(Type::kPath) 39 : fType(Type::kPath)
38 , fPath(&path) { 40 , fPath(&path) {
39 this->attemptToReduceFromPath(); 41 this->attemptToReduceFromPath();
40 } 42 }
41 43
42 GrShape() : fType(Type::kEmpty) {} 44 explicit GrShape(const SkRRect& rrect)
45 : fType(Type::kRRect)
46 , fRRect(rrect) {
47 this->attemptToReduceFromRRect();
48 }
43 49
44 explicit GrShape(const SkRRect& rrect) : fType(Type::kRRect), fRRect(rrect) {} 50 explicit GrShape(const SkRect& rect)
45 explicit GrShape(const SkRect& rect) : fType(Type::kRRect), fRRect(SkRRect:: MakeRect(rect)) {} 51 : fType(Type::kRRect)
52 , fRRect(SkRRect::MakeRect(rect)) {
53 this->attemptToReduceFromRRect();
54 }
46 55
47 GrShape(const SkPath& path, const GrStyle& style) 56 GrShape(const SkPath& path, const GrStyle& style)
48 : fType(Type::kPath) 57 : fType(Type::kPath)
49 , fPath(&path) 58 , fPath(&path)
50 , fStyle(style) { 59 , fStyle(style) {
51 this->attemptToReduceFromPath(); 60 this->attemptToReduceFromPath();
52 } 61 }
53 62
54 GrShape(const SkRRect& rrect, const GrStyle& style) 63 GrShape(const SkRRect& rrect, const GrStyle& style)
55 : fType(Type::kRRect) 64 : fType(Type::kRRect)
56 , fRRect(rrect) 65 , fRRect(rrect)
57 , fStyle(style) {} 66 , fStyle(style) {
67 this->attemptToReduceFromRRect();
68 }
58 69
59 GrShape(const SkRect& rect, const GrStyle& style) 70 GrShape(const SkRect& rect, const GrStyle& style)
60 : fType(Type::kRRect) 71 : fType(Type::kRRect)
61 , fRRect(SkRRect::MakeRect(rect)) 72 , fRRect(SkRRect::MakeRect(rect))
62 , fStyle(style) {} 73 , fStyle(style) {
74 this->attemptToReduceFromRRect();
75 }
63 76
64 GrShape(const SkPath& path, const SkPaint& paint) 77 GrShape(const SkPath& path, const SkPaint& paint)
65 : fType(Type::kPath) 78 : fType(Type::kPath)
66 , fPath(&path) 79 , fPath(&path)
67 , fStyle(paint) { 80 , fStyle(paint) {
68 this->attemptToReduceFromPath(); 81 this->attemptToReduceFromPath();
69 } 82 }
70 83
71 GrShape(const SkRRect& rrect, const SkPaint& paint) 84 GrShape(const SkRRect& rrect, const SkPaint& paint)
72 : fType(Type::kRRect) 85 : fType(Type::kRRect)
73 , fRRect(rrect) 86 , fRRect(rrect)
74 , fStyle(paint) {} 87 , fStyle(paint) {
88 this->attemptToReduceFromRRect();
89 }
75 90
76 GrShape(const SkRect& rect, const SkPaint& paint) 91 GrShape(const SkRect& rect, const SkPaint& paint)
77 : fType(Type::kRRect) 92 : fType(Type::kRRect)
78 , fRRect(SkRRect::MakeRect(rect)) 93 , fRRect(SkRRect::MakeRect(rect))
79 , fStyle(paint) {} 94 , fStyle(paint) {
95 this->attemptToReduceFromRRect();
96 }
80 97
81 GrShape(const GrShape&); 98 GrShape(const GrShape&);
82 GrShape& operator=(const GrShape& that); 99 GrShape& operator=(const GrShape& that);
83 100
84 ~GrShape() { 101 ~GrShape() {
85 if (Type::kPath == fType) { 102 if (Type::kPath == fType) {
86 fPath.reset(); 103 fPath.reset();
87 } 104 }
88 } 105 }
89 106
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 void attemptToReduceFromPath() { 192 void attemptToReduceFromPath() {
176 SkASSERT(Type::kPath == fType); 193 SkASSERT(Type::kPath == fType);
177 fType = AttemptToReduceFromPathImpl(*fPath.get(), &fRRect, fStyle.pathEf fect(), 194 fType = AttemptToReduceFromPathImpl(*fPath.get(), &fRRect, fStyle.pathEf fect(),
178 fStyle.strokeRec()); 195 fStyle.strokeRec());
179 if (Type::kPath != fType) { 196 if (Type::kPath != fType) {
180 fPath.reset(); 197 fPath.reset();
181 fInheritedKey.reset(0); 198 fInheritedKey.reset(0);
182 } 199 }
183 } 200 }
184 201
202 void attemptToReduceFromRRect() {
203 SkASSERT(Type::kRRect == fType);
204 SkASSERT(!fInheritedKey.count());
205 if (fRRect.isEmpty()) {
206 fType = Type::kEmpty;
207 }
208 }
209
185 static Type AttemptToReduceFromPathImpl(const SkPath& path, SkRRect* rrect, 210 static Type AttemptToReduceFromPathImpl(const SkPath& path, SkRRect* rrect,
186 const SkPathEffect* pe, const SkStro keRec& strokeRec) { 211 const SkPathEffect* pe, const SkStro keRec& strokeRec) {
187 if (path.isEmpty()) { 212 if (path.isEmpty()) {
188 return Type::kEmpty; 213 return Type::kEmpty;
189 } 214 }
190 if (path.isRRect(rrect)) { 215 if (path.isRRect(rrect)) {
216 SkASSERT(!rrect->isEmpty());
191 return Type::kRRect; 217 return Type::kRRect;
192 } 218 }
193 SkRect rect; 219 SkRect rect;
194 if (path.isOval(&rect)) { 220 if (path.isOval(&rect)) {
195 rrect->setOval(rect); 221 rrect->setOval(rect);
196 return Type::kRRect; 222 return Type::kRRect;
197 } 223 }
198 bool closed; 224 bool closed;
199 if (path.isRect(&rect, &closed, nullptr)) { 225 if (path.isRect(&rect, &closed, nullptr)) {
200 if (closed || (!pe && strokeRec.isFillStyle())) { 226 if (closed || (!pe && strokeRec.isFillStyle())) {
201 rrect->setRect(rect); 227 rrect->setRect(rect);
202 return Type::kRRect; 228 return Type::kRRect;
203 } 229 }
204 } 230 }
205 return Type::kPath; 231 return Type::kPath;
206 } 232 }
207 233
208 Type fType; 234 Type fType;
209 SkRRect fRRect; 235 SkRRect fRRect;
210 SkTLazy<SkPath> fPath; 236 SkTLazy<SkPath> fPath;
211 GrStyle fStyle; 237 GrStyle fStyle;
212 SkAutoSTArray<8, uint32_t> fInheritedKey; 238 SkAutoSTArray<8, uint32_t> fInheritedKey;
213 }; 239 };
214 #endif 240 #endif
OLDNEW
« no previous file with comments | « no previous file | tests/GrShapeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698