| 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" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 } | 113 } |
| 114 | 114 |
| 115 virtual void emitCode(GrGLShaderBuilder* builder, | 115 virtual void emitCode(GrGLShaderBuilder* builder, |
| 116 const GrDrawEffect&, | 116 const GrDrawEffect&, |
| 117 EffectKey, | 117 EffectKey, |
| 118 const char* outputColor, | 118 const char* outputColor, |
| 119 const char* inputColor, | 119 const char* inputColor, |
| 120 const TransformedCoordsArray&, | 120 const TransformedCoordsArray&, |
| 121 const TextureSamplerArray&) SK_OVERRIDE { | 121 const TextureSamplerArray&) SK_OVERRIDE { |
| 122 if (NULL == inputColor) { | 122 if (NULL == inputColor) { |
| 123 inputColor = GrGLSLOnesVecf(4); | 123 inputColor = "vec4(1)"; |
| 124 } | 124 } |
| 125 | 125 |
| 126 // The max() is to guard against 0 / 0 during unpremul when the inco
ming color is | 126 // The max() is to guard against 0 / 0 during unpremul when the inco
ming color is |
| 127 // transparent black. | 127 // transparent black. |
| 128 builder->fsCodeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n
", inputColor); | 128 builder->fsCodeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n
", inputColor); |
| 129 builder->fsCodeAppendf("\tfloat luma = dot(vec3(%f, %f, %f), %s.rgb)
;\n", | 129 builder->fsCodeAppendf("\tfloat luma = dot(vec3(%f, %f, %f), %s.rgb)
;\n", |
| 130 SK_ITU_BT709_LUM_COEFF_R, | 130 SK_ITU_BT709_LUM_COEFF_R, |
| 131 SK_ITU_BT709_LUM_COEFF_G, | 131 SK_ITU_BT709_LUM_COEFF_G, |
| 132 SK_ITU_BT709_LUM_COEFF_B, | 132 SK_ITU_BT709_LUM_COEFF_B, |
| 133 inputColor); | 133 inputColor); |
| 134 builder->fsCodeAppendf("\t%s = vec4(%s.rgb * luma / nonZeroAlpha, lu
ma);\n", | 134 builder->fsCodeAppendf("\t%s = vec4(%s.rgb * luma / nonZeroAlpha, lu
ma);\n", |
| 135 outputColor, inputColor); | 135 outputColor, inputColor); |
| 136 | 136 |
| 137 } | 137 } |
| 138 | 138 |
| 139 private: | 139 private: |
| 140 typedef GrGLEffect INHERITED; | 140 typedef GrGLEffect INHERITED; |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 private: | 143 private: |
| 144 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { | 144 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE { |
| 145 return true; | 145 return true; |
| 146 } | 146 } |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 GrEffectRef* SkLumaColorFilter::asNewEffect(GrContext*) const { | 149 GrEffectRef* SkLumaColorFilter::asNewEffect(GrContext*) const { |
| 150 return LumaColorFilterEffect::Create(); | 150 return LumaColorFilterEffect::Create(); |
| 151 } | 151 } |
| 152 #endif | 152 #endif |
| OLD | NEW |