OLD | NEW |
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 gr_instanced_InstancedRenderingTypes_DEFINED | 8 #ifndef gr_instanced_InstancedRenderingTypes_DEFINED |
9 #define gr_instanced_InstancedRenderingTypes_DEFINED | 9 #define gr_instanced_InstancedRenderingTypes_DEFINED |
10 | 10 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 | 117 |
118 GR_STATIC_ASSERT(0 == offsetof(ParamsTexel, fX)); | 118 GR_STATIC_ASSERT(0 == offsetof(ParamsTexel, fX)); |
119 GR_STATIC_ASSERT(4 * 4 == sizeof(ParamsTexel)); | 119 GR_STATIC_ASSERT(4 * 4 == sizeof(ParamsTexel)); |
120 | 120 |
121 /** | 121 /** |
122 * Tracks all information needed in order to draw a batch of instances. This str
uct also serves | 122 * Tracks all information needed in order to draw a batch of instances. This str
uct also serves |
123 * as an all-in-one shader key for the batch. | 123 * as an all-in-one shader key for the batch. |
124 */ | 124 */ |
125 struct BatchInfo { | 125 struct BatchInfo { |
126 BatchInfo() : fData(0) {} | 126 BatchInfo() : fData(0) {} |
| 127 explicit BatchInfo(uint32_t data) : fData(data) {} |
| 128 |
| 129 static bool CanCombine(const BatchInfo& a, const BatchInfo& b); |
127 | 130 |
128 bool isSimpleRects() const { | 131 bool isSimpleRects() const { |
129 return !((fShapeTypes & ~kRect_ShapeFlag) | fInnerShapeTypes); | 132 return !((fShapeTypes & ~kRect_ShapeFlag) | fInnerShapeTypes); |
130 } | 133 } |
131 | 134 |
132 bool canJoin(BatchInfo that) const { | |
133 if (fAntialiasMode != that.fAntialiasMode) { | |
134 return false; | |
135 } | |
136 if (SkToBool(fInnerShapeTypes) != SkToBool(that.fInnerShapeTypes)) { | |
137 // GrInstanceProcessor can't currently combine draws with and withou
t inner shapes. | |
138 return false; | |
139 } | |
140 if (fCannotDiscard != that.fCannotDiscard) { | |
141 // For stencil draws, the use of discard can be a requirement. | |
142 return false; | |
143 } | |
144 return true; | |
145 } | |
146 | |
147 void join(BatchInfo that) { | |
148 SkASSERT(this->canJoin(that)); | |
149 fData |= that.fData; | |
150 } | |
151 | |
152 union { | 135 union { |
153 struct { | 136 struct { |
154 AntialiasMode fAntialiasMode; | 137 AntialiasMode fAntialiasMode; |
155 uint8_t fShapeTypes; | 138 uint8_t fShapeTypes; |
156 uint8_t fInnerShapeTypes; | 139 uint8_t fInnerShapeTypes; |
157 bool fHasPerspective : 1; | 140 bool fHasPerspective : 1; |
158 bool fHasLocalMatrix : 1; | 141 bool fHasLocalMatrix : 1; |
159 bool fHasParams : 1; | 142 bool fHasParams : 1; |
160 bool fNonSquare : 1; | 143 bool fNonSquare : 1; |
161 bool fUsesLocalCoords : 1; | 144 bool fUsesLocalCoords : 1; |
162 bool fCannotTweakAlphaForCoverage : 1; | 145 bool fCannotTweakAlphaForCoverage : 1; |
163 bool fCannotDiscard : 1; | 146 bool fCannotDiscard : 1; |
164 }; | 147 }; |
165 uint32_t fData; | 148 uint32_t fData; |
166 }; | 149 }; |
167 }; | 150 }; |
168 | 151 |
169 // This is required since all the data must fit into 32 bits of a shader key. | 152 // This is required since all the data must fit into 32 bits of a shader key. |
170 GR_STATIC_ASSERT(sizeof(uint32_t) == sizeof(BatchInfo)); | 153 GR_STATIC_ASSERT(sizeof(uint32_t) == sizeof(BatchInfo)); |
171 GR_STATIC_ASSERT(kNumShapeTypes <= 8); | 154 GR_STATIC_ASSERT(kNumShapeTypes <= 8); |
172 | 155 |
| 156 inline bool BatchInfo::CanCombine(const BatchInfo& a, const BatchInfo& b) { |
| 157 if (a.fAntialiasMode != b.fAntialiasMode) { |
| 158 return false; |
| 159 } |
| 160 if (SkToBool(a.fInnerShapeTypes) != SkToBool(b.fInnerShapeTypes)) { |
| 161 // GrInstanceProcessor can't currently combine draws with and without in
ner shapes. |
| 162 return false; |
| 163 } |
| 164 if (a.fCannotDiscard != b.fCannotDiscard) { |
| 165 // For stencil draws, the use of discard can be a requirement. |
| 166 return false; |
| 167 } |
| 168 return true; |
| 169 } |
| 170 |
| 171 inline BatchInfo operator|(const BatchInfo& a, const BatchInfo& b) { |
| 172 SkASSERT(BatchInfo::CanCombine(a, b)); |
| 173 return BatchInfo(a.fData | b.fData); |
| 174 } |
| 175 |
173 template<typename T> struct TRange { | 176 template<typename T> struct TRange { |
174 bool operator ==(const TRange& that) const { | 177 bool operator ==(const TRange& that) const { |
175 return fStart == that.fStart && fCount == that.fCount; | 178 return fStart == that.fStart && fCount == that.fCount; |
176 } | 179 } |
177 bool operator !=(const TRange& that) const { return !(*this == that); } | 180 bool operator !=(const TRange& that) const { return !(*this == that); } |
178 | 181 |
179 bool isEmpty() const { return fCount <= 0; } | 182 bool isEmpty() const { return fCount <= 0; } |
180 T end() { return fStart + fCount; } | 183 T end() { return fStart + fCount; } |
181 | 184 |
182 T fStart; | 185 T fStart; |
183 T fCount; | 186 T fCount; |
184 }; | 187 }; |
185 | 188 |
186 typedef TRange<int16_t> IndexRange; | 189 typedef TRange<int16_t> IndexRange; |
187 typedef TRange<int> InstanceRange; | 190 typedef TRange<int> InstanceRange; |
188 | 191 |
189 } | 192 } |
190 | 193 |
191 #endif | 194 #endif |
OLD | NEW |