| 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 "GrGLShaderBuilder.h" |
| 13 | 14 |
| 14 class GrGpuGL; | 15 class GrGpuGL; |
| 15 | 16 |
| 16 // optionally compile the experimental GS code. Set to GR_DEBUG so that debug bu
ild bots will | 17 // optionally compile the experimental GS code. Set to GR_DEBUG so that debug bu
ild bots will |
| 17 // execute the code. | 18 // execute the code. |
| 18 #define GR_GL_EXPERIMENTAL_GS GR_DEBUG | 19 #define GR_GL_EXPERIMENTAL_GS GR_DEBUG |
| 19 | 20 |
| 20 | 21 |
| 21 /** This class describes a program to generate. It also serves as a program cach
e key. The only | 22 /** This class describes a program to generate. It also serves as a program cach
e key. Very little |
| 22 thing GL-specific about this is the generation of GrGLEffect::EffectKeys. Wi
th some refactoring | 23 of this is GL-specific. There is the generation of GrGLEffect::EffectKeys an
d the dst-read part |
| 23 it could be made backend-neutral. */ | 24 of the key set by GrGLShaderBuilder. If the interfaces that set those portio
ns were abstracted |
| 25 to be API-neutral then so could this class. */ |
| 24 class GrGLProgramDesc { | 26 class GrGLProgramDesc { |
| 25 public: | 27 public: |
| 26 GrGLProgramDesc() { | 28 GrGLProgramDesc() { |
| 27 // since we use this as part of a key we can't have any uninitialized pa
dding | 29 // since we use this as part of a key we can't have any uninitialized pa
dding |
| 28 memset(this, 0, sizeof(GrGLProgramDesc)); | 30 memset(this, 0, sizeof(GrGLProgramDesc)); |
| 29 } | 31 } |
| 30 | 32 |
| 31 // 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 |
| 32 const uint32_t* asKey() const { | 34 const uint32_t* asKey() const { |
| 33 return reinterpret_cast<const uint32_t*>(this); | 35 return reinterpret_cast<const uint32_t*>(this); |
| 34 } | 36 } |
| 35 | 37 |
| 36 // For unit testing. | 38 // For unit testing. |
| 37 void setRandom(SkMWCRandom*, | 39 void setRandom(SkMWCRandom*, |
| 38 const GrGpuGL* gpu, | 40 const GrGpuGL* gpu, |
| 39 const GrEffectStage stages[GrDrawState::kNumStages]); | 41 const GrEffectStage stages[GrDrawState::kNumStages]); |
| 40 | 42 |
| 41 /** | 43 /** |
| 42 * Builds a program descriptor from a GrDrawState. Whether the primitive typ
e is points, the | 44 * Builds a program descriptor from a GrDrawState. Whether the primitive typ
e is points, the |
| 43 * output of GrDrawState::getBlendOpts, and the caps of the GrGpuGL are also
inputs. | 45 * output of GrDrawState::getBlendOpts, and the caps of the GrGpuGL are also
inputs. |
| 44 */ | 46 */ |
| 45 static void Build(const GrDrawState&, | 47 static void Build(const GrDrawState&, |
| 46 bool isPoints, | 48 bool isPoints, |
| 47 GrDrawState::BlendOptFlags, | 49 GrDrawState::BlendOptFlags, |
| 48 GrBlendCoeff srcCoeff, | 50 GrBlendCoeff srcCoeff, |
| 49 GrBlendCoeff dstCoeff, | 51 GrBlendCoeff dstCoeff, |
| 50 const GrGpuGL* gpu, | 52 const GrGpuGL* gpu, |
| 53 const GrDeviceCoordTexture* dstCopy, |
| 51 GrGLProgramDesc* outDesc); | 54 GrGLProgramDesc* outDesc); |
| 52 | 55 |
| 53 private: | 56 private: |
| 54 // Specifies where the initial color comes from before the stages are applie
d. | 57 // Specifies where the initial color comes from before the stages are applie
d. |
| 55 enum ColorInput { | 58 enum ColorInput { |
| 56 kSolidWhite_ColorInput, | 59 kSolidWhite_ColorInput, |
| 57 kTransBlack_ColorInput, | 60 kTransBlack_ColorInput, |
| 58 kAttribute_ColorInput, | 61 kAttribute_ColorInput, |
| 59 kUniform_ColorInput, | 62 kUniform_ColorInput, |
| 60 | 63 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 79 GrAttribBindings fAttribBindings; | 82 GrAttribBindings fAttribBindings; |
| 80 | 83 |
| 81 /** Non-zero if this stage has an effect */ | 84 /** Non-zero if this stage has an effect */ |
| 82 GrGLEffect::EffectKey fEffectKeys[GrDrawState::kNumStages]; | 85 GrGLEffect::EffectKey fEffectKeys[GrDrawState::kNumStages]; |
| 83 | 86 |
| 84 // To enable experimental geometry shader code (not for use in | 87 // To enable experimental geometry shader code (not for use in |
| 85 // production) | 88 // production) |
| 86 #if GR_GL_EXPERIMENTAL_GS | 89 #if GR_GL_EXPERIMENTAL_GS |
| 87 bool fExperimentalGS; | 90 bool fExperimentalGS; |
| 88 #endif | 91 #endif |
| 92 GrGLShaderBuilder::DstReadKey fDstRead; // set by GrGLShaderBuil
der if there |
| 93 // are effects that must
read the dst. |
| 94 // Otherwise, 0. |
| 95 |
| 89 uint8_t fColorInput; // casts to enum ColorIn
put | 96 uint8_t fColorInput; // casts to enum ColorIn
put |
| 90 uint8_t fCoverageInput; // casts to enum ColorIn
put | 97 uint8_t fCoverageInput; // casts to enum ColorIn
put |
| 91 uint8_t fDualSrcOutput; // casts to enum DualSrc
Output | 98 uint8_t fDualSrcOutput; // casts to enum DualSrc
Output |
| 92 int8_t fFirstCoverageStage; | 99 int8_t fFirstCoverageStage; |
| 93 SkBool8 fEmitsPointSize; | 100 SkBool8 fEmitsPointSize; |
| 94 uint8_t fColorFilterXfermode; // casts to enum SkXferm
ode::Mode | 101 uint8_t fColorFilterXfermode; // casts to enum SkXferm
ode::Mode |
| 95 | 102 |
| 96 int8_t fPositionAttributeIndex; | 103 int8_t fPositionAttributeIndex; |
| 97 int8_t fColorAttributeIndex; | 104 int8_t fColorAttributeIndex; |
| 98 int8_t fCoverageAttributeIndex; | 105 int8_t fCoverageAttributeIndex; |
| 99 int8_t fLocalCoordsAttributeIndex; | 106 int8_t fLocalCoordsAttributeIndex; |
| 100 | 107 |
| 101 // GrGLProgram reads the private fields to generate code. | 108 // GrGLProgram and GrGLShaderBuilder read the private fields to generate cod
e. TODO: Move all |
| 109 // code generation to GrGLShaderBuilder (and maybe add getters rather than f
riending). |
| 102 friend class GrGLProgram; | 110 friend class GrGLProgram; |
| 111 friend class GrGLShaderBuilder; |
| 103 }; | 112 }; |
| 104 | 113 |
| 105 #endif | 114 #endif |
| OLD | NEW |