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

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

Issue 1852923002: Enable sampling from DXGI NV12 formats in GLRenderer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/gl_renderer.h ('k') | 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 1939 matching lines...) Expand 10 before | Expand all | Expand 10 after
1950 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, 1950 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame,
1951 const YUVVideoDrawQuad* quad, 1951 const YUVVideoDrawQuad* quad,
1952 const gfx::QuadF* clip_region) { 1952 const gfx::QuadF* clip_region) {
1953 SetBlendEnabled(quad->ShouldDrawWithBlending()); 1953 SetBlendEnabled(quad->ShouldDrawWithBlending());
1954 1954
1955 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( 1955 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired(
1956 gl_, &highp_threshold_cache_, highp_threshold_min_, 1956 gl_, &highp_threshold_cache_, highp_threshold_min_,
1957 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); 1957 quad->shared_quad_state->visible_quad_layer_rect.bottom_right());
1958 1958
1959 bool use_alpha_plane = quad->a_plane_resource_id() != 0; 1959 bool use_alpha_plane = quad->a_plane_resource_id() != 0;
1960 bool use_nv12 = quad->v_plane_resource_id() == quad->u_plane_resource_id();
1961
1962 DCHECK(!(use_nv12 && use_alpha_plane));
1960 1963
1961 ResourceProvider::ScopedSamplerGL y_plane_lock( 1964 ResourceProvider::ScopedSamplerGL y_plane_lock(
1962 resource_provider_, quad->y_plane_resource_id(), GL_TEXTURE1, GL_LINEAR); 1965 resource_provider_, quad->y_plane_resource_id(), GL_TEXTURE1, GL_LINEAR);
1963 ResourceProvider::ScopedSamplerGL u_plane_lock( 1966 ResourceProvider::ScopedSamplerGL u_plane_lock(
1964 resource_provider_, quad->u_plane_resource_id(), GL_TEXTURE2, GL_LINEAR); 1967 resource_provider_, quad->u_plane_resource_id(), GL_TEXTURE2, GL_LINEAR);
1965 DCHECK_EQ(y_plane_lock.target(), u_plane_lock.target()); 1968 DCHECK_EQ(y_plane_lock.target(), u_plane_lock.target());
1966 ResourceProvider::ScopedSamplerGL v_plane_lock( 1969 // TODO(jbauman): Use base::Optional when available.
1967 resource_provider_, quad->v_plane_resource_id(), GL_TEXTURE3, GL_LINEAR); 1970 std::unique_ptr<ResourceProvider::ScopedSamplerGL> v_plane_lock;
1968 DCHECK_EQ(y_plane_lock.target(), v_plane_lock.target()); 1971 if (!use_nv12) {
1972 v_plane_lock.reset(new ResourceProvider::ScopedSamplerGL(
1973 resource_provider_, quad->v_plane_resource_id(), GL_TEXTURE3,
1974 GL_LINEAR));
1975 DCHECK_EQ(y_plane_lock.target(), v_plane_lock->target());
1976 }
1969 std::unique_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock; 1977 std::unique_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock;
1970 if (use_alpha_plane) { 1978 if (use_alpha_plane) {
1971 a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( 1979 a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL(
1972 resource_provider_, quad->a_plane_resource_id(), GL_TEXTURE4, 1980 resource_provider_, quad->a_plane_resource_id(), GL_TEXTURE4,
1973 GL_LINEAR)); 1981 GL_LINEAR));
1974 DCHECK_EQ(y_plane_lock.target(), a_plane_lock->target()); 1982 DCHECK_EQ(y_plane_lock.target(), a_plane_lock->target());
1975 } 1983 }
1976 1984
1977 // All planes must have the same sampler type. 1985 // All planes must have the same sampler type.
1978 SamplerType sampler = SamplerTypeFromTextureTarget(y_plane_lock.target()); 1986 SamplerType sampler = SamplerTypeFromTextureTarget(y_plane_lock.target());
(...skipping 26 matching lines...) Expand all
2005 u_texture_location = program->fragment_shader().u_texture_location(); 2013 u_texture_location = program->fragment_shader().u_texture_location();
2006 v_texture_location = program->fragment_shader().v_texture_location(); 2014 v_texture_location = program->fragment_shader().v_texture_location();
2007 a_texture_location = program->fragment_shader().a_texture_location(); 2015 a_texture_location = program->fragment_shader().a_texture_location();
2008 yuv_matrix_location = program->fragment_shader().yuv_matrix_location(); 2016 yuv_matrix_location = program->fragment_shader().yuv_matrix_location();
2009 yuv_adj_location = program->fragment_shader().yuv_adj_location(); 2017 yuv_adj_location = program->fragment_shader().yuv_adj_location();
2010 ya_clamp_rect_location = 2018 ya_clamp_rect_location =
2011 program->fragment_shader().ya_clamp_rect_location(); 2019 program->fragment_shader().ya_clamp_rect_location();
2012 uv_clamp_rect_location = 2020 uv_clamp_rect_location =
2013 program->fragment_shader().uv_clamp_rect_location(); 2021 program->fragment_shader().uv_clamp_rect_location();
2014 alpha_location = program->fragment_shader().alpha_location(); 2022 alpha_location = program->fragment_shader().alpha_location();
2015 } else { 2023 } else if (!use_nv12) {
2016 const VideoYUVProgram* program = 2024 const VideoYUVProgram* program =
2017 GetVideoYUVProgram(tex_coord_precision, sampler); 2025 GetVideoYUVProgram(tex_coord_precision, sampler);
2018 DCHECK(program && (program->initialized() || IsContextLost())); 2026 DCHECK(program && (program->initialized() || IsContextLost()));
2019 SetUseProgram(program->program()); 2027 SetUseProgram(program->program());
2020 matrix_location = program->vertex_shader().matrix_location(); 2028 matrix_location = program->vertex_shader().matrix_location();
2021 ya_tex_scale_location = program->vertex_shader().ya_tex_scale_location(); 2029 ya_tex_scale_location = program->vertex_shader().ya_tex_scale_location();
2022 ya_tex_offset_location = program->vertex_shader().ya_tex_offset_location(); 2030 ya_tex_offset_location = program->vertex_shader().ya_tex_offset_location();
2023 uv_tex_scale_location = program->vertex_shader().uv_tex_scale_location(); 2031 uv_tex_scale_location = program->vertex_shader().uv_tex_scale_location();
2024 uv_tex_offset_location = program->vertex_shader().uv_tex_offset_location(); 2032 uv_tex_offset_location = program->vertex_shader().uv_tex_offset_location();
2025 y_texture_location = program->fragment_shader().y_texture_location(); 2033 y_texture_location = program->fragment_shader().y_texture_location();
2026 u_texture_location = program->fragment_shader().u_texture_location(); 2034 u_texture_location = program->fragment_shader().u_texture_location();
2027 v_texture_location = program->fragment_shader().v_texture_location(); 2035 v_texture_location = program->fragment_shader().v_texture_location();
2028 yuv_matrix_location = program->fragment_shader().yuv_matrix_location(); 2036 yuv_matrix_location = program->fragment_shader().yuv_matrix_location();
2029 yuv_adj_location = program->fragment_shader().yuv_adj_location(); 2037 yuv_adj_location = program->fragment_shader().yuv_adj_location();
2030 ya_clamp_rect_location = 2038 ya_clamp_rect_location =
2031 program->fragment_shader().ya_clamp_rect_location(); 2039 program->fragment_shader().ya_clamp_rect_location();
2032 uv_clamp_rect_location = 2040 uv_clamp_rect_location =
2033 program->fragment_shader().uv_clamp_rect_location(); 2041 program->fragment_shader().uv_clamp_rect_location();
2034 alpha_location = program->fragment_shader().alpha_location(); 2042 alpha_location = program->fragment_shader().alpha_location();
2043 } else {
2044 const VideoNV12Program* program =
2045 GetVideoNV12Program(tex_coord_precision, sampler);
2046 DCHECK(program && (program->initialized() || IsContextLost()));
2047 SetUseProgram(program->program());
2048 matrix_location = program->vertex_shader().matrix_location();
2049 ya_tex_scale_location = program->vertex_shader().ya_tex_scale_location();
2050 ya_tex_offset_location = program->vertex_shader().ya_tex_offset_location();
2051 uv_tex_scale_location = program->vertex_shader().uv_tex_scale_location();
2052 uv_tex_offset_location = program->vertex_shader().uv_tex_offset_location();
2053 y_texture_location = program->fragment_shader().y_texture_location();
2054 u_texture_location = program->fragment_shader().uv_texture_location();
2055 yuv_matrix_location = program->fragment_shader().yuv_matrix_location();
2056 yuv_adj_location = program->fragment_shader().yuv_adj_location();
2057 ya_clamp_rect_location =
2058 program->fragment_shader().ya_clamp_rect_location();
2059 uv_clamp_rect_location =
2060 program->fragment_shader().uv_clamp_rect_location();
2061 alpha_location = program->fragment_shader().alpha_location();
2035 } 2062 }
2036 2063
2037 gfx::SizeF ya_tex_scale(1.0f, 1.0f); 2064 gfx::SizeF ya_tex_scale(1.0f, 1.0f);
2038 gfx::SizeF uv_tex_scale(1.0f, 1.0f); 2065 gfx::SizeF uv_tex_scale(1.0f, 1.0f);
2039 if (sampler != SAMPLER_TYPE_2D_RECT) { 2066 if (sampler != SAMPLER_TYPE_2D_RECT) {
2040 DCHECK(!quad->ya_tex_size.IsEmpty()); 2067 DCHECK(!quad->ya_tex_size.IsEmpty());
2041 DCHECK(!quad->uv_tex_size.IsEmpty()); 2068 DCHECK(!quad->uv_tex_size.IsEmpty());
2042 ya_tex_scale = gfx::SizeF(1.0f / quad->ya_tex_size.width(), 2069 ya_tex_scale = gfx::SizeF(1.0f / quad->ya_tex_size.width(),
2043 1.0f / quad->ya_tex_size.height()); 2070 1.0f / quad->ya_tex_size.height());
2044 uv_tex_scale = gfx::SizeF(1.0f / quad->uv_tex_size.width(), 2071 uv_tex_scale = gfx::SizeF(1.0f / quad->uv_tex_size.width(),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2080 uv_vertex_tex_scale_x, uv_vertex_tex_scale_y); 2107 uv_vertex_tex_scale_x, uv_vertex_tex_scale_y);
2081 uv_clamp_rect.Inset(0.5f * uv_tex_scale.width(), 2108 uv_clamp_rect.Inset(0.5f * uv_tex_scale.width(),
2082 0.5f * uv_tex_scale.height()); 2109 0.5f * uv_tex_scale.height());
2083 gl_->Uniform4f(ya_clamp_rect_location, ya_clamp_rect.x(), ya_clamp_rect.y(), 2110 gl_->Uniform4f(ya_clamp_rect_location, ya_clamp_rect.x(), ya_clamp_rect.y(),
2084 ya_clamp_rect.right(), ya_clamp_rect.bottom()); 2111 ya_clamp_rect.right(), ya_clamp_rect.bottom());
2085 gl_->Uniform4f(uv_clamp_rect_location, uv_clamp_rect.x(), uv_clamp_rect.y(), 2112 gl_->Uniform4f(uv_clamp_rect_location, uv_clamp_rect.x(), uv_clamp_rect.y(),
2086 uv_clamp_rect.right(), uv_clamp_rect.bottom()); 2113 uv_clamp_rect.right(), uv_clamp_rect.bottom());
2087 2114
2088 gl_->Uniform1i(y_texture_location, 1); 2115 gl_->Uniform1i(y_texture_location, 1);
2089 gl_->Uniform1i(u_texture_location, 2); 2116 gl_->Uniform1i(u_texture_location, 2);
2090 gl_->Uniform1i(v_texture_location, 3); 2117 if (!use_nv12)
2118 gl_->Uniform1i(v_texture_location, 3);
2091 if (use_alpha_plane) 2119 if (use_alpha_plane)
2092 gl_->Uniform1i(a_texture_location, 4); 2120 gl_->Uniform1i(a_texture_location, 4);
2093 2121
2094 // These values are magic numbers that are used in the transformation from YUV 2122 // These values are magic numbers that are used in the transformation from YUV
2095 // to RGB color values. They are taken from the following webpage: 2123 // to RGB color values. They are taken from the following webpage:
2096 // http://www.fourcc.org/fccyvrgb.php 2124 // http://www.fourcc.org/fccyvrgb.php
2097 float yuv_to_rgb_rec601[9] = { 2125 float yuv_to_rgb_rec601[9] = {
2098 1.164f, 1.164f, 1.164f, 0.0f, -.391f, 2.018f, 1.596f, -.813f, 0.0f, 2126 1.164f, 1.164f, 1.164f, 0.0f, -.391f, 2.018f, 1.596f, -.813f, 0.0f,
2099 }; 2127 };
2100 float yuv_to_rgb_jpeg[9] = { 2128 float yuv_to_rgb_jpeg[9] = {
(...skipping 1292 matching lines...) Expand 10 before | Expand all | Expand 10 after
3393 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); 3421 DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
3394 VideoYUVProgram* program = &video_yuv_program_[precision][sampler]; 3422 VideoYUVProgram* program = &video_yuv_program_[precision][sampler];
3395 if (!program->initialized()) { 3423 if (!program->initialized()) {
3396 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); 3424 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize");
3397 program->Initialize(output_surface_->context_provider(), precision, 3425 program->Initialize(output_surface_->context_provider(), precision,
3398 sampler); 3426 sampler);
3399 } 3427 }
3400 return program; 3428 return program;
3401 } 3429 }
3402 3430
3431 const GLRenderer::VideoNV12Program* GLRenderer::GetVideoNV12Program(
3432 TexCoordPrecision precision,
3433 SamplerType sampler) {
3434 DCHECK_GE(precision, 0);
3435 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
3436 DCHECK_GE(sampler, 0);
3437 DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
3438 VideoNV12Program* program = &video_nv12_program_[precision][sampler];
3439 if (!program->initialized()) {
3440 TRACE_EVENT0("cc", "GLRenderer::videoNV12Program::initialize");
3441 program->Initialize(output_surface_->context_provider(), precision,
3442 sampler);
3443 }
3444 return program;
3445 }
3446
3403 const GLRenderer::VideoYUVAProgram* GLRenderer::GetVideoYUVAProgram( 3447 const GLRenderer::VideoYUVAProgram* GLRenderer::GetVideoYUVAProgram(
3404 TexCoordPrecision precision, 3448 TexCoordPrecision precision,
3405 SamplerType sampler) { 3449 SamplerType sampler) {
3406 DCHECK_GE(precision, 0); 3450 DCHECK_GE(precision, 0);
3407 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); 3451 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION);
3408 DCHECK_GE(sampler, 0); 3452 DCHECK_GE(sampler, 0);
3409 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); 3453 DCHECK_LE(sampler, LAST_SAMPLER_TYPE);
3410 VideoYUVAProgram* program = &video_yuva_program_[precision][sampler]; 3454 VideoYUVAProgram* program = &video_yuva_program_[precision][sampler];
3411 if (!program->initialized()) { 3455 if (!program->initialized()) {
3412 TRACE_EVENT0("cc", "GLRenderer::videoYUVAProgram::initialize"); 3456 TRACE_EVENT0("cc", "GLRenderer::videoYUVAProgram::initialize");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3446 for (int l = 0; l <= LAST_MASK_VALUE; ++l) { 3490 for (int l = 0; l <= LAST_MASK_VALUE; ++l) {
3447 render_pass_mask_program_[i][j][k][l].Cleanup(gl_); 3491 render_pass_mask_program_[i][j][k][l].Cleanup(gl_);
3448 render_pass_mask_program_aa_[i][j][k][l].Cleanup(gl_); 3492 render_pass_mask_program_aa_[i][j][k][l].Cleanup(gl_);
3449 render_pass_mask_color_matrix_program_aa_[i][j][k][l].Cleanup(gl_); 3493 render_pass_mask_color_matrix_program_aa_[i][j][k][l].Cleanup(gl_);
3450 render_pass_mask_color_matrix_program_[i][j][k][l].Cleanup(gl_); 3494 render_pass_mask_color_matrix_program_[i][j][k][l].Cleanup(gl_);
3451 } 3495 }
3452 } 3496 }
3453 3497
3454 video_yuv_program_[i][j].Cleanup(gl_); 3498 video_yuv_program_[i][j].Cleanup(gl_);
3455 video_yuva_program_[i][j].Cleanup(gl_); 3499 video_yuva_program_[i][j].Cleanup(gl_);
3500 video_nv12_program_[i][j].Cleanup(gl_);
3456 } 3501 }
3457 for (int j = 0; j <= LAST_BLEND_MODE; j++) { 3502 for (int j = 0; j <= LAST_BLEND_MODE; j++) {
3458 render_pass_program_[i][j].Cleanup(gl_); 3503 render_pass_program_[i][j].Cleanup(gl_);
3459 render_pass_program_aa_[i][j].Cleanup(gl_); 3504 render_pass_program_aa_[i][j].Cleanup(gl_);
3460 render_pass_color_matrix_program_[i][j].Cleanup(gl_); 3505 render_pass_color_matrix_program_[i][j].Cleanup(gl_);
3461 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); 3506 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_);
3462 } 3507 }
3463 3508
3464 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { 3509 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) {
3465 texture_program_[i][j].Cleanup(gl_); 3510 texture_program_[i][j].Cleanup(gl_);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
3592 texture_id = pending_overlay_resources_.back()->texture_id(); 3637 texture_id = pending_overlay_resources_.back()->texture_id();
3593 } 3638 }
3594 3639
3595 context_support_->ScheduleOverlayPlane( 3640 context_support_->ScheduleOverlayPlane(
3596 overlay.plane_z_order, overlay.transform, texture_id, 3641 overlay.plane_z_order, overlay.transform, texture_id,
3597 ToNearestRect(overlay.display_rect), overlay.uv_rect); 3642 ToNearestRect(overlay.display_rect), overlay.uv_rect);
3598 } 3643 }
3599 } 3644 }
3600 3645
3601 } // namespace cc 3646 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/output/gl_renderer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698