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

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

Issue 2173563002: Improve GL shader YUV adjustment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: switch to uint32_t Created 4 years, 4 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/layers/video_layer_impl.cc ('k') | cc/output/renderer_pixeltest.cc » ('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 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 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/gl_renderer.h" 5 #include "cc/output/gl_renderer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 2210 matching lines...) Expand 10 before | Expand all | Expand 10 after
2221 float yuv_to_rgb_rec601[9] = { 2221 float yuv_to_rgb_rec601[9] = {
2222 1.164f, 1.164f, 1.164f, 0.0f, -.391f, 2.018f, 1.596f, -.813f, 0.0f, 2222 1.164f, 1.164f, 1.164f, 0.0f, -.391f, 2.018f, 1.596f, -.813f, 0.0f,
2223 }; 2223 };
2224 float yuv_to_rgb_jpeg[9] = { 2224 float yuv_to_rgb_jpeg[9] = {
2225 1.f, 1.f, 1.f, 0.0f, -.34414f, 1.772f, 1.402f, -.71414f, 0.0f, 2225 1.f, 1.f, 1.f, 0.0f, -.34414f, 1.772f, 1.402f, -.71414f, 0.0f,
2226 }; 2226 };
2227 float yuv_to_rgb_rec709[9] = { 2227 float yuv_to_rgb_rec709[9] = {
2228 1.164f, 1.164f, 1.164f, 0.0f, -0.213f, 2.112f, 1.793f, -0.533f, 0.0f, 2228 1.164f, 1.164f, 1.164f, 0.0f, -0.213f, 2.112f, 1.793f, -0.533f, 0.0f,
2229 }; 2229 };
2230 2230
2231 // These values map to 16, 128, and 128 respectively, and are computed
2232 // as a fraction over 256 (e.g. 16 / 256 = 0.0625).
2233 // They are used in the YUV to RGBA conversion formula: 2231 // They are used in the YUV to RGBA conversion formula:
2234 // Y - 16 : Gives 16 values of head and footroom for overshooting 2232 // Y - 16 : Gives 16 values of head and footroom for overshooting
2235 // U - 128 : Turns unsigned U into signed U [-128,127] 2233 // U - 128 : Turns unsigned U into signed U [-128,127]
2236 // V - 128 : Turns unsigned V into signed V [-128,127] 2234 // V - 128 : Turns unsigned V into signed V [-128,127]
2237 float yuv_adjust_constrained[3] = { 2235 float yuv_adjust_constrained[3] = {
2238 -0.0625f, -0.5f, -0.5f, 2236 -16.f, -128.f, -128.f,
2239 }; 2237 };
2240 2238
2241 // Same as above, but without the head and footroom. 2239 // Same as above, but without the head and footroom.
2242 float yuv_adjust_full[3] = { 2240 float yuv_adjust_full[3] = {
2243 0.0f, -0.5f, -0.5f, 2241 0.0f, -128.f, -128.f,
2244 }; 2242 };
2245 2243
2246 float* yuv_to_rgb = NULL; 2244 float* yuv_to_rgb = NULL;
2247 float* yuv_adjust = NULL; 2245 float* yuv_adjust = NULL;
2248 2246
2249 switch (quad->color_space) { 2247 switch (quad->color_space) {
2250 case YUVVideoDrawQuad::REC_601: 2248 case YUVVideoDrawQuad::REC_601:
2251 yuv_to_rgb = yuv_to_rgb_rec601; 2249 yuv_to_rgb = yuv_to_rgb_rec601;
2252 yuv_adjust = yuv_adjust_constrained; 2250 yuv_adjust = yuv_adjust_constrained;
2253 break; 2251 break;
2254 case YUVVideoDrawQuad::REC_709: 2252 case YUVVideoDrawQuad::REC_709:
2255 yuv_to_rgb = yuv_to_rgb_rec709; 2253 yuv_to_rgb = yuv_to_rgb_rec709;
2256 yuv_adjust = yuv_adjust_constrained; 2254 yuv_adjust = yuv_adjust_constrained;
2257 break; 2255 break;
2258 case YUVVideoDrawQuad::JPEG: 2256 case YUVVideoDrawQuad::JPEG:
2259 yuv_to_rgb = yuv_to_rgb_jpeg; 2257 yuv_to_rgb = yuv_to_rgb_jpeg;
2260 yuv_adjust = yuv_adjust_full; 2258 yuv_adjust = yuv_adjust_full;
2261 break; 2259 break;
2262 } 2260 }
2263 2261
2264 float yuv_to_rgb_multiplied[9]; 2262 float yuv_to_rgb_multiplied[9];
2265 float yuv_adjust_with_offset[3]; 2263 float yuv_adjust_with_offset[3];
2266 2264
2265 // Formula according to BT.601-7 section 2.5.3.
2266 float adjustment_multiplier = (1 << (quad->bits_per_channel - 8)) * 1.0f /
dcheng 2016/07/29 02:37:07 What happens if bits_per_channel is < 8 or > 39? A
2267 ((1 << quad->bits_per_channel) - 1);
2268
2267 for (int i = 0; i < 9; ++i) 2269 for (int i = 0; i < 9; ++i)
2268 yuv_to_rgb_multiplied[i] = yuv_to_rgb[i] * quad->resource_multiplier; 2270 yuv_to_rgb_multiplied[i] = yuv_to_rgb[i] * quad->resource_multiplier;
2269 2271
2270 for (int i = 0; i < 3; ++i) 2272 for (int i = 0; i < 3; ++i) {
2271 yuv_adjust_with_offset[i] = 2273 yuv_adjust_with_offset[i] =
2272 yuv_adjust[i] / quad->resource_multiplier - quad->resource_offset; 2274 yuv_adjust[i] * adjustment_multiplier / quad->resource_multiplier -
2275 quad->resource_offset;
2276 }
2273 2277
2274 // The transform and vertex data are used to figure out the extents that the 2278 // The transform and vertex data are used to figure out the extents that the
2275 // un-antialiased quad should have and which vertex this is and the float 2279 // un-antialiased quad should have and which vertex this is and the float
2276 // quad passed in via uniform is the actual geometry that gets used to draw 2280 // quad passed in via uniform is the actual geometry that gets used to draw
2277 // it. This is why this centered rect is used and not the original quad_rect. 2281 // it. This is why this centered rect is used and not the original quad_rect.
2278 auto tile_rect = gfx::RectF(quad->rect); 2282 auto tile_rect = gfx::RectF(quad->rect);
2279 gl_->UniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb_multiplied); 2283 gl_->UniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb_multiplied);
2280 gl_->Uniform3fv(yuv_adj_location, 1, yuv_adjust_with_offset); 2284 gl_->Uniform3fv(yuv_adj_location, 1, yuv_adjust_with_offset);
2281 2285
2282 SetShaderOpacity(quad->shared_quad_state->opacity, alpha_location); 2286 SetShaderOpacity(quad->shared_quad_state->opacity, alpha_location);
(...skipping 1494 matching lines...) Expand 10 before | Expand all | Expand 10 after
3777 resource_provider_, contents_texture->id())); 3781 resource_provider_, contents_texture->id()));
3778 source_texture = source->texture_id(); 3782 source_texture = source->texture_id();
3779 } 3783 }
3780 gl_->CopySubTextureCHROMIUM(source_texture, destination.texture_id(), 0, 0, 0, 3784 gl_->CopySubTextureCHROMIUM(source_texture, destination.texture_id(), 0, 0, 0,
3781 0, contents_texture->size().width(), 3785 0, contents_texture->size().width(),
3782 contents_texture->size().height(), GL_TRUE, 3786 contents_texture->size().height(), GL_TRUE,
3783 GL_FALSE, GL_FALSE); 3787 GL_FALSE, GL_FALSE);
3784 } 3788 }
3785 3789
3786 } // namespace cc 3790 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/video_layer_impl.cc ('k') | cc/output/renderer_pixeltest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698