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 |
| 927 void FragmentShaderYUVAVideo::Init(WebGraphicsContext3D* context, |
| 928 unsigned program, |
| 929 bool using_bind_uniform, |
| 930 int* base_uniform_index) |
| 931 { |
| 932 static const char* shader_uniforms[] = { |
| 933 "y_texture", |
| 934 "u_texture", |
| 935 "v_texture", |
| 936 "a_texture", |
| 937 "alpha", |
| 938 "cc_matrix", |
| 939 "yuv_adj", |
| 940 }; |
| 941 int locations[7]; |
| 942 |
| 943 GetProgramUniformLocations(context, |
| 944 program, |
| 945 shader_uniforms, |
| 946 arraysize(shader_uniforms), |
| 947 arraysize(locations), |
| 948 locations, |
| 949 using_bind_uniform, |
| 950 base_uniform_index); |
| 951 |
| 952 y_texture_location_ = locations[0]; |
| 953 u_texture_location_ = locations[1]; |
| 954 v_texture_location_ = locations[2]; |
| 955 a_texture_location_ = locations[3]; |
| 956 alpha_location_ = locations[4]; |
| 957 yuv_matrix_location_ = locations[5]; |
| 958 yuv_adj_location_ = locations[6]; |
| 959 |
| 960 DCHECK(y_texture_location_ != -1 && u_texture_location_ != -1 && |
| 961 v_texture_location_ != -1 && a_texture_location_ != -1 && |
| 962 alpha_location_ != -1 && yuv_matrix_location_ != -1 && |
| 963 yuv_adj_location_ != -1); |
| 964 } |
| 965 |
| 966 std::string FragmentShaderYUVAVideo::GetShaderString() const |
| 967 { |
| 968 return SHADER( |
| 969 precision mediump float; |
| 970 precision mediump int; |
| 971 varying vec2 y_texCoord; |
| 972 varying vec2 uv_texCoord; |
| 973 uniform sampler2D y_texture; |
| 974 uniform sampler2D u_texture; |
| 975 uniform sampler2D v_texture; |
| 976 uniform sampler2D a_texture; |
| 977 uniform float alpha; |
| 978 uniform vec3 yuv_adj; |
| 979 uniform mat3 cc_matrix; |
| 980 void main() |
| 981 { |
| 982 float y_raw = texture2D(y_texture, y_texCoord).x; |
| 983 float u_unsigned = texture2D(u_texture, uv_texCoord).x; |
| 984 float v_unsigned = texture2D(v_texture, uv_texCoord).x; |
| 985 float a_raw = texture2D(a_texture, y_texCoord).x; |
| 986 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
| 987 vec3 rgb = cc_matrix * yuv; |
| 988 gl_FragColor = vec4(rgb, float(1)) * (a_raw * alpha); |
| 989 } |
| 990 ); |
| 991 } |
| 992 |
916 FragmentShaderColor::FragmentShaderColor() | 993 FragmentShaderColor::FragmentShaderColor() |
917 : color_location_(-1) {} | 994 : color_location_(-1) {} |
918 | 995 |
919 void FragmentShaderColor::Init(WebGraphicsContext3D* context, | 996 void FragmentShaderColor::Init(WebGraphicsContext3D* context, |
920 unsigned program, | 997 unsigned program, |
921 bool using_bind_uniform, | 998 bool using_bind_uniform, |
922 int* base_uniform_index) { | 999 int* base_uniform_index) { |
923 static const char* shader_uniforms[] = { | 1000 static const char* shader_uniforms[] = { |
924 "color", | 1001 "color", |
925 }; | 1002 }; |
(...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 + | 1125 vec2 texCoord = clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + |
1049 texTransform.xy; | 1126 texTransform.xy; |
1050 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 1127 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
1051 float picker = abs(coord.x - coord.y); | 1128 float picker = abs(coord.x - coord.y); |
1052 gl_FragColor = mix(color1, color2, picker) * alpha; | 1129 gl_FragColor = mix(color1, color2, picker) * alpha; |
1053 } | 1130 } |
1054 ); | 1131 ); |
1055 } | 1132 } |
1056 | 1133 |
1057 } // namespace cc | 1134 } // namespace cc |
OLD | NEW |