| 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 |
| 11 #include "GrContext.h" | 11 #include "GrContext.h" |
| 12 #include "GrFragmentProcessor.h" | 12 #include "GrFragmentProcessor.h" |
| 13 #include "GrInvariantOutput.h" | 13 #include "GrInvariantOutput.h" |
| 14 #include "GrProcessor.h" | 14 #include "GrProcessor.h" |
| 15 #include "GrTexture.h" | 15 #include "GrTexture.h" |
| 16 #include "gl/GrGLCaps.h" | |
| 17 #include "gl/GrGLFragmentProcessor.h" | |
| 18 #include "gl/GrGLXferProcessor.h" | 16 #include "gl/GrGLXferProcessor.h" |
| 17 #include "glsl/GrGLSLFragmentProcessor.h" |
| 19 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 18 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 20 #include "glsl/GrGLSLProgramBuilder.h" | 19 #include "glsl/GrGLSLProgramBuilder.h" |
| 21 #include "glsl/GrGLSLProgramDataManager.h" | 20 #include "glsl/GrGLSLProgramDataManager.h" |
| 22 | 21 |
| 23 static const bool gUseUnpremul = false; | 22 static const bool gUseUnpremul = false; |
| 24 | 23 |
| 25 static void add_arithmetic_code(GrGLSLFragmentBuilder* fsBuilder, | 24 static void add_arithmetic_code(GrGLSLFragmentBuilder* fsBuilder, |
| 26 const char* srcColor, | 25 const char* srcColor, |
| 27 const char* dstColor, | 26 const char* dstColor, |
| 28 const char* outputColor, | 27 const char* outputColor, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 47 outputColor, kUni, kUni, kUni, kUni); | 46 outputColor, kUni, kUni, kUni, kUni); |
| 48 fsBuilder->codeAppendf("%s = clamp(%s, 0.0, 1.0);\n", outputColor, outputCol
or); | 47 fsBuilder->codeAppendf("%s = clamp(%s, 0.0, 1.0);\n", outputColor, outputCol
or); |
| 49 if (gUseUnpremul) { | 48 if (gUseUnpremul) { |
| 50 fsBuilder->codeAppendf("%s.rgb *= %s.a;", outputColor, outputColor); | 49 fsBuilder->codeAppendf("%s.rgb *= %s.a;", outputColor, outputColor); |
| 51 } else if (enforcePMColor) { | 50 } else if (enforcePMColor) { |
| 52 fsBuilder->codeAppendf("%s.rgb = min(%s.rgb, %s.a);", | 51 fsBuilder->codeAppendf("%s.rgb = min(%s.rgb, %s.a);", |
| 53 outputColor, outputColor, outputColor); | 52 outputColor, outputColor, outputColor); |
| 54 } | 53 } |
| 55 } | 54 } |
| 56 | 55 |
| 57 class GLArithmeticFP : public GrGLFragmentProcessor { | 56 class GLArithmeticFP : public GrGLSLFragmentProcessor { |
| 58 public: | 57 public: |
| 59 GLArithmeticFP(const GrArithmeticFP& arithmeticFP) | 58 GLArithmeticFP(const GrArithmeticFP& arithmeticFP) |
| 60 : fEnforcePMColor(arithmeticFP.enforcePMColor()) {} | 59 : fEnforcePMColor(arithmeticFP.enforcePMColor()) {} |
| 61 | 60 |
| 62 ~GLArithmeticFP() override {} | 61 ~GLArithmeticFP() override {} |
| 63 | 62 |
| 64 void emitCode(EmitArgs& args) override { | 63 void emitCode(EmitArgs& args) override { |
| 65 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuild
er(); | 64 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuild
er(); |
| 66 SkString dstColor("dstColor"); | 65 SkString dstColor("dstColor"); |
| 67 this->emitChild(0, nullptr, &dstColor, args); | 66 this->emitChild(0, nullptr, &dstColor, args); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 85 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& pro
c) override { | 84 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& pro
c) override { |
| 86 const GrArithmeticFP& arith = proc.cast<GrArithmeticFP>(); | 85 const GrArithmeticFP& arith = proc.cast<GrArithmeticFP>(); |
| 87 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); | 86 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); |
| 88 fEnforcePMColor = arith.enforcePMColor(); | 87 fEnforcePMColor = arith.enforcePMColor(); |
| 89 } | 88 } |
| 90 | 89 |
| 91 private: | 90 private: |
| 92 GrGLSLProgramDataManager::UniformHandle fKUni; | 91 GrGLSLProgramDataManager::UniformHandle fKUni; |
| 93 bool fEnforcePMColor; | 92 bool fEnforcePMColor; |
| 94 | 93 |
| 95 typedef GrGLFragmentProcessor INHERITED; | 94 typedef GrGLSLFragmentProcessor INHERITED; |
| 96 }; | 95 }; |
| 97 | 96 |
| 98 /////////////////////////////////////////////////////////////////////////////// | 97 /////////////////////////////////////////////////////////////////////////////// |
| 99 | 98 |
| 100 GrArithmeticFP::GrArithmeticFP(float k1, float k2, float k3, float k4, bool enfo
rcePMColor, | 99 GrArithmeticFP::GrArithmeticFP(float k1, float k2, float k3, float k4, bool enfo
rcePMColor, |
| 101 const GrFragmentProcessor* dst) | 100 const GrFragmentProcessor* dst) |
| 102 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { | 101 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { |
| 103 this->initClassID<GrArithmeticFP>(); | 102 this->initClassID<GrArithmeticFP>(); |
| 104 | 103 |
| 105 SkASSERT(dst); | 104 SkASSERT(dst); |
| 106 SkDEBUGCODE(int dstIndex = )this->registerChildProcessor(dst); | 105 SkDEBUGCODE(int dstIndex = )this->registerChildProcessor(dst); |
| 107 SkASSERT(0 == dstIndex); | 106 SkASSERT(0 == dstIndex); |
| 108 } | 107 } |
| 109 | 108 |
| 110 void GrArithmeticFP::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyB
uilder* b) const { | 109 void GrArithmeticFP::onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyB
uilder* b) const { |
| 111 GLArithmeticFP::GenKey(*this, caps, b); | 110 GLArithmeticFP::GenKey(*this, caps, b); |
| 112 } | 111 } |
| 113 | 112 |
| 114 GrGLFragmentProcessor* GrArithmeticFP::onCreateGLInstance() const { | 113 GrGLSLFragmentProcessor* GrArithmeticFP::onCreateGLInstance() const { |
| 115 return new GLArithmeticFP(*this); | 114 return new GLArithmeticFP(*this); |
| 116 } | 115 } |
| 117 | 116 |
| 118 bool GrArithmeticFP::onIsEqual(const GrFragmentProcessor& fpBase) const { | 117 bool GrArithmeticFP::onIsEqual(const GrFragmentProcessor& fpBase) const { |
| 119 const GrArithmeticFP& fp = fpBase.cast<GrArithmeticFP>(); | 118 const GrArithmeticFP& fp = fpBase.cast<GrArithmeticFP>(); |
| 120 return fK1 == fp.fK1 && | 119 return fK1 == fp.fK1 && |
| 121 fK2 == fp.fK2 && | 120 fK2 == fp.fK2 && |
| 122 fK3 == fp.fK3 && | 121 fK3 == fp.fK3 && |
| 123 fK4 == fp.fK4 && | 122 fK4 == fp.fK4 && |
| 124 fEnforcePMColor == fp.fEnforcePMColor; | 123 fEnforcePMColor == fp.fEnforcePMColor; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 float k1 = d->fRandom->nextF(); | 293 float k1 = d->fRandom->nextF(); |
| 295 float k2 = d->fRandom->nextF(); | 294 float k2 = d->fRandom->nextF(); |
| 296 float k3 = d->fRandom->nextF(); | 295 float k3 = d->fRandom->nextF(); |
| 297 float k4 = d->fRandom->nextF(); | 296 float k4 = d->fRandom->nextF(); |
| 298 bool enforcePMColor = d->fRandom->nextBool(); | 297 bool enforcePMColor = d->fRandom->nextBool(); |
| 299 | 298 |
| 300 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); | 299 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); |
| 301 } | 300 } |
| 302 | 301 |
| 303 #endif | 302 #endif |
| OLD | NEW |