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

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

Issue 1918203002: Revert of Add initial implementation of GrShape and GrStyle classes and tests (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: Created 4 years, 8 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 | « gyp/gpu.gypi ('k') | src/gpu/GrShape.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef GrShape_DEFINED
9 #define GrShape_DEFINED
10
11 #include "GrStyle.h"
12 #include "SkPath.h"
13 #include "SkRRect.h"
14 #include "SkTemplates.h"
15 #include "SkTLazy.h"
16
17 /**
18 * Represents a geometric shape (rrect or path) and the GrStyle that it should b e rendered with.
19 * It is possible to apply the style to the GrShape to produce a new GrShape whe re the geometry
20 * reflects the styling information (e.g. is stroked). It is also possible to ap ply just the
21 * path effect from the style. In this case the resulting shape will include any remaining
22 * stroking information that is to be applied after the path effect.
23 *
24 * Shapes can produce keys that represent only the geometry information, not the style. Note that
25 * when styling information is applied to produce a new shape then the style has been converted
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
28 * will be the same.
29 *
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
32 * have SkCanvas::draw APIs.
33 */
34 class GrShape {
35 public:
36 GrShape() : fType(Type::kEmpty) {}
37
38 explicit GrShape(const SkRRect& rrect) : fType(Type::kRRect), fRRect(rrect) {}
39 explicit GrShape(const SkRect& rect) : fType(Type::kRRect), fRRect(SkRRect:: MakeRect(rect)) {}
40
41 GrShape(const SkRRect& rrect, const GrStyle& style)
42 : fType(Type::kRRect)
43 , fRRect(rrect)
44 , fStyle(style) {}
45
46 GrShape(const SkRect& rect, const GrStyle& style)
47 : fType(Type::kRRect)
48 , fRRect(SkRRect::MakeRect(rect))
49 , fStyle(style) {}
50
51 GrShape(const SkRRect& rrect, const SkPaint& paint)
52 : fType(Type::kRRect)
53 , fRRect(rrect)
54 , fStyle(paint) {}
55
56 GrShape(const SkRect& rect, const SkPaint& paint)
57 : fType(Type::kRRect)
58 , fRRect(SkRRect::MakeRect(rect))
59 , fStyle(paint) {}
60
61 GrShape(const GrShape&);
62 GrShape& operator=(const GrShape& that);
63
64 ~GrShape() {
65 if (Type::kPath == fType) {
66 fPath.reset();
67 }
68 }
69
70 const GrStyle& style() const { return fStyle; }
71
72 /**
73 * Returns a GrShape where the shape's geometry fully reflects the original shape's GrStyle.
74 * The GrStyle of the returned shape will either be fill or hairline.
75 */
76 GrShape applyFullStyle() { return GrShape(*this, false); }
77
78 /**
79 * Similar to above but applies only the path effect. Path effects take the original geometry
80 * and fill/stroking information and compute a new geometry and residual fil l/stroking
81 * information to be applied. The path effect's output geometry and stroking will be captured
82 * in the returned GrShape.
83 */
84 GrShape applyPathEffect() { return GrShape(*this, true); }
85
86 bool asRRect(SkRRect* rrect) const {
87 if (Type::kRRect != fType) {
88 return false;
89 }
90 if (rrect) {
91 *rrect = fRRect;
92 }
93 return true;
94 }
95
96 void asPath(SkPath* out) const {
97 switch (fType) {
98 case Type::kRRect:
99 out->reset();
100 out->addRRect(fRRect);
101 break;
102 case Type::kPath:
103 *out = *fPath.get();
104 break;
105 case Type::kEmpty:
106 out->reset();
107 break;
108 }
109 }
110
111 /**
112 * Gets the size of the key for the shape represented by this GrShape (ignor ing its styling).
113 * A negative value is returned if the shape has no key (shouldn't be cached ).
114 */
115 int unstyledKeySize() const;
116
117 /**
118 * 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
120 * for this shape.
121 */
122 void writeUnstyledKey(uint32_t* key) const;
123
124 private:
125 /**
126 * Computes the key length for a GrStyle. The return will be negative if it cannot be turned
127 * into a key.
128 */
129 static int StyleKeySize(const GrStyle& , bool stopAfterPE);
130
131 /**
132 * 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
134 * 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
136 * key for applying dashing and SkStrokeRec all at once.
137 */
138 static void StyleKey(uint32_t*, const GrStyle&, bool stopAfterPE);
139
140 /** Constructor used by Apply* functions */
141 GrShape(const GrShape& parentShape, bool stopAfterPE);
142
143 /**
144 * 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.
146 */
147 void setInheritedKey(const GrShape& parentShape, bool stopAfterPE);
148
149 enum class Type {
150 kEmpty,
151 kRRect,
152 kPath,
153 } fType;
154
155 SkRRect fRRect;
156 SkTLazy<SkPath> fPath;
157 GrStyle fStyle;
158 SkAutoSTArray<8, uint32_t> fInheritedKey;
159 };
160 #endif
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | src/gpu/GrShape.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698