Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(495)

Side by Side Diff: cc/output/shader.cc

Issue 951673002: Revert "Pull chromium at 2c3ffb2355a27c32f45e508ef861416b820c823b" (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/output/shader.h ('k') | cc/output/shader_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 for (size_t i = 0; i < count; i++) { 45 for (size_t i = 0; i < count; i++) {
46 locations[i] = (*base_uniform_index)++; 46 locations[i] = (*base_uniform_index)++;
47 context->BindUniformLocationCHROMIUM(program, locations[i], uniforms[i]); 47 context->BindUniformLocationCHROMIUM(program, locations[i], uniforms[i]);
48 } 48 }
49 } 49 }
50 50
51 static std::string SetFragmentTexCoordPrecision( 51 static std::string SetFragmentTexCoordPrecision(
52 TexCoordPrecision requested_precision, 52 TexCoordPrecision requested_precision,
53 std::string shader_string) { 53 std::string shader_string) {
54 switch (requested_precision) { 54 switch (requested_precision) {
55 case TEX_COORD_PRECISION_HIGH: 55 case TexCoordPrecisionHigh:
56 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); 56 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos);
57 return "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" 57 return "#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
58 " #define TexCoordPrecision highp\n" 58 " #define TexCoordPrecision highp\n"
59 "#else\n" 59 "#else\n"
60 " #define TexCoordPrecision mediump\n" 60 " #define TexCoordPrecision mediump\n"
61 "#endif\n" + 61 "#endif\n" +
62 shader_string; 62 shader_string;
63 case TEX_COORD_PRECISION_MEDIUM: 63 case TexCoordPrecisionMedium:
64 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos); 64 DCHECK_NE(shader_string.find("TexCoordPrecision"), std::string::npos);
65 return "#define TexCoordPrecision mediump\n" + shader_string; 65 return "#define TexCoordPrecision mediump\n" + shader_string;
66 case TEX_COORD_PRECISION_NA: 66 case TexCoordPrecisionNA:
67 DCHECK_EQ(shader_string.find("TexCoordPrecision"), std::string::npos); 67 DCHECK_EQ(shader_string.find("TexCoordPrecision"), std::string::npos);
68 DCHECK_EQ(shader_string.find("texture2D"), std::string::npos); 68 DCHECK_EQ(shader_string.find("texture2D"), std::string::npos);
69 DCHECK_EQ(shader_string.find("texture2DRect"), std::string::npos); 69 DCHECK_EQ(shader_string.find("texture2DRect"), std::string::npos);
70 return shader_string; 70 return shader_string;
71 default: 71 default:
72 NOTREACHED(); 72 NOTREACHED();
73 break; 73 break;
74 } 74 }
75 return shader_string; 75 return shader_string;
76 } 76 }
(...skipping 20 matching lines...) Expand all
97 GLint range[2] = {14, 14}; 97 GLint range[2] = {14, 14};
98 GLint precision = 10; 98 GLint precision = 10;
99 GLC(context, 99 GLC(context,
100 context->GetShaderPrecisionFormat( 100 context->GetShaderPrecisionFormat(
101 GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT, range, &precision)); 101 GL_FRAGMENT_SHADER, GL_MEDIUM_FLOAT, range, &precision));
102 *highp_threshold_cache = 1 << precision; 102 *highp_threshold_cache = 1 << precision;
103 } 103 }
104 104
105 int highp_threshold = std::max(*highp_threshold_cache, highp_threshold_min); 105 int highp_threshold = std::max(*highp_threshold_cache, highp_threshold_min);
106 if (x > highp_threshold || y > highp_threshold) 106 if (x > highp_threshold || y > highp_threshold)
107 return TEX_COORD_PRECISION_HIGH; 107 return TexCoordPrecisionHigh;
108 return TEX_COORD_PRECISION_MEDIUM; 108 return TexCoordPrecisionMedium;
109 } 109 }
110 110
111 static std::string SetFragmentSamplerType(SamplerType requested_type, 111 static std::string SetFragmentSamplerType(SamplerType requested_type,
112 std::string shader_string) { 112 std::string shader_string) {
113 switch (requested_type) { 113 switch (requested_type) {
114 case SAMPLER_TYPE_2D: 114 case SamplerType2D:
115 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); 115 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos);
116 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); 116 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos);
117 return "#define SamplerType sampler2D\n" 117 return "#define SamplerType sampler2D\n"
118 "#define TextureLookup texture2D\n" + 118 "#define TextureLookup texture2D\n" +
119 shader_string; 119 shader_string;
120 case SAMPLER_TYPE_2D_RECT: 120 case SamplerType2DRect:
121 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); 121 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos);
122 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); 122 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos);
123 return "#extension GL_ARB_texture_rectangle : require\n" 123 return "#extension GL_ARB_texture_rectangle : require\n"
124 "#define SamplerType sampler2DRect\n" 124 "#define SamplerType sampler2DRect\n"
125 "#define TextureLookup texture2DRect\n" + 125 "#define TextureLookup texture2DRect\n" +
126 shader_string; 126 shader_string;
127 case SAMPLER_TYPE_EXTERNAL_OES: 127 case SamplerTypeExternalOES:
128 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos); 128 DCHECK_NE(shader_string.find("SamplerType"), std::string::npos);
129 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos); 129 DCHECK_NE(shader_string.find("TextureLookup"), std::string::npos);
130 return "#extension GL_OES_EGL_image_external : require\n" 130 return "#extension GL_OES_EGL_image_external : require\n"
131 "#define SamplerType samplerExternalOES\n" 131 "#define SamplerType samplerExternalOES\n"
132 "#define TextureLookup texture2D\n" + 132 "#define TextureLookup texture2D\n" +
133 shader_string; 133 shader_string;
134 case SAMPLER_TYPE_NA: 134 case SamplerTypeNA:
135 DCHECK_EQ(shader_string.find("SamplerType"), std::string::npos); 135 DCHECK_EQ(shader_string.find("SamplerType"), std::string::npos);
136 DCHECK_EQ(shader_string.find("TextureLookup"), std::string::npos); 136 DCHECK_EQ(shader_string.find("TextureLookup"), std::string::npos);
137 return shader_string; 137 return shader_string;
138 default: 138 default:
139 NOTREACHED(); 139 NOTREACHED();
140 break; 140 break;
141 } 141 }
142 return shader_string; 142 return shader_string;
143 } 143 }
144 144
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ 727 #define BLEND_MODE_SET_LOCATIONS(X, POS) \
728 if (has_blend_mode()) { \ 728 if (has_blend_mode()) { \
729 DCHECK_LT(static_cast<size_t>(POS) + 1, arraysize(X)); \ 729 DCHECK_LT(static_cast<size_t>(POS) + 1, arraysize(X)); \
730 backdrop_location_ = locations[POS]; \ 730 backdrop_location_ = locations[POS]; \
731 backdrop_rect_location_ = locations[POS + 1]; \ 731 backdrop_rect_location_ = locations[POS + 1]; \
732 } 732 }
733 733
734 FragmentTexBlendMode::FragmentTexBlendMode() 734 FragmentTexBlendMode::FragmentTexBlendMode()
735 : backdrop_location_(-1), 735 : backdrop_location_(-1),
736 backdrop_rect_location_(-1), 736 backdrop_rect_location_(-1),
737 blend_mode_(BLEND_MODE_NONE) { 737 blend_mode_(BlendModeNone) {
738 } 738 }
739 739
740 std::string FragmentTexBlendMode::SetBlendModeFunctions( 740 std::string FragmentTexBlendMode::SetBlendModeFunctions(
741 std::string shader_string) const { 741 std::string shader_string) const {
742 if (shader_string.find("ApplyBlendMode") == std::string::npos) 742 if (shader_string.find("ApplyBlendMode") == std::string::npos)
743 return shader_string; 743 return shader_string;
744 744
745 if (!has_blend_mode()) { 745 if (!has_blend_mode()) {
746 return "#define ApplyBlendMode(X) (X)\n" + shader_string; 746 return "#define ApplyBlendMode(X) (X)\n" + shader_string;
747 } 747 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 hueLumColor.r, sat); 901 hueLumColor.r, sat);
902 } else { 902 } else {
903 hueLumColor.bgr = set_saturation_helper(hueLumColor.b, hueLumColor.g, 903 hueLumColor.bgr = set_saturation_helper(hueLumColor.b, hueLumColor.g,
904 hueLumColor.r, sat); 904 hueLumColor.r, sat);
905 } 905 }
906 return hueLumColor; 906 return hueLumColor;
907 } 907 }
908 }); 908 });
909 909
910 switch (blend_mode_) { 910 switch (blend_mode_) {
911 case BLEND_MODE_OVERLAY: 911 case BlendModeOverlay:
912 case BLEND_MODE_HARD_LIGHT: 912 case BlendModeHardLight:
913 return kFunctionHardLight; 913 return kFunctionHardLight;
914 case BLEND_MODE_COLOR_DODGE: 914 case BlendModeColorDodge:
915 return kFunctionColorDodgeComponent; 915 return kFunctionColorDodgeComponent;
916 case BLEND_MODE_COLOR_BURN: 916 case BlendModeColorBurn:
917 return kFunctionColorBurnComponent; 917 return kFunctionColorBurnComponent;
918 case BLEND_MODE_SOFT_LIGHT: 918 case BlendModeSoftLight:
919 return kFunctionSoftLightComponentPosDstAlpha; 919 return kFunctionSoftLightComponentPosDstAlpha;
920 case BLEND_MODE_HUE: 920 case BlendModeHue:
921 case BLEND_MODE_SATURATION: 921 case BlendModeSaturation:
922 return kFunctionLum + kFunctionSat; 922 return kFunctionLum + kFunctionSat;
923 case BLEND_MODE_COLOR: 923 case BlendModeColor:
924 case BLEND_MODE_LUMINOSITY: 924 case BlendModeLuminosity:
925 return kFunctionLum; 925 return kFunctionLum;
926 default: 926 default:
927 return std::string(); 927 return std::string();
928 } 928 }
929 } 929 }
930 930
931 std::string FragmentTexBlendMode::GetBlendFunction() const { 931 std::string FragmentTexBlendMode::GetBlendFunction() const {
932 return "vec4 Blend(vec4 src, vec4 dst) {" 932 return "vec4 Blend(vec4 src, vec4 dst) {"
933 " vec4 result;" 933 " vec4 result;"
934 " result.a = src.a + (1.0 - src.a) * dst.a;" + 934 " result.a = src.a + (1.0 - src.a) * dst.a;" +
935 GetBlendFunctionBodyForRGB() + 935 GetBlendFunctionBodyForRGB() +
936 " return result;" 936 " return result;"
937 "}"; 937 "}";
938 } 938 }
939 939
940 std::string FragmentTexBlendMode::GetBlendFunctionBodyForRGB() const { 940 std::string FragmentTexBlendMode::GetBlendFunctionBodyForRGB() const {
941 switch (blend_mode_) { 941 switch (blend_mode_) {
942 case BLEND_MODE_NORMAL: 942 case BlendModeNormal:
943 return "result.rgb = src.rgb + dst.rgb * (1.0 - src.a);"; 943 return "result.rgb = src.rgb + dst.rgb * (1.0 - src.a);";
944 case BLEND_MODE_SCREEN: 944 case BlendModeScreen:
945 return "result.rgb = src.rgb + (1.0 - src.rgb) * dst.rgb;"; 945 return "result.rgb = src.rgb + (1.0 - src.rgb) * dst.rgb;";
946 case BLEND_MODE_LIGHTEN: 946 case BlendModeLighten:
947 return "result.rgb = max((1.0 - src.a) * dst.rgb + src.rgb," 947 return "result.rgb = max((1.0 - src.a) * dst.rgb + src.rgb,"
948 " (1.0 - dst.a) * src.rgb + dst.rgb);"; 948 " (1.0 - dst.a) * src.rgb + dst.rgb);";
949 case BLEND_MODE_OVERLAY: 949 case BlendModeOverlay:
950 return "result.rgb = hardLight(dst, src);"; 950 return "result.rgb = hardLight(dst, src);";
951 case BLEND_MODE_DARKEN: 951 case BlendModeDarken:
952 return "result.rgb = min((1.0 - src.a) * dst.rgb + src.rgb," 952 return "result.rgb = min((1.0 - src.a) * dst.rgb + src.rgb,"
953 " (1.0 - dst.a) * src.rgb + dst.rgb);"; 953 " (1.0 - dst.a) * src.rgb + dst.rgb);";
954 case BLEND_MODE_COLOR_DODGE: 954 case BlendModeColorDodge:
955 return "result.r = getColorDodgeComponent(src.r, src.a, dst.r, dst.a);" 955 return "result.r = getColorDodgeComponent(src.r, src.a, dst.r, dst.a);"
956 "result.g = getColorDodgeComponent(src.g, src.a, dst.g, dst.a);" 956 "result.g = getColorDodgeComponent(src.g, src.a, dst.g, dst.a);"
957 "result.b = getColorDodgeComponent(src.b, src.a, dst.b, dst.a);"; 957 "result.b = getColorDodgeComponent(src.b, src.a, dst.b, dst.a);";
958 case BLEND_MODE_COLOR_BURN: 958 case BlendModeColorBurn:
959 return "result.r = getColorBurnComponent(src.r, src.a, dst.r, dst.a);" 959 return "result.r = getColorBurnComponent(src.r, src.a, dst.r, dst.a);"
960 "result.g = getColorBurnComponent(src.g, src.a, dst.g, dst.a);" 960 "result.g = getColorBurnComponent(src.g, src.a, dst.g, dst.a);"
961 "result.b = getColorBurnComponent(src.b, src.a, dst.b, dst.a);"; 961 "result.b = getColorBurnComponent(src.b, src.a, dst.b, dst.a);";
962 case BLEND_MODE_HARD_LIGHT: 962 case BlendModeHardLight:
963 return "result.rgb = hardLight(src, dst);"; 963 return "result.rgb = hardLight(src, dst);";
964 case BLEND_MODE_SOFT_LIGHT: 964 case BlendModeSoftLight:
965 return "if (0.0 == dst.a) {" 965 return "if (0.0 == dst.a) {"
966 " result.rgb = src.rgb;" 966 " result.rgb = src.rgb;"
967 "} else {" 967 "} else {"
968 " result.r = getSoftLightComponent(src.r, src.a, dst.r, dst.a);" 968 " result.r = getSoftLightComponent(src.r, src.a, dst.r, dst.a);"
969 " result.g = getSoftLightComponent(src.g, src.a, dst.g, dst.a);" 969 " result.g = getSoftLightComponent(src.g, src.a, dst.g, dst.a);"
970 " result.b = getSoftLightComponent(src.b, src.a, dst.b, dst.a);" 970 " result.b = getSoftLightComponent(src.b, src.a, dst.b, dst.a);"
971 "}"; 971 "}";
972 case BLEND_MODE_DIFFERENCE: 972 case BlendModeDifference:
973 return "result.rgb = src.rgb + dst.rgb -" 973 return "result.rgb = src.rgb + dst.rgb -"
974 " 2.0 * min(src.rgb * dst.a, dst.rgb * src.a);"; 974 " 2.0 * min(src.rgb * dst.a, dst.rgb * src.a);";
975 case BLEND_MODE_EXCLUSION: 975 case BlendModeExclusion:
976 return "result.rgb = dst.rgb + src.rgb - 2.0 * dst.rgb * src.rgb;"; 976 return "result.rgb = dst.rgb + src.rgb - 2.0 * dst.rgb * src.rgb;";
977 case BLEND_MODE_MULTIPLY: 977 case BlendModeMultiply:
978 return "result.rgb = (1.0 - src.a) * dst.rgb +" 978 return "result.rgb = (1.0 - src.a) * dst.rgb +"
979 " (1.0 - dst.a) * src.rgb + src.rgb * dst.rgb;"; 979 " (1.0 - dst.a) * src.rgb + src.rgb * dst.rgb;";
980 case BLEND_MODE_HUE: 980 case BlendModeHue:
981 return "vec4 dstSrcAlpha = dst * src.a;" 981 return "vec4 dstSrcAlpha = dst * src.a;"
982 "result.rgb =" 982 "result.rgb ="
983 " set_luminance(set_saturation(src.rgb * dst.a," 983 " set_luminance(set_saturation(src.rgb * dst.a,"
984 " dstSrcAlpha.rgb)," 984 " dstSrcAlpha.rgb),"
985 " dstSrcAlpha.a," 985 " dstSrcAlpha.a,"
986 " dstSrcAlpha.rgb);" 986 " dstSrcAlpha.rgb);"
987 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;"; 987 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;";
988 case BLEND_MODE_SATURATION: 988 case BlendModeSaturation:
989 return "vec4 dstSrcAlpha = dst * src.a;" 989 return "vec4 dstSrcAlpha = dst * src.a;"
990 "result.rgb = set_luminance(set_saturation(dstSrcAlpha.rgb," 990 "result.rgb = set_luminance(set_saturation(dstSrcAlpha.rgb,"
991 " src.rgb * dst.a)," 991 " src.rgb * dst.a),"
992 " dstSrcAlpha.a," 992 " dstSrcAlpha.a,"
993 " dstSrcAlpha.rgb);" 993 " dstSrcAlpha.rgb);"
994 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;"; 994 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;";
995 case BLEND_MODE_COLOR: 995 case BlendModeColor:
996 return "vec4 srcDstAlpha = src * dst.a;" 996 return "vec4 srcDstAlpha = src * dst.a;"
997 "result.rgb = set_luminance(srcDstAlpha.rgb," 997 "result.rgb = set_luminance(srcDstAlpha.rgb,"
998 " srcDstAlpha.a," 998 " srcDstAlpha.a,"
999 " dst.rgb * src.a);" 999 " dst.rgb * src.a);"
1000 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;"; 1000 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;";
1001 case BLEND_MODE_LUMINOSITY: 1001 case BlendModeLuminosity:
1002 return "vec4 srcDstAlpha = src * dst.a;" 1002 return "vec4 srcDstAlpha = src * dst.a;"
1003 "result.rgb = set_luminance(dst.rgb * src.a," 1003 "result.rgb = set_luminance(dst.rgb * src.a,"
1004 " srcDstAlpha.a," 1004 " srcDstAlpha.a,"
1005 " srcDstAlpha.rgb);" 1005 " srcDstAlpha.rgb);"
1006 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;"; 1006 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;";
1007 case BLEND_MODE_NONE: 1007 case BlendModeNone:
1008 case NumBlendModes:
1008 NOTREACHED(); 1009 NOTREACHED();
1009 } 1010 }
1010 return "result = vec4(1.0, 0.0, 0.0, 1.0);"; 1011 return "result = vec4(1.0, 0.0, 0.0, 1.0);";
1011 } 1012 }
1012 1013
1013 FragmentTexAlphaBinding::FragmentTexAlphaBinding() 1014 FragmentTexAlphaBinding::FragmentTexAlphaBinding()
1014 : sampler_location_(-1), alpha_location_(-1) { 1015 : sampler_location_(-1), alpha_location_(-1) {
1015 } 1016 }
1016 1017
1017 void FragmentTexAlphaBinding::Init(GLES2Interface* context, 1018 void FragmentTexAlphaBinding::Init(GLES2Interface* context,
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2140 vec2 texCoord = 2141 vec2 texCoord =
2141 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; 2142 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy;
2142 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); 2143 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0);
2143 float picker = abs(coord.x - coord.y); // NOLINT 2144 float picker = abs(coord.x - coord.y); // NOLINT
2144 gl_FragColor = mix(color1, color2, picker) * alpha; 2145 gl_FragColor = mix(color1, color2, picker) * alpha;
2145 } 2146 }
2146 }); 2147 });
2147 } 2148 }
2148 2149
2149 } // namespace cc 2150 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/shader.h ('k') | cc/output/shader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698