| 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 30 matching lines...) Expand all Loading... |
| 41 uint32_t keyLength() const { return *this->atOffset<uint32_t, kLengthOffset>
(); } | 41 uint32_t keyLength() const { return *this->atOffset<uint32_t, kLengthOffset>
(); } |
| 42 | 42 |
| 43 // Gets the a checksum of the key. Can be used as a hash value for a fast lo
okup in a cache. | 43 // Gets the a checksum of the key. Can be used as a hash value for a fast lo
okup in a cache. |
| 44 uint32_t getChecksum() const { return *this->atOffset<uint32_t, kChecksumOff
set>(); } | 44 uint32_t getChecksum() const { return *this->atOffset<uint32_t, kChecksumOff
set>(); } |
| 45 | 45 |
| 46 // For unit testing. | 46 // For unit testing. |
| 47 bool setRandom(SkRandom*, | 47 bool setRandom(SkRandom*, |
| 48 const GrGpuGL* gpu, | 48 const GrGpuGL* gpu, |
| 49 const GrRenderTarget* dummyDstRenderTarget, | 49 const GrRenderTarget* dummyDstRenderTarget, |
| 50 const GrTexture* dummyDstCopyTexture, | 50 const GrTexture* dummyDstCopyTexture, |
| 51 const GrEffectStage* geometryProcessor, |
| 51 const GrEffectStage* stages[], | 52 const GrEffectStage* stages[], |
| 52 int numColorStages, | 53 int numColorStages, |
| 53 int numCoverageStages, | 54 int numCoverageStages, |
| 54 int currAttribIndex); | 55 int currAttribIndex); |
| 55 | 56 |
| 56 /** | 57 /** |
| 57 * Builds a program descriptor from a GrDrawState. Whether the primitive typ
e is points, the | 58 * Builds a program descriptor from a GrDrawState. Whether the primitive typ
e is points, the |
| 58 * output of GrDrawState::getBlendOpts, and the caps of the GrGpuGL are also
inputs. It also | 59 * output of GrDrawState::getBlendOpts, and the caps of the GrGpuGL are also
inputs. It also |
| 59 * outputs the color and coverage stages referenced by the generated descrip
tor. This may | 60 * outputs the color and coverage stages referenced by the generated descrip
tor. This may |
| 60 * not contain all stages from the draw state and coverage stages from the d
rawState may | 61 * not contain all stages from the draw state and coverage stages from the d
rawState may |
| 61 * be treated as color stages in the output. | 62 * be treated as color stages in the output. |
| 62 */ | 63 */ |
| 63 static bool Build(const GrDrawState&, | 64 static bool Build(const GrDrawState&, |
| 64 GrGpu::DrawType drawType, | 65 GrGpu::DrawType drawType, |
| 65 GrDrawState::BlendOptFlags, | 66 GrDrawState::BlendOptFlags, |
| 66 GrBlendCoeff srcCoeff, | 67 GrBlendCoeff srcCoeff, |
| 67 GrBlendCoeff dstCoeff, | 68 GrBlendCoeff dstCoeff, |
| 68 const GrGpuGL* gpu, | 69 const GrGpuGL* gpu, |
| 69 const GrDeviceCoordTexture* dstCopy, | 70 const GrDeviceCoordTexture* dstCopy, |
| 71 const GrEffectStage** outGeometryProcessor, |
| 70 SkTArray<const GrEffectStage*, true>* outColorStages, | 72 SkTArray<const GrEffectStage*, true>* outColorStages, |
| 71 SkTArray<const GrEffectStage*, true>* outCoverageStages, | 73 SkTArray<const GrEffectStage*, true>* outCoverageStages, |
| 72 GrGLProgramDesc* outDesc); | 74 GrGLProgramDesc* outDesc); |
| 73 | 75 |
| 76 bool hasGeometryProcessor() const { |
| 77 return SkToBool(this->getHeader().fHasGeometryProcessor); |
| 78 } |
| 79 |
| 74 int numColorEffects() const { | 80 int numColorEffects() const { |
| 75 return this->getHeader().fColorEffectCnt; | 81 return this->getHeader().fColorEffectCnt; |
| 76 } | 82 } |
| 77 | 83 |
| 78 int numCoverageEffects() const { | 84 int numCoverageEffects() const { |
| 79 return this->getHeader().fCoverageEffectCnt; | 85 return this->getHeader().fCoverageEffectCnt; |
| 80 } | 86 } |
| 81 | 87 |
| 82 int numTotalEffects() const { return this->numColorEffects() + this->numCove
rageEffects(); } | 88 int numTotalEffects() const { return this->numColorEffects() + this->numCove
rageEffects(); } |
| 83 | 89 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // production) | 160 // production) |
| 155 #if GR_GL_EXPERIMENTAL_GS | 161 #if GR_GL_EXPERIMENTAL_GS |
| 156 SkBool8 fExperimentalGS; | 162 SkBool8 fExperimentalGS; |
| 157 #endif | 163 #endif |
| 158 | 164 |
| 159 int8_t fPositionAttributeIndex; | 165 int8_t fPositionAttributeIndex; |
| 160 int8_t fLocalCoordAttributeIndex; | 166 int8_t fLocalCoordAttributeIndex; |
| 161 int8_t fColorAttributeIndex; | 167 int8_t fColorAttributeIndex; |
| 162 int8_t fCoverageAttributeIndex; | 168 int8_t fCoverageAttributeIndex; |
| 163 | 169 |
| 170 SkBool8 fHasGeometryProcessor; |
| 164 int8_t fColorEffectCnt; | 171 int8_t fColorEffectCnt; |
| 165 int8_t fCoverageEffectCnt; | 172 int8_t fCoverageEffectCnt; |
| 166 }; | 173 }; |
| 167 | 174 |
| 168 // The key, stored in fKey, is composed of five parts: | 175 // The key, stored in fKey, is composed of five parts: |
| 169 // 1. uint32_t for total key length. | 176 // 1. uint32_t for total key length. |
| 170 // 2. uint32_t for a checksum. | 177 // 2. uint32_t for a checksum. |
| 171 // 3. Header struct defined above. | 178 // 3. Header struct defined above. |
| 172 // 4. An array of offsets to effect keys and their sizes (see 5). uint16_t f
or each | 179 // 4. An array of offsets to effect keys and their sizes (see 5). uint16_t f
or each |
| 173 // offset and size. | 180 // offset and size. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 bool* setTrueIfRequiresVertexShader); | 213 bool* setTrueIfRequiresVertexShader); |
| 207 | 214 |
| 208 void finalize(); | 215 void finalize(); |
| 209 | 216 |
| 210 const KeyHeader& getHeader() const { return *this->atOffset<KeyHeader, kHead
erOffset>(); } | 217 const KeyHeader& getHeader() const { return *this->atOffset<KeyHeader, kHead
erOffset>(); } |
| 211 | 218 |
| 212 /** Used to provide effects' keys to their emitCode() function. */ | 219 /** Used to provide effects' keys to their emitCode() function. */ |
| 213 class EffectKeyProvider { | 220 class EffectKeyProvider { |
| 214 public: | 221 public: |
| 215 enum EffectType { | 222 enum EffectType { |
| 223 kGeometryProcessor_EffectType, |
| 216 kColor_EffectType, | 224 kColor_EffectType, |
| 217 kCoverage_EffectType, | 225 kCoverage_EffectType, |
| 218 }; | 226 }; |
| 219 | 227 |
| 220 EffectKeyProvider(const GrGLProgramDesc* desc, EffectType type) : fDesc(
desc) { | 228 EffectKeyProvider(const GrGLProgramDesc* desc, EffectType type) : fDesc(
desc) { |
| 221 // Coverage effect key offsets begin immediately after those of the
color effects. | 229 switch (type) { |
| 222 fBaseIndex = kColor_EffectType == type ? 0 : desc->numColorEffects()
; | 230 case kGeometryProcessor_EffectType: |
| 231 // there can be only one |
| 232 fBaseIndex = 0; |
| 233 break; |
| 234 case kColor_EffectType: |
| 235 fBaseIndex = desc->hasGeometryProcessor() ? 1 : 0; |
| 236 break; |
| 237 case kCoverage_EffectType: |
| 238 fBaseIndex = desc->numColorEffects() + (desc->hasGeometryPro
cessor() ? 1 : 0); |
| 239 break; |
| 240 } |
| 223 } | 241 } |
| 224 | 242 |
| 225 GrEffectKey get(int index) const { | 243 GrEffectKey get(int index) const { |
| 226 const uint16_t* offsetsAndLengths = reinterpret_cast<const uint16_t*
>( | 244 const uint16_t* offsetsAndLengths = reinterpret_cast<const uint16_t*
>( |
| 227 fDesc->fKey.begin() + kEffectKeyOffsetsAndLengthOffset); | 245 fDesc->fKey.begin() + kEffectKeyOffsetsAndLengthOffset); |
| 228 // We store two uint16_ts per effect, one for the offset to the effe
ct's key and one for | 246 // We store two uint16_ts per effect, one for the offset to the effe
ct's key and one for |
| 229 // its length. Here we just need the offset. | 247 // its length. Here we just need the offset. |
| 230 uint16_t offset = offsetsAndLengths[2 * (fBaseIndex + index) + 0]; | 248 uint16_t offset = offsetsAndLengths[2 * (fBaseIndex + index) + 0]; |
| 231 uint16_t length = offsetsAndLengths[2 * (fBaseIndex + index) + 1]; | 249 uint16_t length = offsetsAndLengths[2 * (fBaseIndex + index) + 1]; |
| 232 // Currently effects must add to the key in units of uint32_t. | 250 // Currently effects must add to the key in units of uint32_t. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 254 friend class GrGLProgram; | 272 friend class GrGLProgram; |
| 255 friend class GrGLProgramBuilder; | 273 friend class GrGLProgramBuilder; |
| 256 friend class GrGLFullProgramBuilder; | 274 friend class GrGLFullProgramBuilder; |
| 257 friend class GrGLFragmentOnlyProgramBuilder; | 275 friend class GrGLFragmentOnlyProgramBuilder; |
| 258 friend class GrGLVertexShaderBuilder; | 276 friend class GrGLVertexShaderBuilder; |
| 259 friend class GrGLFragmentShaderBuilder; | 277 friend class GrGLFragmentShaderBuilder; |
| 260 friend class GrGLGeometryShaderBuilder; | 278 friend class GrGLGeometryShaderBuilder; |
| 261 }; | 279 }; |
| 262 | 280 |
| 263 #endif | 281 #endif |
| OLD | NEW |