Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/effects/SkArithmeticMode_gpu.cpp

Issue 1666773002: Clean up GrGLSLFragmentProcessor-derived classes (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/effects/SkAlphaThresholdFilter.cpp ('k') | src/effects/SkBlurMaskFilter.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 if (gUseUnpremul) { 48 if (gUseUnpremul) {
49 fragBuilder->codeAppendf("%s.rgb *= %s.a;", outputColor, outputColor); 49 fragBuilder->codeAppendf("%s.rgb *= %s.a;", outputColor, outputColor);
50 } else if (enforcePMColor) { 50 } else if (enforcePMColor) {
51 fragBuilder->codeAppendf("%s.rgb = min(%s.rgb, %s.a);", 51 fragBuilder->codeAppendf("%s.rgb = min(%s.rgb, %s.a);",
52 outputColor, outputColor, outputColor); 52 outputColor, outputColor, outputColor);
53 } 53 }
54 } 54 }
55 55
56 class GLArithmeticFP : public GrGLSLFragmentProcessor { 56 class GLArithmeticFP : public GrGLSLFragmentProcessor {
57 public: 57 public:
58 GLArithmeticFP(const GrArithmeticFP& arithmeticFP) 58 void emitCode(EmitArgs& args) override {
59 : fEnforcePMColor(arithmeticFP.enforcePMColor()) {} 59 const GrArithmeticFP& arith = args.fFp.cast<GrArithmeticFP>();
60 60
61 ~GLArithmeticFP() override {}
62
63 void emitCode(EmitArgs& args) override {
64 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 61 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
65 SkString dstColor("dstColor"); 62 SkString dstColor("dstColor");
66 this->emitChild(0, nullptr, &dstColor, args); 63 this->emitChild(0, nullptr, &dstColor, args);
67 64
68 fKUni = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFragment _Visibility, 65 fKUni = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFragment _Visibility,
69 kVec4f_GrSLType, kDefault_GrSLP recision, 66 kVec4f_GrSLType, kDefault_GrSLP recision,
70 "k"); 67 "k");
71 const char* kUni = args.fUniformHandler->getUniformCStr(fKUni); 68 const char* kUni = args.fUniformHandler->getUniformCStr(fKUni);
72 69
73 add_arithmetic_code(fragBuilder, 70 add_arithmetic_code(fragBuilder,
74 args.fInputColor, 71 args.fInputColor,
75 dstColor.c_str(), 72 dstColor.c_str(),
76 args.fOutputColor, 73 args.fOutputColor,
77 kUni, 74 kUni,
78 fEnforcePMColor); 75 arith.enforcePMColor());
79 } 76 }
80 77
81 static void GenKey(const GrProcessor& proc, const GrGLSLCaps& caps, GrProces sorKeyBuilder* b) { 78 static void GenKey(const GrProcessor& proc, const GrGLSLCaps& caps, GrProces sorKeyBuilder* b) {
82 const GrArithmeticFP& arith = proc.cast<GrArithmeticFP>(); 79 const GrArithmeticFP& arith = proc.cast<GrArithmeticFP>();
83 uint32_t key = arith.enforcePMColor() ? 1 : 0; 80 uint32_t key = arith.enforcePMColor() ? 1 : 0;
84 b->add32(key); 81 b->add32(key);
85 } 82 }
86 83
87 protected: 84 protected:
88 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& pro c) override { 85 void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& pro c) override {
89 const GrArithmeticFP& arith = proc.cast<GrArithmeticFP>(); 86 const GrArithmeticFP& arith = proc.cast<GrArithmeticFP>();
90 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); 87 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4());
91 fEnforcePMColor = arith.enforcePMColor();
92 } 88 }
93 89
94 private: 90 private:
95 GrGLSLProgramDataManager::UniformHandle fKUni; 91 GrGLSLProgramDataManager::UniformHandle fKUni;
96 bool fEnforcePMColor;
97 92
98 typedef GrGLSLFragmentProcessor INHERITED; 93 typedef GrGLSLFragmentProcessor INHERITED;
99 }; 94 };
100 95
101 /////////////////////////////////////////////////////////////////////////////// 96 ///////////////////////////////////////////////////////////////////////////////
102 97
103 GrArithmeticFP::GrArithmeticFP(float k1, float k2, float k3, float k4, bool enfo rcePMColor, 98 GrArithmeticFP::GrArithmeticFP(float k1, float k2, float k3, float k4, bool enfo rcePMColor,
104 const GrFragmentProcessor* dst) 99 const GrFragmentProcessor* dst)
105 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) { 100 : fK1(k1), fK2(k2), fK3(k3), fK4(k4), fEnforcePMColor(enforcePMColor) {
106 this->initClassID<GrArithmeticFP>(); 101 this->initClassID<GrArithmeticFP>();
107 102
108 SkASSERT(dst); 103 SkASSERT(dst);
109 SkDEBUGCODE(int dstIndex = )this->registerChildProcessor(dst); 104 SkDEBUGCODE(int dstIndex = )this->registerChildProcessor(dst);
110 SkASSERT(0 == dstIndex); 105 SkASSERT(0 == dstIndex);
111 } 106 }
112 107
113 void GrArithmeticFP::onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKe yBuilder* b) const { 108 void GrArithmeticFP::onGetGLSLProcessorKey(const GrGLSLCaps& caps, GrProcessorKe yBuilder* b) const {
114 GLArithmeticFP::GenKey(*this, caps, b); 109 GLArithmeticFP::GenKey(*this, caps, b);
115 } 110 }
116 111
117 GrGLSLFragmentProcessor* GrArithmeticFP::onCreateGLSLInstance() const { 112 GrGLSLFragmentProcessor* GrArithmeticFP::onCreateGLSLInstance() const {
118 return new GLArithmeticFP(*this); 113 return new GLArithmeticFP;
119 } 114 }
120 115
121 bool GrArithmeticFP::onIsEqual(const GrFragmentProcessor& fpBase) const { 116 bool GrArithmeticFP::onIsEqual(const GrFragmentProcessor& fpBase) const {
122 const GrArithmeticFP& fp = fpBase.cast<GrArithmeticFP>(); 117 const GrArithmeticFP& fp = fpBase.cast<GrArithmeticFP>();
123 return fK1 == fp.fK1 && 118 return fK1 == fp.fK1 &&
124 fK2 == fp.fK2 && 119 fK2 == fp.fK2 &&
125 fK3 == fp.fK3 && 120 fK3 == fp.fK3 &&
126 fK4 == fp.fK4 && 121 fK4 == fp.fK4 &&
127 fEnforcePMColor == fp.fEnforcePMColor; 122 fEnforcePMColor == fp.fEnforcePMColor;
128 } 123 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 float k1 = d->fRandom->nextF(); 298 float k1 = d->fRandom->nextF();
304 float k2 = d->fRandom->nextF(); 299 float k2 = d->fRandom->nextF();
305 float k3 = d->fRandom->nextF(); 300 float k3 = d->fRandom->nextF();
306 float k4 = d->fRandom->nextF(); 301 float k4 = d->fRandom->nextF();
307 bool enforcePMColor = d->fRandom->nextBool(); 302 bool enforcePMColor = d->fRandom->nextBool();
308 303
309 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor); 304 return GrArithmeticXPFactory::Create(k1, k2, k3, k4, enforcePMColor);
310 } 305 }
311 306
312 #endif 307 #endif
OLDNEW
« no previous file with comments | « src/effects/SkAlphaThresholdFilter.cpp ('k') | src/effects/SkBlurMaskFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698