OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 GrProgramDesc_DEFINED | 8 #ifndef GrProgramDesc_DEFINED |
9 #define GrProgramDesc_DEFINED | 9 #define GrProgramDesc_DEFINED |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } | 47 } |
48 | 48 |
49 bool operator!= (const GrProgramDesc& other) const { | 49 bool operator!= (const GrProgramDesc& other) const { |
50 return !(*this == other); | 50 return !(*this == other); |
51 } | 51 } |
52 | 52 |
53 static bool Less(const GrProgramDesc& a, const GrProgramDesc& b) { | 53 static bool Less(const GrProgramDesc& a, const GrProgramDesc& b) { |
54 return memcmp(a.asKey(), b.asKey(), a.keyLength() & ~0x3) < 0; | 54 return memcmp(a.asKey(), b.asKey(), a.keyLength() & ~0x3) < 0; |
55 } | 55 } |
56 | 56 |
57 | |
58 // Specifies where the initial color comes from before the stages are applie
d. | |
59 enum ColorInput { | |
60 kAllOnes_ColorInput, | |
61 kAttribute_ColorInput, | |
62 kUniform_ColorInput, | |
63 | |
64 kColorInputCnt | |
65 }; | |
66 | |
67 struct KeyHeader { | 57 struct KeyHeader { |
68 uint8_t fDstReadKey; // set by GrGLShaderBuilder i
f there | 58 uint8_t fDstReadKey; // set by GrGLShaderBuilder i
f there |
69 // are effects that must read
the dst. | 59 // are effects that must read
the dst. |
70 // Otherwise, 0. | 60 // Otherwise, 0. |
71 uint8_t fFragPosKey; // set by GrGLShaderBuilder i
f there are | 61 uint8_t fFragPosKey; // set by GrGLShaderBuilder i
f there are |
72 // effects that read the frag
ment position. | 62 // effects that read the frag
ment position. |
73 // Otherwise, 0. | 63 // Otherwise, 0. |
74 | 64 |
75 ColorInput fColorInput : 8; | |
76 ColorInput fCoverageInput : 8; | |
77 | |
78 SkBool8 fHasGeometryProcessor; | |
79 int8_t fColorEffectCnt; | 65 int8_t fColorEffectCnt; |
80 int8_t fCoverageEffectCnt; | 66 int8_t fCoverageEffectCnt; |
81 }; | 67 }; |
82 | 68 |
83 | |
84 bool hasGeometryProcessor() const { | |
85 return SkToBool(this->header().fHasGeometryProcessor); | |
86 } | |
87 | |
88 int numColorEffects() const { | 69 int numColorEffects() const { |
89 return this->header().fColorEffectCnt; | 70 return this->header().fColorEffectCnt; |
90 } | 71 } |
91 | 72 |
92 int numCoverageEffects() const { | 73 int numCoverageEffects() const { |
93 return this->header().fCoverageEffectCnt; | 74 return this->header().fCoverageEffectCnt; |
94 } | 75 } |
95 | 76 |
96 int numTotalEffects() const { return this->numColorEffects() + this->numCove
rageEffects(); } | 77 int numTotalEffects() const { return this->numColorEffects() + this->numCove
rageEffects(); } |
97 | 78 |
98 // This should really only be used internally, base classes should return th
eir own headers | 79 // This should really only be used internally, base classes should return th
eir own headers |
99 const KeyHeader& header() const { return *this->atOffset<KeyHeader, kHeaderO
ffset>(); } | 80 const KeyHeader& header() const { return *this->atOffset<KeyHeader, kHeaderO
ffset>(); } |
100 | 81 |
101 // A struct to communicate descriptor information to the program descriptor
builder | 82 // A struct to communicate descriptor information to the program descriptor
builder |
102 struct DescInfo { | 83 struct DescInfo { |
103 bool operator==(const DescInfo& that) const { | 84 bool operator==(const DescInfo& that) const { |
104 return fHasVertexColor == that.fHasVertexColor && | 85 return fReadsDst == that.fReadsDst && |
105 fHasVertexCoverage == that.fHasVertexCoverage && | |
106 fInputColorIsUsed == that.fInputColorIsUsed && | |
107 fInputCoverageIsUsed == that.fInputCoverageIsUsed && | |
108 fReadsDst == that.fReadsDst && | |
109 fReadsFragPosition == that.fReadsFragPosition && | 86 fReadsFragPosition == that.fReadsFragPosition && |
110 fRequiresLocalCoordAttrib == that.fRequiresLocalCoordAttrib; | 87 fRequiresLocalCoordAttrib == that.fRequiresLocalCoordAttrib; |
111 } | 88 } |
112 bool operator!=(const DescInfo& that) const { return !(*this == that); }
; | 89 bool operator!=(const DescInfo& that) const { return !(*this == that); }
; |
113 // TODO when GPs control uniform / attribute handling of color / coverag
e, then we can | |
114 // clean this up | |
115 bool fHasVertexColor; | |
116 bool fHasVertexCoverage; | |
117 | |
118 // These flags are needed to protect the code from creating an unused un
iform color/coverage | |
119 // which will cause shader compiler errors. | |
120 bool fInputColorIsUsed; | |
121 bool fInputCoverageIsUsed; | |
122 | 90 |
123 // These flags give aggregated info on the processor stages that are use
d when building | 91 // These flags give aggregated info on the processor stages that are use
d when building |
124 // programs. | 92 // programs. |
125 bool fReadsDst; | 93 bool fReadsDst; |
126 bool fReadsFragPosition; | 94 bool fReadsFragPosition; |
127 bool fRequiresLocalCoordAttrib; | 95 bool fRequiresLocalCoordAttrib; |
128 | |
129 }; | 96 }; |
130 | 97 |
131 private: | 98 private: |
132 template<typename T, size_t OFFSET> T* atOffset() { | 99 template<typename T, size_t OFFSET> T* atOffset() { |
133 return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + O
FFSET); | 100 return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + O
FFSET); |
134 } | 101 } |
135 | 102 |
136 template<typename T, size_t OFFSET> const T* atOffset() const { | 103 template<typename T, size_t OFFSET> const T* atOffset() const { |
137 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin(
)) + OFFSET); | 104 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin(
)) + OFFSET); |
138 } | 105 } |
(...skipping 29 matching lines...) Expand all Loading... |
168 kPreAllocSize = kHeaderOffset + kHeaderSize + | 135 kPreAllocSize = kHeaderOffset + kHeaderSize + |
169 kMaxPreallocProcessors * sizeof(uint32_t) * kIntsPerProc
essor, | 136 kMaxPreallocProcessors * sizeof(uint32_t) * kIntsPerProc
essor, |
170 }; | 137 }; |
171 | 138 |
172 SkSTArray<kPreAllocSize, uint8_t, true> fKey; | 139 SkSTArray<kPreAllocSize, uint8_t, true> fKey; |
173 | 140 |
174 friend class GrGLProgramDescBuilder; | 141 friend class GrGLProgramDescBuilder; |
175 }; | 142 }; |
176 | 143 |
177 #endif | 144 #endif |
OLD | NEW |