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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 if (gUseUnpremul) { | 47 if (gUseUnpremul) { |
48 fsBuilder->codeAppendf("%s.rgb *= %s.a;", outputColor, outputColor); | 48 fsBuilder->codeAppendf("%s.rgb *= %s.a;", outputColor, outputColor); |
49 } else if (enforcePMColor) { | 49 } else if (enforcePMColor) { |
50 fsBuilder->codeAppendf("%s.rgb = min(%s.rgb, %s.a);", | 50 fsBuilder->codeAppendf("%s.rgb = min(%s.rgb, %s.a);", |
51 outputColor, outputColor, outputColor); | 51 outputColor, outputColor, outputColor); |
52 } | 52 } |
53 } | 53 } |
54 | 54 |
55 class GLArithmeticFP : public GrGLFragmentProcessor { | 55 class GLArithmeticFP : public GrGLFragmentProcessor { |
56 public: | 56 public: |
57 GLArithmeticFP(const GrProcessor&) : fEnforcePMColor(true) {} | 57 GLArithmeticFP(const GrArithmeticFP& arithmeticFP) |
| 58 : fEnforcePMColor(arithmeticFP.enforcePMColor()) {} |
58 | 59 |
59 ~GLArithmeticFP() override {} | 60 ~GLArithmeticFP() override {} |
60 | 61 |
61 void emitCode(EmitArgs& args) override { | 62 void emitCode(EmitArgs& args) override { |
62 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder
(); | 63 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder
(); |
63 SkString dstColor("dstColor"); | 64 SkString dstColor("dstColor"); |
64 this->emitChild(0, nullptr, &dstColor, args); | 65 this->emitChild(0, nullptr, &dstColor, args); |
65 | 66 |
66 fKUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibili
ty, | 67 fKUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Visibili
ty, |
67 kVec4f_GrSLType, kDefault_GrSLPrecisio
n, | 68 kVec4f_GrSLType, kDefault_GrSLPrecisio
n, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 float fK1, fK2, fK3, fK4; | 185 float fK1, fK2, fK3, fK4; |
185 bool fEnforcePMColor; | 186 bool fEnforcePMColor; |
186 | 187 |
187 typedef GrXferProcessor INHERITED; | 188 typedef GrXferProcessor INHERITED; |
188 }; | 189 }; |
189 | 190 |
190 /////////////////////////////////////////////////////////////////////////////// | 191 /////////////////////////////////////////////////////////////////////////////// |
191 | 192 |
192 class GLArithmeticXP : public GrGLXferProcessor { | 193 class GLArithmeticXP : public GrGLXferProcessor { |
193 public: | 194 public: |
194 GLArithmeticXP(const GrProcessor&) | 195 GLArithmeticXP(const ArithmeticXP& arithmeticXP) |
195 : fEnforcePMColor(true) { | 196 : fEnforcePMColor(arithmeticXP.enforcePMColor()) { |
196 } | 197 } |
197 | 198 |
198 ~GLArithmeticXP() override {} | 199 ~GLArithmeticXP() override {} |
199 | 200 |
200 static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, | 201 static void GenKey(const GrProcessor& processor, const GrGLSLCaps& caps, |
201 GrProcessorKeyBuilder* b) { | 202 GrProcessorKeyBuilder* b) { |
202 const ArithmeticXP& arith = processor.cast<ArithmeticXP>(); | 203 const ArithmeticXP& arith = processor.cast<ArithmeticXP>(); |
203 uint32_t key = arith.enforcePMColor() ? 1 : 0; | 204 uint32_t key = arith.enforcePMColor() ? 1 : 0; |
204 b->add32(key); | 205 b->add32(key); |
205 } | 206 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 const GrProcOptInfo&
coveragePOI, | 254 const GrProcOptInfo&
coveragePOI, |
254 bool doesStencilWrite
, | 255 bool doesStencilWrite
, |
255 GrColor* overrideColo
r, | 256 GrColor* overrideColo
r, |
256 const GrCaps& caps) { | 257 const GrCaps& caps) { |
257 return GrXferProcessor::kNone_OptFlags; | 258 return GrXferProcessor::kNone_OptFlags; |
258 } | 259 } |
259 | 260 |
260 /////////////////////////////////////////////////////////////////////////////// | 261 /////////////////////////////////////////////////////////////////////////////// |
261 | 262 |
262 GrArithmeticXPFactory::GrArithmeticXPFactory(float k1, float k2, float k3, float
k4, | 263 GrArithmeticXPFactory::GrArithmeticXPFactory(float k1, float k2, float k3, float
k4, |
263 bool enforcePMColor) | 264 bool enforcePMColor) |
264 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { | 265 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { |
265 this->initClassID<GrArithmeticXPFactory>(); | 266 this->initClassID<GrArithmeticXPFactory>(); |
266 } | 267 } |
267 | 268 |
268 GrXferProcessor* | 269 GrXferProcessor* |
269 GrArithmeticXPFactory::onCreateXferProcessor(const GrCaps& caps, | 270 GrArithmeticXPFactory::onCreateXferProcessor(const GrCaps& caps, |
270 const GrProcOptInfo& colorPOI, | 271 const GrProcOptInfo& colorPOI, |
271 const GrProcOptInfo& coveragePOI, | 272 const GrProcOptInfo& coveragePOI, |
272 bool hasMixedSamples, | 273 bool hasMixedSamples, |
273 const DstTexture* dstTexture) const
{ | 274 const DstTexture* dstTexture) const
{ |
(...skipping 17 matching lines...) Expand all Loading... |
291 float k1 = d->fRandom->nextF(); | 292 float k1 = d->fRandom->nextF(); |
292 float k2 = d->fRandom->nextF(); | 293 float k2 = d->fRandom->nextF(); |
293 float k3 = d->fRandom->nextF(); | 294 float k3 = d->fRandom->nextF(); |
294 float k4 = d->fRandom->nextF(); | 295 float k4 = d->fRandom->nextF(); |
295 bool enforcePMColor = d->fRandom->nextBool(); | 296 bool enforcePMColor = d->fRandom->nextBool(); |
296 | 297 |
297 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); | 298 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); |
298 } | 299 } |
299 | 300 |
300 #endif | 301 #endif |
OLD | NEW |