bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrGLProgramDesc_DEFINED |
| 9 | #define GrGLProgramDesc_DEFINED |
| 10 | |
| 11 | #include "GrGLEffect.h" |
bsalomon@google.com | 798c8c4 | 2013-03-27 19:50:27 +0000 | [diff] [blame^] | 12 | #include "GrDrawState.h" |
bsalomon@google.com | 31ec798 | 2013-03-27 18:14:57 +0000 | [diff] [blame] | 13 | |
| 14 | class GrGpuGL; |
| 15 | |
| 16 | // optionally compile the experimental GS code. Set to GR_DEBUG so that debug build bots will |
| 17 | // execute the code. |
| 18 | #define GR_GL_EXPERIMENTAL_GS GR_DEBUG |
| 19 | |
| 20 | |
| 21 | /** This class describes a program to generate. It also serves as a program cache key. The only |
| 22 | thing GL-specific about this is the generation of GrGLEffect::EffectKeys. With some refactoring |
| 23 | it could be made backend-neutral. */ |
| 24 | class GrGLProgramDesc { |
| 25 | public: |
| 26 | GrGLProgramDesc() { |
| 27 | // since we use this as part of a key we can't have any uninitialized padding |
| 28 | memset(this, 0, sizeof(GrGLProgramDesc)); |
| 29 | } |
| 30 | |
| 31 | // Returns this as a uint32_t array to be used as a key in the program cache |
| 32 | const uint32_t* asKey() const { |
| 33 | return reinterpret_cast<const uint32_t*>(this); |
| 34 | } |
| 35 | |
| 36 | // For unit testing. |
| 37 | void setRandom(SkMWCRandom*, |
| 38 | const GrGpuGL* gpu, |
| 39 | const GrEffectStage stages[GrDrawState::kNumStages]); |
| 40 | |
| 41 | /** |
| 42 | * Builds a program descriptor from a GrDrawState. Whether the primitive type is points, the |
| 43 | * output of GrDrawState::getBlendOpts, and the caps of the GrGpuGL are also inputs. |
| 44 | */ |
| 45 | static void Build(const GrDrawState&, |
| 46 | bool isPoints, |
| 47 | GrDrawState::BlendOptFlags, |
| 48 | GrBlendCoeff srcCoeff, |
| 49 | GrBlendCoeff dstCoeff, |
| 50 | const GrGpuGL* gpu, |
| 51 | GrGLProgramDesc* outDesc); |
| 52 | |
| 53 | private: |
| 54 | // Specifies where the initial color comes from before the stages are applied. |
| 55 | enum ColorInput { |
| 56 | kSolidWhite_ColorInput, |
| 57 | kTransBlack_ColorInput, |
| 58 | kAttribute_ColorInput, |
| 59 | kUniform_ColorInput, |
| 60 | |
| 61 | kColorInputCnt |
| 62 | }; |
| 63 | // Dual-src blending makes use of a secondary output color that can be |
| 64 | // used as a per-pixel blend coefficient. This controls whether a |
| 65 | // secondary source is output and what value it holds. |
| 66 | enum DualSrcOutput { |
| 67 | kNone_DualSrcOutput, |
| 68 | kCoverage_DualSrcOutput, |
| 69 | kCoverageISA_DualSrcOutput, |
| 70 | kCoverageISC_DualSrcOutput, |
| 71 | |
| 72 | kDualSrcOutputCnt |
| 73 | }; |
| 74 | |
| 75 | // should the FS discard if the coverage is zero (to avoid stencil manipulation) |
| 76 | bool fDiscardIfZeroCoverage; |
| 77 | |
| 78 | // stripped of bits that don't affect program generation |
| 79 | GrAttribBindings fAttribBindings; |
| 80 | |
| 81 | /** Non-zero if this stage has an effect */ |
| 82 | GrGLEffect::EffectKey fEffectKeys[GrDrawState::kNumStages]; |
| 83 | |
| 84 | // To enable experimental geometry shader code (not for use in |
| 85 | // production) |
| 86 | #if GR_GL_EXPERIMENTAL_GS |
| 87 | bool fExperimentalGS; |
| 88 | #endif |
| 89 | uint8_t fColorInput; // casts to enum ColorInput |
| 90 | uint8_t fCoverageInput; // casts to enum ColorInput |
| 91 | uint8_t fDualSrcOutput; // casts to enum DualSrcOutput |
| 92 | int8_t fFirstCoverageStage; |
| 93 | SkBool8 fEmitsPointSize; |
| 94 | uint8_t fColorFilterXfermode; // casts to enum SkXfermode::Mode |
| 95 | |
| 96 | int8_t fPositionAttributeIndex; |
| 97 | int8_t fColorAttributeIndex; |
| 98 | int8_t fCoverageAttributeIndex; |
| 99 | int8_t fLocalCoordsAttributeIndex; |
| 100 | |
| 101 | // GrGLProgram reads the private fields to generate code. |
| 102 | friend class GrGLProgram; |
| 103 | }; |
| 104 | |
| 105 | #endif |