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/SkLumaColorFilter.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/SkDisplacementMapEffect.cpp ('k') | src/effects/SkMagnifierImageFilter.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 2013 Google Inc. 2 * Copyright 2013 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 "SkLumaColorFilter.h" 8 #include "SkLumaColorFilter.h"
9 9
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 class LumaColorFilterEffect : public GrFragmentProcessor { 55 class LumaColorFilterEffect : public GrFragmentProcessor {
56 public: 56 public:
57 static const GrFragmentProcessor* Create() { 57 static const GrFragmentProcessor* Create() {
58 return new LumaColorFilterEffect; 58 return new LumaColorFilterEffect;
59 } 59 }
60 60
61 const char* name() const override { return "Luminance-to-Alpha"; } 61 const char* name() const override { return "Luminance-to-Alpha"; }
62 62
63 class GLSLProcessor : public GrGLSLFragmentProcessor { 63 class GLSLProcessor : public GrGLSLFragmentProcessor {
64 public: 64 public:
65 GLSLProcessor(const GrProcessor&) {}
66
67 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey Builder* b) {} 65 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey Builder* b) {}
68 66
69 virtual void emitCode(EmitArgs& args) override { 67 void emitCode(EmitArgs& args) override {
70 if (nullptr == args.fInputColor) { 68 if (nullptr == args.fInputColor) {
71 args.fInputColor = "vec4(1)"; 69 args.fInputColor = "vec4(1)";
72 } 70 }
73 71
74 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 72 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
75 fragBuilder->codeAppendf("\tfloat luma = dot(vec3(%f, %f, %f), %s.rg b);\n", 73 fragBuilder->codeAppendf("\tfloat luma = dot(vec3(%f, %f, %f), %s.rg b);\n",
76 SK_ITU_BT709_LUM_COEFF_R, 74 SK_ITU_BT709_LUM_COEFF_R,
77 SK_ITU_BT709_LUM_COEFF_G, 75 SK_ITU_BT709_LUM_COEFF_G,
78 SK_ITU_BT709_LUM_COEFF_B, 76 SK_ITU_BT709_LUM_COEFF_B,
79 args.fInputColor); 77 args.fInputColor);
80 fragBuilder->codeAppendf("\t%s = vec4(0, 0, 0, luma);\n", 78 fragBuilder->codeAppendf("\t%s = vec4(0, 0, 0, luma);\n",
81 args.fOutputColor); 79 args.fOutputColor);
82 80
83 } 81 }
84 82
85 private: 83 private:
86 typedef GrGLSLFragmentProcessor INHERITED; 84 typedef GrGLSLFragmentProcessor INHERITED;
87 }; 85 };
88 86
89 private: 87 private:
90 LumaColorFilterEffect() { 88 LumaColorFilterEffect() {
91 this->initClassID<LumaColorFilterEffect>(); 89 this->initClassID<LumaColorFilterEffect>();
92 } 90 }
93 91
94 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override { 92 GrGLSLFragmentProcessor* onCreateGLSLInstance() const override {
95 return new GLSLProcessor(*this); 93 return new GLSLProcessor;
96 } 94 }
97 95
98 virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps, 96 virtual void onGetGLSLProcessorKey(const GrGLSLCaps& caps,
99 GrProcessorKeyBuilder* b) const override { 97 GrProcessorKeyBuilder* b) const override {
100 GLSLProcessor::GenKey(*this, caps, b); 98 GLSLProcessor::GenKey(*this, caps, b);
101 } 99 }
102 100
103 bool onIsEqual(const GrFragmentProcessor&) const override { return true; } 101 bool onIsEqual(const GrFragmentProcessor&) const override { return true; }
104 102
105 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { 103 void onComputeInvariantOutput(GrInvariantOutput* inout) const override {
106 // The output is always black. The alpha value for the color passed in i s arbitrary. 104 // The output is always black. The alpha value for the color passed in i s arbitrary.
107 inout->setToOther(kRGB_GrColorComponentFlags, GrColorPackRGBA(0, 0, 0, 0 ), 105 inout->setToOther(kRGB_GrColorComponentFlags, GrColorPackRGBA(0, 0, 0, 0 ),
108 GrInvariantOutput::kWill_ReadInput); 106 GrInvariantOutput::kWill_ReadInput);
109 } 107 }
110 }; 108 };
111 109
112 const GrFragmentProcessor* SkLumaColorFilter::asFragmentProcessor(GrContext*) co nst { 110 const GrFragmentProcessor* SkLumaColorFilter::asFragmentProcessor(GrContext*) co nst {
113 111
114 return LumaColorFilterEffect::Create(); 112 return LumaColorFilterEffect::Create();
115 } 113 }
116 #endif 114 #endif
OLDNEW
« no previous file with comments | « src/effects/SkDisplacementMapEffect.cpp ('k') | src/effects/SkMagnifierImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698