OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "SkArithmeticMode_gpu.h" | 8 #include "SkArithmeticMode_gpu.h" |
9 | 9 |
10 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 /////////////////////////////////////////////////////////////////////////////// | 159 /////////////////////////////////////////////////////////////////////////////// |
160 | 160 |
161 class GLArithmeticXP : public GrGLXferProcessor { | 161 class GLArithmeticXP : public GrGLXferProcessor { |
162 public: | 162 public: |
163 GLArithmeticXP(const GrProcessor&) | 163 GLArithmeticXP(const GrProcessor&) |
164 : fEnforcePMColor(true) { | 164 : fEnforcePMColor(true) { |
165 } | 165 } |
166 | 166 |
167 ~GLArithmeticXP() SK_OVERRIDE {} | 167 ~GLArithmeticXP() SK_OVERRIDE {} |
168 | 168 |
169 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps, | 169 void emitCode(const EmitArgs& args) SK_OVERRIDE { |
170 GrProcessorKeyBuilder* b) { | |
171 const GrArithmeticXP& arith = processor.cast<GrArithmeticXP>(); | |
172 uint32_t key = arith.enforcePMColor() ? 1 : 0; | |
173 b->add32(key); | |
174 } | |
175 | |
176 private: | |
177 void onEmitCode(const EmitArgs& args) SK_OVERRIDE { | |
178 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 170 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
179 | 171 |
180 const char* dstColor = fsBuilder->dstColor(); | 172 const char* dstColor = fsBuilder->dstColor(); |
181 | 173 |
182 fKUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 174 fKUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
183 kVec4f_GrSLType, kDefault_GrSLPrecision, | 175 kVec4f_GrSLType, kDefault_GrSLPrecision, |
184 "k"); | 176 "k"); |
185 const char* kUni = args.fPB->getUniformCStr(fKUni); | 177 const char* kUni = args.fPB->getUniformCStr(fKUni); |
186 | 178 |
187 add_arithmetic_code(fsBuilder, args.fInputColor, dstColor, args.fOutputP
rimary, kUni, | 179 add_arithmetic_code(fsBuilder, args.fInputColor, dstColor, args.fOutputP
rimary, kUni, |
188 fEnforcePMColor); | 180 fEnforcePMColor); |
189 | 181 |
190 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;", | 182 fsBuilder->codeAppendf("%s = %s * %s + (vec4(1.0) - %s) * %s;", |
191 args.fOutputPrimary, args.fOutputPrimary, args.fI
nputCoverage, | 183 args.fOutputPrimary, args.fOutputPrimary, args.fI
nputCoverage, |
192 args.fInputCoverage, dstColor); | 184 args.fInputCoverage, dstColor); |
193 } | 185 } |
194 | 186 |
195 void onSetData(const GrGLProgramDataManager& pdman, | 187 void setData(const GrGLProgramDataManager& pdman, |
196 const GrXferProcessor& processor) SK_OVERRIDE { | 188 const GrXferProcessor& processor) SK_OVERRIDE { |
197 const GrArithmeticXP& arith = processor.cast<GrArithmeticXP>(); | 189 const GrArithmeticXP& arith = processor.cast<GrArithmeticXP>(); |
198 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); | 190 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); |
199 fEnforcePMColor = arith.enforcePMColor(); | 191 fEnforcePMColor = arith.enforcePMColor(); |
200 }; | 192 }; |
201 | 193 |
| 194 static void GenKey(const GrProcessor& processor, const GrGLCaps& caps, |
| 195 GrProcessorKeyBuilder* b) { |
| 196 const GrArithmeticXP& arith = processor.cast<GrArithmeticXP>(); |
| 197 uint32_t key = arith.enforcePMColor() ? 1 : 0; |
| 198 b->add32(key); |
| 199 } |
| 200 |
| 201 private: |
202 GrGLProgramDataManager::UniformHandle fKUni; | 202 GrGLProgramDataManager::UniformHandle fKUni; |
203 bool fEnforcePMColor; | 203 bool fEnforcePMColor; |
204 | 204 |
205 typedef GrGLXferProcessor INHERITED; | 205 typedef GrGLXferProcessor INHERITED; |
206 }; | 206 }; |
207 | 207 |
208 /////////////////////////////////////////////////////////////////////////////// | 208 /////////////////////////////////////////////////////////////////////////////// |
209 | 209 |
210 GrArithmeticXP::GrArithmeticXP(float k1, float k2, float k3, float k4, bool enfo
rcePMColor, | 210 GrArithmeticXP::GrArithmeticXP(float k1, float k2, float k3, float k4, bool enfo
rcePMColor) |
211 const GrDeviceCoordTexture* dstCopy, bool willRea
dDstColor) | 211 : fK1(k1) |
212 : INHERITED(dstCopy, willReadDstColor) | |
213 , fK1(k1) | |
214 , fK2(k2) | 212 , fK2(k2) |
215 , fK3(k3) | 213 , fK3(k3) |
216 , fK4(k4) | 214 , fK4(k4) |
217 , fEnforcePMColor(enforcePMColor) { | 215 , fEnforcePMColor(enforcePMColor) { |
218 this->initClassID<GrPorterDuffXferProcessor>(); | 216 this->initClassID<GrPorterDuffXferProcessor>(); |
| 217 this->setWillReadDstColor(); |
219 } | 218 } |
220 | 219 |
221 void GrArithmeticXP::onGetGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBui
lder* b) const { | 220 void GrArithmeticXP::getGLProcessorKey(const GrGLCaps& caps, GrProcessorKeyBuild
er* b) const { |
222 GLArithmeticXP::GenKey(*this, caps, b); | 221 GLArithmeticXP::GenKey(*this, caps, b); |
223 } | 222 } |
224 | 223 |
225 GrGLXferProcessor* GrArithmeticXP::createGLInstance() const { | 224 GrGLXferProcessor* GrArithmeticXP::createGLInstance() const { |
226 return SkNEW_ARGS(GLArithmeticXP, (*this)); | 225 return SkNEW_ARGS(GLArithmeticXP, (*this)); |
227 } | 226 } |
228 | 227 |
229 GrXferProcessor::OptFlags GrArithmeticXP::getOptimizations(const GrProcOptInfo&
colorPOI, | 228 GrXferProcessor::OptFlags GrArithmeticXP::getOptimizations(const GrProcOptInfo&
colorPOI, |
230 const GrProcOptInfo&
coveragePOI, | 229 const GrProcOptInfo&
coveragePOI, |
231 bool doesStencilWrite
, | 230 bool doesStencilWrite
, |
(...skipping 30 matching lines...) Expand all Loading... |
262 float k1 = random->nextF(); | 261 float k1 = random->nextF(); |
263 float k2 = random->nextF(); | 262 float k2 = random->nextF(); |
264 float k3 = random->nextF(); | 263 float k3 = random->nextF(); |
265 float k4 = random->nextF(); | 264 float k4 = random->nextF(); |
266 bool enforcePMColor = random->nextBool(); | 265 bool enforcePMColor = random->nextBool(); |
267 | 266 |
268 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); | 267 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); |
269 } | 268 } |
270 | 269 |
271 #endif | 270 #endif |
OLD | NEW |