| 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 "GrGLProcessor.h" |
| 12 #include "GrDrawState.h" | 12 #include "GrDrawState.h" |
| 13 #include "GrGpu.h" | 13 #include "GrGpu.h" |
| 14 #include "GrOptDrawState.h" | 14 #include "GrOptDrawState.h" |
| 15 | 15 |
| 16 class GrGpuGL; | 16 class GrGpuGL; |
| 17 | 17 |
| 18 #ifdef SK_DEBUG | 18 #ifdef SK_DEBUG |
| 19 // Optionally compile the experimental GS code. Set to SK_DEBUG so that debug
build bots will | 19 // Optionally compile the experimental GS code. Set to SK_DEBUG so that debug
build bots will |
| 20 // execute the code. | 20 // execute the code. |
| 21 #define GR_GL_EXPERIMENTAL_GS 1 | 21 #define GR_GL_EXPERIMENTAL_GS 1 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 39 // Gets the number of bytes in asKey(). It will be a 4-byte aligned value. W
hen comparing two | 39 // Gets the number of bytes in asKey(). It will be a 4-byte aligned value. W
hen comparing two |
| 40 // keys the size of either key can be used with memcmp() since the lengths t
hemselves begin the | 40 // keys the size of either key can be used with memcmp() since the lengths t
hemselves begin the |
| 41 // keys and thus the memcmp will exit early if the keys are of different len
gths. | 41 // keys and thus the memcmp will exit early if the keys are of different len
gths. |
| 42 uint32_t keyLength() const { return *this->atOffset<uint32_t, kLengthOffset>
(); } | 42 uint32_t keyLength() const { return *this->atOffset<uint32_t, kLengthOffset>
(); } |
| 43 | 43 |
| 44 // Gets the a checksum of the key. Can be used as a hash value for a fast lo
okup in a cache. | 44 // Gets the a checksum of the key. Can be used as a hash value for a fast lo
okup in a cache. |
| 45 uint32_t getChecksum() const { return *this->atOffset<uint32_t, kChecksumOff
set>(); } | 45 uint32_t getChecksum() const { return *this->atOffset<uint32_t, kChecksumOff
set>(); } |
| 46 | 46 |
| 47 // For unit testing. | 47 // For unit testing. |
| 48 bool setRandom(SkRandom*, | 48 bool setRandom(SkRandom*, |
| 49 GrGpuGL* gpu, | 49 GrGpuGL*, |
| 50 const GrRenderTarget* dummyDstRenderTarget, | 50 const GrRenderTarget* dummyDstRenderTarget, |
| 51 const GrTexture* dummyDstCopyTexture, | 51 const GrTexture* dummyDstCopyTexture, |
| 52 const GrEffectStage* geometryProcessor, | 52 const GrGeometryStage* geometryProcessor, |
| 53 const GrEffectStage* stages[], | 53 const GrFragmentStage* stages[], |
| 54 int numColorStages, | 54 int numColorStages, |
| 55 int numCoverageStages, | 55 int numCoverageStages, |
| 56 int currAttribIndex, | 56 int currAttribIndex, |
| 57 GrGpu::DrawType); | 57 GrGpu::DrawType); |
| 58 | 58 |
| 59 /** | 59 /** |
| 60 * Builds a program descriptor from a GrOptDrawState. Whether the primitive
type is points, and | 60 * Builds a program descriptor from a GrOptDrawState. Whether the primitive
type is points, and |
| 61 * the caps of the GrGpuGL are also inputs. It also outputs the color and co
verage stages | 61 * the caps of the GrGpuGL are also inputs. It also outputs the color and co
verage stages |
| 62 * referenced by the generated descriptor. Coverage stages from the drawStat
e may be treated as | 62 * referenced by the generated descriptor. Coverage stages from the drawStat
e may be treated as |
| 63 * color stages in the output. | 63 * color stages in the output. |
| 64 */ | 64 */ |
| 65 static bool Build(const GrOptDrawState&, | 65 static bool Build(const GrOptDrawState&, |
| 66 GrGpu::DrawType drawType, | 66 GrGpu::DrawType, |
| 67 GrBlendCoeff srcCoeff, | 67 GrBlendCoeff srcCoeff, |
| 68 GrBlendCoeff dstCoeff, | 68 GrBlendCoeff dstCoeff, |
| 69 GrGpuGL* gpu, | 69 GrGpuGL*, |
| 70 const GrDeviceCoordTexture* dstCopy, | 70 const GrDeviceCoordTexture* dstCopy, |
| 71 const GrEffectStage** outGeometryProcessor, | 71 const GrGeometryStage** geometryProcessor, |
| 72 SkTArray<const GrEffectStage*, true>* outColorStages, | 72 SkTArray<const GrFragmentStage*, true>* colorStages, |
| 73 SkTArray<const GrEffectStage*, true>* outCoverageStages, | 73 SkTArray<const GrFragmentStage*, true>* coverageStages, |
| 74 GrGLProgramDesc* outDesc); | 74 GrGLProgramDesc*); |
| 75 | 75 |
| 76 bool hasGeometryProcessor() const { | 76 bool hasGeometryProcessor() const { |
| 77 return SkToBool(this->getHeader().fHasGeometryProcessor); | 77 return SkToBool(this->getHeader().fHasGeometryProcessor); |
| 78 } | 78 } |
| 79 | 79 |
| 80 int numColorEffects() const { | 80 int numColorEffects() const { |
| 81 return this->getHeader().fColorEffectCnt; | 81 return this->getHeader().fColorEffectCnt; |
| 82 } | 82 } |
| 83 | 83 |
| 84 int numCoverageEffects() const { | 84 int numCoverageEffects() const { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + O
FFSET); | 170 return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + O
FFSET); |
| 171 } | 171 } |
| 172 | 172 |
| 173 template<typename T, size_t OFFSET> const T* atOffset() const { | 173 template<typename T, size_t OFFSET> const T* atOffset() const { |
| 174 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin(
)) + OFFSET); | 174 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin(
)) + OFFSET); |
| 175 } | 175 } |
| 176 | 176 |
| 177 KeyHeader* header() { return this->atOffset<KeyHeader, kHeaderOffset>(); } | 177 KeyHeader* header() { return this->atOffset<KeyHeader, kHeaderOffset>(); } |
| 178 | 178 |
| 179 // Shared code between setRandom() and Build(). | 179 // Shared code between setRandom() and Build(). |
| 180 static bool GetEffectKey(const GrEffectStage& stage, const GrGLCaps& caps, | 180 static bool GetProcessorKey(const GrProcessorStage& stage, |
| 181 bool useExplicitLocalCoords, GrEffectKeyBuilder* b, | 181 const GrGLCaps& caps, |
| 182 uint16_t* effectKeySize); | 182 bool useExplicitLocalCoords, |
| 183 GrProcessorKeyBuilder* b, |
| 184 uint16_t* effectKeySize); |
| 183 | 185 |
| 186 static bool GetGeometryProcessorKey(const GrGeometryStage& stage, |
| 187 const GrGLCaps& caps, |
| 188 bool useExplicitLocalCoords, |
| 189 GrProcessorKeyBuilder* b, |
| 190 uint16_t* effectKeySize); |
| 184 void finalize(); | 191 void finalize(); |
| 185 | 192 |
| 186 const KeyHeader& getHeader() const { return *this->atOffset<KeyHeader, kHead
erOffset>(); } | 193 const KeyHeader& getHeader() const { return *this->atOffset<KeyHeader, kHead
erOffset>(); } |
| 187 | 194 |
| 188 /** Used to provide effects' keys to their emitCode() function. */ | 195 /** Used to provide effects' keys to their emitCode() function. */ |
| 189 class EffectKeyProvider { | 196 class EffectKeyProvider { |
| 190 public: | 197 public: |
| 191 enum EffectType { | 198 enum EffectType { |
| 192 kGeometryProcessor_EffectType, | 199 kGeometryProcessor_EffectType, |
| 193 kColor_EffectType, | 200 kColor_EffectType, |
| 194 kCoverage_EffectType, | 201 kCoverage_EffectType, |
| 195 }; | 202 }; |
| 196 | 203 |
| 197 EffectKeyProvider(const GrGLProgramDesc* desc, EffectType type) : fDesc(
desc) { | 204 EffectKeyProvider(const GrGLProgramDesc* desc, EffectType type) : fDesc(
desc) { |
| 198 switch (type) { | 205 switch (type) { |
| 199 case kGeometryProcessor_EffectType: | 206 case kGeometryProcessor_EffectType: |
| 200 // there can be only one | 207 // there can be only one |
| 201 fBaseIndex = 0; | 208 fBaseIndex = 0; |
| 202 break; | 209 break; |
| 203 case kColor_EffectType: | 210 case kColor_EffectType: |
| 204 fBaseIndex = desc->hasGeometryProcessor() ? 1 : 0; | 211 fBaseIndex = desc->hasGeometryProcessor() ? 1 : 0; |
| 205 break; | 212 break; |
| 206 case kCoverage_EffectType: | 213 case kCoverage_EffectType: |
| 207 fBaseIndex = desc->numColorEffects() + (desc->hasGeometryPro
cessor() ? 1 : 0); | 214 fBaseIndex = desc->numColorEffects() + (desc->hasGeometryPro
cessor() ? 1 : 0); |
| 208 break; | 215 break; |
| 209 } | 216 } |
| 210 } | 217 } |
| 211 | 218 |
| 212 GrEffectKey get(int index) const { | 219 GrProcessorKey get(int index) const { |
| 213 const uint16_t* offsetsAndLengths = reinterpret_cast<const uint16_t*
>( | 220 const uint16_t* offsetsAndLengths = reinterpret_cast<const uint16_t*
>( |
| 214 fDesc->fKey.begin() + kEffectKeyOffsetsAndLengthOffset); | 221 fDesc->fKey.begin() + kEffectKeyOffsetsAndLengthOffset); |
| 215 // We store two uint16_ts per effect, one for the offset to the effe
ct's key and one for | 222 // We store two uint16_ts per effect, one for the offset to the effe
ct's key and one for |
| 216 // its length. Here we just need the offset. | 223 // its length. Here we just need the offset. |
| 217 uint16_t offset = offsetsAndLengths[2 * (fBaseIndex + index) + 0]; | 224 uint16_t offset = offsetsAndLengths[2 * (fBaseIndex + index) + 0]; |
| 218 uint16_t length = offsetsAndLengths[2 * (fBaseIndex + index) + 1]; | 225 uint16_t length = offsetsAndLengths[2 * (fBaseIndex + index) + 1]; |
| 219 // Currently effects must add to the key in units of uint32_t. | 226 // Currently effects must add to the key in units of uint32_t. |
| 220 SkASSERT(0 == (length % sizeof(uint32_t))); | 227 SkASSERT(0 == (length % sizeof(uint32_t))); |
| 221 return GrEffectKey(reinterpret_cast<const uint32_t*>(fDesc->fKey.beg
in() + offset), | 228 return GrProcessorKey(reinterpret_cast<const uint32_t*>(fDesc->fKey.
begin() + offset), |
| 222 length / sizeof(uint32_t)); | 229 length / sizeof(uint32_t)); |
| 223 } | 230 } |
| 224 private: | 231 private: |
| 225 const GrGLProgramDesc* fDesc; | 232 const GrGLProgramDesc* fDesc; |
| 226 int fBaseIndex; | 233 int fBaseIndex; |
| 227 }; | 234 }; |
| 228 | 235 |
| 229 enum { | 236 enum { |
| 230 kMaxPreallocEffects = 8, | 237 kMaxPreallocEffects = 8, |
| 231 kIntsPerEffect = 4, // This is an overestimate of the average ef
fect key size. | 238 kIntsPerEffect = 4, // This is an overestimate of the average ef
fect key size. |
| 232 kPreAllocSize = kEffectKeyOffsetsAndLengthOffset + | 239 kPreAllocSize = kEffectKeyOffsetsAndLengthOffset + |
| 233 kMaxPreallocEffects * sizeof(uint32_t) * kIntsPerEffect, | 240 kMaxPreallocEffects * sizeof(uint32_t) * kIntsPerEffect, |
| 234 }; | 241 }; |
| 235 | 242 |
| 236 SkSTArray<kPreAllocSize, uint8_t, true> fKey; | 243 SkSTArray<kPreAllocSize, uint8_t, true> fKey; |
| 237 | 244 |
| 238 // GrGLProgram and GrGLShaderBuilder read the private fields to generate cod
e. TODO: Split out | 245 // GrGLProgram and GrGLShaderBuilder read the private fields to generate cod
e. TODO: Split out |
| 239 // part of GrGLShaderBuilder that is used by effects so that this header doe
sn't need to be | 246 // part of GrGLShaderBuilder that is used by effects so that this header doe
sn't need to be |
| 240 // visible to GrGLEffects. Then make public accessors as necessary and remov
e friends. | 247 // visible to GrGLProcessors. Then make public accessors as necessary and re
move friends. |
| 241 friend class GrGLProgram; | 248 friend class GrGLProgram; |
| 242 friend class GrGLProgramBuilder; | 249 friend class GrGLProgramBuilder; |
| 243 friend class GrGLFullProgramBuilder; | 250 friend class GrGLFullProgramBuilder; |
| 244 friend class GrGLFragmentOnlyProgramBuilder; | 251 friend class GrGLFragmentOnlyProgramBuilder; |
| 245 friend class GrGLVertexShaderBuilder; | 252 friend class GrGLVertexShaderBuilder; |
| 246 friend class GrGLFragmentShaderBuilder; | 253 friend class GrGLFragmentShaderBuilder; |
| 247 friend class GrGLGeometryShaderBuilder; | 254 friend class GrGLGeometryShaderBuilder; |
| 248 }; | 255 }; |
| 249 | 256 |
| 250 #endif | 257 #endif |
| OLD | NEW |