| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/output/shader.h" | 5 #include "cc/output/shader.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 gl_Position = matrix * a_position; | 662 gl_Position = matrix * a_position; |
| 663 v_texCoord = | 663 v_texCoord = |
| 664 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); | 664 vec2(texMatrix * vec4(a_texCoord.x, 1.0 - a_texCoord.y, 0.0, 1.0)); |
| 665 } | 665 } |
| 666 // clang-format off | 666 // clang-format off |
| 667 ); // NOLINT(whitespace/parens) | 667 ); // NOLINT(whitespace/parens) |
| 668 // clang-format on | 668 // clang-format on |
| 669 } | 669 } |
| 670 | 670 |
| 671 #define BLEND_MODE_UNIFORMS "s_backdropTexture", "backdropRect" | 671 #define BLEND_MODE_UNIFORMS "s_backdropTexture", "backdropRect" |
| 672 #define UNUSED_BLEND_MODE_UNIFORMS (is_default_blend_mode() ? 2 : 0) | 672 #define UNUSED_BLEND_MODE_UNIFORMS (!has_blend_mode() ? 2 : 0) |
| 673 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ | 673 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ |
| 674 if (!is_default_blend_mode()) { \ | 674 if (has_blend_mode()) { \ |
| 675 DCHECK_LT(static_cast<size_t>(POS) + 1, arraysize(X)); \ | 675 DCHECK_LT(static_cast<size_t>(POS) + 1, arraysize(X)); \ |
| 676 backdrop_location_ = locations[POS]; \ | 676 backdrop_location_ = locations[POS]; \ |
| 677 backdrop_rect_location_ = locations[POS + 1]; \ | 677 backdrop_rect_location_ = locations[POS + 1]; \ |
| 678 } | 678 } |
| 679 | 679 |
| 680 FragmentTexBlendMode::FragmentTexBlendMode() | 680 FragmentTexBlendMode::FragmentTexBlendMode() |
| 681 : backdrop_location_(-1), | 681 : backdrop_location_(-1), |
| 682 backdrop_rect_location_(-1), | 682 backdrop_rect_location_(-1), |
| 683 blend_mode_(BlendModeNormal) { | 683 blend_mode_(BlendModeNone) { |
| 684 } | 684 } |
| 685 | 685 |
| 686 std::string FragmentTexBlendMode::SetBlendModeFunctions( | 686 std::string FragmentTexBlendMode::SetBlendModeFunctions( |
| 687 std::string shader_string) const { | 687 std::string shader_string) const { |
| 688 if (shader_string.find("ApplyBlendMode") == std::string::npos) | 688 if (shader_string.find("ApplyBlendMode") == std::string::npos) |
| 689 return shader_string; | 689 return shader_string; |
| 690 | 690 |
| 691 if (is_default_blend_mode()) { | 691 if (!has_blend_mode()) { |
| 692 return "#define ApplyBlendMode(X) (X)\n" + shader_string; | 692 return "#define ApplyBlendMode(X) (X)\n" + shader_string; |
| 693 } | 693 } |
| 694 | 694 |
| 695 // clang-format off | 695 // clang-format off |
| 696 static const std::string kFunctionApplyBlendMode = SHADER0( | 696 static const std::string kFunctionApplyBlendMode = SHADER0( |
| 697 // clang-format on | 697 // clang-format on |
| 698 uniform SamplerType s_backdropTexture; | 698 uniform SamplerType s_backdropTexture; |
| 699 uniform TexCoordPrecision vec4 backdropRect; | 699 uniform TexCoordPrecision vec4 backdropRect; |
| 700 | 700 |
| 701 vec4 GetBackdropColor() { | 701 vec4 GetBackdropColor() { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 return "vec4 Blend(vec4 src, vec4 dst) {" | 895 return "vec4 Blend(vec4 src, vec4 dst) {" |
| 896 " vec4 result;" | 896 " vec4 result;" |
| 897 " result.a = src.a + (1.0 - src.a) * dst.a;" + | 897 " result.a = src.a + (1.0 - src.a) * dst.a;" + |
| 898 GetBlendFunctionBodyForRGB() + | 898 GetBlendFunctionBodyForRGB() + |
| 899 " return result;" | 899 " return result;" |
| 900 "}"; | 900 "}"; |
| 901 } | 901 } |
| 902 | 902 |
| 903 std::string FragmentTexBlendMode::GetBlendFunctionBodyForRGB() const { | 903 std::string FragmentTexBlendMode::GetBlendFunctionBodyForRGB() const { |
| 904 switch (blend_mode_) { | 904 switch (blend_mode_) { |
| 905 case BlendModeNormal: |
| 906 return "result.rgb = src.rgb + dst.rgb * (1.0 - src.a);"; |
| 907 case BlendModeScreen: |
| 908 return "result.rgb = src.rgb + (1.0 - src.rgb) * dst.rgb;"; |
| 905 case BlendModeLighten: | 909 case BlendModeLighten: |
| 906 return "result.rgb = max((1.0 - src.a) * dst.rgb + src.rgb," | 910 return "result.rgb = max((1.0 - src.a) * dst.rgb + src.rgb," |
| 907 " (1.0 - dst.a) * src.rgb + dst.rgb);"; | 911 " (1.0 - dst.a) * src.rgb + dst.rgb);"; |
| 908 case BlendModeOverlay: | 912 case BlendModeOverlay: |
| 909 return "result.rgb = hardLight(dst, src);"; | 913 return "result.rgb = hardLight(dst, src);"; |
| 910 case BlendModeDarken: | 914 case BlendModeDarken: |
| 911 return "result.rgb = min((1.0 - src.a) * dst.rgb + src.rgb," | 915 return "result.rgb = min((1.0 - src.a) * dst.rgb + src.rgb," |
| 912 " (1.0 - dst.a) * src.rgb + dst.rgb);"; | 916 " (1.0 - dst.a) * src.rgb + dst.rgb);"; |
| 913 case BlendModeColorDodge: | 917 case BlendModeColorDodge: |
| 914 return "result.r = getColorDodgeComponent(src.r, src.a, dst.r, dst.a);" | 918 return "result.r = getColorDodgeComponent(src.r, src.a, dst.r, dst.a);" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 "result.rgb = set_luminance(srcDstAlpha.rgb," | 960 "result.rgb = set_luminance(srcDstAlpha.rgb," |
| 957 " srcDstAlpha.a," | 961 " srcDstAlpha.a," |
| 958 " dst.rgb * src.a);" | 962 " dst.rgb * src.a);" |
| 959 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;"; | 963 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;"; |
| 960 case BlendModeLuminosity: | 964 case BlendModeLuminosity: |
| 961 return "vec4 srcDstAlpha = src * dst.a;" | 965 return "vec4 srcDstAlpha = src * dst.a;" |
| 962 "result.rgb = set_luminance(dst.rgb * src.a," | 966 "result.rgb = set_luminance(dst.rgb * src.a," |
| 963 " srcDstAlpha.a," | 967 " srcDstAlpha.a," |
| 964 " srcDstAlpha.rgb);" | 968 " srcDstAlpha.rgb);" |
| 965 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;"; | 969 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;"; |
| 966 default: | 970 case BlendModeNone: |
| 971 case NumBlendModes: |
| 967 NOTREACHED(); | 972 NOTREACHED(); |
| 968 // simple alpha compositing | |
| 969 return "result.rgb = src.rgb * src.a + dst.rgb * dst.a * (1 - src.a)"; | |
| 970 } | 973 } |
| 974 return "result = vec4(1.0, 0.0, 0.0, 1.0);"; |
| 971 } | 975 } |
| 972 | 976 |
| 973 FragmentTexAlphaBinding::FragmentTexAlphaBinding() | 977 FragmentTexAlphaBinding::FragmentTexAlphaBinding() |
| 974 : sampler_location_(-1), alpha_location_(-1) { | 978 : sampler_location_(-1), alpha_location_(-1) { |
| 975 } | 979 } |
| 976 | 980 |
| 977 void FragmentTexAlphaBinding::Init(GLES2Interface* context, | 981 void FragmentTexAlphaBinding::Init(GLES2Interface* context, |
| 978 unsigned program, | 982 unsigned program, |
| 979 int* base_uniform_index) { | 983 int* base_uniform_index) { |
| 980 static const char* uniforms[] = { | 984 static const char* uniforms[] = { |
| (...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1980 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1984 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
| 1981 float picker = abs(coord.x - coord.y); // NOLINT | 1985 float picker = abs(coord.x - coord.y); // NOLINT |
| 1982 gl_FragColor = mix(color1, color2, picker) * alpha; | 1986 gl_FragColor = mix(color1, color2, picker) * alpha; |
| 1983 } | 1987 } |
| 1984 // clang-format off | 1988 // clang-format off |
| 1985 ); // NOLINT(whitespace/parens) | 1989 ); // NOLINT(whitespace/parens) |
| 1986 // clang-format on | 1990 // clang-format on |
| 1987 } | 1991 } |
| 1988 | 1992 |
| 1989 } // namespace cc | 1993 } // namespace cc |
| OLD | NEW |