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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" | 9 #include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3
D.h" |
10 | 10 |
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 float y_raw = texture2D(y_texture, v_texCoord).x; | 906 float y_raw = texture2D(y_texture, v_texCoord).x; |
907 float u_unsigned = texture2D(u_texture, v_texCoord).x; | 907 float u_unsigned = texture2D(u_texture, v_texCoord).x; |
908 float v_unsigned = texture2D(v_texture, v_texCoord).x; | 908 float v_unsigned = texture2D(v_texture, v_texCoord).x; |
909 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 909 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
910 vec3 rgb = yuv_matrix * yuv; | 910 vec3 rgb = yuv_matrix * yuv; |
911 gl_FragColor = vec4(rgb, float(1)) * alpha; | 911 gl_FragColor = vec4(rgb, float(1)) * alpha; |
912 } | 912 } |
913 ); | 913 ); |
914 } | 914 } |
915 | 915 |
| 916 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() |
| 917 : y_texture_location_(-1), |
| 918 u_texture_location_(-1), |
| 919 v_texture_location_(-1), |
| 920 a_texture_location_(-1), |
| 921 alpha_location_(-1), |
| 922 yuv_matrix_location_(-1), |
| 923 yuv_adj_location_(-1) { |
| 924 } |
| 925 |
| 926 void FragmentShaderYUVAVideo::Init(WebGraphicsContext3D* context, |
| 927 unsigned program, |
| 928 bool using_bind_uniform, |
| 929 int* base_uniform_index) { |
| 930 static const char* shader_uniforms[] = { |
| 931 "y_texture", |
| 932 "u_texture", |
| 933 "v_texture", |
| 934 "a_texture", |
| 935 "alpha", |
| 936 "cc_matrix", |
| 937 "yuv_adj", |
| 938 }; |
| 939 int locations[7]; |
| 940 |
| 941 GetProgramUniformLocations(context, |
| 942 program, |
| 943 shader_uniforms, |
| 944 arraysize(shader_uniforms), |
| 945 arraysize(locations), |
| 946 locations, |
| 947 using_bind_uniform, |
| 948 base_uniform_index); |
| 949 |
| 950 y_texture_location_ = locations[0]; |
| 951 u_texture_location_ = locations[1]; |
| 952 v_texture_location_ = locations[2]; |
| 953 a_texture_location_ = locations[3]; |
| 954 alpha_location_ = locations[4]; |
| 955 yuv_matrix_location_ = locations[5]; |
| 956 yuv_adj_location_ = locations[6]; |
| 957 |
| 958 DCHECK(y_texture_location_ != -1 && u_texture_location_ != -1 && |
| 959 v_texture_location_ != -1 && a_texture_location_ != -1 && |
| 960 alpha_location_ != -1 && yuv_matrix_location_ != -1 && |
| 961 yuv_adj_location_ != -1); |
| 962 } |
| 963 |
| 964 std::string FragmentShaderYUVAVideo::GetShaderString() const { |
| 965 return SHADER( |
| 966 precision mediump float; |
| 967 precision mediump int; |
| 968 varying vec2 v_texCoord; |
| 969 uniform sampler2D y_texture; |
| 970 uniform sampler2D u_texture; |
| 971 uniform sampler2D v_texture; |
| 972 uniform sampler2D a_texture; |
| 973 uniform float alpha; |
| 974 uniform vec3 yuv_adj; |
| 975 uniform mat3 yuv_matrix; |
| 976 void main() { |
| 977 float y_raw = texture2D(y_texture, v_texCoord).x; |
| 978 float u_unsigned = texture2D(u_texture, v_texCoord).x; |
| 979 float v_unsigned = texture2D(v_texture, v_texCoord).x; |
| 980 float a_raw = texture2D(a_texture, v_texCoord).x; |
| 981 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
| 982 vec3 rgb = yuv_matrix * yuv; |
| 983 gl_FragColor = vec4(rgb, float(1)) * (a_raw * alpha); |
| 984 } |
| 985 ); |
| 986 } |
| 987 |
916 FragmentShaderColor::FragmentShaderColor() | 988 FragmentShaderColor::FragmentShaderColor() |
917 : color_location_(-1) {} | 989 : color_location_(-1) {} |
918 | 990 |
919 void FragmentShaderColor::Init(WebGraphicsContext3D* context, | 991 void FragmentShaderColor::Init(WebGraphicsContext3D* context, |
920 unsigned program, | 992 unsigned program, |
921 bool using_bind_uniform, | 993 bool using_bind_uniform, |
922 int* base_uniform_index) { | 994 int* base_uniform_index) { |
923 static const char* shader_uniforms[] = { | 995 static const char* shader_uniforms[] = { |
924 "color", | 996 "color", |
925 }; | 997 }; |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + | 1120 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + |
1049 texTransform.xy; | 1121 texTransform.xy; |
1050 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1122 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
1051 float picker = abs(coord.x - coord.y); | 1123 float picker = abs(coord.x - coord.y); |
1052 gl_FragColor = mix(color1, color2, picker) * alpha; | 1124 gl_FragColor = mix(color1, color2, picker) * alpha; |
1053 } | 1125 } |
1054 ); | 1126 ); |
1055 } | 1127 } |
1056 | 1128 |
1057 } // namespace cc | 1129 } // namespace cc |
OLD | NEW |