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

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

Issue 1822723003: Add initial implementation of GrShape and GrStyle classes and tests (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: more cleanup 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
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
16 /**
17 * Represents a geometric shape (rrect or path) and the GrStyle that it should b e rendered with.
18 * It is possible to apply the style to the GrShape to produce a new GrShape whe re the geometry
19 * reflects the styling information (e.g. is stroked). It is also possible to ap ply just the
20 * path effect from the style. In this case the resulting shape will include any remaining
21 * stroking information that is to be applied after the path effect.
22 *
23 * Shapes can produce keys that represent only the geometry information, not the style. Note that
24 * when styling information is applied to produce a new shape then the style has been converted
robertphillips 2016/04/24 23:00:44 shapes -> shape's
bsalomon 2016/04/25 13:32:26 Done.
25 * to geometric information and is included in the new shapes key. When the same style is applied
26 * to two shapes that reflect the same underlying geometry the computed keys of the stylized shapes
27 * will be the same.
28 *
29 * Currently this can only be constructed from a rrect, though it can become a p ath by applying
30 * style to the geometry. The idea is to expand this to cover most or all of the geometries that
31 * have SkCanvas::draw APIs.
32 */
33 class GrShape {
34 public:
35 GrShape() : fType(Type::kEmpty) {}
36
37 explicit GrShape(const SkRRect& rrect) : fType(Type::kRRect), fRRect(rrect) {}
38 explicit GrShape(const SkRect& rect) : fType(Type::kRRect), fRRect(SkRRect:: MakeRect(rect)) {}
39
40 GrShape(const SkRRect& rrect, const GrStyle& style)
41 : fType(Type::kRRect)
42 , fRRect(rrect)
43 , fStyle(style) {}
44
45 GrShape(const SkRect& rect, const GrStyle& style)
46 : fType(Type::kRRect)
47 , fRRect(SkRRect::MakeRect(rect))
48 , fStyle(style) {}
49
50 GrShape(const SkRRect& rrect, const SkPaint& paint)
51 : fType(Type::kRRect)
52 , fRRect(rrect)
53 , fStyle(paint) {}
54
55 GrShape(const SkRect& rect, const SkPaint& paint)
56 : fType(Type::kRRect)
57 , fRRect(SkRRect::MakeRect(rect))
58 , fStyle(paint) {}
59
60 GrShape(const GrShape&);
61 GrShape& operator=(const GrShape& that);
62
63 ~GrShape() {
64 if (Type::kPath == fType) {
65 fPath.~SkPath();
66 }
67 }
68
69 const GrStyle& style() const { return fStyle; }
70
71 /**
robertphillips 2016/04/24 23:00:44 fully ?
bsalomon 2016/04/25 13:32:26 Done.
72 * Returns a GrShape where the shape's geometry full reflects the original s hape's GrStyle.
robertphillips 2016/04/24 23:00:44 shap -> shape ?
bsalomon 2016/04/25 13:32:26 Done.
73 * The GrStyle of the returned shap will either be fill or hairline.
74 */
75 GrShape applyFullStyle() { return GrShape(*this, false); }
76
77 /**
78 * Similar to above but applies only the path effect. Path effects take the original geometry
79 * and fill/stroking information and compute a new geometry and residual fil l/stroking
80 * information to be applied. The path effect's output geometry and stroking will be captured
81 * in the returned GrShape.
82 */
83 GrShape applyPathEffect() { return GrShape(*this, true); }
84
85 bool asRRect(SkRRect* rrect) const {
86 if (Type::kRRect != fType) {
87 return false;
88 }
89 if (rrect) {
90 *rrect = fRRect;
91 }
92 return true;
93 }
94
95 void asPath(SkPath* out) const {
96 switch (fType) {
97 case Type::kRRect:
98 out->reset();
99 out->addRRect(fRRect);
100 break;
101 case Type::kPath:
102 *out = fPath;
103 break;
104 case Type::kEmpty:
105 out->reset();
106 break;
107 }
108 }
109
110 /**
111 * Gets the size of the key for the shape represented by this GrShape (ignor ing its styling).
112 * A negative value is returned if the shape has no key (shouldn't be cached ).
113 */
114 int unstyledKeySize() const;
115
116 /**
117 * Writes unstyledKeySize() bytes into the provided pointer. Assumes that th ere is enough
118 * space allocated for the key and that unstyledKeySize() does not return a negative value
119 * for this shape.
120 */
121 void writeUnstyledKey(uint32_t* key) const;
122
123 private:
124 /**
125 * Computes the key length for a GrStyle. The return will be negative if it cannot be turned
126 * into a key.
127 */
128 static int StyleKeySize(const GrStyle& , bool stopAfterPE);
129
130 /**
131 * Writes a unique key for the style into the provided buffer. This function assumes the buffer
132 * has room for at least StyleKeySize() values. It assumes that StyleKeySize () returns a
133 * positive value for the style and stopAfterPE param. This is written so th at the key for just
134 * dash application followed by the key for the remaining SkStrokeRec is the same as the
135 * key for applying dashing and SkStrokeRec all at once.
136 */
137 static void StyleKey(uint32_t*, const GrStyle&, bool stopAfterPE);
138
139 /** Constructor used by Apply* functions */
140 GrShape(const GrShape& parentShape, bool stopAfterPE);
141
142 /**
143 * Determines the key we should inherit from the input shape's geometry and style when
144 * we are applying the style to create a new shape.
145 */
146 void setInheritedKey(const GrShape& parentShape, bool stopAfterPE);
147
148 enum class Type {
149 kEmpty,
150 kRRect,
151 kPath,
152 } fType;
153
154 union {
155 SkRRect fRRect;
156 SkPath fPath;
157 };
158 GrStyle fStyle;
159 SkAutoSTArray<8, uint32_t> fInheritedKey;
160 };
161 #endif
OLDNEW
« no previous file with comments | « gyp/gpu.gypi ('k') | src/gpu/GrShape.cpp » ('j') | src/gpu/GrShape.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698