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 "gl/GrGLEffect.h" | 14 #include "gl/GrGLProcessor.h" |
15 #include "gl/builders/GrGLProgramBuilder.h" | 15 #include "gl/builders/GrGLProgramBuilder.h" |
16 #include "GrContext.h" | 16 #include "GrContext.h" |
17 #include "GrTBackendEffectFactory.h" | 17 #include "GrTBackendProcessorFactory.h" |
18 #endif | 18 #endif |
19 | 19 |
20 void SkLumaColorFilter::filterSpan(const SkPMColor src[], int count, | 20 void SkLumaColorFilter::filterSpan(const SkPMColor src[], int count, |
21 SkPMColor dst[]) const { | 21 SkPMColor dst[]) const { |
22 for (int i = 0; i < count; ++i) { | 22 for (int i = 0; i < count; ++i) { |
23 SkPMColor c = src[i]; | 23 SkPMColor c = src[i]; |
24 | 24 |
25 /* | 25 /* |
26 * While LuminanceToAlpha is defined to operate on un-premultiplied | 26 * While LuminanceToAlpha is defined to operate on un-premultiplied |
27 * inputs, due to the final alpha scaling it can be computed based on | 27 * inputs, due to the final alpha scaling it can be computed based on |
(...skipping 25 matching lines...) Expand all Loading... |
53 | 53 |
54 void SkLumaColorFilter::flatten(SkWriteBuffer&) const {} | 54 void SkLumaColorFilter::flatten(SkWriteBuffer&) const {} |
55 | 55 |
56 #ifndef SK_IGNORE_TO_STRING | 56 #ifndef SK_IGNORE_TO_STRING |
57 void SkLumaColorFilter::toString(SkString* str) const { | 57 void SkLumaColorFilter::toString(SkString* str) const { |
58 str->append("SkLumaColorFilter "); | 58 str->append("SkLumaColorFilter "); |
59 } | 59 } |
60 #endif | 60 #endif |
61 | 61 |
62 #if SK_SUPPORT_GPU | 62 #if SK_SUPPORT_GPU |
63 class LumaColorFilterEffect : public GrEffect { | 63 class LumaColorFilterEffect : public GrFragmentProcessor { |
64 public: | 64 public: |
65 static GrEffect* Create() { | 65 static GrFragmentProcessor* Create() { |
66 GR_CREATE_STATIC_EFFECT(gLumaEffect, LumaColorFilterEffect, ()); | 66 GR_CREATE_STATIC_FRAGMENT_PROCESSOR(gLumaEffect, LumaColorFilterEffect,
()); |
67 return SkRef(gLumaEffect); | 67 return SkRef(gLumaEffect); |
68 } | 68 } |
69 | 69 |
70 static const char* Name() { return "Luminance-to-Alpha"; } | 70 static const char* Name() { return "Luminance-to-Alpha"; } |
71 | 71 |
72 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { | 72 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE { |
73 return GrTBackendEffectFactory<LumaColorFilterEffect>::getInstance(); | 73 return GrTBackendFragmentProcessorFactory<LumaColorFilterEffect>::getIns
tance(); |
74 } | 74 } |
75 | 75 |
76 virtual void getConstantColorComponents(GrColor* color, | 76 virtual void getConstantColorComponents(GrColor* color, |
77 uint32_t* validFlags) const SK_OVERR
IDE { | 77 uint32_t* validFlags) const SK_OVERR
IDE { |
78 // The output is always black. | 78 // The output is always black. |
79 *color = GrColorPackRGBA(0, 0, 0, GrColorUnpackA(*color)); | 79 *color = GrColorPackRGBA(0, 0, 0, GrColorUnpackA(*color)); |
80 *validFlags = kRGB_GrColorComponentFlags; | 80 *validFlags = kRGB_GrColorComponentFlags; |
81 } | 81 } |
82 | 82 |
83 class GLEffect : public GrGLEffect { | 83 class GLProcessor : public GrGLFragmentProcessor { |
84 public: | 84 public: |
85 GLEffect(const GrBackendEffectFactory& factory, | 85 GLProcessor(const GrBackendProcessorFactory& factory, |
86 const GrEffect&) | 86 const GrProcessor&) |
87 : INHERITED(factory) { | 87 : INHERITED(factory) { |
88 } | 88 } |
89 | 89 |
90 static void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuilder*
b) {} | 90 static void GenKey(const GrProcessor&, const GrGLCaps&, GrProcessorKeyBu
ilder* b) {} |
91 | 91 |
92 virtual void emitCode(GrGLProgramBuilder* builder, | 92 virtual void emitCode(GrGLProgramBuilder* builder, |
93 const GrEffect&, | 93 const GrFragmentProcessor&, |
94 const GrEffectKey&, | 94 const GrProcessorKey&, |
95 const char* outputColor, | 95 const char* outputColor, |
96 const char* inputColor, | 96 const char* inputColor, |
97 const TransformedCoordsArray&, | 97 const TransformedCoordsArray&, |
98 const TextureSamplerArray&) SK_OVERRIDE { | 98 const TextureSamplerArray&) SK_OVERRIDE { |
99 if (NULL == inputColor) { | 99 if (NULL == inputColor) { |
100 inputColor = "vec4(1)"; | 100 inputColor = "vec4(1)"; |
101 } | 101 } |
102 | 102 |
103 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui
lder(); | 103 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui
lder(); |
104 fsBuilder->codeAppendf("\tfloat luma = dot(vec3(%f, %f, %f), %s.rgb)
;\n", | 104 fsBuilder->codeAppendf("\tfloat luma = dot(vec3(%f, %f, %f), %s.rgb)
;\n", |
105 SK_ITU_BT709_LUM_COEFF_R, | 105 SK_ITU_BT709_LUM_COEFF_R, |
106 SK_ITU_BT709_LUM_COEFF_G, | 106 SK_ITU_BT709_LUM_COEFF_G, |
107 SK_ITU_BT709_LUM_COEFF_B, | 107 SK_ITU_BT709_LUM_COEFF_B, |
108 inputColor); | 108 inputColor); |
109 fsBuilder->codeAppendf("\t%s = vec4(0, 0, 0, luma);\n", | 109 fsBuilder->codeAppendf("\t%s = vec4(0, 0, 0, luma);\n", |
110 outputColor); | 110 outputColor); |
111 | 111 |
112 } | 112 } |
113 | 113 |
114 private: | 114 private: |
115 typedef GrGLEffect INHERITED; | 115 typedef GrGLFragmentProcessor INHERITED; |
116 }; | 116 }; |
117 | 117 |
118 private: | 118 private: |
119 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { | 119 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE { |
120 return true; | 120 return true; |
121 } | 121 } |
122 }; | 122 }; |
123 | 123 |
124 GrEffect* SkLumaColorFilter::asNewEffect(GrContext*) const { | 124 GrFragmentProcessor* SkLumaColorFilter::asFragmentProcessor(GrContext*) const { |
125 return LumaColorFilterEffect::Create(); | 125 return LumaColorFilterEffect::Create(); |
126 } | 126 } |
127 #endif | 127 #endif |
OLD | NEW |