OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 GrGLProgramDesc_DEFINED | 8 #ifndef GrGLProgramDesc_DEFINED |
9 #define GrGLProgramDesc_DEFINED | 9 #define GrGLProgramDesc_DEFINED |
10 | 10 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 int8_t fCoverageAttributeIndex; | 165 int8_t fCoverageAttributeIndex; |
166 | 166 |
167 int8_t fColorEffectCnt; | 167 int8_t fColorEffectCnt; |
168 int8_t fCoverageEffectCnt; | 168 int8_t fCoverageEffectCnt; |
169 }; | 169 }; |
170 | 170 |
171 // The key, stored in fKey, is composed of five parts: | 171 // The key, stored in fKey, is composed of five parts: |
172 // 1. uint32_t for total key length. | 172 // 1. uint32_t for total key length. |
173 // 2. uint32_t for a checksum. | 173 // 2. uint32_t for a checksum. |
174 // 3. Header struct defined above. | 174 // 3. Header struct defined above. |
175 // 4. An array of offsets to effect keys and their sizes (see 5). uint16_t f
or each | 175 // 4. uint32_t offsets to beginning of every effects' key (see 5). |
176 // offset and size. | |
177 // 5. per-effect keys. Each effect's key is a variable length array of uint3
2_t. | 176 // 5. per-effect keys. Each effect's key is a variable length array of uint3
2_t. |
178 enum { | 177 enum { |
179 // Part 1. | |
180 kLengthOffset = 0, | 178 kLengthOffset = 0, |
181 // Part 2. | |
182 kChecksumOffset = kLengthOffset + sizeof(uint32_t), | 179 kChecksumOffset = kLengthOffset + sizeof(uint32_t), |
183 // Part 3. | |
184 kHeaderOffset = kChecksumOffset + sizeof(uint32_t), | 180 kHeaderOffset = kChecksumOffset + sizeof(uint32_t), |
185 kHeaderSize = SkAlign4(sizeof(KeyHeader)), | 181 kHeaderSize = SkAlign4(sizeof(KeyHeader)), |
186 // Part 4. | 182 kEffectKeyLengthsOffset = kHeaderOffset + kHeaderSize, |
187 // This is the offset in the overall key to the array of per-effect offs
et,length pairs. | |
188 kEffectKeyOffsetsAndLengthOffset = kHeaderOffset + kHeaderSize, | |
189 }; | 183 }; |
190 | 184 |
191 template<typename T, size_t OFFSET> T* atOffset() { | 185 template<typename T, size_t OFFSET> T* atOffset() { |
192 return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + O
FFSET); | 186 return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + O
FFSET); |
193 } | 187 } |
194 | 188 |
195 template<typename T, size_t OFFSET> const T* atOffset() const { | 189 template<typename T, size_t OFFSET> const T* atOffset() const { |
196 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin(
)) + OFFSET); | 190 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin(
)) + OFFSET); |
197 } | 191 } |
198 | 192 |
199 typedef GrBackendEffectFactory::EffectKey EffectKey; | 193 typedef GrBackendEffectFactory::EffectKey EffectKey; |
200 | 194 |
201 KeyHeader* header() { return this->atOffset<KeyHeader, kHeaderOffset>(); } | 195 KeyHeader* header() { return this->atOffset<KeyHeader, kHeaderOffset>(); } |
202 | 196 |
203 // Shared code between setRandom() and Build(). | |
204 static bool GetEffectKeyAndUpdateStats(const GrEffectStage& stage, | |
205 const GrGLCaps& caps, | |
206 bool useExplicitLocalCoords, | |
207 GrEffectKeyBuilder* b, | |
208 uint16_t* effectKeySize, | |
209 bool* setTrueIfReadsDst, | |
210 bool* setTrueIfReadsPos, | |
211 bool* setTrueIfHasVertexCode); | |
212 | |
213 void finalize(); | 197 void finalize(); |
214 | 198 |
215 const KeyHeader& getHeader() const { return *this->atOffset<KeyHeader, kHead
erOffset>(); } | 199 const KeyHeader& getHeader() const { return *this->atOffset<KeyHeader, kHead
erOffset>(); } |
216 | 200 |
217 /** Used to provide effects' keys to their emitCode() function. */ | 201 /** Used to provide effects' keys to their emitCode() function. */ |
218 class EffectKeyProvider { | 202 class EffectKeyProvider { |
219 public: | 203 public: |
220 enum EffectType { | 204 enum EffectType { |
221 kColor_EffectType, | 205 kColor_EffectType, |
222 kCoverage_EffectType, | 206 kCoverage_EffectType, |
223 }; | 207 }; |
224 | 208 |
225 EffectKeyProvider(const GrGLProgramDesc* desc, EffectType type) : fDesc(
desc) { | 209 EffectKeyProvider(const GrGLProgramDesc* desc, EffectType type) : fDesc(
desc) { |
226 // Coverage effect key offsets begin immediately after those of the
color effects. | 210 // Coverage effect key offsets begin immediately after those of the
color effects. |
227 fBaseIndex = kColor_EffectType == type ? 0 : desc->numColorEffects()
; | 211 fBaseIndex = kColor_EffectType == type ? 0 : desc->numColorEffects()
; |
228 } | 212 } |
229 | 213 |
230 EffectKey get(int index) const { | 214 EffectKey get(int index) const { |
231 const uint16_t* offsets = reinterpret_cast<const uint16_t*>( | 215 const uint32_t* offsets = reinterpret_cast<const uint32_t*>(fDesc->f
Key.begin() + |
232 fDesc->fKey.begin() + kEffectKeyOffsetsAndLengthOffset); | 216 kEffectK
eyLengthsOffset); |
233 // We store two uint16_ts per effect, one for the offset to the effe
ct's key and one for | 217 uint32_t offset = offsets[fBaseIndex + index]; |
234 // its length. Here we just need the offset. | |
235 uint16_t offset = offsets[2 * (fBaseIndex + index)]; | |
236 return *reinterpret_cast<const EffectKey*>(fDesc->fKey.begin() + off
set); | 218 return *reinterpret_cast<const EffectKey*>(fDesc->fKey.begin() + off
set); |
237 } | 219 } |
238 private: | 220 private: |
239 const GrGLProgramDesc* fDesc; | 221 const GrGLProgramDesc* fDesc; |
240 int fBaseIndex; | 222 int fBaseIndex; |
241 }; | 223 }; |
242 | 224 |
243 enum { | 225 enum { |
244 kMaxPreallocEffects = 8, | 226 kMaxPreallocEffects = 8, |
245 kIntsPerEffect = 4, // This is an overestimate of the average ef
fect key size. | 227 kIntsPerEffect = 4, // This is an overestimate of the average ef
fect key size. |
246 kPreAllocSize = kEffectKeyOffsetsAndLengthOffset + | 228 kPreAllocSize = kEffectKeyLengthsOffset + |
247 kMaxPreallocEffects * sizeof(uint32_t) * kIntsPerEffect, | 229 kMaxPreallocEffects * sizeof(uint32_t) * kIntsPerEffect, |
248 }; | 230 }; |
249 | 231 |
250 SkSTArray<kPreAllocSize, uint8_t, true> fKey; | 232 SkSTArray<kPreAllocSize, uint8_t, true> fKey; |
251 | 233 |
252 // GrGLProgram and GrGLShaderBuilder read the private fields to generate cod
e. TODO: Split out | 234 // GrGLProgram and GrGLShaderBuilder read the private fields to generate cod
e. TODO: Split out |
253 // part of GrGLShaderBuilder that is used by effects so that this header doe
sn't need to be | 235 // part of GrGLShaderBuilder that is used by effects so that this header doe
sn't need to be |
254 // visible to GrGLEffects. Then make public accessors as necessary and remov
e friends. | 236 // visible to GrGLEffects. Then make public accessors as necessary and remov
e friends. |
255 friend class GrGLProgram; | 237 friend class GrGLProgram; |
256 friend class GrGLShaderBuilder; | 238 friend class GrGLShaderBuilder; |
257 friend class GrGLFullShaderBuilder; | 239 friend class GrGLFullShaderBuilder; |
258 friend class GrGLFragmentOnlyShaderBuilder; | 240 friend class GrGLFragmentOnlyShaderBuilder; |
259 }; | 241 }; |
260 | 242 |
261 #endif | 243 #endif |
OLD | NEW |