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

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

Issue 2601343002: The great shader refactor: Merge fragment uniforms (Closed)
Patch Set: The great shader refactor: Merge fragment uniforms Created 3 years, 11 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') | no next file » | 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector>
10 11
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 #include "cc/output/static_geometry_binding.h" 14 #include "cc/output/static_geometry_binding.h"
14 #include "gpu/command_buffer/client/gles2_interface.h" 15 #include "gpu/command_buffer/client/gles2_interface.h"
15 #include "ui/gfx/geometry/point.h" 16 #include "ui/gfx/geometry/point.h"
16 #include "ui/gfx/geometry/size.h" 17 #include "ui/gfx/geometry/size.h"
17 18
18 template <size_t size> 19 template <size_t size>
19 std::string StripLambda(const char(&shader)[size]) { 20 std::string StripLambda(const char(&shader)[size]) {
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 "backdropRect" 759 "backdropRect"
759 #define UNUSED_BLEND_MODE_UNIFORMS (!has_blend_mode() ? 3 : 0) 760 #define UNUSED_BLEND_MODE_UNIFORMS (!has_blend_mode() ? 3 : 0)
760 #define BLEND_MODE_SET_LOCATIONS(X, POS) \ 761 #define BLEND_MODE_SET_LOCATIONS(X, POS) \
761 if (has_blend_mode()) { \ 762 if (has_blend_mode()) { \
762 DCHECK_LT(static_cast<size_t>(POS) + 2, arraysize(X)); \ 763 DCHECK_LT(static_cast<size_t>(POS) + 2, arraysize(X)); \
763 backdrop_location_ = locations[POS]; \ 764 backdrop_location_ = locations[POS]; \
764 original_backdrop_location_ = locations[POS + 1]; \ 765 original_backdrop_location_ = locations[POS + 1]; \
765 backdrop_rect_location_ = locations[POS + 2]; \ 766 backdrop_rect_location_ = locations[POS + 2]; \
766 } 767 }
767 768
768 FragmentShaderBase::FragmentShaderBase() 769 FragmentShaderBase::FragmentShaderBase() {}
769 : backdrop_location_(-1),
770 original_backdrop_location_(-1),
771 backdrop_rect_location_(-1),
772 blend_mode_(BLEND_MODE_NONE),
773 mask_for_background_(false) {}
774 770
775 std::string FragmentShaderBase::GetShaderString(TexCoordPrecision precision, 771 std::string FragmentShaderBase::GetShaderString(TexCoordPrecision precision,
776 SamplerType sampler) const { 772 SamplerType sampler) const {
777 return SetFragmentTexCoordPrecision( 773 return SetFragmentTexCoordPrecision(
778 precision, SetFragmentSamplerType( 774 precision, SetFragmentSamplerType(
779 sampler, SetBlendModeFunctions(GetShaderSource()))); 775 sampler, SetBlendModeFunctions(GetShaderSource())));
780 } 776 }
781 777
778 void FragmentShaderBase::Init(GLES2Interface* context,
779 unsigned program,
780 int* base_uniform_index) {
781 std::vector<const char*> uniforms;
782 std::vector<int> locations;
783 if (has_blend_mode()) {
784 uniforms.push_back("s_backdropTexture");
785 uniforms.push_back("s_originalBackdropTexture");
786 uniforms.push_back("backdropRect");
787 }
788 if (has_mask_sampler_) {
789 uniforms.push_back("s_mask");
790 uniforms.push_back("maskTexCoordScale");
791 uniforms.push_back("maskTexCoordOffset");
792 }
793 if (has_color_matrix_) {
794 uniforms.push_back("colorMatrix");
795 uniforms.push_back("colorOffset");
796 }
797 if (has_sampler_)
798 uniforms.push_back("s_texture");
799 if (has_uniform_alpha_)
800 uniforms.push_back("alpha");
801 if (has_background_color_)
802 uniforms.push_back("background_color");
803 if (has_fragment_tex_transform_)
804 uniforms.push_back("fragmentTexTransform");
805 if (has_uniform_color_)
806 uniforms.push_back("color");
807
808 locations.resize(uniforms.size());
809
810 GetProgramUniformLocations(context, program, uniforms.size(), uniforms.data(),
811 locations.data(), base_uniform_index);
812
813 size_t index = 0;
814 if (has_blend_mode()) {
815 backdrop_location_ = locations[index++];
816 original_backdrop_location_ = locations[index++];
817 backdrop_rect_location_ = locations[index++];
818 }
819 if (has_mask_sampler_) {
820 mask_sampler_location_ = locations[index++];
821 mask_tex_coord_scale_location_ = locations[index++];
822 mask_tex_coord_offset_location_ = locations[index++];
823 }
824 if (has_color_matrix_) {
825 color_matrix_location_ = locations[index++];
826 color_offset_location_ = locations[index++];
827 }
828 if (has_sampler_)
829 sampler_location_ = locations[index++];
830 if (has_uniform_alpha_)
831 alpha_location_ = locations[index++];
832 if (has_background_color_)
833 background_color_location_ = locations[index++];
834 if (has_fragment_tex_transform_)
835 fragment_tex_transform_location_ = locations[index++];
836 if (has_uniform_color_)
837 color_location_ = locations[index++];
838 DCHECK_EQ(index, locations.size());
839 }
840
841 void FragmentShaderBase::FillLocations(ShaderLocations* locations) const {
842 if (has_blend_mode()) {
843 locations->backdrop = backdrop_location_;
844 locations->backdrop_rect = backdrop_rect_location_;
845 }
846 if (mask_for_background())
847 locations->original_backdrop = original_backdrop_location_;
848 if (has_mask_sampler_) {
849 locations->mask_sampler = mask_sampler_location_;
850 locations->mask_tex_coord_scale = mask_tex_coord_scale_location_;
851 locations->mask_tex_coord_offset = mask_tex_coord_offset_location_;
852 }
853 if (has_color_matrix_) {
854 locations->color_matrix = color_matrix_location_;
855 locations->color_offset = color_offset_location_;
856 }
857 if (has_sampler_)
858 locations->sampler = sampler_location_;
859 if (has_uniform_alpha_)
860 locations->alpha = alpha_location_;
861 }
862
782 std::string FragmentShaderBase::SetBlendModeFunctions( 863 std::string FragmentShaderBase::SetBlendModeFunctions(
783 const std::string& shader_string) const { 864 const std::string& shader_string) const {
784 if (shader_string.find("ApplyBlendMode") == std::string::npos) 865 if (shader_string.find("ApplyBlendMode") == std::string::npos)
785 return shader_string; 866 return shader_string;
786 867
787 if (!has_blend_mode()) { 868 if (!has_blend_mode()) {
788 return "#define ApplyBlendMode(X, Y) (X)\n" + shader_string; 869 return "#define ApplyBlendMode(X, Y) (X)\n" + shader_string;
789 } 870 }
790 871
791 static const std::string kUniforms = SHADER0([]() { 872 static const std::string kUniforms = SHADER0([]() {
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 "result.rgb = set_luminance(dst.rgb * src.a," 1148 "result.rgb = set_luminance(dst.rgb * src.a,"
1068 " srcDstAlpha.a," 1149 " srcDstAlpha.a,"
1069 " srcDstAlpha.rgb);" 1150 " srcDstAlpha.rgb);"
1070 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;"; 1151 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;";
1071 case BLEND_MODE_NONE: 1152 case BLEND_MODE_NONE:
1072 NOTREACHED(); 1153 NOTREACHED();
1073 } 1154 }
1074 return "result = vec4(1.0, 0.0, 0.0, 1.0);"; 1155 return "result = vec4(1.0, 0.0, 0.0, 1.0);";
1075 } 1156 }
1076 1157
1077 FragmentTexAlphaBinding::FragmentTexAlphaBinding()
1078 : sampler_location_(-1), alpha_location_(-1) {
1079 }
1080
1081 void FragmentTexAlphaBinding::Init(GLES2Interface* context,
1082 unsigned program,
1083 int* base_uniform_index) {
1084 static const char* uniforms[] = {
1085 "s_texture", "alpha", BLEND_MODE_UNIFORMS,
1086 };
1087 int locations[arraysize(uniforms)];
1088
1089 GetProgramUniformLocations(context,
1090 program,
1091 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS,
1092 uniforms,
1093 locations,
1094 base_uniform_index);
1095 sampler_location_ = locations[0];
1096 alpha_location_ = locations[1];
1097 BLEND_MODE_SET_LOCATIONS(locations, 2);
1098 }
1099
1100 FragmentTexColorMatrixAlphaBinding::FragmentTexColorMatrixAlphaBinding()
1101 : sampler_location_(-1),
1102 alpha_location_(-1),
1103 color_matrix_location_(-1),
1104 color_offset_location_(-1) {
1105 }
1106
1107 void FragmentTexColorMatrixAlphaBinding::Init(GLES2Interface* context,
1108 unsigned program,
1109 int* base_uniform_index) {
1110 static const char* uniforms[] = {
1111 "s_texture", "alpha", "colorMatrix", "colorOffset", BLEND_MODE_UNIFORMS,
1112 };
1113 int locations[arraysize(uniforms)];
1114
1115 GetProgramUniformLocations(context,
1116 program,
1117 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS,
1118 uniforms,
1119 locations,
1120 base_uniform_index);
1121 sampler_location_ = locations[0];
1122 alpha_location_ = locations[1];
1123 color_matrix_location_ = locations[2];
1124 color_offset_location_ = locations[3];
1125 BLEND_MODE_SET_LOCATIONS(locations, 4);
1126 }
1127
1128 FragmentTexOpaqueBinding::FragmentTexOpaqueBinding() : sampler_location_(-1) {
1129 }
1130
1131 void FragmentTexOpaqueBinding::Init(GLES2Interface* context,
1132 unsigned program,
1133 int* base_uniform_index) {
1134 static const char* uniforms[] = {
1135 "s_texture",
1136 };
1137 int locations[arraysize(uniforms)];
1138
1139 GetProgramUniformLocations(context,
1140 program,
1141 arraysize(uniforms),
1142 uniforms,
1143 locations,
1144 base_uniform_index);
1145 sampler_location_ = locations[0];
1146 }
1147
1148 std::string FragmentShaderRGBATexAlpha::GetShaderSource() const { 1158 std::string FragmentShaderRGBATexAlpha::GetShaderSource() const {
1149 return SHADER0([]() { 1159 return SHADER0([]() {
1150 precision mediump float; 1160 precision mediump float;
1151 varying TexCoordPrecision vec2 v_texCoord; 1161 varying TexCoordPrecision vec2 v_texCoord;
1152 uniform SamplerType s_texture; 1162 uniform SamplerType s_texture;
1153 uniform float alpha; 1163 uniform float alpha;
1154 void main() { 1164 void main() {
1155 vec4 texColor = TextureLookup(s_texture, v_texCoord); 1165 vec4 texColor = TextureLookup(s_texture, v_texCoord);
1156 gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0); 1166 gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0);
1157 } 1167 }
1158 }); 1168 });
1159 } 1169 }
1160 1170
1161 void FragmentShaderRGBATexAlpha::FillLocations(
1162 ShaderLocations* locations) const {
1163 locations->sampler = sampler_location();
1164 locations->alpha = alpha_location();
1165 locations->backdrop = backdrop_location();
1166 locations->backdrop_rect = backdrop_rect_location();
1167 }
1168
1169 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderSource() const { 1171 std::string FragmentShaderRGBATexColorMatrixAlpha::GetShaderSource() const {
1170 return SHADER0([]() { 1172 return SHADER0([]() {
1171 precision mediump float; 1173 precision mediump float;
1172 varying TexCoordPrecision vec2 v_texCoord; 1174 varying TexCoordPrecision vec2 v_texCoord;
1173 uniform SamplerType s_texture; 1175 uniform SamplerType s_texture;
1174 uniform float alpha; 1176 uniform float alpha;
1175 uniform mat4 colorMatrix; 1177 uniform mat4 colorMatrix;
1176 uniform vec4 colorOffset; 1178 uniform vec4 colorOffset;
1177 void main() { 1179 void main() {
1178 vec4 texColor = TextureLookup(s_texture, v_texCoord); 1180 vec4 texColor = TextureLookup(s_texture, v_texCoord);
1179 float nonZeroAlpha = max(texColor.a, 0.00001); 1181 float nonZeroAlpha = max(texColor.a, 0.00001);
1180 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); 1182 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha);
1181 texColor = colorMatrix * texColor + colorOffset; 1183 texColor = colorMatrix * texColor + colorOffset;
1182 texColor.rgb *= texColor.a; 1184 texColor.rgb *= texColor.a;
1183 texColor = clamp(texColor, 0.0, 1.0); 1185 texColor = clamp(texColor, 0.0, 1.0);
1184 gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0); 1186 gl_FragColor = ApplyBlendMode(texColor * alpha, 0.0);
1185 } 1187 }
1186 }); 1188 });
1187 } 1189 }
1188 1190
1189 void FragmentShaderRGBATexColorMatrixAlpha::FillLocations(
1190 ShaderLocations* locations) const {
1191 locations->sampler = sampler_location();
1192 locations->alpha = alpha_location();
1193 locations->color_matrix = color_matrix_location();
1194 locations->color_offset = color_offset_location();
1195 locations->backdrop = backdrop_location();
1196 locations->backdrop_rect = backdrop_rect_location();
1197 }
1198
1199 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderSource() const { 1191 std::string FragmentShaderRGBATexVaryingAlpha::GetShaderSource() const {
1200 return SHADER0([]() { 1192 return SHADER0([]() {
1201 precision mediump float; 1193 precision mediump float;
1202 varying TexCoordPrecision vec2 v_texCoord; 1194 varying TexCoordPrecision vec2 v_texCoord;
1203 varying float v_alpha; 1195 varying float v_alpha;
1204 uniform SamplerType s_texture; 1196 uniform SamplerType s_texture;
1205 void main() { 1197 void main() {
1206 vec4 texColor = TextureLookup(s_texture, v_texCoord); 1198 vec4 texColor = TextureLookup(s_texture, v_texCoord);
1207 gl_FragColor = texColor * v_alpha; 1199 gl_FragColor = texColor * v_alpha;
1208 } 1200 }
1209 }); 1201 });
1210 } 1202 }
1211 1203
1212 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderSource() const { 1204 std::string FragmentShaderRGBATexPremultiplyAlpha::GetShaderSource() const {
1213 return SHADER0([]() { 1205 return SHADER0([]() {
1214 precision mediump float; 1206 precision mediump float;
1215 varying TexCoordPrecision vec2 v_texCoord; 1207 varying TexCoordPrecision vec2 v_texCoord;
1216 varying float v_alpha; 1208 varying float v_alpha;
1217 uniform SamplerType s_texture; 1209 uniform SamplerType s_texture;
1218 void main() { 1210 void main() {
1219 vec4 texColor = TextureLookup(s_texture, v_texCoord); 1211 vec4 texColor = TextureLookup(s_texture, v_texCoord);
1220 texColor.rgb *= texColor.a; 1212 texColor.rgb *= texColor.a;
1221 gl_FragColor = texColor * v_alpha; 1213 gl_FragColor = texColor * v_alpha;
1222 } 1214 }
1223 }); 1215 });
1224 } 1216 }
1225 1217
1226 FragmentTexBackgroundBinding::FragmentTexBackgroundBinding()
1227 : background_color_location_(-1), sampler_location_(-1) {
1228 }
1229
1230 void FragmentTexBackgroundBinding::Init(GLES2Interface* context,
1231 unsigned program,
1232 int* base_uniform_index) {
1233 static const char* uniforms[] = {
1234 "s_texture", "background_color",
1235 };
1236 int locations[arraysize(uniforms)];
1237
1238 GetProgramUniformLocations(context,
1239 program,
1240 arraysize(uniforms),
1241 uniforms,
1242 locations,
1243 base_uniform_index);
1244
1245 sampler_location_ = locations[0];
1246 DCHECK_NE(sampler_location_, -1);
1247
1248 background_color_location_ = locations[1];
1249 DCHECK_NE(background_color_location_, -1);
1250 }
1251
1252 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderSource() const { 1218 std::string FragmentShaderTexBackgroundVaryingAlpha::GetShaderSource() const {
1253 return SHADER0([]() { 1219 return SHADER0([]() {
1254 precision mediump float; 1220 precision mediump float;
1255 varying TexCoordPrecision vec2 v_texCoord; 1221 varying TexCoordPrecision vec2 v_texCoord;
1256 varying float v_alpha; 1222 varying float v_alpha;
1257 uniform vec4 background_color; 1223 uniform vec4 background_color;
1258 uniform SamplerType s_texture; 1224 uniform SamplerType s_texture;
1259 void main() { 1225 void main() {
1260 vec4 texColor = TextureLookup(s_texture, v_texCoord); 1226 vec4 texColor = TextureLookup(s_texture, v_texCoord);
1261 texColor += background_color * (1.0 - texColor.a); 1227 texColor += background_color * (1.0 - texColor.a);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 precision mediump float; 1287 precision mediump float;
1322 varying TexCoordPrecision vec2 v_texCoord; 1288 varying TexCoordPrecision vec2 v_texCoord;
1323 uniform SamplerType s_texture; 1289 uniform SamplerType s_texture;
1324 void main() { 1290 void main() {
1325 vec4 texColor = TextureLookup(s_texture, v_texCoord); 1291 vec4 texColor = TextureLookup(s_texture, v_texCoord);
1326 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0); 1292 gl_FragColor = vec4(texColor.z, texColor.y, texColor.x, 1.0);
1327 } 1293 }
1328 }); 1294 });
1329 } 1295 }
1330 1296
1331 FragmentShaderRGBATexAlphaAA::FragmentShaderRGBATexAlphaAA()
1332 : sampler_location_(-1), alpha_location_(-1) {
1333 }
1334
1335 void FragmentShaderRGBATexAlphaAA::Init(GLES2Interface* context,
1336 unsigned program,
1337 int* base_uniform_index) {
1338 static const char* uniforms[] = {
1339 "s_texture", "alpha", BLEND_MODE_UNIFORMS,
1340 };
1341 int locations[arraysize(uniforms)];
1342
1343 GetProgramUniformLocations(context,
1344 program,
1345 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS,
1346 uniforms,
1347 locations,
1348 base_uniform_index);
1349 sampler_location_ = locations[0];
1350 alpha_location_ = locations[1];
1351 BLEND_MODE_SET_LOCATIONS(locations, 2);
1352 }
1353
1354 std::string FragmentShaderRGBATexAlphaAA::GetShaderSource() const { 1297 std::string FragmentShaderRGBATexAlphaAA::GetShaderSource() const {
1355 return SHADER0([]() { 1298 return SHADER0([]() {
1356 precision mediump float; 1299 precision mediump float;
1357 uniform SamplerType s_texture; 1300 uniform SamplerType s_texture;
1358 uniform float alpha; 1301 uniform float alpha;
1359 varying TexCoordPrecision vec2 v_texCoord; 1302 varying TexCoordPrecision vec2 v_texCoord;
1360 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 1303 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
1361 void main() { 1304 void main() {
1362 vec4 texColor = TextureLookup(s_texture, v_texCoord); 1305 vec4 texColor = TextureLookup(s_texture, v_texCoord);
1363 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1306 vec4 d4 = min(edge_dist[0], edge_dist[1]);
1364 vec2 d2 = min(d4.xz, d4.yw); 1307 vec2 d2 = min(d4.xz, d4.yw);
1365 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1308 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
1366 gl_FragColor = ApplyBlendMode(texColor * alpha * aa, 0.0); 1309 gl_FragColor = ApplyBlendMode(texColor * alpha * aa, 0.0);
1367 } 1310 }
1368 }); 1311 });
1369 } 1312 }
1370 1313
1371 void FragmentShaderRGBATexAlphaAA::FillLocations(
1372 ShaderLocations* locations) const {
1373 locations->sampler = sampler_location();
1374 locations->alpha = alpha_location();
1375 locations->backdrop = backdrop_location();
1376 locations->backdrop_rect = backdrop_rect_location();
1377 }
1378
1379 FragmentTexClampAlphaAABinding::FragmentTexClampAlphaAABinding()
1380 : sampler_location_(-1),
1381 alpha_location_(-1),
1382 fragment_tex_transform_location_(-1) {
1383 }
1384
1385 void FragmentTexClampAlphaAABinding::Init(GLES2Interface* context,
1386 unsigned program,
1387 int* base_uniform_index) {
1388 static const char* uniforms[] = {
1389 "s_texture", "alpha", "fragmentTexTransform",
1390 };
1391 int locations[arraysize(uniforms)];
1392
1393 GetProgramUniformLocations(context,
1394 program,
1395 arraysize(uniforms),
1396 uniforms,
1397 locations,
1398 base_uniform_index);
1399 sampler_location_ = locations[0];
1400 alpha_location_ = locations[1];
1401 fragment_tex_transform_location_ = locations[2];
1402 }
1403
1404 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderSource() const { 1314 std::string FragmentShaderRGBATexClampAlphaAA::GetShaderSource() const {
1405 return SHADER0([]() { 1315 return SHADER0([]() {
1406 precision mediump float; 1316 precision mediump float;
1407 uniform SamplerType s_texture; 1317 uniform SamplerType s_texture;
1408 uniform float alpha; 1318 uniform float alpha;
1409 uniform TexCoordPrecision vec4 fragmentTexTransform; 1319 uniform TexCoordPrecision vec4 fragmentTexTransform;
1410 varying TexCoordPrecision vec2 v_texCoord; 1320 varying TexCoordPrecision vec2 v_texCoord;
1411 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 1321 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
1412 void main() { 1322 void main() {
1413 TexCoordPrecision vec2 texCoord = 1323 TexCoordPrecision vec2 texCoord =
(...skipping 23 matching lines...) Expand all
1437 vec4 texColor = TextureLookup(s_texture, texCoord); 1347 vec4 texColor = TextureLookup(s_texture, texCoord);
1438 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1348 vec4 d4 = min(edge_dist[0], edge_dist[1]);
1439 vec2 d2 = min(d4.xz, d4.yw); 1349 vec2 d2 = min(d4.xz, d4.yw);
1440 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1350 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
1441 gl_FragColor = 1351 gl_FragColor =
1442 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha * aa; 1352 vec4(texColor.z, texColor.y, texColor.x, texColor.w) * alpha * aa;
1443 } 1353 }
1444 }); 1354 });
1445 } 1355 }
1446 1356
1447 FragmentShaderRGBATexAlphaMask::FragmentShaderRGBATexAlphaMask()
1448 : sampler_location_(-1),
1449 mask_sampler_location_(-1),
1450 alpha_location_(-1),
1451 mask_tex_coord_scale_location_(-1) {
1452 }
1453
1454 void FragmentShaderRGBATexAlphaMask::Init(GLES2Interface* context,
1455 unsigned program,
1456 int* base_uniform_index) {
1457 static const char* uniforms[] = {
1458 "s_texture",
1459 "s_mask",
1460 "alpha",
1461 "maskTexCoordScale",
1462 "maskTexCoordOffset",
1463 BLEND_MODE_UNIFORMS,
1464 };
1465 int locations[arraysize(uniforms)];
1466
1467 GetProgramUniformLocations(context,
1468 program,
1469 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS,
1470 uniforms,
1471 locations,
1472 base_uniform_index);
1473 sampler_location_ = locations[0];
1474 mask_sampler_location_ = locations[1];
1475 alpha_location_ = locations[2];
1476 mask_tex_coord_scale_location_ = locations[3];
1477 mask_tex_coord_offset_location_ = locations[4];
1478 BLEND_MODE_SET_LOCATIONS(locations, 5);
1479 }
1480
1481 std::string FragmentShaderRGBATexAlphaMask::GetShaderSource() const { 1357 std::string FragmentShaderRGBATexAlphaMask::GetShaderSource() const {
1482 return SHADER0([]() { 1358 return SHADER0([]() {
1483 precision mediump float; 1359 precision mediump float;
1484 varying TexCoordPrecision vec2 v_texCoord; 1360 varying TexCoordPrecision vec2 v_texCoord;
1485 uniform sampler2D s_texture; 1361 uniform sampler2D s_texture;
1486 uniform SamplerType s_mask; 1362 uniform SamplerType s_mask;
1487 uniform TexCoordPrecision vec2 maskTexCoordScale; 1363 uniform TexCoordPrecision vec2 maskTexCoordScale;
1488 uniform TexCoordPrecision vec2 maskTexCoordOffset; 1364 uniform TexCoordPrecision vec2 maskTexCoordOffset;
1489 uniform float alpha; 1365 uniform float alpha;
1490 void main() { 1366 void main() {
1491 vec4 texColor = texture2D(s_texture, v_texCoord); 1367 vec4 texColor = texture2D(s_texture, v_texCoord);
1492 TexCoordPrecision vec2 maskTexCoord = 1368 TexCoordPrecision vec2 maskTexCoord =
1493 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, 1369 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
1494 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 1370 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
1495 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1371 vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
1496 gl_FragColor = ApplyBlendMode( 1372 gl_FragColor = ApplyBlendMode(
1497 texColor * alpha * maskColor.w, maskColor.w); 1373 texColor * alpha * maskColor.w, maskColor.w);
1498 } 1374 }
1499 }); 1375 });
1500 } 1376 }
1501 1377
1502 void FragmentShaderRGBATexAlphaMask::FillLocations(
1503 ShaderLocations* locations) const {
1504 locations->sampler = sampler_location();
1505 locations->mask_sampler = mask_sampler_location();
1506 locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
1507 locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
1508 locations->alpha = alpha_location();
1509 locations->backdrop = backdrop_location();
1510 locations->backdrop_rect = backdrop_rect_location();
1511 if (mask_for_background())
1512 locations->original_backdrop = original_backdrop_location();
1513 }
1514
1515 FragmentShaderRGBATexAlphaMaskAA::FragmentShaderRGBATexAlphaMaskAA()
1516 : sampler_location_(-1),
1517 mask_sampler_location_(-1),
1518 alpha_location_(-1),
1519 mask_tex_coord_scale_location_(-1),
1520 mask_tex_coord_offset_location_(-1) {
1521 }
1522
1523 void FragmentShaderRGBATexAlphaMaskAA::Init(GLES2Interface* context,
1524 unsigned program,
1525 int* base_uniform_index) {
1526 static const char* uniforms[] = {
1527 "s_texture",
1528 "s_mask",
1529 "alpha",
1530 "maskTexCoordScale",
1531 "maskTexCoordOffset",
1532 BLEND_MODE_UNIFORMS,
1533 };
1534 int locations[arraysize(uniforms)];
1535
1536 GetProgramUniformLocations(context,
1537 program,
1538 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS,
1539 uniforms,
1540 locations,
1541 base_uniform_index);
1542 sampler_location_ = locations[0];
1543 mask_sampler_location_ = locations[1];
1544 alpha_location_ = locations[2];
1545 mask_tex_coord_scale_location_ = locations[3];
1546 mask_tex_coord_offset_location_ = locations[4];
1547 BLEND_MODE_SET_LOCATIONS(locations, 5);
1548 }
1549
1550 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderSource() const { 1378 std::string FragmentShaderRGBATexAlphaMaskAA::GetShaderSource() const {
1551 return SHADER0([]() { 1379 return SHADER0([]() {
1552 precision mediump float; 1380 precision mediump float;
1553 uniform sampler2D s_texture; 1381 uniform sampler2D s_texture;
1554 uniform SamplerType s_mask; 1382 uniform SamplerType s_mask;
1555 uniform TexCoordPrecision vec2 maskTexCoordScale; 1383 uniform TexCoordPrecision vec2 maskTexCoordScale;
1556 uniform TexCoordPrecision vec2 maskTexCoordOffset; 1384 uniform TexCoordPrecision vec2 maskTexCoordOffset;
1557 uniform float alpha; 1385 uniform float alpha;
1558 varying TexCoordPrecision vec2 v_texCoord; 1386 varying TexCoordPrecision vec2 v_texCoord;
1559 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 1387 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
1560 void main() { 1388 void main() {
1561 vec4 texColor = texture2D(s_texture, v_texCoord); 1389 vec4 texColor = texture2D(s_texture, v_texCoord);
1562 TexCoordPrecision vec2 maskTexCoord = 1390 TexCoordPrecision vec2 maskTexCoord =
1563 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, 1391 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
1564 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 1392 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
1565 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1393 vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
1566 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1394 vec4 d4 = min(edge_dist[0], edge_dist[1]);
1567 vec2 d2 = min(d4.xz, d4.yw); 1395 vec2 d2 = min(d4.xz, d4.yw);
1568 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1396 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
1569 gl_FragColor = ApplyBlendMode( 1397 gl_FragColor = ApplyBlendMode(
1570 texColor * alpha * maskColor.w * aa, maskColor.w); 1398 texColor * alpha * maskColor.w * aa, maskColor.w);
1571 } 1399 }
1572 }); 1400 });
1573 } 1401 }
1574 1402
1575 void FragmentShaderRGBATexAlphaMaskAA::FillLocations(
1576 ShaderLocations* locations) const {
1577 locations->sampler = sampler_location();
1578 locations->mask_sampler = mask_sampler_location();
1579 locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
1580 locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
1581 locations->alpha = alpha_location();
1582 locations->backdrop = backdrop_location();
1583 locations->backdrop_rect = backdrop_rect_location();
1584 if (mask_for_background())
1585 locations->original_backdrop = original_backdrop_location();
1586 }
1587
1588 FragmentShaderRGBATexAlphaMaskColorMatrixAA::
1589 FragmentShaderRGBATexAlphaMaskColorMatrixAA()
1590 : sampler_location_(-1),
1591 mask_sampler_location_(-1),
1592 alpha_location_(-1),
1593 mask_tex_coord_scale_location_(-1),
1594 color_matrix_location_(-1),
1595 color_offset_location_(-1) {
1596 }
1597
1598 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::Init(
1599 GLES2Interface* context,
1600 unsigned program,
1601 int* base_uniform_index) {
1602 static const char* uniforms[] = {
1603 "s_texture",
1604 "s_mask",
1605 "alpha",
1606 "maskTexCoordScale",
1607 "maskTexCoordOffset",
1608 "colorMatrix",
1609 "colorOffset",
1610 BLEND_MODE_UNIFORMS,
1611 };
1612 int locations[arraysize(uniforms)];
1613
1614 GetProgramUniformLocations(context,
1615 program,
1616 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS,
1617 uniforms,
1618 locations,
1619 base_uniform_index);
1620 sampler_location_ = locations[0];
1621 mask_sampler_location_ = locations[1];
1622 alpha_location_ = locations[2];
1623 mask_tex_coord_scale_location_ = locations[3];
1624 mask_tex_coord_offset_location_ = locations[4];
1625 color_matrix_location_ = locations[5];
1626 color_offset_location_ = locations[6];
1627 BLEND_MODE_SET_LOCATIONS(locations, 7);
1628 }
1629
1630 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderSource() 1403 std::string FragmentShaderRGBATexAlphaMaskColorMatrixAA::GetShaderSource()
1631 const { 1404 const {
1632 return SHADER0([]() { 1405 return SHADER0([]() {
1633 precision mediump float; 1406 precision mediump float;
1634 uniform sampler2D s_texture; 1407 uniform sampler2D s_texture;
1635 uniform SamplerType s_mask; 1408 uniform SamplerType s_mask;
1636 uniform vec2 maskTexCoordScale; 1409 uniform vec2 maskTexCoordScale;
1637 uniform vec2 maskTexCoordOffset; 1410 uniform vec2 maskTexCoordOffset;
1638 uniform mat4 colorMatrix; 1411 uniform mat4 colorMatrix;
1639 uniform vec4 colorOffset; 1412 uniform vec4 colorOffset;
(...skipping 13 matching lines...) Expand all
1653 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1426 vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
1654 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1427 vec4 d4 = min(edge_dist[0], edge_dist[1]);
1655 vec2 d2 = min(d4.xz, d4.yw); 1428 vec2 d2 = min(d4.xz, d4.yw);
1656 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1429 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
1657 gl_FragColor = ApplyBlendMode( 1430 gl_FragColor = ApplyBlendMode(
1658 texColor * alpha * maskColor.w * aa, maskColor.w); 1431 texColor * alpha * maskColor.w * aa, maskColor.w);
1659 } 1432 }
1660 }); 1433 });
1661 } 1434 }
1662 1435
1663 void FragmentShaderRGBATexAlphaMaskColorMatrixAA::FillLocations(
1664 ShaderLocations* locations) const {
1665 locations->sampler = sampler_location();
1666 locations->alpha = alpha_location();
1667 locations->mask_sampler = mask_sampler_location();
1668 locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
1669 locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
1670 locations->color_matrix = color_matrix_location();
1671 locations->color_offset = color_offset_location();
1672 locations->backdrop = backdrop_location();
1673 locations->backdrop_rect = backdrop_rect_location();
1674 if (mask_for_background())
1675 locations->original_backdrop = original_backdrop_location();
1676 }
1677
1678 FragmentShaderRGBATexAlphaColorMatrixAA::
1679 FragmentShaderRGBATexAlphaColorMatrixAA()
1680 : sampler_location_(-1),
1681 alpha_location_(-1),
1682 color_matrix_location_(-1),
1683 color_offset_location_(-1) {
1684 }
1685
1686 void FragmentShaderRGBATexAlphaColorMatrixAA::Init(GLES2Interface* context,
1687 unsigned program,
1688 int* base_uniform_index) {
1689 static const char* uniforms[] = {
1690 "s_texture", "alpha", "colorMatrix", "colorOffset", BLEND_MODE_UNIFORMS,
1691 };
1692 int locations[arraysize(uniforms)];
1693
1694 GetProgramUniformLocations(context,
1695 program,
1696 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS,
1697 uniforms,
1698 locations,
1699 base_uniform_index);
1700 sampler_location_ = locations[0];
1701 alpha_location_ = locations[1];
1702 color_matrix_location_ = locations[2];
1703 color_offset_location_ = locations[3];
1704 BLEND_MODE_SET_LOCATIONS(locations, 4);
1705 }
1706
1707 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderSource() const { 1436 std::string FragmentShaderRGBATexAlphaColorMatrixAA::GetShaderSource() const {
1708 return SHADER0([]() { 1437 return SHADER0([]() {
1709 precision mediump float; 1438 precision mediump float;
1710 uniform SamplerType s_texture; 1439 uniform SamplerType s_texture;
1711 uniform float alpha; 1440 uniform float alpha;
1712 uniform mat4 colorMatrix; 1441 uniform mat4 colorMatrix;
1713 uniform vec4 colorOffset; 1442 uniform vec4 colorOffset;
1714 varying TexCoordPrecision vec2 v_texCoord; 1443 varying TexCoordPrecision vec2 v_texCoord;
1715 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances. 1444 varying TexCoordPrecision vec4 edge_dist[2]; // 8 edge distances.
1716 void main() { 1445 void main() {
1717 vec4 texColor = TextureLookup(s_texture, v_texCoord); 1446 vec4 texColor = TextureLookup(s_texture, v_texCoord);
1718 float nonZeroAlpha = max(texColor.a, 0.00001); 1447 float nonZeroAlpha = max(texColor.a, 0.00001);
1719 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); 1448 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha);
1720 texColor = colorMatrix * texColor + colorOffset; 1449 texColor = colorMatrix * texColor + colorOffset;
1721 texColor.rgb *= texColor.a; 1450 texColor.rgb *= texColor.a;
1722 texColor = clamp(texColor, 0.0, 1.0); 1451 texColor = clamp(texColor, 0.0, 1.0);
1723 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1452 vec4 d4 = min(edge_dist[0], edge_dist[1]);
1724 vec2 d2 = min(d4.xz, d4.yw); 1453 vec2 d2 = min(d4.xz, d4.yw);
1725 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1454 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
1726 gl_FragColor = ApplyBlendMode(texColor * alpha * aa, 0.0); 1455 gl_FragColor = ApplyBlendMode(texColor * alpha * aa, 0.0);
1727 } 1456 }
1728 }); 1457 });
1729 } 1458 }
1730 1459
1731 void FragmentShaderRGBATexAlphaColorMatrixAA::FillLocations(
1732 ShaderLocations* locations) const {
1733 locations->sampler = sampler_location();
1734 locations->alpha = alpha_location();
1735 locations->color_matrix = color_matrix_location();
1736 locations->color_offset = color_offset_location();
1737 locations->backdrop = backdrop_location();
1738 locations->backdrop_rect = backdrop_rect_location();
1739 }
1740
1741 FragmentShaderRGBATexAlphaMaskColorMatrix::
1742 FragmentShaderRGBATexAlphaMaskColorMatrix()
1743 : sampler_location_(-1),
1744 mask_sampler_location_(-1),
1745 alpha_location_(-1),
1746 mask_tex_coord_scale_location_(-1) {
1747 }
1748
1749 void FragmentShaderRGBATexAlphaMaskColorMatrix::Init(GLES2Interface* context,
1750 unsigned program,
1751 int* base_uniform_index) {
1752 static const char* uniforms[] = {
1753 "s_texture",
1754 "s_mask",
1755 "alpha",
1756 "maskTexCoordScale",
1757 "maskTexCoordOffset",
1758 "colorMatrix",
1759 "colorOffset",
1760 BLEND_MODE_UNIFORMS,
1761 };
1762 int locations[arraysize(uniforms)];
1763
1764 GetProgramUniformLocations(context,
1765 program,
1766 arraysize(uniforms) - UNUSED_BLEND_MODE_UNIFORMS,
1767 uniforms,
1768 locations,
1769 base_uniform_index);
1770 sampler_location_ = locations[0];
1771 mask_sampler_location_ = locations[1];
1772 alpha_location_ = locations[2];
1773 mask_tex_coord_scale_location_ = locations[3];
1774 mask_tex_coord_offset_location_ = locations[4];
1775 color_matrix_location_ = locations[5];
1776 color_offset_location_ = locations[6];
1777 BLEND_MODE_SET_LOCATIONS(locations, 7);
1778 }
1779
1780 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderSource() const { 1460 std::string FragmentShaderRGBATexAlphaMaskColorMatrix::GetShaderSource() const {
1781 return SHADER0([]() { 1461 return SHADER0([]() {
1782 precision mediump float; 1462 precision mediump float;
1783 varying TexCoordPrecision vec2 v_texCoord; 1463 varying TexCoordPrecision vec2 v_texCoord;
1784 uniform sampler2D s_texture; 1464 uniform sampler2D s_texture;
1785 uniform SamplerType s_mask; 1465 uniform SamplerType s_mask;
1786 uniform vec2 maskTexCoordScale; 1466 uniform vec2 maskTexCoordScale;
1787 uniform vec2 maskTexCoordOffset; 1467 uniform vec2 maskTexCoordOffset;
1788 uniform mat4 colorMatrix; 1468 uniform mat4 colorMatrix;
1789 uniform vec4 colorOffset; 1469 uniform vec4 colorOffset;
1790 uniform float alpha; 1470 uniform float alpha;
1791 void main() { 1471 void main() {
1792 vec4 texColor = texture2D(s_texture, v_texCoord); 1472 vec4 texColor = texture2D(s_texture, v_texCoord);
1793 float nonZeroAlpha = max(texColor.a, 0.00001); 1473 float nonZeroAlpha = max(texColor.a, 0.00001);
1794 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha); 1474 texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha);
1795 texColor = colorMatrix * texColor + colorOffset; 1475 texColor = colorMatrix * texColor + colorOffset;
1796 texColor.rgb *= texColor.a; 1476 texColor.rgb *= texColor.a;
1797 texColor = clamp(texColor, 0.0, 1.0); 1477 texColor = clamp(texColor, 0.0, 1.0);
1798 TexCoordPrecision vec2 maskTexCoord = 1478 TexCoordPrecision vec2 maskTexCoord =
1799 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x, 1479 vec2(maskTexCoordOffset.x + v_texCoord.x * maskTexCoordScale.x,
1800 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y); 1480 maskTexCoordOffset.y + v_texCoord.y * maskTexCoordScale.y);
1801 vec4 maskColor = TextureLookup(s_mask, maskTexCoord); 1481 vec4 maskColor = TextureLookup(s_mask, maskTexCoord);
1802 gl_FragColor = ApplyBlendMode( 1482 gl_FragColor = ApplyBlendMode(
1803 texColor * alpha * maskColor.w, maskColor.w); 1483 texColor * alpha * maskColor.w, maskColor.w);
1804 } 1484 }
1805 }); 1485 });
1806 } 1486 }
1807 1487
1808 void FragmentShaderRGBATexAlphaMaskColorMatrix::FillLocations(
1809 ShaderLocations* locations) const {
1810 locations->sampler = sampler_location();
1811 locations->mask_sampler = mask_sampler_location();
1812 locations->mask_tex_coord_scale = mask_tex_coord_scale_location();
1813 locations->mask_tex_coord_offset = mask_tex_coord_offset_location();
1814 locations->alpha = alpha_location();
1815 locations->color_matrix = color_matrix_location();
1816 locations->color_offset = color_offset_location();
1817 locations->backdrop = backdrop_location();
1818 locations->backdrop_rect = backdrop_rect_location();
1819 if (mask_for_background())
1820 locations->original_backdrop = original_backdrop_location();
1821 }
1822
1823 FragmentShaderYUVVideo::FragmentShaderYUVVideo() 1488 FragmentShaderYUVVideo::FragmentShaderYUVVideo()
1824 : y_texture_location_(-1), 1489 : y_texture_location_(-1),
1825 u_texture_location_(-1), 1490 u_texture_location_(-1),
1826 v_texture_location_(-1), 1491 v_texture_location_(-1),
1827 uv_texture_location_(-1), 1492 uv_texture_location_(-1),
1828 a_texture_location_(-1), 1493 a_texture_location_(-1),
1829 lut_texture_location_(-1), 1494 lut_texture_location_(-1),
1830 alpha_location_(-1), 1495 alpha_location_(-1),
1831 yuv_matrix_location_(-1), 1496 yuv_matrix_location_(-1),
1832 yuv_adj_location_(-1), 1497 yuv_adj_location_(-1),
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1975 vec2 uv_clamped = 1640 vec2 uv_clamped =
1976 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); 1641 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord));
1977 vec3 yuv = vec3(y_raw, GetUV(uv_clamped)); 1642 vec3 yuv = vec3(y_raw, GetUV(uv_clamped));
1978 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped); 1643 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped);
1979 } 1644 }
1980 }); 1645 });
1981 1646
1982 return head + functions; 1647 return head + functions;
1983 } 1648 }
1984 1649
1985 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) {
1986 }
1987
1988 void FragmentShaderColor::Init(GLES2Interface* context,
1989 unsigned program,
1990 int* base_uniform_index) {
1991 static const char* uniforms[] = {
1992 "color",
1993 };
1994 int locations[arraysize(uniforms)];
1995
1996 GetProgramUniformLocations(context,
1997 program,
1998 arraysize(uniforms),
1999 uniforms,
2000 locations,
2001 base_uniform_index);
2002 color_location_ = locations[0];
2003 }
2004
2005 std::string FragmentShaderColor::GetShaderSource() const { 1650 std::string FragmentShaderColor::GetShaderSource() const {
2006 return SHADER0([]() { 1651 return SHADER0([]() {
2007 precision mediump float; 1652 precision mediump float;
2008 uniform vec4 color; 1653 uniform vec4 color;
2009 void main() { gl_FragColor = color; } 1654 void main() { gl_FragColor = color; }
2010 }); 1655 });
2011 } 1656 }
2012 1657
2013 FragmentShaderColorAA::FragmentShaderColorAA() : color_location_(-1) {
2014 }
2015
2016 void FragmentShaderColorAA::Init(GLES2Interface* context,
2017 unsigned program,
2018 int* base_uniform_index) {
2019 static const char* uniforms[] = {
2020 "color",
2021 };
2022 int locations[arraysize(uniforms)];
2023
2024 GetProgramUniformLocations(context,
2025 program,
2026 arraysize(uniforms),
2027 uniforms,
2028 locations,
2029 base_uniform_index);
2030 color_location_ = locations[0];
2031 }
2032
2033 std::string FragmentShaderColorAA::GetShaderSource() const { 1658 std::string FragmentShaderColorAA::GetShaderSource() const {
2034 return SHADER0([]() { 1659 return SHADER0([]() {
2035 precision mediump float; 1660 precision mediump float;
2036 uniform vec4 color; 1661 uniform vec4 color;
2037 varying vec4 edge_dist[2]; // 8 edge distances. 1662 varying vec4 edge_dist[2]; // 8 edge distances.
2038 void main() { 1663 void main() {
2039 vec4 d4 = min(edge_dist[0], edge_dist[1]); 1664 vec4 d4 = min(edge_dist[0], edge_dist[1]);
2040 vec2 d2 = min(d4.xz, d4.yw); 1665 vec2 d2 = min(d4.xz, d4.yw);
2041 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 1666 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
2042 gl_FragColor = color * aa; 1667 gl_FragColor = color * aa;
2043 } 1668 }
2044 }); 1669 });
2045 } 1670 }
2046 1671
2047 } // namespace cc 1672 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/shader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698