| 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 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 bgTexCoord.x /= backdropRect.z; | 702 bgTexCoord.x /= backdropRect.z; |
| 703 bgTexCoord.y /= backdropRect.w; | 703 bgTexCoord.y /= backdropRect.w; |
| 704 return TextureLookup(s_backdropTexture, bgTexCoord); | 704 return TextureLookup(s_backdropTexture, bgTexCoord); |
| 705 } | 705 } |
| 706 | 706 |
| 707 vec4 ApplyBlendMode(vec4 src) { | 707 vec4 ApplyBlendMode(vec4 src) { |
| 708 vec4 dst = GetBackdropColor(); | 708 vec4 dst = GetBackdropColor(); |
| 709 return Blend(src, dst); | 709 return Blend(src, dst); |
| 710 } | 710 } |
| 711 // clang-format off | 711 // clang-format off |
| 712 ); | 712 ); // NOLINT(whitespace/parens) |
| 713 // clang-format on | 713 // clang-format on |
| 714 | 714 |
| 715 return "precision mediump float;" + GetHelperFunctions() + | 715 return "precision mediump float;" + GetHelperFunctions() + |
| 716 GetBlendFunction() + kFunctionApplyBlendMode + shader_string; | 716 GetBlendFunction() + kFunctionApplyBlendMode + shader_string; |
| 717 } | 717 } |
| 718 | 718 |
| 719 std::string FragmentTexBlendMode::GetHelperFunctions() const { | 719 std::string FragmentTexBlendMode::GetHelperFunctions() const { |
| 720 // clang-format off | 720 // clang-format off |
| 721 static const std::string kFunctionHardLight = SHADER0( | 721 static const std::string kFunctionHardLight = SHADER0( |
| 722 // clang-format on | 722 // clang-format on |
| 723 vec3 hardLight(vec4 src, vec4 dst) { | 723 vec3 hardLight(vec4 src, vec4 dst) { |
| 724 vec3 result; | 724 vec3 result; |
| 725 result.r = | 725 result.r = |
| 726 (2.0 * src.r <= src.a) | 726 (2.0 * src.r <= src.a) |
| 727 ? (2.0 * src.r * dst.r) | 727 ? (2.0 * src.r * dst.r) |
| 728 : (src.a * dst.a - 2.0 * (dst.a - dst.r) * (src.a - src.r)); | 728 : (src.a * dst.a - 2.0 * (dst.a - dst.r) * (src.a - src.r)); |
| 729 result.g = | 729 result.g = |
| 730 (2.0 * src.g <= src.a) | 730 (2.0 * src.g <= src.a) |
| 731 ? (2.0 * src.g * dst.g) | 731 ? (2.0 * src.g * dst.g) |
| 732 : (src.a * dst.a - 2.0 * (dst.a - dst.g) * (src.a - src.g)); | 732 : (src.a * dst.a - 2.0 * (dst.a - dst.g) * (src.a - src.g)); |
| 733 result.b = | 733 result.b = |
| 734 (2.0 * src.b <= src.a) | 734 (2.0 * src.b <= src.a) |
| 735 ? (2.0 * src.b * dst.b) | 735 ? (2.0 * src.b * dst.b) |
| 736 : (src.a * dst.a - 2.0 * (dst.a - dst.b) * (src.a - src.b)); | 736 : (src.a * dst.a - 2.0 * (dst.a - dst.b) * (src.a - src.b)); |
| 737 result.rgb += src.rgb * (1.0 - dst.a) + dst.rgb * (1.0 - src.a); | 737 result.rgb += src.rgb * (1.0 - dst.a) + dst.rgb * (1.0 - src.a); |
| 738 return result; | 738 return result; |
| 739 } | 739 } |
| 740 // clang-format off | 740 // clang-format off |
| 741 ); | 741 ); // NOLINT(whitespace/parens) |
| 742 | 742 |
| 743 static const std::string kFunctionColorDodgeComponent = SHADER0( | 743 static const std::string kFunctionColorDodgeComponent = SHADER0( |
| 744 // clang-format on | 744 // clang-format on |
| 745 float getColorDodgeComponent( | 745 float getColorDodgeComponent( |
| 746 float srcc, float srca, float dstc, float dsta) { | 746 float srcc, float srca, float dstc, float dsta) { |
| 747 if (0.0 == dstc) | 747 if (0.0 == dstc) |
| 748 return srcc * (1.0 - dsta); | 748 return srcc * (1.0 - dsta); |
| 749 float d = srca - srcc; | 749 float d = srca - srcc; |
| 750 if (0.0 == d) | 750 if (0.0 == d) |
| 751 return srca * dsta + srcc * (1.0 - dsta) + dstc * (1.0 - srca); | 751 return srca * dsta + srcc * (1.0 - dsta) + dstc * (1.0 - srca); |
| 752 d = min(dsta, dstc * srca / d); | 752 d = min(dsta, dstc * srca / d); |
| 753 return d * srca + srcc * (1.0 - dsta) + dstc * (1.0 - srca); | 753 return d * srca + srcc * (1.0 - dsta) + dstc * (1.0 - srca); |
| 754 } | 754 } |
| 755 // clang-format off | 755 // clang-format off |
| 756 ); | 756 ); // NOLINT(whitespace/parens) |
| 757 | 757 |
| 758 static const std::string kFunctionColorBurnComponent = SHADER0( | 758 static const std::string kFunctionColorBurnComponent = SHADER0( |
| 759 // clang-format on | 759 // clang-format on |
| 760 float getColorBurnComponent( | 760 float getColorBurnComponent( |
| 761 float srcc, float srca, float dstc, float dsta) { | 761 float srcc, float srca, float dstc, float dsta) { |
| 762 if (dsta == dstc) | 762 if (dsta == dstc) |
| 763 return srca * dsta + srcc * (1.0 - dsta) + dstc * (1.0 - srca); | 763 return srca * dsta + srcc * (1.0 - dsta) + dstc * (1.0 - srca); |
| 764 if (0.0 == srcc) | 764 if (0.0 == srcc) |
| 765 return dstc * (1.0 - srca); | 765 return dstc * (1.0 - srca); |
| 766 float d = max(0.0, dsta - (dsta - dstc) * srca / srcc); | 766 float d = max(0.0, dsta - (dsta - dstc) * srca / srcc); |
| 767 return srca * d + srcc * (1.0 - dsta) + dstc * (1.0 - srca); | 767 return srca * d + srcc * (1.0 - dsta) + dstc * (1.0 - srca); |
| 768 } | 768 } |
| 769 // clang-format off | 769 // clang-format off |
| 770 ); | 770 ); // NOLINT(whitespace/parens) |
| 771 | 771 |
| 772 static const std::string kFunctionSoftLightComponentPosDstAlpha = SHADER0( | 772 static const std::string kFunctionSoftLightComponentPosDstAlpha = SHADER0( |
| 773 // clang-format on | 773 // clang-format on |
| 774 float getSoftLightComponent( | 774 float getSoftLightComponent( |
| 775 float srcc, float srca, float dstc, float dsta) { | 775 float srcc, float srca, float dstc, float dsta) { |
| 776 if (2.0 * srcc <= srca) { | 776 if (2.0 * srcc <= srca) { |
| 777 return (dstc * dstc * (srca - 2.0 * srcc)) / dsta + | 777 return (dstc * dstc * (srca - 2.0 * srcc)) / dsta + |
| 778 (1.0 - dsta) * srcc + dstc * (-srca + 2.0 * srcc + 1.0); | 778 (1.0 - dsta) * srcc + dstc * (-srca + 2.0 * srcc + 1.0); |
| 779 } else if (4.0 * dstc <= dsta) { | 779 } else if (4.0 * dstc <= dsta) { |
| 780 float DSqd = dstc * dstc; | 780 float DSqd = dstc * dstc; |
| 781 float DCub = DSqd * dstc; | 781 float DCub = DSqd * dstc; |
| 782 float DaSqd = dsta * dsta; | 782 float DaSqd = dsta * dsta; |
| 783 float DaCub = DaSqd * dsta; | 783 float DaCub = DaSqd * dsta; |
| 784 return (-DaCub * srcc + | 784 return (-DaCub * srcc + |
| 785 DaSqd * (srcc - dstc * (3.0 * srca - 6.0 * srcc - 1.0)) + | 785 DaSqd * (srcc - dstc * (3.0 * srca - 6.0 * srcc - 1.0)) + |
| 786 12.0 * dsta * DSqd * (srca - 2.0 * srcc) - | 786 12.0 * dsta * DSqd * (srca - 2.0 * srcc) - |
| 787 16.0 * DCub * (srca - 2.0 * srcc)) / | 787 16.0 * DCub * (srca - 2.0 * srcc)) / |
| 788 DaSqd; | 788 DaSqd; |
| 789 } else { | 789 } else { |
| 790 return -sqrt(dsta * dstc) * (srca - 2.0 * srcc) - dsta * srcc + | 790 return -sqrt(dsta * dstc) * (srca - 2.0 * srcc) - dsta * srcc + |
| 791 dstc * (srca - 2.0 * srcc + 1.0) + srcc; | 791 dstc * (srca - 2.0 * srcc + 1.0) + srcc; |
| 792 } | 792 } |
| 793 } | 793 } |
| 794 // clang-format off | 794 // clang-format off |
| 795 ); | 795 ); // NOLINT(whitespace/parens) |
| 796 | 796 |
| 797 static const std::string kFunctionLum = SHADER0( | 797 static const std::string kFunctionLum = SHADER0( |
| 798 // clang-format on | 798 // clang-format on |
| 799 float luminance(vec3 color) { return dot(vec3(0.3, 0.59, 0.11), color); } | 799 float luminance(vec3 color) { return dot(vec3(0.3, 0.59, 0.11), color); } |
| 800 | 800 |
| 801 vec3 set_luminance(vec3 hueSat, float alpha, vec3 lumColor) { | 801 vec3 set_luminance(vec3 hueSat, float alpha, vec3 lumColor) { |
| 802 float diff = luminance(lumColor - hueSat); | 802 float diff = luminance(lumColor - hueSat); |
| 803 vec3 outColor = hueSat + diff; | 803 vec3 outColor = hueSat + diff; |
| 804 float outLum = luminance(outColor); | 804 float outLum = luminance(outColor); |
| 805 float minComp = min(min(outColor.r, outColor.g), outColor.b); | 805 float minComp = min(min(outColor.r, outColor.g), outColor.b); |
| 806 float maxComp = max(max(outColor.r, outColor.g), outColor.b); | 806 float maxComp = max(max(outColor.r, outColor.g), outColor.b); |
| 807 if (minComp < 0.0) { | 807 if (minComp < 0.0) { |
| 808 outColor = outLum + | 808 outColor = outLum + |
| 809 ((outColor - vec3(outLum, outLum, outLum)) * outLum) / | 809 ((outColor - vec3(outLum, outLum, outLum)) * outLum) / |
| 810 (outLum - minComp); | 810 (outLum - minComp); |
| 811 } | 811 } |
| 812 if (maxComp > alpha) { | 812 if (maxComp > alpha) { |
| 813 outColor = | 813 outColor = |
| 814 outLum + | 814 outLum + |
| 815 ((outColor - vec3(outLum, outLum, outLum)) * (alpha - outLum)) / | 815 ((outColor - vec3(outLum, outLum, outLum)) * (alpha - outLum)) / |
| 816 (maxComp - outLum); | 816 (maxComp - outLum); |
| 817 } | 817 } |
| 818 return outColor; | 818 return outColor; |
| 819 } | 819 } |
| 820 // clang-format off | 820 // clang-format off |
| 821 ); | 821 ); // NOLINT(whitespace/parens) |
| 822 | 822 |
| 823 static const std::string kFunctionSat = SHADER0( | 823 static const std::string kFunctionSat = SHADER0( |
| 824 // clang-format on | 824 // clang-format on |
| 825 float saturation(vec3 color) { | 825 float saturation(vec3 color) { |
| 826 return max(max(color.r, color.g), color.b) - | 826 return max(max(color.r, color.g), color.b) - |
| 827 min(min(color.r, color.g), color.b); | 827 min(min(color.r, color.g), color.b); |
| 828 } | 828 } |
| 829 | 829 |
| 830 vec3 set_saturation_helper( | 830 vec3 set_saturation_helper( |
| 831 float minComp, float midComp, float maxComp, float sat) { | 831 float minComp, float midComp, float maxComp, float sat) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 859 } else if (hueLumColor.g <= hueLumColor.b) { | 859 } else if (hueLumColor.g <= hueLumColor.b) { |
| 860 hueLumColor.gbr = set_saturation_helper( | 860 hueLumColor.gbr = set_saturation_helper( |
| 861 hueLumColor.g, hueLumColor.b, hueLumColor.r, sat); | 861 hueLumColor.g, hueLumColor.b, hueLumColor.r, sat); |
| 862 } else { | 862 } else { |
| 863 hueLumColor.bgr = set_saturation_helper( | 863 hueLumColor.bgr = set_saturation_helper( |
| 864 hueLumColor.b, hueLumColor.g, hueLumColor.r, sat); | 864 hueLumColor.b, hueLumColor.g, hueLumColor.r, sat); |
| 865 } | 865 } |
| 866 return hueLumColor; | 866 return hueLumColor; |
| 867 } | 867 } |
| 868 // clang-format off | 868 // clang-format off |
| 869 ); | 869 ); // NOLINT(whitespace/parens) |
| 870 // clang-format on | 870 // clang-format on |
| 871 | 871 |
| 872 switch (blend_mode_) { | 872 switch (blend_mode_) { |
| 873 case BlendModeOverlay: | 873 case BlendModeOverlay: |
| 874 case BlendModeHardLight: | 874 case BlendModeHardLight: |
| 875 return kFunctionHardLight; | 875 return kFunctionHardLight; |
| 876 case BlendModeColorDodge: | 876 case BlendModeColorDodge: |
| 877 return kFunctionColorDodgeComponent; | 877 return kFunctionColorDodgeComponent; |
| 878 case BlendModeColorBurn: | 878 case BlendModeColorBurn: |
| 879 return kFunctionColorBurnComponent; | 879 return kFunctionColorBurnComponent; |
| (...skipping 1099 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1979 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
| 1980 float picker = abs(coord.x - coord.y); // NOLINT | 1980 float picker = abs(coord.x - coord.y); // NOLINT |
| 1981 gl_FragColor = mix(color1, color2, picker) * alpha; | 1981 gl_FragColor = mix(color1, color2, picker) * alpha; |
| 1982 } | 1982 } |
| 1983 // clang-format off | 1983 // clang-format off |
| 1984 ); // NOLINT(whitespace/parens) | 1984 ); // NOLINT(whitespace/parens) |
| 1985 // clang-format on | 1985 // clang-format on |
| 1986 } | 1986 } |
| 1987 | 1987 |
| 1988 } // namespace cc | 1988 } // namespace cc |
| OLD | NEW |