| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 int* highp_threshold_cache, | 159 int* highp_threshold_cache, |
| 160 int highp_threshold_min, | 160 int highp_threshold_min, |
| 161 const gfx::Size& max_size) { | 161 const gfx::Size& max_size) { |
| 162 return TexCoordPrecisionRequired(context, | 162 return TexCoordPrecisionRequired(context, |
| 163 highp_threshold_cache, | 163 highp_threshold_cache, |
| 164 highp_threshold_min, | 164 highp_threshold_min, |
| 165 max_size.width(), | 165 max_size.width(), |
| 166 max_size.height()); | 166 max_size.height()); |
| 167 } | 167 } |
| 168 | 168 |
| 169 VertexShaderBase::VertexShaderBase() {} | 169 VertexShader::VertexShader() {} |
| 170 | 170 |
| 171 void VertexShaderBase::Init(GLES2Interface* context, | 171 void VertexShader::Init(GLES2Interface* context, |
| 172 unsigned program, | 172 unsigned program, |
| 173 int* base_uniform_index) { | 173 int* base_uniform_index) { |
| 174 std::vector<const char*> uniforms; | 174 std::vector<const char*> uniforms; |
| 175 std::vector<int> locations; | 175 std::vector<int> locations; |
| 176 | 176 |
| 177 switch (tex_coord_transform_) { | 177 switch (tex_coord_transform_) { |
| 178 case TEX_COORD_TRANSFORM_NONE: | 178 case TEX_COORD_TRANSFORM_NONE: |
| 179 break; | 179 break; |
| 180 case TEX_COORD_TRANSFORM_VEC4: | 180 case TEX_COORD_TRANSFORM_VEC4: |
| 181 case TEX_COORD_TRANSFORM_TRANSLATED_VEC4: | 181 case TEX_COORD_TRANSFORM_TRANSLATED_VEC4: |
| 182 uniforms.push_back("vertexTexTransform"); | 182 uniforms.push_back("vertexTexTransform"); |
| 183 break; | 183 break; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 if (has_vertex_opacity_) | 230 if (has_vertex_opacity_) |
| 231 vertex_opacity_location_ = locations[index++]; | 231 vertex_opacity_location_ = locations[index++]; |
| 232 if (aa_mode_ == USE_AA) { | 232 if (aa_mode_ == USE_AA) { |
| 233 viewport_location_ = locations[index++]; | 233 viewport_location_ = locations[index++]; |
| 234 edge_location_ = locations[index++]; | 234 edge_location_ = locations[index++]; |
| 235 } | 235 } |
| 236 if (position_source_ == POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM) | 236 if (position_source_ == POSITION_SOURCE_ATTRIBUTE_INDEXED_UNIFORM) |
| 237 quad_location_ = locations[index++]; | 237 quad_location_ = locations[index++]; |
| 238 } | 238 } |
| 239 | 239 |
| 240 std::string VertexShaderBase::GetShaderString() const { | 240 std::string VertexShader::GetShaderString() const { |
| 241 // We unconditionally use highp in the vertex shader since | 241 // We unconditionally use highp in the vertex shader since |
| 242 // we are unlikely to be vertex shader bound when drawing large quads. | 242 // we are unlikely to be vertex shader bound when drawing large quads. |
| 243 // Also, some vertex shaders mutate the texture coordinate in such a | 243 // Also, some vertex shaders mutate the texture coordinate in such a |
| 244 // way that the effective precision might be lower than expected. | 244 // way that the effective precision might be lower than expected. |
| 245 std::string header = "#define TexCoordPrecision highp\n"; | 245 std::string header = "#define TexCoordPrecision highp\n"; |
| 246 std::string source = "void main() {\n"; | 246 std::string source = "void main() {\n"; |
| 247 | 247 |
| 248 // Define the size of quads for attribute indexed uniform arrays. | 248 // Define the size of quads for attribute indexed uniform arrays. |
| 249 if (use_uniform_arrays_) { | 249 if (use_uniform_arrays_) { |
| 250 header += base::StringPrintf("#define NUM_QUADS %d\n", | 250 header += base::StringPrintf("#define NUM_QUADS %d\n", |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 if (has_dummy_variables_) { | 375 if (has_dummy_variables_) { |
| 376 HDR("uniform TexCoordPrecision vec2 dummy_uniform;"); | 376 HDR("uniform TexCoordPrecision vec2 dummy_uniform;"); |
| 377 HDR("varying TexCoordPrecision vec2 dummy_varying;"); | 377 HDR("varying TexCoordPrecision vec2 dummy_varying;"); |
| 378 SRC("dummy_varying = dummy_uniform;"); | 378 SRC("dummy_varying = dummy_uniform;"); |
| 379 } | 379 } |
| 380 | 380 |
| 381 source += "}\n"; | 381 source += "}\n"; |
| 382 return header + source; | 382 return header + source; |
| 383 } | 383 } |
| 384 | 384 |
| 385 FragmentShaderBase::FragmentShaderBase() {} | 385 FragmentShader::FragmentShader() {} |
| 386 | 386 |
| 387 std::string FragmentShaderBase::GetShaderString() const { | 387 std::string FragmentShader::GetShaderString() const { |
| 388 // TODO(ccameron): Merge YUV shaders into the main shader generator. |
| 389 std::string source; |
| 390 if (input_color_type_ == INPUT_COLOR_SOURCE_YUV_TEXTURES) |
| 391 source = GetShaderStringYUVVideo(); |
| 392 else |
| 393 source = GetShaderSource(); |
| 394 |
| 388 TexCoordPrecision precision = tex_coord_precision_; | 395 TexCoordPrecision precision = tex_coord_precision_; |
| 389 // The AA shader values will use TexCoordPrecision. | 396 // The AA shader values will use TexCoordPrecision. |
| 390 if (aa_mode_ == USE_AA && precision == TEX_COORD_PRECISION_NA) | 397 if (aa_mode_ == USE_AA && precision == TEX_COORD_PRECISION_NA) |
| 391 precision = TEX_COORD_PRECISION_MEDIUM; | 398 precision = TEX_COORD_PRECISION_MEDIUM; |
| 392 return SetFragmentTexCoordPrecision( | 399 return SetFragmentTexCoordPrecision( |
| 393 precision, SetFragmentSamplerType( | 400 precision, |
| 394 sampler_type_, SetBlendModeFunctions(GetShaderSource()))); | 401 SetFragmentSamplerType(sampler_type_, SetBlendModeFunctions(source))); |
| 395 } | 402 } |
| 396 | 403 |
| 397 void FragmentShaderBase::Init(GLES2Interface* context, | 404 void FragmentShader::Init(GLES2Interface* context, |
| 398 unsigned program, | 405 unsigned program, |
| 399 int* base_uniform_index) { | 406 int* base_uniform_index) { |
| 407 // TODO(ccameron): Merge YUV shaders into the main shader generator. |
| 408 if (input_color_type_ == INPUT_COLOR_SOURCE_YUV_TEXTURES) { |
| 409 InitYUVVideo(context, program, base_uniform_index); |
| 410 return; |
| 411 } |
| 412 |
| 400 std::vector<const char*> uniforms; | 413 std::vector<const char*> uniforms; |
| 401 std::vector<int> locations; | 414 std::vector<int> locations; |
| 402 if (has_blend_mode()) { | 415 if (has_blend_mode()) { |
| 403 uniforms.push_back("s_backdropTexture"); | 416 uniforms.push_back("s_backdropTexture"); |
| 404 uniforms.push_back("s_originalBackdropTexture"); | 417 uniforms.push_back("s_originalBackdropTexture"); |
| 405 uniforms.push_back("backdropRect"); | 418 uniforms.push_back("backdropRect"); |
| 406 } | 419 } |
| 407 if (mask_mode_ != NO_MASK) { | 420 if (mask_mode_ != NO_MASK) { |
| 408 uniforms.push_back("s_mask"); | 421 uniforms.push_back("s_mask"); |
| 409 uniforms.push_back("maskTexCoordScale"); | 422 uniforms.push_back("maskTexCoordScale"); |
| 410 uniforms.push_back("maskTexCoordOffset"); | 423 uniforms.push_back("maskTexCoordOffset"); |
| 411 } | 424 } |
| 412 if (has_color_matrix_) { | 425 if (has_color_matrix_) { |
| 413 uniforms.push_back("colorMatrix"); | 426 uniforms.push_back("colorMatrix"); |
| 414 uniforms.push_back("colorOffset"); | 427 uniforms.push_back("colorOffset"); |
| 415 } | 428 } |
| 416 if (has_uniform_alpha_) | 429 if (has_uniform_alpha_) |
| 417 uniforms.push_back("alpha"); | 430 uniforms.push_back("alpha"); |
| 418 if (has_background_color_) | 431 if (has_background_color_) |
| 419 uniforms.push_back("background_color"); | 432 uniforms.push_back("background_color"); |
| 420 switch (input_color_type_) { | 433 switch (input_color_type_) { |
| 421 case INPUT_COLOR_SOURCE_RGBA_TEXTURE: | 434 case INPUT_COLOR_SOURCE_RGBA_TEXTURE: |
| 422 uniforms.push_back("s_texture"); | 435 uniforms.push_back("s_texture"); |
| 423 if (has_rgba_fragment_tex_transform_) | 436 if (has_rgba_fragment_tex_transform_) |
| 424 uniforms.push_back("fragmentTexTransform"); | 437 uniforms.push_back("fragmentTexTransform"); |
| 425 break; | 438 break; |
| 439 case INPUT_COLOR_SOURCE_YUV_TEXTURES: |
| 440 NOTREACHED(); |
| 441 break; |
| 426 case INPUT_COLOR_SOURCE_UNIFORM: | 442 case INPUT_COLOR_SOURCE_UNIFORM: |
| 427 uniforms.push_back("color"); | 443 uniforms.push_back("color"); |
| 428 break; | 444 break; |
| 429 } | 445 } |
| 430 | 446 |
| 431 locations.resize(uniforms.size()); | 447 locations.resize(uniforms.size()); |
| 432 | 448 |
| 433 GetProgramUniformLocations(context, program, uniforms.size(), uniforms.data(), | 449 GetProgramUniformLocations(context, program, uniforms.size(), uniforms.data(), |
| 434 locations.data(), base_uniform_index); | 450 locations.data(), base_uniform_index); |
| 435 | 451 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 451 if (has_uniform_alpha_) | 467 if (has_uniform_alpha_) |
| 452 alpha_location_ = locations[index++]; | 468 alpha_location_ = locations[index++]; |
| 453 if (has_background_color_) | 469 if (has_background_color_) |
| 454 background_color_location_ = locations[index++]; | 470 background_color_location_ = locations[index++]; |
| 455 switch (input_color_type_) { | 471 switch (input_color_type_) { |
| 456 case INPUT_COLOR_SOURCE_RGBA_TEXTURE: | 472 case INPUT_COLOR_SOURCE_RGBA_TEXTURE: |
| 457 sampler_location_ = locations[index++]; | 473 sampler_location_ = locations[index++]; |
| 458 if (has_rgba_fragment_tex_transform_) | 474 if (has_rgba_fragment_tex_transform_) |
| 459 fragment_tex_transform_location_ = locations[index++]; | 475 fragment_tex_transform_location_ = locations[index++]; |
| 460 break; | 476 break; |
| 477 case INPUT_COLOR_SOURCE_YUV_TEXTURES: |
| 478 NOTREACHED(); |
| 479 break; |
| 461 case INPUT_COLOR_SOURCE_UNIFORM: | 480 case INPUT_COLOR_SOURCE_UNIFORM: |
| 462 color_location_ = locations[index++]; | 481 color_location_ = locations[index++]; |
| 463 break; | 482 break; |
| 464 } | 483 } |
| 465 DCHECK_EQ(index, locations.size()); | 484 DCHECK_EQ(index, locations.size()); |
| 466 } | 485 } |
| 467 | 486 |
| 468 std::string FragmentShaderBase::SetBlendModeFunctions( | 487 std::string FragmentShader::SetBlendModeFunctions( |
| 469 const std::string& shader_string) const { | 488 const std::string& shader_string) const { |
| 470 if (shader_string.find("ApplyBlendMode") == std::string::npos) | 489 if (shader_string.find("ApplyBlendMode") == std::string::npos) |
| 471 return shader_string; | 490 return shader_string; |
| 472 | 491 |
| 473 if (!has_blend_mode()) { | 492 if (!has_blend_mode()) { |
| 474 return "#define ApplyBlendMode(X, Y) (X)\n" + shader_string; | 493 return "#define ApplyBlendMode(X, Y) (X)\n" + shader_string; |
| 475 } | 494 } |
| 476 | 495 |
| 477 static const std::string kUniforms = SHADER0([]() { | 496 static const std::string kUniforms = SHADER0([]() { |
| 478 uniform sampler2D s_backdropTexture; | 497 uniform sampler2D s_backdropTexture; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 vec4 dst = GetBackdropColor(mask); | 529 vec4 dst = GetBackdropColor(mask); |
| 511 return Blend(src, dst); | 530 return Blend(src, dst); |
| 512 } | 531 } |
| 513 }); | 532 }); |
| 514 | 533 |
| 515 return "precision mediump float;" + GetHelperFunctions() + | 534 return "precision mediump float;" + GetHelperFunctions() + |
| 516 GetBlendFunction() + kUniforms + mixFunction + | 535 GetBlendFunction() + kUniforms + mixFunction + |
| 517 kFunctionApplyBlendMode + shader_string; | 536 kFunctionApplyBlendMode + shader_string; |
| 518 } | 537 } |
| 519 | 538 |
| 520 std::string FragmentShaderBase::GetHelperFunctions() const { | 539 std::string FragmentShader::GetHelperFunctions() const { |
| 521 static const std::string kFunctionHardLight = SHADER0([]() { | 540 static const std::string kFunctionHardLight = SHADER0([]() { |
| 522 vec3 hardLight(vec4 src, vec4 dst) { | 541 vec3 hardLight(vec4 src, vec4 dst) { |
| 523 vec3 result; | 542 vec3 result; |
| 524 result.r = | 543 result.r = |
| 525 (2.0 * src.r <= src.a) | 544 (2.0 * src.r <= src.a) |
| 526 ? (2.0 * src.r * dst.r) | 545 ? (2.0 * src.r * dst.r) |
| 527 : (src.a * dst.a - 2.0 * (dst.a - dst.r) * (src.a - src.r)); | 546 : (src.a * dst.a - 2.0 * (dst.a - dst.r) * (src.a - src.r)); |
| 528 result.g = | 547 result.g = |
| 529 (2.0 * src.g <= src.a) | 548 (2.0 * src.g <= src.a) |
| 530 ? (2.0 * src.g * dst.g) | 549 ? (2.0 * src.g * dst.g) |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 case BLEND_MODE_SATURATION: | 690 case BLEND_MODE_SATURATION: |
| 672 return kFunctionLum + kFunctionSat; | 691 return kFunctionLum + kFunctionSat; |
| 673 case BLEND_MODE_COLOR: | 692 case BLEND_MODE_COLOR: |
| 674 case BLEND_MODE_LUMINOSITY: | 693 case BLEND_MODE_LUMINOSITY: |
| 675 return kFunctionLum; | 694 return kFunctionLum; |
| 676 default: | 695 default: |
| 677 return std::string(); | 696 return std::string(); |
| 678 } | 697 } |
| 679 } | 698 } |
| 680 | 699 |
| 681 std::string FragmentShaderBase::GetBlendFunction() const { | 700 std::string FragmentShader::GetBlendFunction() const { |
| 682 return "vec4 Blend(vec4 src, vec4 dst) {" | 701 return "vec4 Blend(vec4 src, vec4 dst) {" |
| 683 " vec4 result;" | 702 " vec4 result;" |
| 684 " result.a = src.a + (1.0 - src.a) * dst.a;" + | 703 " result.a = src.a + (1.0 - src.a) * dst.a;" + |
| 685 GetBlendFunctionBodyForRGB() + | 704 GetBlendFunctionBodyForRGB() + |
| 686 " return result;" | 705 " return result;" |
| 687 "}"; | 706 "}"; |
| 688 } | 707 } |
| 689 | 708 |
| 690 std::string FragmentShaderBase::GetBlendFunctionBodyForRGB() const { | 709 std::string FragmentShader::GetBlendFunctionBodyForRGB() const { |
| 691 switch (blend_mode_) { | 710 switch (blend_mode_) { |
| 692 case BLEND_MODE_NORMAL: | 711 case BLEND_MODE_NORMAL: |
| 693 return "result.rgb = src.rgb + dst.rgb * (1.0 - src.a);"; | 712 return "result.rgb = src.rgb + dst.rgb * (1.0 - src.a);"; |
| 694 case BLEND_MODE_SCREEN: | 713 case BLEND_MODE_SCREEN: |
| 695 return "result.rgb = src.rgb + (1.0 - src.rgb) * dst.rgb;"; | 714 return "result.rgb = src.rgb + (1.0 - src.rgb) * dst.rgb;"; |
| 696 case BLEND_MODE_LIGHTEN: | 715 case BLEND_MODE_LIGHTEN: |
| 697 return "result.rgb = max((1.0 - src.a) * dst.rgb + src.rgb," | 716 return "result.rgb = max((1.0 - src.a) * dst.rgb + src.rgb," |
| 698 " (1.0 - dst.a) * src.rgb + dst.rgb);"; | 717 " (1.0 - dst.a) * src.rgb + dst.rgb);"; |
| 699 case BLEND_MODE_OVERLAY: | 718 case BLEND_MODE_OVERLAY: |
| 700 return "result.rgb = hardLight(dst, src);"; | 719 return "result.rgb = hardLight(dst, src);"; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 "result.rgb = set_luminance(dst.rgb * src.a," | 772 "result.rgb = set_luminance(dst.rgb * src.a," |
| 754 " srcDstAlpha.a," | 773 " srcDstAlpha.a," |
| 755 " srcDstAlpha.rgb);" | 774 " srcDstAlpha.rgb);" |
| 756 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;"; | 775 "result.rgb += (1.0 - src.a) * dst.rgb + (1.0 - dst.a) * src.rgb;"; |
| 757 case BLEND_MODE_NONE: | 776 case BLEND_MODE_NONE: |
| 758 NOTREACHED(); | 777 NOTREACHED(); |
| 759 } | 778 } |
| 760 return "result = vec4(1.0, 0.0, 0.0, 1.0);"; | 779 return "result = vec4(1.0, 0.0, 0.0, 1.0);"; |
| 761 } | 780 } |
| 762 | 781 |
| 763 std::string FragmentShaderBase::GetShaderSource() const { | 782 std::string FragmentShader::GetShaderSource() const { |
| 764 std::string header = "precision mediump float;\n"; | 783 std::string header = "precision mediump float;\n"; |
| 765 std::string source = "void main() {\n"; | 784 std::string source = "void main() {\n"; |
| 766 | 785 |
| 767 // Read the input into vec4 texColor. | 786 // Read the input into vec4 texColor. |
| 768 switch (input_color_type_) { | 787 switch (input_color_type_) { |
| 769 case INPUT_COLOR_SOURCE_RGBA_TEXTURE: | 788 case INPUT_COLOR_SOURCE_RGBA_TEXTURE: |
| 770 if (ignore_sampler_type_) | 789 if (ignore_sampler_type_) |
| 771 HDR("uniform sampler2D s_texture;"); | 790 HDR("uniform sampler2D s_texture;"); |
| 772 else | 791 else |
| 773 HDR("uniform SamplerType s_texture;"); | 792 HDR("uniform SamplerType s_texture;"); |
| 774 HDR("varying TexCoordPrecision vec2 v_texCoord;"); | 793 HDR("varying TexCoordPrecision vec2 v_texCoord;"); |
| 775 if (has_rgba_fragment_tex_transform_) { | 794 if (has_rgba_fragment_tex_transform_) { |
| 776 HDR("uniform TexCoordPrecision vec4 fragmentTexTransform;"); | 795 HDR("uniform TexCoordPrecision vec4 fragmentTexTransform;"); |
| 777 SRC("// Transformed texture lookup"); | 796 SRC("// Transformed texture lookup"); |
| 778 SRC("TexCoordPrecision vec2 texCoord ="); | 797 SRC("TexCoordPrecision vec2 texCoord ="); |
| 779 SRC(" clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw +"); | 798 SRC(" clamp(v_texCoord, 0.0, 1.0) * fragmentTexTransform.zw +"); |
| 780 SRC(" fragmentTexTransform.xy;"); | 799 SRC(" fragmentTexTransform.xy;"); |
| 781 SRC("vec4 texColor = TextureLookup(s_texture, texCoord);"); | 800 SRC("vec4 texColor = TextureLookup(s_texture, texCoord);"); |
| 782 DCHECK(!ignore_sampler_type_); | 801 DCHECK(!ignore_sampler_type_); |
| 783 } else { | 802 } else { |
| 784 SRC("// Texture lookup"); | 803 SRC("// Texture lookup"); |
| 785 if (ignore_sampler_type_) | 804 if (ignore_sampler_type_) |
| 786 SRC("vec4 texColor = texture2D(s_texture, v_texCoord);"); | 805 SRC("vec4 texColor = texture2D(s_texture, v_texCoord);"); |
| 787 else | 806 else |
| 788 SRC("vec4 texColor = TextureLookup(s_texture, v_texCoord);"); | 807 SRC("vec4 texColor = TextureLookup(s_texture, v_texCoord);"); |
| 789 } | 808 } |
| 790 break; | 809 break; |
| 810 case INPUT_COLOR_SOURCE_YUV_TEXTURES: |
| 811 NOTREACHED(); |
| 812 break; |
| 791 case INPUT_COLOR_SOURCE_UNIFORM: | 813 case INPUT_COLOR_SOURCE_UNIFORM: |
| 792 DCHECK(!ignore_sampler_type_); | 814 DCHECK(!ignore_sampler_type_); |
| 793 DCHECK(!has_rgba_fragment_tex_transform_); | 815 DCHECK(!has_rgba_fragment_tex_transform_); |
| 794 HDR("uniform vec4 color;"); | 816 HDR("uniform vec4 color;"); |
| 795 SRC("// Uniform color"); | 817 SRC("// Uniform color"); |
| 796 SRC("vec4 texColor = color;"); | 818 SRC("vec4 texColor = color;"); |
| 797 break; | 819 break; |
| 798 } | 820 } |
| 799 // Apply the color matrix to texColor. | 821 // Apply the color matrix to texColor. |
| 800 if (has_color_matrix_) { | 822 if (has_color_matrix_) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 SRC("gl_FragColor = ApplyBlendMode(texColor, maskColor.w);"); | 911 SRC("gl_FragColor = ApplyBlendMode(texColor, maskColor.w);"); |
| 890 else | 912 else |
| 891 SRC("gl_FragColor = ApplyBlendMode(texColor, 0.0);"); | 913 SRC("gl_FragColor = ApplyBlendMode(texColor, 0.0);"); |
| 892 break; | 914 break; |
| 893 } | 915 } |
| 894 source += "}\n"; | 916 source += "}\n"; |
| 895 | 917 |
| 896 return header + source; | 918 return header + source; |
| 897 } | 919 } |
| 898 | 920 |
| 899 FragmentShaderYUVVideo::FragmentShaderYUVVideo() {} | 921 void FragmentShader::InitYUVVideo(GLES2Interface* context, |
| 900 | |
| 901 void FragmentShaderYUVVideo::Init(GLES2Interface* context, | |
| 902 unsigned program, | 922 unsigned program, |
| 903 int* base_uniform_index) { | 923 int* base_uniform_index) { |
| 904 static const char* uniforms[] = { | 924 static const char* uniforms[] = { |
| 905 "y_texture", | 925 "y_texture", |
| 906 "u_texture", | 926 "u_texture", |
| 907 "v_texture", | 927 "v_texture", |
| 908 "uv_texture", | 928 "uv_texture", |
| 909 "a_texture", | 929 "a_texture", |
| 910 "lut_texture", | 930 "lut_texture", |
| 911 "resource_multiplier", | 931 "resource_multiplier", |
| (...skipping 28 matching lines...) Expand all Loading... |
| 940 resource_offset_location_ = locations[7]; | 960 resource_offset_location_ = locations[7]; |
| 941 } else { | 961 } else { |
| 942 yuv_matrix_location_ = locations[8]; | 962 yuv_matrix_location_ = locations[8]; |
| 943 yuv_adj_location_ = locations[9]; | 963 yuv_adj_location_ = locations[9]; |
| 944 } | 964 } |
| 945 alpha_location_ = locations[10]; | 965 alpha_location_ = locations[10]; |
| 946 ya_clamp_rect_location_ = locations[11]; | 966 ya_clamp_rect_location_ = locations[11]; |
| 947 uv_clamp_rect_location_ = locations[12]; | 967 uv_clamp_rect_location_ = locations[12]; |
| 948 } | 968 } |
| 949 | 969 |
| 950 std::string FragmentShaderYUVVideo::GetShaderSource() const { | 970 std::string FragmentShader::GetShaderStringYUVVideo() const { |
| 951 std::string head = SHADER0([]() { | 971 std::string head = SHADER0([]() { |
| 952 precision mediump float; | 972 precision mediump float; |
| 953 precision mediump int; | 973 precision mediump int; |
| 954 varying TexCoordPrecision vec2 v_yaTexCoord; | 974 varying TexCoordPrecision vec2 v_yaTexCoord; |
| 955 varying TexCoordPrecision vec2 v_uvTexCoord; | 975 varying TexCoordPrecision vec2 v_uvTexCoord; |
| 956 uniform SamplerType y_texture; | 976 uniform SamplerType y_texture; |
| 957 uniform float alpha; | 977 uniform float alpha; |
| 958 uniform vec4 ya_clamp_rect; | 978 uniform vec4 ya_clamp_rect; |
| 959 uniform vec4 uv_clamp_rect; | 979 uniform vec4 uv_clamp_rect; |
| 960 }); | 980 }); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); | 1051 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); |
| 1032 vec3 yuv = vec3(y_raw, GetUV(uv_clamped)); | 1052 vec3 yuv = vec3(y_raw, GetUV(uv_clamped)); |
| 1033 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped); | 1053 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped); |
| 1034 } | 1054 } |
| 1035 }); | 1055 }); |
| 1036 | 1056 |
| 1037 return head + functions; | 1057 return head + functions; |
| 1038 } | 1058 } |
| 1039 | 1059 |
| 1040 } // namespace cc | 1060 } // namespace cc |
| OLD | NEW |