| 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 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 uniforms.push_back("resource_offset"); | 442 uniforms.push_back("resource_offset"); |
| 443 } else { | 443 } else { |
| 444 uniforms.push_back("yuv_matrix"); | 444 uniforms.push_back("yuv_matrix"); |
| 445 uniforms.push_back("yuv_adj"); | 445 uniforms.push_back("yuv_adj"); |
| 446 } | 446 } |
| 447 break; | 447 break; |
| 448 case INPUT_COLOR_SOURCE_UNIFORM: | 448 case INPUT_COLOR_SOURCE_UNIFORM: |
| 449 uniforms.push_back("color"); | 449 uniforms.push_back("color"); |
| 450 break; | 450 break; |
| 451 } | 451 } |
| 452 if (color_conversion_mode_ == COLOR_CONVERSION_MODE_ANALYTIC) { |
| 453 uniforms.push_back("color_src_to_dst_primary_matrix"); |
| 454 uniforms.push_back("color_src_to_linear_tr_fn"); |
| 455 uniforms.push_back("color_linear_to_dst_tr_fn"); |
| 456 } |
| 452 | 457 |
| 453 locations.resize(uniforms.size()); | 458 locations.resize(uniforms.size()); |
| 454 | 459 |
| 455 GetProgramUniformLocations(context, program, uniforms.size(), uniforms.data(), | 460 GetProgramUniformLocations(context, program, uniforms.size(), uniforms.data(), |
| 456 locations.data(), base_uniform_index); | 461 locations.data(), base_uniform_index); |
| 457 | 462 |
| 458 size_t index = 0; | 463 size_t index = 0; |
| 459 if (has_blend_mode()) { | 464 if (has_blend_mode()) { |
| 460 backdrop_location_ = locations[index++]; | 465 backdrop_location_ = locations[index++]; |
| 461 original_backdrop_location_ = locations[index++]; | 466 original_backdrop_location_ = locations[index++]; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 resource_offset_location_ = locations[index++]; | 504 resource_offset_location_ = locations[index++]; |
| 500 } else { | 505 } else { |
| 501 yuv_matrix_location_ = locations[index++]; | 506 yuv_matrix_location_ = locations[index++]; |
| 502 yuv_adj_location_ = locations[index++]; | 507 yuv_adj_location_ = locations[index++]; |
| 503 } | 508 } |
| 504 break; | 509 break; |
| 505 case INPUT_COLOR_SOURCE_UNIFORM: | 510 case INPUT_COLOR_SOURCE_UNIFORM: |
| 506 color_location_ = locations[index++]; | 511 color_location_ = locations[index++]; |
| 507 break; | 512 break; |
| 508 } | 513 } |
| 514 if (color_conversion_mode_ == COLOR_CONVERSION_MODE_ANALYTIC) { |
| 515 color_src_to_dst_primary_matrix_location_ = locations[index++]; |
| 516 color_src_to_linear_tr_fn_location_ = locations[index++]; |
| 517 color_linear_to_dst_tr_fn_location_ = locations[index++]; |
| 518 } |
| 509 DCHECK_EQ(index, locations.size()); | 519 DCHECK_EQ(index, locations.size()); |
| 510 } | 520 } |
| 511 | 521 |
| 512 std::string FragmentShader::SetBlendModeFunctions( | 522 std::string FragmentShader::SetBlendModeFunctions( |
| 513 const std::string& shader_string) const { | 523 const std::string& shader_string) const { |
| 514 if (shader_string.find("ApplyBlendMode") == std::string::npos) | 524 if (shader_string.find("ApplyBlendMode") == std::string::npos) |
| 515 return shader_string; | 525 return shader_string; |
| 516 | 526 |
| 517 if (!has_blend_mode()) { | 527 if (!has_blend_mode()) { |
| 518 return "#define ApplyBlendMode(X, Y) (X)\n" + shader_string; | 528 return "#define ApplyBlendMode(X, Y) (X)\n" + shader_string; |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 SRC("vec4 texColor = vec4(yuv2rgb(yuv), 1.0);"); | 901 SRC("vec4 texColor = vec4(yuv2rgb(yuv), 1.0);"); |
| 892 break; | 902 break; |
| 893 case INPUT_COLOR_SOURCE_UNIFORM: | 903 case INPUT_COLOR_SOURCE_UNIFORM: |
| 894 DCHECK(!ignore_sampler_type_); | 904 DCHECK(!ignore_sampler_type_); |
| 895 DCHECK(!has_rgba_fragment_tex_transform_); | 905 DCHECK(!has_rgba_fragment_tex_transform_); |
| 896 HDR("uniform vec4 color;"); | 906 HDR("uniform vec4 color;"); |
| 897 SRC("// Uniform color"); | 907 SRC("// Uniform color"); |
| 898 SRC("vec4 texColor = color;"); | 908 SRC("vec4 texColor = color;"); |
| 899 break; | 909 break; |
| 900 } | 910 } |
| 911 |
| 912 // Apply color conversion |
| 913 if (color_conversion_mode_ == COLOR_CONVERSION_MODE_ANALYTIC) { |
| 914 HDR("uniform mat3 color_src_to_dst_primary_matrix;"); |
| 915 HDR("// Transfer function parameter uniforms. Parameters are based on"); |
| 916 HDR("// SkColorSpaceTransferFn (as fA at index 0 through fG at index 6)."); |
| 917 HDR("uniform float color_src_to_linear_tr_fn[7];"); |
| 918 HDR("uniform float color_linear_to_dst_tr_fn[7];"); |
| 919 HDR("float TransferFn(float x, float params[7]) {"); |
| 920 HDR(" x = clamp(x, 0.0, 1.0);"); |
| 921 HDR(" if (x < params[3])"); |
| 922 HDR(" return params[2]*x + params[5];"); |
| 923 HDR(" return pow(params[0] * x + params[1], params[6]) + params[4];"); |
| 924 HDR("}"); |
| 925 SRC("// Apply color conversion"); |
| 926 SRC("texColor.r = TransferFn(texColor.x, color_src_to_linear_tr_fn);"); |
| 927 SRC("texColor.g = TransferFn(texColor.y, color_src_to_linear_tr_fn);"); |
| 928 SRC("texColor.b = TransferFn(texColor.z, color_src_to_linear_tr_fn);"); |
| 929 SRC("texColor.rgb = color_src_to_dst_primary_matrix * texColor.rgb;"); |
| 930 SRC("texColor.r = TransferFn(texColor.x, color_linear_to_dst_tr_fn);"); |
| 931 SRC("texColor.g = TransferFn(texColor.y, color_linear_to_dst_tr_fn);"); |
| 932 SRC("texColor.b = TransferFn(texColor.z, color_linear_to_dst_tr_fn);"); |
| 933 } |
| 934 |
| 901 // Apply the color matrix to texColor. | 935 // Apply the color matrix to texColor. |
| 902 if (has_color_matrix_) { | 936 if (has_color_matrix_) { |
| 903 HDR("uniform mat4 colorMatrix;"); | 937 HDR("uniform mat4 colorMatrix;"); |
| 904 HDR("uniform vec4 colorOffset;"); | 938 HDR("uniform vec4 colorOffset;"); |
| 905 SRC("// Apply color matrix"); | 939 SRC("// Apply color matrix"); |
| 906 SRC("float nonZeroAlpha = max(texColor.a, 0.00001);"); | 940 SRC("float nonZeroAlpha = max(texColor.a, 0.00001);"); |
| 907 SRC("texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha);"); | 941 SRC("texColor = vec4(texColor.rgb / nonZeroAlpha, nonZeroAlpha);"); |
| 908 SRC("texColor = colorMatrix * texColor + colorOffset;"); | 942 SRC("texColor = colorMatrix * texColor + colorOffset;"); |
| 909 SRC("texColor.rgb *= texColor.a;"); | 943 SRC("texColor.rgb *= texColor.a;"); |
| 910 SRC("texColor = clamp(texColor, 0.0, 1.0);"); | 944 SRC("texColor = clamp(texColor, 0.0, 1.0);"); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 else | 1028 else |
| 995 SRC("gl_FragColor = ApplyBlendMode(texColor, 0.0);"); | 1029 SRC("gl_FragColor = ApplyBlendMode(texColor, 0.0);"); |
| 996 break; | 1030 break; |
| 997 } | 1031 } |
| 998 source += "}\n"; | 1032 source += "}\n"; |
| 999 | 1033 |
| 1000 return header + source; | 1034 return header + source; |
| 1001 } | 1035 } |
| 1002 | 1036 |
| 1003 } // namespace cc | 1037 } // namespace cc |
| OLD | NEW |