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

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

Issue 2400033004: cc: custom bilinear filtering for YUV quad.
Patch Set: fix SAMPLER_TYPE_2D_RECT logic 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 | « no previous file | cc/output/gl_renderer_unittest.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 2188 matching lines...) Expand 10 before | Expand all | Expand 10 after
2199 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 2199 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
2200 gl_, &highp_threshold_cache_, highp_threshold_min_, 2200 gl_, &highp_threshold_cache_, highp_threshold_min_,
2201 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); 2201 quad->shared_quad_state->visible_quad_layer_rect.bottom_right());
2202 2202
2203 bool use_alpha_plane = quad->a_plane_resource_id() != 0; 2203 bool use_alpha_plane = quad->a_plane_resource_id() != 0;
2204 bool use_nv12 = quad->v_plane_resource_id() == quad->u_plane_resource_id(); 2204 bool use_nv12 = quad->v_plane_resource_id() == quad->u_plane_resource_id();
2205 bool use_color_lut = 2205 bool use_color_lut =
2206 base::FeatureList::IsEnabled(media::kVideoColorManagement); 2206 base::FeatureList::IsEnabled(media::kVideoColorManagement);
2207 DCHECK(!(use_nv12 && use_alpha_plane)); 2207 DCHECK(!(use_nv12 && use_alpha_plane));
2208 2208
2209 // GL_LINEAR cannot be used because |u_plane| is sub-sampled.
2209 ResourceProvider::ScopedSamplerGL y_plane_lock( 2210 ResourceProvider::ScopedSamplerGL y_plane_lock(
2210 resource_provider_, quad->y_plane_resource_id(), GL_TEXTURE1, GL_LINEAR); 2211 resource_provider_, quad->y_plane_resource_id(), GL_TEXTURE1, GL_NEAREST);
2211 ResourceProvider::ScopedSamplerGL u_plane_lock( 2212 ResourceProvider::ScopedSamplerGL u_plane_lock(
2212 resource_provider_, quad->u_plane_resource_id(), GL_TEXTURE2, GL_LINEAR); 2213 resource_provider_, quad->u_plane_resource_id(), GL_TEXTURE2, GL_NEAREST);
2213 DCHECK_EQ(y_plane_lock.target(), u_plane_lock.target()); 2214 DCHECK_EQ(y_plane_lock.target(), u_plane_lock.target());
2214 // TODO(jbauman): Use base::Optional when available. 2215 // TODO(jbauman): Use base::Optional when available.
2215 std::unique_ptr<ResourceProvider::ScopedSamplerGL> v_plane_lock; 2216 std::unique_ptr<ResourceProvider::ScopedSamplerGL> v_plane_lock;
2216 if (!use_nv12) { 2217 if (!use_nv12) {
2217 v_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( 2218 v_plane_lock.reset(new ResourceProvider::ScopedSamplerGL(
2218 resource_provider_, quad->v_plane_resource_id(), GL_TEXTURE3, 2219 resource_provider_, quad->v_plane_resource_id(), GL_TEXTURE3,
2219 GL_LINEAR)); 2220 GL_NEAREST));
2220 DCHECK_EQ(y_plane_lock.target(), v_plane_lock->target()); 2221 DCHECK_EQ(y_plane_lock.target(), v_plane_lock->target());
2221 } 2222 }
2222 std::unique_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock; 2223 std::unique_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock;
2223 if (use_alpha_plane) { 2224 if (use_alpha_plane) {
2224 a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( 2225 a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL(
2225 resource_provider_, quad->a_plane_resource_id(), GL_TEXTURE4, 2226 resource_provider_, quad->a_plane_resource_id(), GL_TEXTURE4,
2226 GL_LINEAR)); 2227 GL_NEAREST));
2227 DCHECK_EQ(y_plane_lock.target(), a_plane_lock->target()); 2228 DCHECK_EQ(y_plane_lock.target(), a_plane_lock->target());
2228 } 2229 }
2229 2230
2230 // All planes must have the same sampler type. 2231 // All planes must have the same sampler type.
2231 SamplerType sampler = SamplerTypeFromTextureTarget(y_plane_lock.target()); 2232 SamplerType sampler = SamplerTypeFromTextureTarget(y_plane_lock.target());
2232 2233
2233 int matrix_location = -1; 2234 int matrix_location = -1;
2234 int ya_tex_scale_location = -1; 2235 int ya_tex_scale_location = -1;
2235 int ya_tex_offset_location = -1; 2236 int ya_tex_offset_location = -1;
2236 int uv_tex_scale_location = -1; 2237 int uv_tex_scale_location = -1;
2237 int uv_tex_offset_location = -1; 2238 int uv_tex_offset_location = -1;
2239 int ya_size_location = -1;
2240 int uv_subsampling_factor_location = -1;
2238 int ya_clamp_rect_location = -1; 2241 int ya_clamp_rect_location = -1;
2239 int uv_clamp_rect_location = -1; 2242 int uv_clamp_rect_location = -1;
2240 int y_texture_location = -1; 2243 int y_texture_location = -1;
2241 int u_texture_location = -1; 2244 int u_texture_location = -1;
2242 int v_texture_location = -1; 2245 int v_texture_location = -1;
2243 int uv_texture_location = -1; 2246 int uv_texture_location = -1;
2244 int a_texture_location = -1; 2247 int a_texture_location = -1;
2245 int lut_texture_location = -1; 2248 int lut_texture_location = -1;
2246 int yuv_matrix_location = -1; 2249 int yuv_matrix_location = -1;
2247 int yuv_adj_location = -1; 2250 int yuv_adj_location = -1;
(...skipping 10 matching lines...) Expand all
2258 uv_tex_scale_location = program->vertex_shader().uv_tex_scale_location(); 2261 uv_tex_scale_location = program->vertex_shader().uv_tex_scale_location();
2259 uv_tex_offset_location = program->vertex_shader().uv_tex_offset_location(); 2262 uv_tex_offset_location = program->vertex_shader().uv_tex_offset_location();
2260 y_texture_location = program->fragment_shader().y_texture_location(); 2263 y_texture_location = program->fragment_shader().y_texture_location();
2261 u_texture_location = program->fragment_shader().u_texture_location(); 2264 u_texture_location = program->fragment_shader().u_texture_location();
2262 v_texture_location = program->fragment_shader().v_texture_location(); 2265 v_texture_location = program->fragment_shader().v_texture_location();
2263 uv_texture_location = program->fragment_shader().uv_texture_location(); 2266 uv_texture_location = program->fragment_shader().uv_texture_location();
2264 a_texture_location = program->fragment_shader().a_texture_location(); 2267 a_texture_location = program->fragment_shader().a_texture_location();
2265 lut_texture_location = program->fragment_shader().lut_texture_location(); 2268 lut_texture_location = program->fragment_shader().lut_texture_location();
2266 yuv_matrix_location = program->fragment_shader().yuv_matrix_location(); 2269 yuv_matrix_location = program->fragment_shader().yuv_matrix_location();
2267 yuv_adj_location = program->fragment_shader().yuv_adj_location(); 2270 yuv_adj_location = program->fragment_shader().yuv_adj_location();
2271 ya_size_location = program->fragment_shader().ya_size_location();
2272 uv_subsampling_factor_location =
2273 program->fragment_shader().uv_subsampling_factor_location();
2268 ya_clamp_rect_location = program->fragment_shader().ya_clamp_rect_location(); 2274 ya_clamp_rect_location = program->fragment_shader().ya_clamp_rect_location();
2269 uv_clamp_rect_location = program->fragment_shader().uv_clamp_rect_location(); 2275 uv_clamp_rect_location = program->fragment_shader().uv_clamp_rect_location();
2270 alpha_location = program->fragment_shader().alpha_location(); 2276 alpha_location = program->fragment_shader().alpha_location();
2271 resource_multiplier_location = 2277 resource_multiplier_location =
2272 program->fragment_shader().resource_multiplier_location(); 2278 program->fragment_shader().resource_multiplier_location();
2273 resource_offset_location = 2279 resource_offset_location =
2274 program->fragment_shader().resource_offset_location(); 2280 program->fragment_shader().resource_offset_location();
2275 2281
2276 gfx::SizeF ya_tex_scale(1.0f, 1.0f); 2282 gfx::SizeF ya_tex_scale(1.0f, 1.0f);
2277 gfx::SizeF uv_tex_scale(1.0f, 1.0f); 2283 gfx::SizeF uv_tex_scale(1.0f, 1.0f);
2278 if (sampler != SAMPLER_TYPE_2D_RECT) { 2284 if (sampler != SAMPLER_TYPE_2D_RECT) {
2285 DCHECK_NE(-1, ya_size_location);
2286 gl_->Uniform2f(ya_size_location, quad->ya_tex_size.width(),
2287 quad->ya_tex_size.height());
2288
2279 DCHECK(!quad->ya_tex_size.IsEmpty()); 2289 DCHECK(!quad->ya_tex_size.IsEmpty());
2280 DCHECK(!quad->uv_tex_size.IsEmpty()); 2290 DCHECK(!quad->uv_tex_size.IsEmpty());
2281 ya_tex_scale = gfx::SizeF(1.0f / quad->ya_tex_size.width(), 2291 ya_tex_scale = gfx::SizeF(1.0f / quad->ya_tex_size.width(),
2282 1.0f / quad->ya_tex_size.height()); 2292 1.0f / quad->ya_tex_size.height());
2283 uv_tex_scale = gfx::SizeF(1.0f / quad->uv_tex_size.width(), 2293 uv_tex_scale = gfx::SizeF(1.0f / quad->uv_tex_size.width(),
2284 1.0f / quad->uv_tex_size.height()); 2294 1.0f / quad->uv_tex_size.height());
2295 } else {
2296 DCHECK_NE(-1, uv_subsampling_factor_location);
2297 gl_->Uniform2f(uv_subsampling_factor_location,
2298 quad->uv_tex_size.width() / quad->ya_tex_size.width(),
2299 quad->uv_tex_size.height() / quad->ya_tex_size.height());
2285 } 2300 }
2286 2301
2287 float ya_vertex_tex_translate_x = 2302 float ya_vertex_tex_translate_x =
2288 quad->ya_tex_coord_rect.x() * ya_tex_scale.width(); 2303 quad->ya_tex_coord_rect.x() * ya_tex_scale.width();
2289 float ya_vertex_tex_translate_y = 2304 float ya_vertex_tex_translate_y =
2290 quad->ya_tex_coord_rect.y() * ya_tex_scale.height(); 2305 quad->ya_tex_coord_rect.y() * ya_tex_scale.height();
2291 float ya_vertex_tex_scale_x = 2306 float ya_vertex_tex_scale_x =
2292 quad->ya_tex_coord_rect.width() * ya_tex_scale.width(); 2307 quad->ya_tex_coord_rect.width() * ya_tex_scale.width();
2293 float ya_vertex_tex_scale_y = 2308 float ya_vertex_tex_scale_y =
2294 quad->ya_tex_coord_rect.height() * ya_tex_scale.height(); 2309 quad->ya_tex_coord_rect.height() * ya_tex_scale.height();
(...skipping 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after
3625 bool use_color_lut) { 3640 bool use_color_lut) {
3626 DCHECK_GE(precision, 0); 3641 DCHECK_GE(precision, 0);
3627 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); 3642 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
3628 DCHECK_GE(sampler, 0); 3643 DCHECK_GE(sampler, 0);
3629 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); 3644 DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
3630 VideoYUVProgram* program = 3645 VideoYUVProgram* program =
3631 &video_yuv_program_[precision][sampler][use_alpha_plane][use_nv12] 3646 &video_yuv_program_[precision][sampler][use_alpha_plane][use_nv12]
3632 [use_color_lut]; 3647 [use_color_lut];
3633 if (!program->initialized()) { 3648 if (!program->initialized()) {
3634 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); 3649 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize");
3635 program->mutable_fragment_shader()->SetFeatures(use_alpha_plane, use_nv12, 3650 program->mutable_fragment_shader()->SetFeatures(sampler, use_alpha_plane,
3636 use_color_lut); 3651 use_nv12, use_color_lut);
3637 program->Initialize(output_surface_->context_provider(), precision, 3652 program->Initialize(output_surface_->context_provider(), precision,
3638 sampler); 3653 sampler);
3639 } 3654 }
3640 return program; 3655 return program;
3641 } 3656 }
3642 3657
3643 const GLRenderer::VideoStreamTextureProgram* 3658 const GLRenderer::VideoStreamTextureProgram*
3644 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { 3659 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) {
3645 DCHECK_GE(precision, 0); 3660 DCHECK_GE(precision, 0);
3646 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); 3661 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
4032 4047
4033 gl_->ScheduleCALayerSharedStateCHROMIUM( 4048 gl_->ScheduleCALayerSharedStateCHROMIUM(
4034 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect, 4049 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect,
4035 sorting_context_id, gl_transform); 4050 sorting_context_id, gl_transform);
4036 gl_->ScheduleCALayerCHROMIUM( 4051 gl_->ScheduleCALayerCHROMIUM(
4037 texture_id, contents_rect, ca_layer_overlay->background_color, 4052 texture_id, contents_rect, ca_layer_overlay->background_color,
4038 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); 4053 ca_layer_overlay->edge_aa_mask, bounds_rect, filter);
4039 } 4054 }
4040 4055
4041 } // namespace cc 4056 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/output/gl_renderer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698