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

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: rebaseline cc tests Created 4 years, 5 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
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 2207 matching lines...) Expand 10 before | Expand all | Expand 10 after
2218 float yuv_to_rgb_rec601[9] = { 2218 float yuv_to_rgb_rec601[9] = {
2219 1.164f, 1.164f, 1.164f, 0.0f, -.391f, 2.018f, 1.596f, -.813f, 0.0f, 2219 1.164f, 1.164f, 1.164f, 0.0f, -.391f, 2.018f, 1.596f, -.813f, 0.0f,
2220 }; 2220 };
2221 float yuv_to_rgb_jpeg[9] = { 2221 float yuv_to_rgb_jpeg[9] = {
2222 1.f, 1.f, 1.f, 0.0f, -.34414f, 1.772f, 1.402f, -.71414f, 0.0f, 2222 1.f, 1.f, 1.f, 0.0f, -.34414f, 1.772f, 1.402f, -.71414f, 0.0f,
2223 }; 2223 };
2224 float yuv_to_rgb_rec709[9] = { 2224 float yuv_to_rgb_rec709[9] = {
2225 1.164f, 1.164f, 1.164f, 0.0f, -0.213f, 2.112f, 1.793f, -0.533f, 0.0f, 2225 1.164f, 1.164f, 1.164f, 0.0f, -0.213f, 2.112f, 1.793f, -0.533f, 0.0f,
2226 }; 2226 };
2227 2227
2228 // These values map to 16, 128, and 128 respectively, and are computed
2229 // as a fraction over 256 (e.g. 16 / 256 = 0.0625).
2230 // They are used in the YUV to RGBA conversion formula: 2228 // They are used in the YUV to RGBA conversion formula:
2231 // Y - 16 : Gives 16 values of head and footroom for overshooting 2229 // Y - 16 : Gives 16 values of head and footroom for overshooting
2232 // U - 128 : Turns unsigned U into signed U [-128,127] 2230 // U - 128 : Turns unsigned U into signed U [-128,127]
2233 // V - 128 : Turns unsigned V into signed V [-128,127] 2231 // V - 128 : Turns unsigned V into signed V [-128,127]
2234 float yuv_adjust_constrained[3] = { 2232 float yuv_adjust_constrained[3] = {
2235 -0.0625f, -0.5f, -0.5f, 2233 -16.f, -128.f, -128.f,
2236 }; 2234 };
2237 2235
2238 // Same as above, but without the head and footroom. 2236 // Same as above, but without the head and footroom.
2239 float yuv_adjust_full[3] = { 2237 float yuv_adjust_full[3] = {
2240 0.0f, -0.5f, -0.5f, 2238 0.0f, -128.f, -128.f,
2241 }; 2239 };
2242 2240
2243 float* yuv_to_rgb = NULL; 2241 float* yuv_to_rgb = NULL;
2244 float* yuv_adjust = NULL; 2242 float* yuv_adjust = NULL;
2245 2243
2246 switch (quad->color_space) { 2244 switch (quad->color_space) {
2247 case YUVVideoDrawQuad::REC_601: 2245 case YUVVideoDrawQuad::REC_601:
2248 yuv_to_rgb = yuv_to_rgb_rec601; 2246 yuv_to_rgb = yuv_to_rgb_rec601;
2249 yuv_adjust = yuv_adjust_constrained; 2247 yuv_adjust = yuv_adjust_constrained;
2250 break; 2248 break;
2251 case YUVVideoDrawQuad::REC_709: 2249 case YUVVideoDrawQuad::REC_709:
2252 yuv_to_rgb = yuv_to_rgb_rec709; 2250 yuv_to_rgb = yuv_to_rgb_rec709;
2253 yuv_adjust = yuv_adjust_constrained; 2251 yuv_adjust = yuv_adjust_constrained;
2254 break; 2252 break;
2255 case YUVVideoDrawQuad::JPEG: 2253 case YUVVideoDrawQuad::JPEG:
2256 yuv_to_rgb = yuv_to_rgb_jpeg; 2254 yuv_to_rgb = yuv_to_rgb_jpeg;
2257 yuv_adjust = yuv_adjust_full; 2255 yuv_adjust = yuv_adjust_full;
2258 break; 2256 break;
2259 } 2257 }
2260 2258
2261 float yuv_to_rgb_multiplied[9]; 2259 float yuv_to_rgb_multiplied[9];
2262 float yuv_adjust_with_offset[3]; 2260 float yuv_adjust_with_offset[3];
2263 2261
2262 // Formula according to BT.601-7 section 2.5.3.
2263 float adjustment_multiplier = (1 << (quad->bits_per_channel - 8)) * 1.0f /
2264 ((1 << quad->bits_per_channel) - 1);
2265
2264 for (int i = 0; i < 9; ++i) 2266 for (int i = 0; i < 9; ++i)
2265 yuv_to_rgb_multiplied[i] = yuv_to_rgb[i] * quad->resource_multiplier; 2267 yuv_to_rgb_multiplied[i] = yuv_to_rgb[i] * quad->resource_multiplier;
2266 2268
2267 for (int i = 0; i < 3; ++i) 2269 for (int i = 0; i < 3; ++i)
piman 2016/07/26 06:46:48 nit: can you add {} per style?
2268 yuv_adjust_with_offset[i] = 2270 yuv_adjust_with_offset[i] =
2269 yuv_adjust[i] / quad->resource_multiplier - quad->resource_offset; 2271 yuv_adjust[i] * adjustment_multiplier / quad->resource_multiplier -
2272 quad->resource_offset;
2270 2273
2271 // The transform and vertex data are used to figure out the extents that the 2274 // The transform and vertex data are used to figure out the extents that the
2272 // un-antialiased quad should have and which vertex this is and the float 2275 // un-antialiased quad should have and which vertex this is and the float
2273 // quad passed in via uniform is the actual geometry that gets used to draw 2276 // quad passed in via uniform is the actual geometry that gets used to draw
2274 // it. This is why this centered rect is used and not the original quad_rect. 2277 // it. This is why this centered rect is used and not the original quad_rect.
2275 auto tile_rect = gfx::RectF(quad->rect); 2278 auto tile_rect = gfx::RectF(quad->rect);
2276 gl_->UniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb_multiplied); 2279 gl_->UniformMatrix3fv(yuv_matrix_location, 1, 0, yuv_to_rgb_multiplied);
2277 gl_->Uniform3fv(yuv_adj_location, 1, yuv_adjust_with_offset); 2280 gl_->Uniform3fv(yuv_adj_location, 1, yuv_adjust_with_offset);
2278 2281
2279 SetShaderOpacity(quad->shared_quad_state->opacity, alpha_location); 2282 SetShaderOpacity(quad->shared_quad_state->opacity, alpha_location);
(...skipping 1410 matching lines...) Expand 10 before | Expand all | Expand 10 after
3690 texture_id = pending_overlay_resources_.back()->texture_id(); 3693 texture_id = pending_overlay_resources_.back()->texture_id();
3691 } 3694 }
3692 3695
3693 context_support_->ScheduleOverlayPlane( 3696 context_support_->ScheduleOverlayPlane(
3694 overlay.plane_z_order, overlay.transform, texture_id, 3697 overlay.plane_z_order, overlay.transform, texture_id,
3695 ToNearestRect(overlay.display_rect), overlay.uv_rect); 3698 ToNearestRect(overlay.display_rect), overlay.uv_rect);
3696 } 3699 }
3697 } 3700 }
3698 3701
3699 } // namespace cc 3702 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698