OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 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 #include "GrProcessor.h" | 8 #include "GrProcessor.h" |
9 #include "GrBackendProcessorFactory.h" | 9 #include "GrBackendProcessorFactory.h" |
10 #include "GrContext.h" | 10 #include "GrContext.h" |
11 #include "GrCoordTransform.h" | 11 #include "GrCoordTransform.h" |
| 12 #include "GrInvariantOutput.h" |
12 #include "GrMemoryPool.h" | 13 #include "GrMemoryPool.h" |
13 #include "SkTLS.h" | 14 #include "SkTLS.h" |
14 | 15 |
15 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS | 16 #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS |
16 | 17 |
17 /* | 18 /* |
18 * Originally these were both in the processor unit test header, but then it see
med to cause linker | 19 * Originally these were both in the processor unit test header, but then it see
med to cause linker |
19 * problems on android. | 20 * problems on android. |
20 */ | 21 */ |
21 template<> | 22 template<> |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 return false; | 122 return false; |
122 } | 123 } |
123 for (int i = 0; i < this->numTextures(); ++i) { | 124 for (int i = 0; i < this->numTextures(); ++i) { |
124 if (this->textureAccess(i) != that.textureAccess(i)) { | 125 if (this->textureAccess(i) != that.textureAccess(i)) { |
125 return false; | 126 return false; |
126 } | 127 } |
127 } | 128 } |
128 return true; | 129 return true; |
129 } | 130 } |
130 | 131 |
| 132 void GrProcessor::computeInvariantOutput(GrInvariantOutput* inout) const { |
| 133 inout->resetWillUseInputColor(); |
| 134 this->onComputeInvariantOutput(inout); |
131 #ifdef SK_DEBUG | 135 #ifdef SK_DEBUG |
132 | 136 inout->validate(); |
133 void GrProcessor::InvariantOutput::validate() const { | 137 #endif |
134 if (fIsSingleComponent) { | |
135 SkASSERT(0 == fValidFlags || kRGBA_GrColorComponentFlags == fValidFlags)
; | |
136 if (kRGBA_GrColorComponentFlags == fValidFlags) { | |
137 SkASSERT(this->colorComponentsAllEqual()); | |
138 } | |
139 } | |
140 | |
141 SkASSERT(this->validPreMulColor()); | |
142 | |
143 // If we claim that we are not using the input color we must not be modulati
ng the input. | |
144 SkASSERT(fNonMulStageFound || fWillUseInputColor); | |
145 } | 138 } |
146 | 139 |
147 bool GrProcessor::InvariantOutput::colorComponentsAllEqual() const { | |
148 unsigned colorA = GrColorUnpackA(fColor); | |
149 return(GrColorUnpackR(fColor) == colorA && | |
150 GrColorUnpackG(fColor) == colorA && | |
151 GrColorUnpackB(fColor) == colorA); | |
152 } | |
153 | |
154 bool GrProcessor::InvariantOutput::validPreMulColor() const { | |
155 if (kA_GrColorComponentFlag & fValidFlags) { | |
156 float c[4]; | |
157 GrColorToRGBAFloat(fColor, c); | |
158 if (kR_GrColorComponentFlag & fValidFlags) { | |
159 if (c[0] > c[3]) { | |
160 return false; | |
161 } | |
162 } | |
163 if (kG_GrColorComponentFlag & fValidFlags) { | |
164 if (c[1] > c[3]) { | |
165 return false; | |
166 } | |
167 } | |
168 if (kB_GrColorComponentFlag & fValidFlags) { | |
169 if (c[2] > c[3]) { | |
170 return false; | |
171 } | |
172 } | |
173 } | |
174 return true; | |
175 } | |
176 #endif // end DEBUG | |
177 | |
178 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 140 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
179 | 141 |
180 void GrFragmentProcessor::addCoordTransform(const GrCoordTransform* transform) { | 142 void GrFragmentProcessor::addCoordTransform(const GrCoordTransform* transform) { |
181 fCoordTransforms.push_back(transform); | 143 fCoordTransforms.push_back(transform); |
182 SkDEBUGCODE(transform->setInProcessor();) | 144 SkDEBUGCODE(transform->setInProcessor();) |
183 } | 145 } |
184 | 146 |
185 bool GrFragmentProcessor::hasSameTransforms(const GrFragmentProcessor& that) con
st { | 147 bool GrFragmentProcessor::hasSameTransforms(const GrFragmentProcessor& that) con
st { |
186 if (fCoordTransforms.count() != that.fCoordTransforms.count()) { | 148 if (fCoordTransforms.count() != that.fCoordTransforms.count()) { |
187 return false; | 149 return false; |
188 } | 150 } |
189 int count = fCoordTransforms.count(); | 151 int count = fCoordTransforms.count(); |
190 for (int i = 0; i < count; ++i) { | 152 for (int i = 0; i < count; ++i) { |
191 if (*fCoordTransforms[i] != *that.fCoordTransforms[i]) { | 153 if (*fCoordTransforms[i] != *that.fCoordTransforms[i]) { |
192 return false; | 154 return false; |
193 } | 155 } |
194 } | 156 } |
195 return true; | 157 return true; |
196 } | 158 } |
OLD | NEW |