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 1986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1997 locations->original_backdrop = original_backdrop_location(); | 1997 locations->original_backdrop = original_backdrop_location(); |
1998 } | 1998 } |
1999 | 1999 |
2000 FragmentShaderYUVVideo::FragmentShaderYUVVideo() | 2000 FragmentShaderYUVVideo::FragmentShaderYUVVideo() |
2001 : y_texture_location_(-1), | 2001 : y_texture_location_(-1), |
2002 u_texture_location_(-1), | 2002 u_texture_location_(-1), |
2003 v_texture_location_(-1), | 2003 v_texture_location_(-1), |
2004 alpha_location_(-1), | 2004 alpha_location_(-1), |
2005 yuv_matrix_location_(-1), | 2005 yuv_matrix_location_(-1), |
2006 yuv_adj_location_(-1), | 2006 yuv_adj_location_(-1), |
2007 clamp_rect_location_(-1) { | 2007 ya_clamp_rect_location_(-1), |
| 2008 uv_clamp_rect_location_(-1) { |
2008 } | 2009 } |
2009 | 2010 |
2010 void FragmentShaderYUVVideo::Init(GLES2Interface* context, | 2011 void FragmentShaderYUVVideo::Init(GLES2Interface* context, |
2011 unsigned program, | 2012 unsigned program, |
2012 int* base_uniform_index) { | 2013 int* base_uniform_index) { |
2013 static const char* uniforms[] = {"y_texture", | 2014 static const char* uniforms[] = {"y_texture", |
2014 "u_texture", | 2015 "u_texture", |
2015 "v_texture", | 2016 "v_texture", |
2016 "alpha", | 2017 "alpha", |
2017 "yuv_matrix", | 2018 "yuv_matrix", |
2018 "yuv_adj", | 2019 "yuv_adj", |
2019 "clamp_rect"}; | 2020 "ya_clamp_rect", |
| 2021 "uv_clamp_rect"}; |
2020 int locations[arraysize(uniforms)]; | 2022 int locations[arraysize(uniforms)]; |
2021 | 2023 |
2022 GetProgramUniformLocations(context, | 2024 GetProgramUniformLocations(context, |
2023 program, | 2025 program, |
2024 arraysize(uniforms), | 2026 arraysize(uniforms), |
2025 uniforms, | 2027 uniforms, |
2026 locations, | 2028 locations, |
2027 base_uniform_index); | 2029 base_uniform_index); |
2028 y_texture_location_ = locations[0]; | 2030 y_texture_location_ = locations[0]; |
2029 u_texture_location_ = locations[1]; | 2031 u_texture_location_ = locations[1]; |
2030 v_texture_location_ = locations[2]; | 2032 v_texture_location_ = locations[2]; |
2031 alpha_location_ = locations[3]; | 2033 alpha_location_ = locations[3]; |
2032 yuv_matrix_location_ = locations[4]; | 2034 yuv_matrix_location_ = locations[4]; |
2033 yuv_adj_location_ = locations[5]; | 2035 yuv_adj_location_ = locations[5]; |
2034 clamp_rect_location_ = locations[6]; | 2036 ya_clamp_rect_location_ = locations[6]; |
| 2037 uv_clamp_rect_location_ = locations[7]; |
2035 } | 2038 } |
2036 | 2039 |
2037 std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, | 2040 std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, |
2038 SamplerType sampler) const { | 2041 SamplerType sampler) const { |
2039 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | 2042 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
2040 } | 2043 } |
2041 | 2044 |
2042 std::string FragmentShaderYUVVideo::GetShaderHead() { | 2045 std::string FragmentShaderYUVVideo::GetShaderHead() { |
2043 return SHADER0([]() { | 2046 return SHADER0([]() { |
2044 precision mediump float; | 2047 precision mediump float; |
2045 precision mediump int; | 2048 precision mediump int; |
2046 varying TexCoordPrecision vec2 v_texCoord; | 2049 varying TexCoordPrecision vec2 v_texCoord; |
2047 uniform SamplerType y_texture; | 2050 uniform SamplerType y_texture; |
2048 uniform SamplerType u_texture; | 2051 uniform SamplerType u_texture; |
2049 uniform SamplerType v_texture; | 2052 uniform SamplerType v_texture; |
2050 uniform float alpha; | 2053 uniform float alpha; |
2051 uniform vec3 yuv_adj; | 2054 uniform vec3 yuv_adj; |
2052 uniform mat3 yuv_matrix; | 2055 uniform mat3 yuv_matrix; |
2053 uniform vec4 clamp_rect; | 2056 uniform vec4 ya_clamp_rect; |
| 2057 uniform vec4 uv_clamp_rect; |
2054 }); | 2058 }); |
2055 } | 2059 } |
2056 | 2060 |
2057 std::string FragmentShaderYUVVideo::GetShaderBody() { | 2061 std::string FragmentShaderYUVVideo::GetShaderBody() { |
2058 return SHADER0([]() { | 2062 return SHADER0([]() { |
2059 void main() { | 2063 void main() { |
2060 vec2 clamped = max(clamp_rect.xy, min(clamp_rect.zw, v_texCoord)); | 2064 vec2 ya_clamped = |
2061 float y_raw = TextureLookup(y_texture, clamped).x; | 2065 max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_texCoord)); |
2062 float u_unsigned = TextureLookup(u_texture, clamped).x; | 2066 float y_raw = TextureLookup(y_texture, ya_clamped).x; |
2063 float v_unsigned = TextureLookup(v_texture, clamped).x; | 2067 vec2 uv_clamped = |
| 2068 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_texCoord)); |
| 2069 float u_unsigned = TextureLookup(u_texture, uv_clamped).x; |
| 2070 float v_unsigned = TextureLookup(v_texture, uv_clamped).x; |
2064 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 2071 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
2065 vec3 rgb = yuv_matrix * yuv; | 2072 vec3 rgb = yuv_matrix * yuv; |
2066 gl_FragColor = vec4(rgb, 1.0) * alpha; | 2073 gl_FragColor = vec4(rgb, 1.0) * alpha; |
2067 } | 2074 } |
2068 }); | 2075 }); |
2069 } | 2076 } |
2070 | 2077 |
2071 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() | 2078 FragmentShaderYUVAVideo::FragmentShaderYUVAVideo() |
2072 : y_texture_location_(-1), | 2079 : y_texture_location_(-1), |
2073 u_texture_location_(-1), | 2080 u_texture_location_(-1), |
2074 v_texture_location_(-1), | 2081 v_texture_location_(-1), |
2075 a_texture_location_(-1), | 2082 a_texture_location_(-1), |
2076 alpha_location_(-1), | 2083 alpha_location_(-1), |
2077 yuv_matrix_location_(-1), | 2084 yuv_matrix_location_(-1), |
2078 yuv_adj_location_(-1) { | 2085 yuv_adj_location_(-1) { |
2079 } | 2086 } |
2080 | 2087 |
2081 void FragmentShaderYUVAVideo::Init(GLES2Interface* context, | 2088 void FragmentShaderYUVAVideo::Init(GLES2Interface* context, |
2082 unsigned program, | 2089 unsigned program, |
2083 int* base_uniform_index) { | 2090 int* base_uniform_index) { |
2084 static const char* uniforms[] = { | 2091 static const char* uniforms[] = { |
2085 "y_texture", | 2092 "y_texture", |
2086 "u_texture", | 2093 "u_texture", |
2087 "v_texture", | 2094 "v_texture", |
2088 "a_texture", | 2095 "a_texture", |
2089 "alpha", | 2096 "alpha", |
2090 "cc_matrix", | 2097 "cc_matrix", |
2091 "yuv_adj", | 2098 "yuv_adj", |
2092 "clamp_rect", | 2099 "ya_clamp_rect", |
| 2100 "uv_clamp_rect", |
2093 }; | 2101 }; |
2094 int locations[arraysize(uniforms)]; | 2102 int locations[arraysize(uniforms)]; |
2095 | 2103 |
2096 GetProgramUniformLocations(context, | 2104 GetProgramUniformLocations(context, |
2097 program, | 2105 program, |
2098 arraysize(uniforms), | 2106 arraysize(uniforms), |
2099 uniforms, | 2107 uniforms, |
2100 locations, | 2108 locations, |
2101 base_uniform_index); | 2109 base_uniform_index); |
2102 y_texture_location_ = locations[0]; | 2110 y_texture_location_ = locations[0]; |
2103 u_texture_location_ = locations[1]; | 2111 u_texture_location_ = locations[1]; |
2104 v_texture_location_ = locations[2]; | 2112 v_texture_location_ = locations[2]; |
2105 a_texture_location_ = locations[3]; | 2113 a_texture_location_ = locations[3]; |
2106 alpha_location_ = locations[4]; | 2114 alpha_location_ = locations[4]; |
2107 yuv_matrix_location_ = locations[5]; | 2115 yuv_matrix_location_ = locations[5]; |
2108 yuv_adj_location_ = locations[6]; | 2116 yuv_adj_location_ = locations[6]; |
2109 clamp_rect_location_ = locations[7]; | 2117 ya_clamp_rect_location_ = locations[7]; |
| 2118 uv_clamp_rect_location_ = locations[8]; |
2110 } | 2119 } |
2111 | 2120 |
2112 std::string FragmentShaderYUVAVideo::GetShaderString( | 2121 std::string FragmentShaderYUVAVideo::GetShaderString( |
2113 TexCoordPrecision precision, | 2122 TexCoordPrecision precision, |
2114 SamplerType sampler) const { | 2123 SamplerType sampler) const { |
2115 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); | 2124 return FRAGMENT_SHADER(GetShaderHead(), GetShaderBody()); |
2116 } | 2125 } |
2117 | 2126 |
2118 std::string FragmentShaderYUVAVideo::GetShaderHead() { | 2127 std::string FragmentShaderYUVAVideo::GetShaderHead() { |
2119 return SHADER0([]() { | 2128 return SHADER0([]() { |
2120 precision mediump float; | 2129 precision mediump float; |
2121 precision mediump int; | 2130 precision mediump int; |
2122 varying TexCoordPrecision vec2 v_texCoord; | 2131 varying TexCoordPrecision vec2 v_texCoord; |
2123 uniform SamplerType y_texture; | 2132 uniform SamplerType y_texture; |
2124 uniform SamplerType u_texture; | 2133 uniform SamplerType u_texture; |
2125 uniform SamplerType v_texture; | 2134 uniform SamplerType v_texture; |
2126 uniform SamplerType a_texture; | 2135 uniform SamplerType a_texture; |
2127 uniform float alpha; | 2136 uniform float alpha; |
2128 uniform vec3 yuv_adj; | 2137 uniform vec3 yuv_adj; |
2129 uniform mat3 yuv_matrix; | 2138 uniform mat3 yuv_matrix; |
2130 uniform vec4 clamp_rect; | 2139 uniform vec4 ya_clamp_rect; |
| 2140 uniform vec4 uv_clamp_rect; |
2131 }); | 2141 }); |
2132 } | 2142 } |
2133 | 2143 |
2134 std::string FragmentShaderYUVAVideo::GetShaderBody() { | 2144 std::string FragmentShaderYUVAVideo::GetShaderBody() { |
2135 return SHADER0([]() { | 2145 return SHADER0([]() { |
2136 void main() { | 2146 void main() { |
2137 vec2 clamped = max(clamp_rect.xy, min(clamp_rect.zw, v_texCoord)); | 2147 vec2 ya_clamped = |
2138 float y_raw = TextureLookup(y_texture, clamped).x; | 2148 max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_texCoord)); |
2139 float u_unsigned = TextureLookup(u_texture, clamped).x; | 2149 float y_raw = TextureLookup(y_texture, ya_clamped).x; |
2140 float v_unsigned = TextureLookup(v_texture, clamped).x; | 2150 vec2 uv_clamped = |
2141 float a_raw = TextureLookup(a_texture, clamped).x; | 2151 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_texCoord)); |
| 2152 float u_unsigned = TextureLookup(u_texture, uv_clamped).x; |
| 2153 float v_unsigned = TextureLookup(v_texture, uv_clamped).x; |
| 2154 float a_raw = TextureLookup(a_texture, ya_clamped).x; |
2142 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; | 2155 vec3 yuv = vec3(y_raw, u_unsigned, v_unsigned) + yuv_adj; |
2143 vec3 rgb = yuv_matrix * yuv; | 2156 vec3 rgb = yuv_matrix * yuv; |
2144 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); | 2157 gl_FragColor = vec4(rgb, 1.0) * (alpha * a_raw); |
2145 } | 2158 } |
2146 }); | 2159 }); |
2147 } | 2160 } |
2148 | 2161 |
2149 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) { | 2162 FragmentShaderColor::FragmentShaderColor() : color_location_(-1) { |
2150 } | 2163 } |
2151 | 2164 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2282 vec2 texCoord = | 2295 vec2 texCoord = |
2283 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; | 2296 clamp(v_texCoord, 0.0, 1.0) * texTransform.zw + texTransform.xy; |
2284 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); | 2297 vec2 coord = mod(floor(texCoord * frequency * 2.0), 2.0); |
2285 float picker = abs(coord.x - coord.y); // NOLINT | 2298 float picker = abs(coord.x - coord.y); // NOLINT |
2286 gl_FragColor = mix(color1, color2, picker) * alpha; | 2299 gl_FragColor = mix(color1, color2, picker) * alpha; |
2287 } | 2300 } |
2288 }); | 2301 }); |
2289 } | 2302 } |
2290 | 2303 |
2291 } // namespace cc | 2304 } // namespace cc |
OLD | NEW |