| 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 2110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2121 }); | 2121 }); |
| 2122 } else { | 2122 } else { |
| 2123 get_alpha = SHADER0([]() { | 2123 get_alpha = SHADER0([]() { |
| 2124 float GetAlpha(vec2 ya_clamped) { return alpha; } | 2124 float GetAlpha(vec2 ya_clamped) { return alpha; } |
| 2125 }); | 2125 }); |
| 2126 } | 2126 } |
| 2127 | 2127 |
| 2128 return FRAGMENT_SHADER(head, get_uv + get_alpha + main); | 2128 return FRAGMENT_SHADER(head, get_uv + get_alpha + main); |
| 2129 } | 2129 } |
| 2130 | 2130 |
| 2131 FragmentShaderYVideo::FragmentShaderYVideo() |
| 2132 : FragmentTexOpaqueBinding(), |
| 2133 x_derivative_location_(-1), |
| 2134 y_derivative_location_(-1) {} |
| 2135 |
| 2136 void FragmentShaderYVideo::Init(GLES2Interface* context, |
| 2137 unsigned program, |
| 2138 int* base_uniform_index) { |
| 2139 FragmentTexOpaqueBinding::Init(context, program, base_uniform_index); |
| 2140 |
| 2141 static const char* uniforms[] = {"x_derivative", "y_derivative"}; |
| 2142 int locations[arraysize(uniforms)]; |
| 2143 |
| 2144 GetProgramUniformLocations(context, program, arraysize(uniforms), uniforms, |
| 2145 locations, base_uniform_index); |
| 2146 x_derivative_location_ = locations[0]; |
| 2147 y_derivative_location_ = locations[1]; |
| 2148 } |
| 2149 |
| 2150 std::string FragmentShaderYVideo::GetShaderString(TexCoordPrecision precision, |
| 2151 SamplerType sampler) const { |
| 2152 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
| 2153 } |
| 2154 |
| 2155 std::string FragmentShaderYVideo::GetShaderHead() { |
| 2156 return SHADER0([]() { |
| 2157 precision mediump float; |
| 2158 varying TexCoordPrecision vec2 v_texCoord; |
| 2159 uniform SamplerType s_texture; |
| 2160 uniform float x_derivative; |
| 2161 uniform float y_derivative; |
| 2162 }); |
| 2163 } |
| 2164 |
| 2165 std::string FragmentShaderYVideo::GetShaderBody() { |
| 2166 return SHADER0([]() { |
| 2167 vec4 TextureLookupBilinear(sampler2D sampler, highp vec2 texCoord) { |
| 2168 vec4 s1 = texture2D(sampler, texCoord); |
| 2169 vec4 s2 = texture2D(sampler, texCoord + vec2(x_derivative, 0.)); |
| 2170 vec4 s3 = texture2D(sampler, texCoord + vec2(0., y_derivative)); |
| 2171 vec4 s4 = texture2D(sampler, texCoord + vec2(x_derivative, y_derivative)); |
| 2172 vec2 f = fract(texCoord.xy / vec2(x_derivative, y_derivative)); |
| 2173 return mix(mix(s1, s2, f.x), mix(s3, s4, f.x), f.y); |
| 2174 } |
| 2175 void main() { |
| 2176 gl_FragColor = |
| 2177 vec4(vec3(TextureLookupBilinear(s_texture, v_texCoord).g), 1.); |
| 2178 } |
| 2179 }); |
| 2180 } |
| 2181 |
| 2131 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) { | 2182 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) { |
| 2132 } | 2183 } |
| 2133 | 2184 |
| 2134 void FragmentShaderColor::Init(GLES2Interface* context, | 2185 void FragmentShaderColor::Init(GLES2Interface* context, |
| 2135 unsigned program, | 2186 unsigned program, |
| 2136 int* base_uniform_index) { | 2187 int* base_uniform_index) { |
| 2137 static const char* uniforms[] = { | 2188 static const char* uniforms[] = { |
| 2138 "color", | 2189 "color", |
| 2139 }; | 2190 }; |
| 2140 int locations[arraysize(uniforms)]; | 2191 int locations[arraysize(uniforms)]; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2204 void main() { | 2255 void main() { |
| 2205 vec4 d4 = min(edge_dist[0], edge_dist[1]); | 2256 vec4 d4 = min(edge_dist[0], edge_dist[1]); |
| 2206 vec2 d2 = min(d4.xz, d4.yw); | 2257 vec2 d2 = min(d4.xz, d4.yw); |
| 2207 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); | 2258 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); |
| 2208 gl_FragColor = color * aa; | 2259 gl_FragColor = color * aa; |
| 2209 } | 2260 } |
| 2210 }); | 2261 }); |
| 2211 } | 2262 } |
| 2212 | 2263 |
| 2213 } // namespace cc | 2264 } // namespace cc |
| OLD | NEW |