| 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/GrGLEffect.h" |
| 15 #include "gl/GrGLShaderBuilder.h" | 15 #include "gl/builders/GrGLProgramBuilder.h" |
| 16 #include "GrContext.h" | 16 #include "GrContext.h" |
| 17 #include "GrTBackendEffectFactory.h" | 17 #include "GrTBackendEffectFactory.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 /* |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 class GLEffect : public GrGLEffect { | 83 class GLEffect : public GrGLEffect { |
| 84 public: | 84 public: |
| 85 GLEffect(const GrBackendEffectFactory& factory, | 85 GLEffect(const GrBackendEffectFactory& factory, |
| 86 const GrDrawEffect&) | 86 const GrDrawEffect&) |
| 87 : INHERITED(factory) { | 87 : INHERITED(factory) { |
| 88 } | 88 } |
| 89 | 89 |
| 90 static void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuil
der* b) {} | 90 static void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyBuil
der* b) {} |
| 91 | 91 |
| 92 virtual void emitCode(GrGLShaderBuilder* builder, | 92 virtual void emitCode(GrGLProgramBuilder* builder, |
| 93 const GrDrawEffect&, | 93 const GrDrawEffect&, |
| 94 const GrEffectKey&, | 94 const GrEffectKey&, |
| 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 builder->fsCodeAppendf("\tfloat luma = dot(vec3(%f, %f, %f), %s.rgb)
;\n", | 103 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBui
lder(); |
| 104 fsBuilder->codeAppendf("\tfloat luma = dot(vec3(%f, %f, %f), %s.rgb)
;\n", |
| 104 SK_ITU_BT709_LUM_COEFF_R, | 105 SK_ITU_BT709_LUM_COEFF_R, |
| 105 SK_ITU_BT709_LUM_COEFF_G, | 106 SK_ITU_BT709_LUM_COEFF_G, |
| 106 SK_ITU_BT709_LUM_COEFF_B, | 107 SK_ITU_BT709_LUM_COEFF_B, |
| 107 inputColor); | 108 inputColor); |
| 108 builder->fsCodeAppendf("\t%s = vec4(0, 0, 0, luma);\n", | 109 fsBuilder->codeAppendf("\t%s = vec4(0, 0, 0, luma);\n", |
| 109 outputColor); | 110 outputColor); |
| 110 | 111 |
| 111 } | 112 } |
| 112 | 113 |
| 113 private: | 114 private: |
| 114 typedef GrGLEffect INHERITED; | 115 typedef GrGLEffect INHERITED; |
| 115 }; | 116 }; |
| 116 | 117 |
| 117 private: | 118 private: |
| 118 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { | 119 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { |
| 119 return true; | 120 return true; |
| 120 } | 121 } |
| 121 }; | 122 }; |
| 122 | 123 |
| 123 GrEffect* SkLumaColorFilter::asNewEffect(GrContext*) const { | 124 GrEffect* SkLumaColorFilter::asNewEffect(GrContext*) const { |
| 124 return LumaColorFilterEffect::Create(); | 125 return LumaColorFilterEffect::Create(); |
| 125 } | 126 } |
| 126 #endif | 127 #endif |
| OLD | NEW |