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 |
11 #include "GrGLEffect.h" | 11 #include "GrGLEffect.h" |
12 #include "GrDrawState.h" | 12 #include "GrDrawState.h" |
13 #include "GrGpu.h" | 13 #include "GrGpu.h" |
14 | 14 |
15 class GrGpuGL; | 15 class GrGpuGL; |
16 | 16 |
17 #ifdef SK_DEBUG | 17 #ifdef SK_DEBUG |
18 // Optionally compile the experimental GS code. Set to SK_DEBUG so that debug
build bots will | 18 // Optionally compile the experimental GS code. Set to SK_DEBUG so that debug
build bots will |
19 // execute the code. | 19 // execute the code. |
20 #define GR_GL_EXPERIMENTAL_GS 1 | 20 #define GR_GL_EXPERIMENTAL_GS 1 |
21 #else | 21 #else |
22 #define GR_GL_EXPERIMENTAL_GS 0 | 22 #define GR_GL_EXPERIMENTAL_GS 0 |
23 #endif | 23 #endif |
24 | 24 |
25 | 25 |
26 /** This class describes a program to generate. It also serves as a program cach
e key. Very little | 26 /** This class describes a program to generate. It also serves as a program cach
e key. Very little |
27 of this is GL-specific. There is the generation of GrGLEffect::EffectKeys an
d the dst-read part | 27 of this is GL-specific. The GL-specific parts could be factored out into a s
ubclass. */ |
28 of the key set by GrGLShaderBuilder. If the interfaces that set those portio
ns were abstracted | |
29 to be API-neutral then so could this class. */ | |
30 class GrGLProgramDesc { | 28 class GrGLProgramDesc { |
31 public: | 29 public: |
32 GrGLProgramDesc() {} | 30 GrGLProgramDesc() {} |
33 GrGLProgramDesc(const GrGLProgramDesc& desc) { *this = desc; } | 31 GrGLProgramDesc(const GrGLProgramDesc& desc) { *this = desc; } |
34 | 32 |
35 // Returns this as a uint32_t array to be used as a key in the program cache
. | 33 // Returns this as a uint32_t array to be used as a key in the program cache
. |
36 const uint32_t* asKey() const { | 34 const uint32_t* asKey() const { |
37 return reinterpret_cast<const uint32_t*>(fKey.begin()); | 35 return reinterpret_cast<const uint32_t*>(fKey.begin()); |
38 } | 36 } |
39 | 37 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 }; | 187 }; |
190 | 188 |
191 template<typename T, size_t OFFSET> T* atOffset() { | 189 template<typename T, size_t OFFSET> T* atOffset() { |
192 return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + O
FFSET); | 190 return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + O
FFSET); |
193 } | 191 } |
194 | 192 |
195 template<typename T, size_t OFFSET> const T* atOffset() const { | 193 template<typename T, size_t OFFSET> const T* atOffset() const { |
196 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin(
)) + OFFSET); | 194 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin(
)) + OFFSET); |
197 } | 195 } |
198 | 196 |
199 typedef GrBackendEffectFactory::EffectKey EffectKey; | |
200 | |
201 KeyHeader* header() { return this->atOffset<KeyHeader, kHeaderOffset>(); } | 197 KeyHeader* header() { return this->atOffset<KeyHeader, kHeaderOffset>(); } |
202 | 198 |
203 // Shared code between setRandom() and Build(). | 199 // Shared code between setRandom() and Build(). |
204 static bool GetEffectKeyAndUpdateStats(const GrEffectStage& stage, | 200 static bool GetEffectKeyAndUpdateStats(const GrEffectStage& stage, |
205 const GrGLCaps& caps, | 201 const GrGLCaps& caps, |
206 bool useExplicitLocalCoords, | 202 bool useExplicitLocalCoords, |
207 GrEffectKeyBuilder* b, | 203 GrEffectKeyBuilder* b, |
208 uint16_t* effectKeySize, | 204 uint16_t* effectKeySize, |
209 bool* setTrueIfReadsDst, | 205 bool* setTrueIfReadsDst, |
210 bool* setTrueIfReadsPos, | 206 bool* setTrueIfReadsPos, |
211 bool* setTrueIfHasVertexCode); | 207 bool* setTrueIfHasVertexCode); |
212 | 208 |
213 void finalize(); | 209 void finalize(); |
214 | 210 |
215 const KeyHeader& getHeader() const { return *this->atOffset<KeyHeader, kHead
erOffset>(); } | 211 const KeyHeader& getHeader() const { return *this->atOffset<KeyHeader, kHead
erOffset>(); } |
216 | 212 |
217 /** Used to provide effects' keys to their emitCode() function. */ | 213 /** Used to provide effects' keys to their emitCode() function. */ |
218 class EffectKeyProvider { | 214 class EffectKeyProvider { |
219 public: | 215 public: |
220 enum EffectType { | 216 enum EffectType { |
221 kColor_EffectType, | 217 kColor_EffectType, |
222 kCoverage_EffectType, | 218 kCoverage_EffectType, |
223 }; | 219 }; |
224 | 220 |
225 EffectKeyProvider(const GrGLProgramDesc* desc, EffectType type) : fDesc(
desc) { | 221 EffectKeyProvider(const GrGLProgramDesc* desc, EffectType type) : fDesc(
desc) { |
226 // Coverage effect key offsets begin immediately after those of the
color effects. | 222 // Coverage effect key offsets begin immediately after those of the
color effects. |
227 fBaseIndex = kColor_EffectType == type ? 0 : desc->numColorEffects()
; | 223 fBaseIndex = kColor_EffectType == type ? 0 : desc->numColorEffects()
; |
228 } | 224 } |
229 | 225 |
230 EffectKey get(int index) const { | 226 GrEffectKey get(int index) const { |
231 const uint16_t* offsets = reinterpret_cast<const uint16_t*>( | 227 const uint16_t* offsetsAndLengths = reinterpret_cast<const uint16_t*
>( |
232 fDesc->fKey.begin() + kEffectKeyOffsetsAndLengthOffset); | 228 fDesc->fKey.begin() + kEffectKeyOffsetsAndLengthOffset); |
233 // We store two uint16_ts per effect, one for the offset to the effe
ct's key and one for | 229 // 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. | 230 // its length. Here we just need the offset. |
235 uint16_t offset = offsets[2 * (fBaseIndex + index)]; | 231 uint16_t offset = offsetsAndLengths[2 * (fBaseIndex + index) + 0]; |
236 return *reinterpret_cast<const EffectKey*>(fDesc->fKey.begin() + off
set); | 232 uint16_t length = offsetsAndLengths[2 * (fBaseIndex + index) + 1]; |
| 233 // Currently effects must add to the key in units of uint32_t. |
| 234 SkASSERT(0 == (length % sizeof(uint32_t))); |
| 235 return GrEffectKey(reinterpret_cast<const uint32_t*>(fDesc->fKey.beg
in() + offset), |
| 236 length / sizeof(uint32_t)); |
237 } | 237 } |
238 private: | 238 private: |
239 const GrGLProgramDesc* fDesc; | 239 const GrGLProgramDesc* fDesc; |
240 int fBaseIndex; | 240 int fBaseIndex; |
241 }; | 241 }; |
242 | 242 |
243 enum { | 243 enum { |
244 kMaxPreallocEffects = 8, | 244 kMaxPreallocEffects = 8, |
245 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. |
246 kPreAllocSize = kEffectKeyOffsetsAndLengthOffset + | 246 kPreAllocSize = kEffectKeyOffsetsAndLengthOffset + |
247 kMaxPreallocEffects * sizeof(uint32_t) * kIntsPerEffect, | 247 kMaxPreallocEffects * sizeof(uint32_t) * kIntsPerEffect, |
248 }; | 248 }; |
249 | 249 |
250 SkSTArray<kPreAllocSize, uint8_t, true> fKey; | 250 SkSTArray<kPreAllocSize, uint8_t, true> fKey; |
251 | 251 |
252 // 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 |
253 // 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 |
254 // 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. |
255 friend class GrGLProgram; | 255 friend class GrGLProgram; |
256 friend class GrGLShaderBuilder; | 256 friend class GrGLShaderBuilder; |
257 friend class GrGLFullShaderBuilder; | 257 friend class GrGLFullShaderBuilder; |
258 friend class GrGLFragmentOnlyShaderBuilder; | 258 friend class GrGLFragmentOnlyShaderBuilder; |
259 }; | 259 }; |
260 | 260 |
261 #endif | 261 #endif |
OLD | NEW |