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 | 10 |
(...skipping 2158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2169 vec2 uv_clamped = | 2169 vec2 uv_clamped = |
2170 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); | 2170 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); |
2171 vec3 yuv = vec3(y_raw, GetUV(uv_clamped)); | 2171 vec3 yuv = vec3(y_raw, GetUV(uv_clamped)); |
2172 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped); | 2172 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped); |
2173 } | 2173 } |
2174 }); | 2174 }); |
2175 | 2175 |
2176 return FRAGMENT_SHADER(head, functions); | 2176 return FRAGMENT_SHADER(head, functions); |
2177 } | 2177 } |
2178 | 2178 |
| 2179 FragmentShaderYVideo::FragmentShaderYVideo() |
| 2180 : FragmentTexOpaqueBinding(), |
| 2181 x_derivative_location_(-1), |
| 2182 y_derivative_location_(-1) {} |
| 2183 |
| 2184 void FragmentShaderYVideo::Init(GLES2Interface* context, |
| 2185 unsigned program, |
| 2186 int* base_uniform_index) { |
| 2187 FragmentTexOpaqueBinding::Init(context, program, base_uniform_index); |
| 2188 |
| 2189 static const char* uniforms[] = {"x_derivative", "y_derivative"}; |
| 2190 int locations[arraysize(uniforms)]; |
| 2191 |
| 2192 GetProgramUniformLocations(context, program, arraysize(uniforms), uniforms, |
| 2193 locations, base_uniform_index); |
| 2194 x_derivative_location_ = locations[0]; |
| 2195 y_derivative_location_ = locations[1]; |
| 2196 } |
| 2197 |
| 2198 std::string FragmentShaderYVideo::GetShaderString(TexCoordPrecision precision, |
| 2199 SamplerType sampler) const { |
| 2200 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
| 2201 } |
| 2202 |
| 2203 std::string FragmentShaderYVideo::GetShaderHead() { |
| 2204 return SHADER0([]() { |
| 2205 precision mediump float; |
| 2206 varying TexCoordPrecision vec2 v_texCoord; |
| 2207 uniform SamplerType s_texture; |
| 2208 uniform float x_derivative; |
| 2209 uniform float y_derivative; |
| 2210 }); |
| 2211 } |
| 2212 |
| 2213 std::string FragmentShaderYVideo::GetShaderBody() { |
| 2214 return SHADER0([]() { |
| 2215 vec4 TextureLookupBilinear(SamplerType sampler, highp vec2 texCoord) { |
| 2216 vec4 s1 = TextureLookup(sampler, texCoord); |
| 2217 vec4 s2 = TextureLookup(sampler, texCoord + vec2(x_derivative, 0.)); |
| 2218 vec4 s3 = TextureLookup(sampler, texCoord + vec2(0., y_derivative)); |
| 2219 vec4 s4 = |
| 2220 TextureLookup(sampler, texCoord + vec2(x_derivative, y_derivative)); |
| 2221 vec2 f = fract(texCoord.xy / vec2(x_derivative, y_derivative)); |
| 2222 return mix(mix(s1, s2, f.x), mix(s3, s4, f.x), f.y); |
| 2223 } |
| 2224 void main() { |
| 2225 gl_FragColor = |
| 2226 vec4(vec3(TextureLookupBilinear(s_texture, v_texCoord).g), 1.); |
| 2227 } |
| 2228 }); |
| 2229 } |
| 2230 |
2179 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) { | 2231 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) { |
2180 } | 2232 } |
2181 | 2233 |
2182 void FragmentShaderColor::Init(GLES2Interface* context, | 2234 void FragmentShaderColor::Init(GLES2Interface* context, |
2183 unsigned program, | 2235 unsigned program, |
2184 int* base_uniform_index) { | 2236 int* base_uniform_index) { |
2185 static const char* uniforms[] = { | 2237 static const char* uniforms[] = { |
2186 "color", | 2238 "color", |
2187 }; | 2239 }; |
2188 int locations[arraysize(uniforms)]; | 2240 int locations[arraysize(uniforms)]; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2252 void main() { | 2304 void main() { |
2253 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 2305 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
2254 vec2 d2 = min(d4.xz, d4.yw); | 2306 vec2 d2 = min(d4.xz, d4.yw); |
2255 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 2307 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
2256 gl_FragColor = color * aa; | 2308 gl_FragColor = color * aa; |
2257 } | 2309 } |
2258 }); | 2310 }); |
2259 } | 2311 } |
2260 | 2312 |
2261 } // namespace cc | 2313 } // namespace cc |
OLD | NEW |