OLD | NEW |
---|---|
(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 GrInstancedRenderingTypes_DEFINED | |
9 #define GrInstancedRenderingTypes_DEFINED | |
10 | |
11 #include "GrTypes.h" | |
12 #include "SkRRect.h" | |
13 | |
14 /** | |
15 * Internal structs and enums for classes involved in instanced rendering. This class is intended | |
16 * to be inherited non-publicly. | |
17 */ | |
18 class GrInstancedRenderingTypes { | |
bsalomon
2016/04/25 13:22:39
Why this pattern of inheriting from this class whi
Chris Dalton
2016/04/25 17:01:19
Mainly because then GrInstanceProcessor.cpp gets l
bsalomon
2016/04/27 14:10:32
I'd prefer a namespace and using decls.
What do y
csmartdalton
2016/05/20 01:09:45
sgtm
| |
19 public: | |
20 /** | |
21 * Per-vertex data. These values get fed into normal vertex attribs. | |
22 */ | |
23 struct ShapeVertex { | |
24 float fX, fY; //!< Shape coordinates. | |
25 int32_t fAttrs; //!< Shape-specific vertex attributes, if needed. | |
26 }; | |
27 | |
28 /** | |
29 * Per-instance data. These values get fed into instanced vertex attribs. | |
30 */ | |
31 struct Instance { | |
32 uint32_t fInfo; //!< Packed info about the instance. See InfoBits. | |
33 float fShapeMatrix2x3[6]; //!< Maps canonical shape coords -> devi ce space coords. | |
34 uint32_t fColor; //!< Color to be written out by the prim itive processor. | |
35 float fLocalRect[4]; //!< Local coords rect that spans [-1, + 1] in shape coords. | |
36 }; | |
37 | |
38 /** | |
39 * Additional parameters required by some instances (e.g. round rect radii, perspective column, | |
40 * local matrix). These are accessed via texel buffer. | |
41 */ | |
42 struct ParamsTexel { | |
43 union { | |
44 struct { float fX, fY, fZ, fW; }; | |
45 float fValues[4]; | |
46 }; | |
47 }; | |
48 | |
49 GR_STATIC_ASSERT(0 == offsetof(ParamsTexel, fX)); | |
50 GR_STATIC_ASSERT(4 * 4 == sizeof(ParamsTexel)); | |
51 | |
52 enum AttribIdx { | |
53 kShapeCoords_AttribIdx, | |
54 kVertexAttrs_AttribIdx, | |
55 kInstanceInfo_AttribIdx, | |
56 kShapeMatrixX_AttribIdx, | |
57 kShapeMatrixY_AttribIdx, | |
58 kColor_AttribIdx, | |
59 kLocalRect_AttribIdx, | |
60 | |
61 kNumVertexAttribs | |
62 }; | |
63 | |
64 enum ShapeType { | |
bsalomon
2016/04/25 13:22:39
I think use of the word "shape" may conflict with
Chris Dalton
2016/04/25 17:01:19
SkRRect also has kEmpty, which I would prefer to n
bsalomon
2016/04/27 14:10:32
I guess it is ok.
| |
65 kRect_ShapeType, | |
66 kOval_ShapeType, | |
67 kSimpleRRect_ShapeType, | |
68 kNinePatch_ShapeType, | |
69 kComplexRRect_ShapeType, | |
70 | |
71 kLast_ShapeType = kComplexRRect_ShapeType | |
72 }; | |
73 | |
74 static ShapeType RRectShapeType(const SkRRect& rrect) { | |
75 SkASSERT(rrect.getType() >= SkRRect::kRect_Type && | |
76 rrect.getType() <= SkRRect::kComplex_Type); | |
77 return static_cast<ShapeType>(rrect.getType() - 1); | |
78 | |
79 GR_STATIC_ASSERT(kRect_ShapeType == SkRRect::kRect_Type - 1); | |
80 GR_STATIC_ASSERT(kOval_ShapeType == SkRRect::kOval_Type - 1); | |
81 GR_STATIC_ASSERT(kSimpleRRect_ShapeType == SkRRect::kSimple_Type - 1); | |
82 GR_STATIC_ASSERT(kNinePatch_ShapeType == SkRRect::kNinePatch_Type - 1); | |
83 GR_STATIC_ASSERT(kComplexRRect_ShapeType == SkRRect::kComplex_Type - 1); | |
84 GR_STATIC_ASSERT(kLast_ShapeType == SkRRect::kComplex_Type - 1); | |
85 } | |
86 | |
87 enum ShapeFlag { | |
88 kRect_ShapeFlag = (1 << kRect_ShapeType), | |
89 kOval_ShapeFlag = (1 << kOval_ShapeType), | |
90 kSimpleRRect_ShapeFlag = (1 << kSimpleRRect_ShapeType), | |
91 kNinePatch_ShapeFlag = (1 << kNinePatch_ShapeType), | |
92 kComplexRRect_ShapeFlag = (1 << kComplexRRect_ShapeType), | |
93 | |
94 kRRect_ShapesMask = kSimpleRRect_ShapeFlag | kNinePatch_ShapeFlag | kCom plexRRect_ShapeFlag | |
95 }; | |
96 | |
97 /** | |
98 * Defines what data is stored at which bits in the fInfo field of the insta nced data. | |
99 */ | |
100 enum InfoBits { | |
101 kShapeType_InfoBit = 29, | |
102 kInnerShapeType_InfoBit = 27, | |
103 kPerspective_InfoBit = 26, | |
104 kLocalMatrix_InfoBit = 25, | |
105 kParamsIdx_InfoBit = 0 | |
106 }; | |
107 | |
108 enum InfoMasks { | |
109 kShapeType_InfoMask = 0u - (1 << kShapeType_InfoBit), | |
110 kInnerShapeType_InfoMask = (1 << kShapeType_InfoBit) - (1 << kInnerShap eType_InfoBit), | |
111 kPerspective_InfoFlag = (1 << kPerspective_InfoBit), | |
112 kLocalMatrix_InfoFlag = (1 << kLocalMatrix_InfoBit), | |
113 kParamsIdx_InfoMask = (1 << kLocalMatrix_InfoBit) - 1 | |
114 }; | |
115 | |
116 GR_STATIC_ASSERT(kLast_ShapeType <= (uint32_t)kShapeType_InfoMask >> kShapeT ype_InfoBit); | |
117 GR_STATIC_ASSERT(kSimpleRRect_ShapeType <= kInnerShapeType_InfoMask >> kInne rShapeType_InfoBit); | |
118 | |
119 struct BatchTracker { | |
bsalomon
2016/04/25 13:22:38
We've been moving away from using "BatchTracker" i
Chris Dalton
2016/04/25 17:01:19
Agreed, I don't like the name either. We can come
Chris Dalton
2016/04/26 19:18:08
Done.
| |
120 BatchTracker() : fData(0) {} | |
121 | |
122 bool isSimpleRects() const { | |
123 return !((fShapeTypes & ~kRect_ShapeFlag) | fInnerShapeTypes); | |
124 } | |
125 | |
126 bool canJoin(BatchTracker that) const { | |
127 if (SkToBool(fInnerShapeTypes) != SkToBool(that.fInnerShapeTypes)) { | |
128 // GrInstanceProcessor can't currently combine draws with and wi thout inner shapes. | |
129 return false; | |
130 } | |
131 if (fCannotDiscard != that.fCannotDiscard) { | |
132 // For stencil draws, the use of discard can be a requirement. | |
133 return false; | |
134 } | |
135 return true; | |
136 } | |
137 | |
138 void join(BatchTracker that) { | |
139 SkASSERT(this->canJoin(that)); | |
140 fData |= that.fData; | |
141 } | |
142 | |
143 union { | |
144 struct { | |
145 uint8_t fShapeTypes; | |
146 uint8_t fInnerShapeTypes; | |
147 bool fHasPerspective : 1; | |
148 bool fHasLocalMatrix : 1; | |
149 bool fHasParams : 1; | |
150 bool fNonSquare : 1; | |
151 bool fUsesColor : 1; | |
bsalomon
2016/04/25 13:22:39
Uses color and uses coverage are rarely useful, do
Chris Dalton
2016/04/25 17:01:19
Ok, I'll gladly take them out.
Chris Dalton
2016/04/26 19:18:08
Done.
| |
152 bool fUsesCoverage : 1; | |
153 bool fUsesLocalCoords : 1; | |
154 bool fCannotTweakAlphaForCoverage : 1; | |
155 bool fCannotDiscard : 1; | |
156 }; | |
157 uint32_t fData; | |
158 }; | |
159 }; | |
160 | |
161 // This is required since all the data must fit into 32 bits of a shader key . | |
162 GR_STATIC_ASSERT(sizeof(uint32_t) == sizeof(BatchTracker)); | |
163 GR_STATIC_ASSERT(kLast_ShapeType <= 8); | |
164 | |
165 enum AntialiasMode { | |
166 kNone_AntialiasMode, | |
167 kCoverage_AntialiasMode, | |
168 kMSAA_AntialiasMode, | |
169 kMixedSamples_AntialiasMode, | |
170 | |
171 kLast_AntialiasMode = kMixedSamples_AntialiasMode | |
172 }; | |
173 | |
174 enum AntialiasFlags { | |
175 kNone_AntialiasFlag = (1 << kNone_AntialiasMode), | |
176 kCoverage_AntialiasFlag = (1 << kCoverage_AntialiasMode), | |
177 kMSAA_AntialiasFlag = (1 << kMSAA_AntialiasMode), | |
178 kMixedSamples_AntialiasFlag = (1 << kMixedSamples_AntialiasMode) | |
179 }; | |
180 }; | |
181 | |
182 #endif | |
OLD | NEW |