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

Side by Side Diff: src/gpu/GrShape.h

Issue 1922713002: Add support for building GrShape from SkPath and more tests (Closed) Base URL: https://chromium.googlesource.com/skia.git@strokeinfo
Patch Set: update 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 | src/gpu/GrShape.cpp » ('j') | tests/GrShapeTest.cpp » ('J')
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 18 matching lines...) Expand all
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() : fType(Type::kEmpty) {} 36 GrShape() : fType(Type::kEmpty) {}
37 37
38 explicit GrShape(const SkRRect& rrect) : fType(Type::kRRect), fRRect(rrect) {} 38 explicit GrShape(const SkRRect& rrect) : fType(Type::kRRect), fRRect(rrect) {}
39 explicit GrShape(const SkRect& rect) : fType(Type::kRRect), fRRect(SkRRect:: MakeRect(rect)) {} 39 explicit GrShape(const SkRect& rect) : fType(Type::kRRect), fRRect(SkRRect:: MakeRect(rect)) {}
robertphillips 2016/04/26 22:18:32 No un-styled variants ?
bsalomon 2016/04/29 23:12:06 Done.
40 40
41 GrShape(const SkPath& path, const GrStyle& style)
42 : fType(Type::kPath)
43 , fPath(&path)
44 , fStyle(style) {
45 this->attemptToReduceFromPath();
46 }
47
41 GrShape(const SkRRect& rrect, const GrStyle& style) 48 GrShape(const SkRRect& rrect, const GrStyle& style)
42 : fType(Type::kRRect) 49 : fType(Type::kRRect)
43 , fRRect(rrect) 50 , fRRect(rrect)
44 , fStyle(style) {} 51 , fStyle(style) {}
45 52
46 GrShape(const SkRect& rect, const GrStyle& style) 53 GrShape(const SkRect& rect, const GrStyle& style)
47 : fType(Type::kRRect) 54 : fType(Type::kRRect)
48 , fRRect(SkRRect::MakeRect(rect)) 55 , fRRect(SkRRect::MakeRect(rect))
49 , fStyle(style) {} 56 , fStyle(style) {}
50 57
58 GrShape(const SkPath& path, const SkPaint& paint)
59 : fType(Type::kPath)
60 , fPath(&path)
61 , fStyle(paint) {
62 this->attemptToReduceFromPath();
63 }
64
51 GrShape(const SkRRect& rrect, const SkPaint& paint) 65 GrShape(const SkRRect& rrect, const SkPaint& paint)
52 : fType(Type::kRRect) 66 : fType(Type::kRRect)
53 , fRRect(rrect) 67 , fRRect(rrect)
54 , fStyle(paint) {} 68 , fStyle(paint) {}
55 69
56 GrShape(const SkRect& rect, const SkPaint& paint) 70 GrShape(const SkRect& rect, const SkPaint& paint)
57 : fType(Type::kRRect) 71 : fType(Type::kRRect)
58 , fRRect(SkRRect::MakeRect(rect)) 72 , fRRect(SkRRect::MakeRect(rect))
59 , fStyle(paint) {} 73 , fStyle(paint) {}
60 74
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 int unstyledKeySize() const; 129 int unstyledKeySize() const;
116 130
117 /** 131 /**
118 * Writes unstyledKeySize() bytes into the provided pointer. Assumes that th ere is enough 132 * Writes unstyledKeySize() bytes into the provided pointer. Assumes that th ere is enough
119 * space allocated for the key and that unstyledKeySize() does not return a negative value 133 * space allocated for the key and that unstyledKeySize() does not return a negative value
120 * for this shape. 134 * for this shape.
121 */ 135 */
122 void writeUnstyledKey(uint32_t* key) const; 136 void writeUnstyledKey(uint32_t* key) const;
123 137
124 private: 138 private:
139 enum class Type {
140 kEmpty,
141 kRRect,
142 kPath,
143 };
144
125 /** 145 /**
126 * Computes the key length for a GrStyle. The return will be negative if it cannot be turned 146 * Computes the key length for a GrStyle. The return will be negative if it cannot be turned
127 * into a key. 147 * into a key.
128 */ 148 */
129 static int StyleKeySize(const GrStyle& , bool stopAfterPE); 149 static int StyleKeySize(const GrStyle& , bool stopAfterPE);
130 150
131 /** 151 /**
132 * Writes a unique key for the style into the provided buffer. This function assumes the buffer 152 * Writes a unique key for the style into the provided buffer. This function assumes the buffer
133 * has room for at least StyleKeySize() values. It assumes that StyleKeySize () returns a 153 * has room for at least StyleKeySize() values. It assumes that StyleKeySize () returns a
134 * positive value for the style and stopAfterPE param. This is written so th at the key for just 154 * positive value for the style and stopAfterPE param. This is written so th at the key for just
135 * dash application followed by the key for the remaining SkStrokeRec is the same as the 155 * dash application followed by the key for the remaining SkStrokeRec is the same as the
136 * key for applying dashing and SkStrokeRec all at once. 156 * key for applying dashing and SkStrokeRec all at once.
137 */ 157 */
138 static void StyleKey(uint32_t*, const GrStyle&, bool stopAfterPE); 158 static void StyleKey(uint32_t*, const GrStyle&, bool stopAfterPE);
139 159
140 /** Constructor used by Apply* functions */ 160 /** Constructor used by Apply* functions */
141 GrShape(const GrShape& parentShape, bool stopAfterPE); 161 GrShape(const GrShape& parentShape, bool stopAfterPE);
142 162
143 /** 163 /**
144 * Determines the key we should inherit from the input shape's geometry and style when 164 * Determines the key we should inherit from the input shape's geometry and style when
145 * we are applying the style to create a new shape. 165 * we are applying the style to create a new shape.
146 */ 166 */
147 void setInheritedKey(const GrShape& parentShape, bool stopAfterPE); 167 void setInheritedKey(const GrShape& parentShape, bool stopAfterPE);
148 168
149 enum class Type { 169 void attemptToReduceFromPath() {
150 kEmpty, 170 SkASSERT(Type::kPath == fType);
151 kRRect, 171 fType = AttemptToReduceFromPathImpl(*fPath.get(), &fRRect, fStyle.pathEf fect(),
152 kPath, 172 fStyle.strokeRec());
153 } fType; 173 if (Type::kPath != fType) {
174 fPath.reset();
175 fInheritedKey.reset(0);
176 }
177 }
154 178
179 static Type AttemptToReduceFromPathImpl(const SkPath& path, SkRRect* rrect,
180 const SkPathEffect* pe, const SkStro keRec& strokeRec) {
181 if (path.isEmpty()) {
182 return Type::kEmpty;
183 }
184 if (path.isRRect(rrect)) {
185 return Type::kRRect;
186 }
187 SkRect rect;
188 if (path.isOval(&rect)) {
189 rrect->setOval(rect);
190 return Type::kRRect;
191 }
192 bool closed;
193 if (path.isRect(&rect, &closed, nullptr)) {
194 if (closed || (!pe && strokeRec.isFillStyle())) {
195 rrect->setRect(rect);
196 return Type::kRRect;
197 }
198 }
199 return Type::kPath;
200 }
201
202 Type fType;
155 SkRRect fRRect; 203 SkRRect fRRect;
156 SkTLazy<SkPath> fPath; 204 SkTLazy<SkPath> fPath;
157 GrStyle fStyle; 205 GrStyle fStyle;
158 SkAutoSTArray<8, uint32_t> fInheritedKey; 206 SkAutoSTArray<8, uint32_t> fInheritedKey;
159 }; 207 };
160 #endif 208 #endif
OLDNEW
« no previous file with comments | « no previous file | src/gpu/GrShape.cpp » ('j') | tests/GrShapeTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698