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