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 <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 std::string VertexShaderPosTex::GetShaderBody() { | 205 std::string VertexShaderPosTex::GetShaderBody() { |
206 return SHADER0([]() { | 206 return SHADER0([]() { |
207 void main() { | 207 void main() { |
208 gl_Position = matrix * a_position; | 208 gl_Position = matrix * a_position; |
209 v_texCoord = a_texCoord; | 209 v_texCoord = a_texCoord; |
210 } | 210 } |
211 }); | 211 }); |
212 } | 212 } |
213 | 213 |
214 VertexShaderPosTexYUVStretchOffset::VertexShaderPosTexYUVStretchOffset() | 214 VertexShaderPosTexYUVStretchOffset::VertexShaderPosTexYUVStretchOffset() |
215 : matrix_location_(-1), tex_scale_location_(-1), tex_offset_location_(-1) { | 215 : matrix_location_(-1), |
| 216 ya_tex_scale_location_(-1), |
| 217 ya_tex_offset_location_(-1), |
| 218 uv_tex_scale_location_(-1), |
| 219 uv_tex_offset_location_(-1) { |
216 } | 220 } |
217 | 221 |
218 void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context, | 222 void VertexShaderPosTexYUVStretchOffset::Init(GLES2Interface* context, |
219 unsigned program, | 223 unsigned program, |
220 int* base_uniform_index) { | 224 int* base_uniform_index) { |
221 static const char* uniforms[] = { | 225 static const char* uniforms[] = { |
222 "matrix", "texScale", "texOffset", | 226 "matrix", "yaTexScale", "yaTexOffset", "uvTexScale", "uvTexOffset", |
223 }; | 227 }; |
224 int locations[arraysize(uniforms)]; | 228 int locations[arraysize(uniforms)]; |
225 | 229 |
226 GetProgramUniformLocations(context, | 230 GetProgramUniformLocations(context, |
227 program, | 231 program, |
228 arraysize(uniforms), | 232 arraysize(uniforms), |
229 uniforms, | 233 uniforms, |
230 locations, | 234 locations, |
231 base_uniform_index); | 235 base_uniform_index); |
232 matrix_location_ = locations[0]; | 236 matrix_location_ = locations[0]; |
233 tex_scale_location_ = locations[1]; | 237 ya_tex_scale_location_ = locations[1]; |
234 tex_offset_location_ = locations[2]; | 238 ya_tex_offset_location_ = locations[2]; |
| 239 uv_tex_scale_location_ = locations[3]; |
| 240 uv_tex_offset_location_ = locations[4]; |
235 } | 241 } |
236 | 242 |
237 std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const { | 243 std::string VertexShaderPosTexYUVStretchOffset::GetShaderString() const { |
238 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); | 244 return VERTEX_SHADER(GetShaderHead(), GetShaderBody()); |
239 } | 245 } |
240 | 246 |
241 std::string VertexShaderPosTexYUVStretchOffset::GetShaderHead() { | 247 std::string VertexShaderPosTexYUVStretchOffset::GetShaderHead() { |
242 return SHADER0([]() { | 248 return SHADER0([]() { |
243 precision mediump float; | 249 precision mediump float; |
244 attribute vec4 a_position; | 250 attribute vec4 a_position; |
245 attribute TexCoordPrecision vec2 a_texCoord; | 251 attribute TexCoordPrecision vec2 a_texCoord; |
246 uniform mat4 matrix; | 252 uniform mat4 matrix; |
247 varying TexCoordPrecision vec2 v_texCoord; | 253 varying TexCoordPrecision vec2 v_yaTexCoord; |
248 uniform TexCoordPrecision vec2 texScale; | 254 varying TexCoordPrecision vec2 v_uvTexCoord; |
249 uniform TexCoordPrecision vec2 texOffset; | 255 uniform TexCoordPrecision vec2 yaTexScale; |
| 256 uniform TexCoordPrecision vec2 yaTexOffset; |
| 257 uniform TexCoordPrecision vec2 uvTexScale; |
| 258 uniform TexCoordPrecision vec2 uvTexOffset; |
250 }); | 259 }); |
251 } | 260 } |
252 | 261 |
253 std::string VertexShaderPosTexYUVStretchOffset::GetShaderBody() { | 262 std::string VertexShaderPosTexYUVStretchOffset::GetShaderBody() { |
254 return SHADER0([]() { | 263 return SHADER0([]() { |
255 void main() { | 264 void main() { |
256 gl_Position = matrix * a_position; | 265 gl_Position = matrix * a_position; |
257 v_texCoord = a_texCoord * texScale + texOffset; | 266 v_yaTexCoord = a_texCoord * yaTexScale + yaTexOffset; |
| 267 v_uvTexCoord = a_texCoord * uvTexScale + uvTexOffset; |
258 } | 268 } |
259 }); | 269 }); |
260 } | 270 } |
261 | 271 |
262 VertexShaderPos::VertexShaderPos() : matrix_location_(-1) { | 272 VertexShaderPos::VertexShaderPos() : matrix_location_(-1) { |
263 } | 273 } |
264 | 274 |
265 void VertexShaderPos::Init(GLES2Interface* context, | 275 void VertexShaderPos::Init(GLES2Interface* context, |
266 unsigned program, | 276 unsigned program, |
267 int* base_uniform_index) { | 277 int* base_uniform_index) { |
(...skipping 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 | 2049 |
2040 std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, | 2050 std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, |
2041 SamplerType sampler) const { | 2051 SamplerType sampler) const { |
2042 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | 2052 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
2043 } | 2053 } |
2044 | 2054 |
2045 std::string FragmentShaderYUVVideo::GetShaderHead() { | 2055 std::string FragmentShaderYUVVideo::GetShaderHead() { |
2046 return SHADER0([]() { | 2056 return SHADER0([]() { |
2047 precision mediump float; | 2057 precision mediump float; |
2048 precision mediump int; | 2058 precision mediump int; |
2049 varying TexCoordPrecision vec2 v_texCoord; | 2059 varying TexCoordPrecision vec2 v_yaTexCoord; |
| 2060 varying TexCoordPrecision vec2 v_uvTexCoord; |
2050 uniform SamplerType y_texture; | 2061 uniform SamplerType y_texture; |
2051 uniform SamplerType u_texture; | 2062 uniform SamplerType u_texture; |
2052 uniform SamplerType v_texture; | 2063 uniform SamplerType v_texture; |
2053 uniform float alpha; | 2064 uniform float alpha; |
2054 uniform vec3 yuv_adj; | 2065 uniform vec3 yuv_adj; |
2055 uniform mat3 yuv_matrix; | 2066 uniform mat3 yuv_matrix; |
2056 uniform vec4 ya_clamp_rect; | 2067 uniform vec4 ya_clamp_rect; |
2057 uniform vec4 uv_clamp_rect; | 2068 uniform vec4 uv_clamp_rect; |
2058 }); | 2069 }); |
2059 } | 2070 } |
2060 | 2071 |
2061 std::string FragmentShaderYUVVideo::GetShaderBody() { | 2072 std::string FragmentShaderYUVVideo::GetShaderBody() { |
2062 return SHADER0([]() { | 2073 return SHADER0([]() { |
2063 void main() { | 2074 void main() { |
2064 vec2 ya_clamped = | 2075 vec2 ya_clamped = |
2065 max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_texCoord)); | 2076 max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_yaTexCoord)); |
2066 float y_raw = TextureLookup(y_texture, ya_clamped).x; | 2077 float y_raw = TextureLookup(y_texture, ya_clamped).x; |
2067 vec2 uv_clamped = | 2078 vec2 uv_clamped = |
2068 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_texCoord)); | 2079 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); |
2069 float u_unsigned = TextureLookup(u_texture, uv_clamped).x; | 2080 float u_unsigned = TextureLookup(u_texture, uv_clamped).x; |
2070 float v_unsigned = TextureLookup(v_texture, uv_clamped).x; | 2081 float v_unsigned = TextureLookup(v_texture, uv_clamped).x; |
2071 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 2082 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
2072 vec3 rgb = yuv_matrix * yuv; | 2083 vec3 rgb = yuv_matrix * yuv; |
2073 gl_FragColor = vec4(rgb, 1.0) * alpha; | 2084 gl_FragColor = vec4(rgb, 1.0) * alpha; |
2074 } | 2085 } |
2075 }); | 2086 }); |
2076 } | 2087 } |
2077 | 2088 |
2078 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() | 2089 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2121 std::string FragmentShaderYUVAVideo::GetShaderString( | 2132 std::string FragmentShaderYUVAVideo::GetShaderString( |
2122 TexCoordPrecision precision, | 2133 TexCoordPrecision precision, |
2123 SamplerType sampler) const { | 2134 SamplerType sampler) const { |
2124 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | 2135 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
2125 } | 2136 } |
2126 | 2137 |
2127 std::string FragmentShaderYUVAVideo::GetShaderHead() { | 2138 std::string FragmentShaderYUVAVideo::GetShaderHead() { |
2128 return SHADER0([]() { | 2139 return SHADER0([]() { |
2129 precision mediump float; | 2140 precision mediump float; |
2130 precision mediump int; | 2141 precision mediump int; |
2131 varying TexCoordPrecision vec2 v_texCoord; | 2142 varying TexCoordPrecision vec2 v_yaTexCoord; |
| 2143 varying TexCoordPrecision vec2 v_uvTexCoord; |
2132 uniform SamplerType y_texture; | 2144 uniform SamplerType y_texture; |
2133 uniform SamplerType u_texture; | 2145 uniform SamplerType u_texture; |
2134 uniform SamplerType v_texture; | 2146 uniform SamplerType v_texture; |
2135 uniform SamplerType a_texture; | 2147 uniform SamplerType a_texture; |
2136 uniform float alpha; | 2148 uniform float alpha; |
2137 uniform vec3 yuv_adj; | 2149 uniform vec3 yuv_adj; |
2138 uniform mat3 yuv_matrix; | 2150 uniform mat3 yuv_matrix; |
2139 uniform vec4 ya_clamp_rect; | 2151 uniform vec4 ya_clamp_rect; |
2140 uniform vec4 uv_clamp_rect; | 2152 uniform vec4 uv_clamp_rect; |
2141 }); | 2153 }); |
2142 } | 2154 } |
2143 | 2155 |
2144 std::string FragmentShaderYUVAVideo::GetShaderBody() { | 2156 std::string FragmentShaderYUVAVideo::GetShaderBody() { |
2145 return SHADER0([]() { | 2157 return SHADER0([]() { |
2146 void main() { | 2158 void main() { |
2147 vec2 ya_clamped = | 2159 vec2 ya_clamped = |
2148 max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_texCoord)); | 2160 max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_yaTexCoord)); |
2149 float y_raw = TextureLookup(y_texture, ya_clamped).x; | 2161 float y_raw = TextureLookup(y_texture, ya_clamped).x; |
2150 vec2 uv_clamped = | 2162 vec2 uv_clamped = |
2151 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_texCoord)); | 2163 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); |
2152 float u_unsigned = TextureLookup(u_texture, uv_clamped).x; | 2164 float u_unsigned = TextureLookup(u_texture, uv_clamped).x; |
2153 float v_unsigned = TextureLookup(v_texture, uv_clamped).x; | 2165 float v_unsigned = TextureLookup(v_texture, uv_clamped).x; |
2154 float a_raw = TextureLookup(a_texture, ya_clamped).x; | 2166 float a_raw = TextureLookup(a_texture, ya_clamped).x; |
2155 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 2167 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
2156 vec3 rgb = yuv_matrix * yuv; | 2168 vec3 rgb = yuv_matrix * yuv; |
2157 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); | 2169 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); |
2158 } | 2170 } |
2159 }); | 2171 }); |
2160 } | 2172 } |
2161 | 2173 |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2295 vec2 texCoord = | 2307 vec2 texCoord = |
2296 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; | 2308 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; |
2297 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 2309 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
2298 float picker = abs(coord.x - coord.y); // NOLINT | 2310 float picker = abs(coord.x - coord.y); // NOLINT |
2299 gl_FragColor = mix(color1, color2, picker) * alpha; | 2311 gl_FragColor = mix(color1, color2, picker) * alpha; |
2300 } | 2312 } |
2301 }); | 2313 }); |
2302 } | 2314 } |
2303 | 2315 |
2304 } // namespace cc | 2316 } // namespace cc |
OLD | NEW |