Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(273)

Side by Side Diff: cc/output/shader.cc

Issue 2122573003: media: replace LUMINANCE_F16 by RG_88 for 9/10-bit h264 videos Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase to ToT Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/output/shader.h ('k') | cc/quads/yuv_video_draw_quad.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2005 matching lines...) Expand 10 before | Expand all | Expand 10 after
2016 FragmentShaderYUVVideo::FragmentShaderYUVVideo() 2016 FragmentShaderYUVVideo::FragmentShaderYUVVideo()
2017 : y_texture_location_(-1), 2017 : y_texture_location_(-1),
2018 u_texture_location_(-1), 2018 u_texture_location_(-1),
2019 v_texture_location_(-1), 2019 v_texture_location_(-1),
2020 uv_texture_location_(-1), 2020 uv_texture_location_(-1),
2021 a_texture_location_(-1), 2021 a_texture_location_(-1),
2022 lut_texture_location_(-1), 2022 lut_texture_location_(-1),
2023 alpha_location_(-1), 2023 alpha_location_(-1),
2024 yuv_matrix_location_(-1), 2024 yuv_matrix_location_(-1),
2025 yuv_adj_location_(-1), 2025 yuv_adj_location_(-1),
2026 ya_size_location_(-1),
2027 uv_size_location_(-1),
2026 ya_clamp_rect_location_(-1), 2028 ya_clamp_rect_location_(-1),
2027 uv_clamp_rect_location_(-1), 2029 uv_clamp_rect_location_(-1),
2028 resource_multiplier_location_(-1), 2030 resource_multiplier_location_(-1),
2029 resource_offset_location_(-1) {} 2031 resource_offset_location_(-1) {}
2030 2032
2031 void FragmentShaderYUVVideo::SetFeatures(bool use_alpha_texture, 2033 void FragmentShaderYUVVideo::SetFeatures(bool use_alpha_texture,
2032 bool use_nv12, 2034 bool use_nv12,
2033 bool use_color_lut) { 2035 bool use_color_lut,
2036 HighbitTexture highbit_texture) {
2034 use_alpha_texture_ = use_alpha_texture; 2037 use_alpha_texture_ = use_alpha_texture;
2035 use_nv12_ = use_nv12; 2038 use_nv12_ = use_nv12;
2036 use_color_lut_ = use_color_lut; 2039 use_color_lut_ = use_color_lut;
2040 highbit_texture_ = highbit_texture;
2037 } 2041 }
2038 2042
2039 void FragmentShaderYUVVideo::Init(GLES2Interface* context, 2043 void FragmentShaderYUVVideo::Init(GLES2Interface* context,
2040 unsigned program, 2044 unsigned program,
2041 int* base_uniform_index) { 2045 int* base_uniform_index) {
2042 static const char* uniforms[] = { 2046 static const char* uniforms[] = {
2043 "y_texture", 2047 "y_texture",
2044 "u_texture", 2048 "u_texture",
2045 "v_texture", 2049 "v_texture",
2046 "uv_texture", 2050 "uv_texture",
2047 "a_texture", 2051 "a_texture",
2048 "lut_texture", 2052 "lut_texture",
2049 "resource_multiplier", 2053 "resource_multiplier",
2050 "resource_offset", 2054 "resource_offset",
2051 "yuv_matrix", 2055 "yuv_matrix",
2052 "yuv_adj", 2056 "yuv_adj",
2057 "ya_size",
2058 "uv_size",
2053 "alpha", 2059 "alpha",
2054 "ya_clamp_rect", 2060 "ya_clamp_rect",
2055 "uv_clamp_rect", 2061 "uv_clamp_rect",
2056 }; 2062 };
2057 int locations[arraysize(uniforms)]; 2063 int locations[arraysize(uniforms)];
2058 2064
2059 GetProgramUniformLocations(context, 2065 GetProgramUniformLocations(context,
2060 program, 2066 program,
2061 arraysize(uniforms), 2067 arraysize(uniforms),
2062 uniforms, 2068 uniforms,
2063 locations, 2069 locations,
2064 base_uniform_index); 2070 base_uniform_index);
2065 y_texture_location_ = locations[0]; 2071 y_texture_location_ = locations[0];
2066 if (!use_nv12_) { 2072 if (!use_nv12_) {
2067 u_texture_location_ = locations[1]; 2073 u_texture_location_ = locations[1];
2068 v_texture_location_ = locations[2]; 2074 v_texture_location_ = locations[2];
2069 } else { 2075 } else {
2070 uv_texture_location_ = locations[3]; 2076 uv_texture_location_ = locations[3];
2071 } 2077 }
2072 if (use_alpha_texture_) { 2078 if (use_alpha_texture_) {
2073 a_texture_location_ = locations[4]; 2079 a_texture_location_ = locations[4];
2074 } 2080 }
2075 if (use_color_lut_) { 2081 if (use_color_lut_) {
2076 lut_texture_location_ = locations[5]; 2082 lut_texture_location_ = locations[5];
2077 resource_multiplier_location_ = locations[6]; 2083 if (highbit_texture_ == HIGHBIT_LUMINANCE_F16 ||
2078 resource_offset_location_ = locations[7]; 2084 highbit_texture_ == HIGHBIT_RG88) {
2085 resource_multiplier_location_ = locations[6];
2086 }
2087 if (highbit_texture_ == HIGHBIT_LUMINANCE_F16) {
2088 resource_offset_location_ = locations[7];
2089 }
2079 } else { 2090 } else {
2080 yuv_matrix_location_ = locations[8]; 2091 yuv_matrix_location_ = locations[8];
2081 yuv_adj_location_ = locations[9]; 2092 yuv_adj_location_ = locations[9];
2082 } 2093 }
2083 alpha_location_ = locations[10]; 2094 if (highbit_texture_ == HIGHBIT_RG88) {
2084 ya_clamp_rect_location_ = locations[11]; 2095 ya_size_location_ = locations[10];
2085 uv_clamp_rect_location_ = locations[12]; 2096 uv_size_location_ = locations[11];
2097 }
2098 alpha_location_ = locations[12];
2099 ya_clamp_rect_location_ = locations[13];
2100 uv_clamp_rect_location_ = locations[14];
2086 } 2101 }
2087 2102
2088 std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision, 2103 std::string FragmentShaderYUVVideo::GetShaderString(TexCoordPrecision precision,
2089 SamplerType sampler) const { 2104 SamplerType sampler) const {
2090 std::string head = SHADER0([]() { 2105 std::string head = SHADER0([]() {
2091 precision mediump float; 2106 precision mediump float;
2092 precision mediump int; 2107 precision mediump int;
2093 varying TexCoordPrecision vec2 v_yaTexCoord; 2108 varying TexCoordPrecision vec2 v_yaTexCoord;
2094 varying TexCoordPrecision vec2 v_uvTexCoord; 2109 varying TexCoordPrecision vec2 v_uvTexCoord;
2095 uniform SamplerType y_texture; 2110 uniform SamplerType y_texture;
2096 uniform float alpha; 2111 uniform float alpha;
2097 uniform vec4 ya_clamp_rect; 2112 uniform vec4 ya_clamp_rect;
2098 uniform vec4 uv_clamp_rect; 2113 uniform vec4 uv_clamp_rect;
2099 }); 2114 });
2100 2115
2101 std::string functions = ""; 2116 std::string functions = "";
2117 if (highbit_texture_ == HIGHBIT_RG88) {
2118 head += " uniform vec2 ya_size;\n";
2119 head += " uniform vec2 uv_size;\n";
2120 functions += SHADER0([]() {
2121 float GetFloat(SamplerType sampler, vec2 tex_coord) {
2122 vec2 rg = TextureLookup(sampler, tex_coord).xy;
2123 return (rg.g * 256.0) + rg.r;
2124 }
2125
2126 // refer to Mesa sample_2d_linear() in s_texfilter.c
2127 // https://cs.chromium.org/chromium/src/third_party/mesa/src/src/mesa/swra st/s_texfilter.c?q=sample_2d_linear&sq=package:chromium
2128 float RGTextureLookupBilinear(SamplerType sampler, vec2 tex_coord,
2129 vec2 tex_size) {
2130 vec2 unit_texel = 1.0 / tex_size;
2131 vec2 unnorm_tex_coord = (tex_coord * tex_size) - vec2(0.5);
2132 vec2 f = fract(unnorm_tex_coord);
2133 vec2 snap_tex_coord = (floor(unnorm_tex_coord) + vec2(0.5)) / tex_size;
2134 float s1 = GetFloat(sampler, snap_tex_coord);
2135 float s2 = GetFloat(sampler, snap_tex_coord + vec2(unit_texel.x, 0.));
2136 float s3 = GetFloat(sampler, snap_tex_coord + vec2(0., unit_texel.y));
2137 float s4 = GetFloat(sampler, snap_tex_coord + unit_texel);
2138 return mix(mix(s1, s2, f.x), mix(s3, s4, f.x), f.y);
2139 }
2140
2141 float GetY(vec2 ya_clamped) {
2142 return RGTextureLookupBilinear(y_texture, ya_clamped, ya_size);
2143 }
2144 });
2145 } else {
2146 functions += SHADER0([]() {
2147 float GetY(vec2 ya_clamped) {
2148 return TextureLookup(y_texture, ya_clamped).x;
2149 }
2150 });
2151 }
2152
2102 if (use_nv12_) { 2153 if (use_nv12_) {
2103 head += " uniform SamplerType uv_texture;\n"; 2154 head += " uniform SamplerType uv_texture;\n";
2104 functions += SHADER0([]() { 2155 functions += SHADER0([]() {
2105 vec2 GetUV(vec2 uv_clamped) { 2156 vec2 GetUV(vec2 uv_clamped) {
2106 return TextureLookup(uv_texture, uv_clamped).xy; 2157 return TextureLookup(uv_texture, uv_clamped).xy;
2107 } 2158 }
2108 }); 2159 });
2109 } else { 2160 } else {
2110 head += " uniform SamplerType u_texture;\n"; 2161 head += " uniform SamplerType u_texture;\n";
2111 head += " uniform SamplerType v_texture;\n"; 2162 head += " uniform SamplerType v_texture;\n";
2112 functions += SHADER0([]() { 2163 if (highbit_texture_ == HIGHBIT_RG88) {
2113 vec2 GetUV(vec2 uv_clamped) { 2164 functions += SHADER0([]() {
2114 return vec2(TextureLookup(u_texture, uv_clamped).x, 2165 vec2 GetUV(vec2 uv_clamped) {
2115 TextureLookup(v_texture, uv_clamped).x); 2166 vec2 uv =
2116 } 2167 vec2(RGTextureLookupBilinear(u_texture, uv_clamped, uv_size),
2117 }); 2168 RGTextureLookupBilinear(v_texture, uv_clamped, uv_size));
2169 return uv;
2170 }
2171 });
2172 } else {
2173 functions += SHADER0([]() {
2174 vec2 GetUV(vec2 uv_clamped) {
2175 vec2 uv = vec2(TextureLookup(u_texture, uv_clamped).x,
2176 TextureLookup(v_texture, uv_clamped).x);
2177 return uv;
2178 }
2179 });
2180 }
2118 } 2181 }
2119 2182
2120 if (use_alpha_texture_) { 2183 if (use_alpha_texture_) {
2121 head += " uniform SamplerType a_texture;\n"; 2184 head += " uniform SamplerType a_texture;\n";
2122 functions += SHADER0([]() { 2185 functions += SHADER0([]() {
2123 float GetAlpha(vec2 ya_clamped) { 2186 float GetAlpha(vec2 ya_clamped) {
2124 return alpha * TextureLookup(a_texture, ya_clamped).x; 2187 return alpha * TextureLookup(a_texture, ya_clamped).x;
2125 } 2188 }
2126 }); 2189 });
2127 } else { 2190 } else {
2128 functions += SHADER0([]() { 2191 functions += SHADER0([]() {
2129 float GetAlpha(vec2 ya_clamped) { return alpha; } 2192 float GetAlpha(vec2 ya_clamped) { return alpha; }
2130 }); 2193 });
2131 } 2194 }
2132 2195
2133 if (use_color_lut_) { 2196 if (use_color_lut_) {
2134 head += " uniform sampler2D lut_texture;\n"; 2197 head += " uniform sampler2D lut_texture;\n";
2135 head += " uniform float resource_multiplier;\n";
2136 head += " uniform float resource_offset;\n";
2137 functions += SHADER0([]() { 2198 functions += SHADER0([]() {
2138 vec4 LUT(sampler2D sampler, vec3 pos, float size) { 2199 vec4 LUT(sampler2D sampler, vec3 pos, float size) {
2139 pos *= size - 1.0; 2200 pos *= size - 1.0;
2140 // Select layer 2201 // Select layer
2141 float layer = min(floor(pos.x), size - 2.0); 2202 float layer = min(floor(pos.x), size - 2.0);
2142 // Compress the yz coordinates so they stay within 2203 // Compress the yz coordinates so they stay within
2143 // [0.5 .. 31.5] / 32 (assuming a LUT size of 32^3) 2204 // [0.5 .. 31.5] / 32 (assuming a LUT size of 32^3)
2144 pos.yz = (pos.yz + vec2(0.5)) / size; 2205 pos.yz = (pos.yz + vec2(0.5)) / size;
2145 pos.z = (pos.z + layer) / size; 2206 pos.z = (pos.z + layer) / size;
2146 return mix(texture2D(sampler, pos.yz), 2207 return mix(texture2D(sampler, pos.yz),
2147 texture2D(sampler, pos.yz + vec2(0, 1.0 / size)), 2208 texture2D(sampler, pos.yz + vec2(0, 1.0 / size)),
2148 pos.x - layer); 2209 pos.x - layer);
2149 } 2210 }
2150
2151 vec3 yuv2rgb(vec3 yuv) {
2152 yuv = (yuv - vec3(resource_offset)) * resource_multiplier;
2153 return LUT(lut_texture, yuv, 32.0).xyz;
2154 }
2155 }); 2211 });
2212 if (highbit_texture_ == HIGHBIT_LUMINANCE_F16) {
2213 head += " uniform float resource_multiplier;\n";
2214 head += " uniform float resource_offset;\n";
2215 functions += SHADER0([]() {
2216 vec3 yuv2rgb(vec3 yuv) {
2217 yuv = (yuv - vec3(resource_offset)) * resource_multiplier;
2218 return LUT(lut_texture, yuv, 32.0).xyz;
2219 }
2220 });
2221 } else if (highbit_texture_ == HIGHBIT_RG88) {
2222 head += " uniform float resource_multiplier;\n";
2223 functions += SHADER0([]() {
2224 vec3 yuv2rgb(vec3 yuv) {
2225 yuv = yuv * resource_multiplier;
2226 return LUT(lut_texture, yuv, 32.0).xyz;
2227 }
2228 });
2229 } else {
2230 functions += SHADER0([]() {
2231 vec3 yuv2rgb(vec3 yuv) { return LUT(lut_texture, yuv, 32.0).xyz; }
2232 });
2233 }
2156 } else { 2234 } else {
2157 head += " uniform mat3 yuv_matrix;\n"; 2235 head += " uniform mat3 yuv_matrix;\n";
2158 head += " uniform vec3 yuv_adj;\n"; 2236 head += " uniform vec3 yuv_adj;\n";
2159 functions += SHADER0([]() { 2237 functions += SHADER0([]() {
2160 vec3 yuv2rgb(vec3 yuv) { return yuv_matrix * (yuv + yuv_adj); } 2238 vec3 yuv2rgb(vec3 yuv) { return yuv_matrix * (yuv + yuv_adj); }
2161 }); 2239 });
2162 } 2240 }
2163 2241
2164 functions += SHADER0([]() { 2242 functions += SHADER0([]() {
2165 void main() { 2243 void main() {
2166 vec2 ya_clamped = 2244 vec2 ya_clamped =
2167 max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_yaTexCoord)); 2245 max(ya_clamp_rect.xy, min(ya_clamp_rect.zw, v_yaTexCoord));
2168 float y_raw = TextureLookup(y_texture, ya_clamped).x; 2246 float y_raw = GetY(ya_clamped);
2169 vec2 uv_clamped = 2247 vec2 uv_clamped =
2170 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord)); 2248 max(uv_clamp_rect.xy, min(uv_clamp_rect.zw, v_uvTexCoord));
2171 vec3 yuv = vec3(y_raw, GetUV(uv_clamped)); 2249 vec3 yuv = vec3(y_raw, GetUV(uv_clamped));
2172 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped); 2250 gl_FragColor = vec4(yuv2rgb(yuv), 1.0) * GetAlpha(ya_clamped);
2173 } 2251 }
2174 }); 2252 });
2175 2253
2176 return FRAGMENT_SHADER(head, functions); 2254 return FRAGMENT_SHADER(head, functions);
2177 } 2255 }
2178 2256
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2252 void main() { 2330 void main() {
2253 vec4 d4 = min(edge_dist[0], edge_dist[1]); 2331 vec4 d4 = min(edge_dist[0], edge_dist[1]);
2254 vec2 d2 = min(d4.xz, d4.yw); 2332 vec2 d2 = min(d4.xz, d4.yw);
2255 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0); 2333 float aa = clamp(gl_FragCoord.w * min(d2.x, d2.y), 0.0, 1.0);
2256 gl_FragColor = color * aa; 2334 gl_FragColor = color * aa;
2257 } 2335 }
2258 }); 2336 });
2259 } 2337 }
2260 2338
2261 } // namespace cc 2339 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/shader.h ('k') | cc/quads/yuv_video_draw_quad.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698