OLD | NEW |
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" |
11 #include "SkString.h" | 11 #include "SkString.h" |
12 | 12 |
13 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
14 #include "GrContext.h" | 14 #include "GrContext.h" |
15 #include "GrInvariantOutput.h" | 15 #include "GrInvariantOutput.h" |
16 #include "gl/GrGLFragmentProcessor.h" | 16 #include "glsl/GrGLSLFragmentProcessor.h" |
17 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 17 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
18 #include "glsl/GrGLSLProgramBuilder.h" | 18 #include "glsl/GrGLSLProgramBuilder.h" |
19 #endif | 19 #endif |
20 | 20 |
21 void SkLumaColorFilter::filterSpan(const SkPMColor src[], int count, | 21 void SkLumaColorFilter::filterSpan(const SkPMColor src[], int count, |
22 SkPMColor dst[]) const { | 22 SkPMColor dst[]) const { |
23 for (int i = 0; i < count; ++i) { | 23 for (int i = 0; i < count; ++i) { |
24 SkPMColor c = src[i]; | 24 SkPMColor c = src[i]; |
25 | 25 |
26 /* | 26 /* |
(...skipping 27 matching lines...) Expand all Loading... |
54 | 54 |
55 #if SK_SUPPORT_GPU | 55 #if SK_SUPPORT_GPU |
56 class LumaColorFilterEffect : public GrFragmentProcessor { | 56 class LumaColorFilterEffect : public GrFragmentProcessor { |
57 public: | 57 public: |
58 static const GrFragmentProcessor* Create() { | 58 static const GrFragmentProcessor* Create() { |
59 return new LumaColorFilterEffect; | 59 return new LumaColorFilterEffect; |
60 } | 60 } |
61 | 61 |
62 const char* name() const override { return "Luminance-to-Alpha"; } | 62 const char* name() const override { return "Luminance-to-Alpha"; } |
63 | 63 |
64 class GLProcessor : public GrGLFragmentProcessor { | 64 class GLProcessor : public GrGLSLFragmentProcessor { |
65 public: | 65 public: |
66 GLProcessor(const GrProcessor&) {} | 66 GLProcessor(const GrProcessor&) {} |
67 | 67 |
68 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder* b) {} | 68 static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKey
Builder* b) {} |
69 | 69 |
70 virtual void emitCode(EmitArgs& args) override { | 70 virtual void emitCode(EmitArgs& args) override { |
71 if (nullptr == args.fInputColor) { | 71 if (nullptr == args.fInputColor) { |
72 args.fInputColor = "vec4(1)"; | 72 args.fInputColor = "vec4(1)"; |
73 } | 73 } |
74 | 74 |
75 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderB
uilder(); | 75 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderB
uilder(); |
76 fsBuilder->codeAppendf("\tfloat luma = dot(vec3(%f, %f, %f), %s.rgb)
;\n", | 76 fsBuilder->codeAppendf("\tfloat luma = dot(vec3(%f, %f, %f), %s.rgb)
;\n", |
77 SK_ITU_BT709_LUM_COEFF_R, | 77 SK_ITU_BT709_LUM_COEFF_R, |
78 SK_ITU_BT709_LUM_COEFF_G, | 78 SK_ITU_BT709_LUM_COEFF_G, |
79 SK_ITU_BT709_LUM_COEFF_B, | 79 SK_ITU_BT709_LUM_COEFF_B, |
80 args.fInputColor); | 80 args.fInputColor); |
81 fsBuilder->codeAppendf("\t%s = vec4(0, 0, 0, luma);\n", | 81 fsBuilder->codeAppendf("\t%s = vec4(0, 0, 0, luma);\n", |
82 args.fOutputColor); | 82 args.fOutputColor); |
83 | 83 |
84 } | 84 } |
85 | 85 |
86 private: | 86 private: |
87 typedef GrGLFragmentProcessor INHERITED; | 87 typedef GrGLSLFragmentProcessor INHERITED; |
88 }; | 88 }; |
89 | 89 |
90 private: | 90 private: |
91 LumaColorFilterEffect() { | 91 LumaColorFilterEffect() { |
92 this->initClassID<LumaColorFilterEffect>(); | 92 this->initClassID<LumaColorFilterEffect>(); |
93 } | 93 } |
94 | 94 |
95 GrGLFragmentProcessor* onCreateGLInstance() const override { return new GLPr
ocessor(*this); } | 95 GrGLSLFragmentProcessor* onCreateGLInstance() const override { return new GL
Processor(*this); } |
96 | 96 |
97 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, | 97 virtual void onGetGLProcessorKey(const GrGLSLCaps& caps, |
98 GrProcessorKeyBuilder* b) const override { | 98 GrProcessorKeyBuilder* b) const override { |
99 GLProcessor::GenKey(*this, caps, b); | 99 GLProcessor::GenKey(*this, caps, b); |
100 } | 100 } |
101 | 101 |
102 bool onIsEqual(const GrFragmentProcessor&) const override { return true; } | 102 bool onIsEqual(const GrFragmentProcessor&) const override { return true; } |
103 | 103 |
104 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 104 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
105 // The output is always black. The alpha value for the color passed in i
s arbitrary. | 105 // The output is always black. The alpha value for the color passed in i
s arbitrary. |
106 inout->setToOther(kRGB_GrColorComponentFlags, GrColorPackRGBA(0, 0, 0, 0
), | 106 inout->setToOther(kRGB_GrColorComponentFlags, GrColorPackRGBA(0, 0, 0, 0
), |
107 GrInvariantOutput::kWill_ReadInput); | 107 GrInvariantOutput::kWill_ReadInput); |
108 } | 108 } |
109 }; | 109 }; |
110 | 110 |
111 const GrFragmentProcessor* SkLumaColorFilter::asFragmentProcessor(GrContext*) co
nst { | 111 const GrFragmentProcessor* SkLumaColorFilter::asFragmentProcessor(GrContext*) co
nst { |
112 | 112 |
113 return LumaColorFilterEffect::Create(); | 113 return LumaColorFilterEffect::Create(); |
114 } | 114 } |
115 #endif | 115 #endif |
OLD | NEW |