Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 1947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1958 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, | 1958 void GLRenderer::DrawYUVVideoQuad(const DrawingFrame* frame, |
| 1959 const YUVVideoDrawQuad* quad, | 1959 const YUVVideoDrawQuad* quad, |
| 1960 const gfx::QuadF* clip_region) { | 1960 const gfx::QuadF* clip_region) { |
| 1961 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 1961 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 1962 | 1962 |
| 1963 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 1963 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 1964 gl_, &highp_threshold_cache_, highp_threshold_min_, | 1964 gl_, &highp_threshold_cache_, highp_threshold_min_, |
| 1965 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); | 1965 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); |
| 1966 | 1966 |
| 1967 bool use_alpha_plane = quad->a_plane_resource_id() != 0; | 1967 bool use_alpha_plane = quad->a_plane_resource_id() != 0; |
| 1968 bool use_nv12 = quad->v_plane_resource_id() == quad->u_plane_resource_id(); | |
| 1969 | |
| 1970 if (use_nv12 && use_alpha_plane) | |
| 1971 return; | |
|
danakj
2016/04/11 23:28:28
do you mean dcheck?
| |
| 1968 | 1972 |
| 1969 ResourceProvider::ScopedSamplerGL y_plane_lock( | 1973 ResourceProvider::ScopedSamplerGL y_plane_lock( |
| 1970 resource_provider_, quad->y_plane_resource_id(), GL_TEXTURE1, GL_LINEAR); | 1974 resource_provider_, quad->y_plane_resource_id(), GL_TEXTURE1, GL_LINEAR); |
| 1971 ResourceProvider::ScopedSamplerGL u_plane_lock( | 1975 ResourceProvider::ScopedSamplerGL u_plane_lock( |
| 1972 resource_provider_, quad->u_plane_resource_id(), GL_TEXTURE2, GL_LINEAR); | 1976 resource_provider_, quad->u_plane_resource_id(), GL_TEXTURE2, GL_LINEAR); |
| 1973 DCHECK_EQ(y_plane_lock.target(), u_plane_lock.target()); | 1977 DCHECK_EQ(y_plane_lock.target(), u_plane_lock.target()); |
| 1974 ResourceProvider::ScopedSamplerGL v_plane_lock( | 1978 scoped_ptr<ResourceProvider::ScopedSamplerGL> v_plane_lock; |
|
danakj
2016/04/11 23:28:28
TODO to use base::Optional, no need for mallocs he
| |
| 1975 resource_provider_, quad->v_plane_resource_id(), GL_TEXTURE3, GL_LINEAR); | 1979 if (!use_nv12) { |
| 1976 DCHECK_EQ(y_plane_lock.target(), v_plane_lock.target()); | 1980 v_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( |
| 1981 resource_provider_, quad->v_plane_resource_id(), GL_TEXTURE3, | |
| 1982 GL_LINEAR)); | |
| 1983 DCHECK_EQ(y_plane_lock.target(), v_plane_lock->target()); | |
| 1984 } | |
| 1977 scoped_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock; | 1985 scoped_ptr<ResourceProvider::ScopedSamplerGL> a_plane_lock; |
| 1978 if (use_alpha_plane) { | 1986 if (use_alpha_plane) { |
| 1979 a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( | 1987 a_plane_lock.reset(new ResourceProvider::ScopedSamplerGL( |
| 1980 resource_provider_, quad->a_plane_resource_id(), GL_TEXTURE4, | 1988 resource_provider_, quad->a_plane_resource_id(), GL_TEXTURE4, |
| 1981 GL_LINEAR)); | 1989 GL_LINEAR)); |
| 1982 DCHECK_EQ(y_plane_lock.target(), a_plane_lock->target()); | 1990 DCHECK_EQ(y_plane_lock.target(), a_plane_lock->target()); |
| 1983 } | 1991 } |
| 1984 | 1992 |
| 1985 // All planes must have the same sampler type. | 1993 // All planes must have the same sampler type. |
| 1986 SamplerType sampler = SamplerTypeFromTextureTarget(y_plane_lock.target()); | 1994 SamplerType sampler = SamplerTypeFromTextureTarget(y_plane_lock.target()); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 2013 u_texture_location = program->fragment_shader().u_texture_location(); | 2021 u_texture_location = program->fragment_shader().u_texture_location(); |
| 2014 v_texture_location = program->fragment_shader().v_texture_location(); | 2022 v_texture_location = program->fragment_shader().v_texture_location(); |
| 2015 a_texture_location = program->fragment_shader().a_texture_location(); | 2023 a_texture_location = program->fragment_shader().a_texture_location(); |
| 2016 yuv_matrix_location = program->fragment_shader().yuv_matrix_location(); | 2024 yuv_matrix_location = program->fragment_shader().yuv_matrix_location(); |
| 2017 yuv_adj_location = program->fragment_shader().yuv_adj_location(); | 2025 yuv_adj_location = program->fragment_shader().yuv_adj_location(); |
| 2018 ya_clamp_rect_location = | 2026 ya_clamp_rect_location = |
| 2019 program->fragment_shader().ya_clamp_rect_location(); | 2027 program->fragment_shader().ya_clamp_rect_location(); |
| 2020 uv_clamp_rect_location = | 2028 uv_clamp_rect_location = |
| 2021 program->fragment_shader().uv_clamp_rect_location(); | 2029 program->fragment_shader().uv_clamp_rect_location(); |
| 2022 alpha_location = program->fragment_shader().alpha_location(); | 2030 alpha_location = program->fragment_shader().alpha_location(); |
| 2023 } else { | 2031 } else if (!use_nv12) { |
| 2024 const VideoYUVProgram* program = | 2032 const VideoYUVProgram* program = |
| 2025 GetVideoYUVProgram(tex_coord_precision, sampler); | 2033 GetVideoYUVProgram(tex_coord_precision, sampler); |
| 2026 DCHECK(program && (program->initialized() || IsContextLost())); | 2034 DCHECK(program && (program->initialized() || IsContextLost())); |
| 2027 SetUseProgram(program->program()); | 2035 SetUseProgram(program->program()); |
| 2028 matrix_location = program->vertex_shader().matrix_location(); | 2036 matrix_location = program->vertex_shader().matrix_location(); |
| 2029 ya_tex_scale_location = program->vertex_shader().ya_tex_scale_location(); | 2037 ya_tex_scale_location = program->vertex_shader().ya_tex_scale_location(); |
| 2030 ya_tex_offset_location = program->vertex_shader().ya_tex_offset_location(); | 2038 ya_tex_offset_location = program->vertex_shader().ya_tex_offset_location(); |
| 2031 uv_tex_scale_location = program->vertex_shader().uv_tex_scale_location(); | 2039 uv_tex_scale_location = program->vertex_shader().uv_tex_scale_location(); |
| 2032 uv_tex_offset_location = program->vertex_shader().uv_tex_offset_location(); | 2040 uv_tex_offset_location = program->vertex_shader().uv_tex_offset_location(); |
| 2033 y_texture_location = program->fragment_shader().y_texture_location(); | 2041 y_texture_location = program->fragment_shader().y_texture_location(); |
| 2034 u_texture_location = program->fragment_shader().u_texture_location(); | 2042 u_texture_location = program->fragment_shader().u_texture_location(); |
| 2035 v_texture_location = program->fragment_shader().v_texture_location(); | 2043 v_texture_location = program->fragment_shader().v_texture_location(); |
| 2036 yuv_matrix_location = program->fragment_shader().yuv_matrix_location(); | 2044 yuv_matrix_location = program->fragment_shader().yuv_matrix_location(); |
| 2037 yuv_adj_location = program->fragment_shader().yuv_adj_location(); | 2045 yuv_adj_location = program->fragment_shader().yuv_adj_location(); |
| 2038 ya_clamp_rect_location = | 2046 ya_clamp_rect_location = |
| 2039 program->fragment_shader().ya_clamp_rect_location(); | 2047 program->fragment_shader().ya_clamp_rect_location(); |
| 2040 uv_clamp_rect_location = | 2048 uv_clamp_rect_location = |
| 2041 program->fragment_shader().uv_clamp_rect_location(); | 2049 program->fragment_shader().uv_clamp_rect_location(); |
| 2042 alpha_location = program->fragment_shader().alpha_location(); | 2050 alpha_location = program->fragment_shader().alpha_location(); |
| 2051 } else { | |
| 2052 const VideoNV12Program* program = | |
| 2053 GetVideoNV12Program(tex_coord_precision, sampler); | |
| 2054 DCHECK(program && (program->initialized() || IsContextLost())); | |
| 2055 SetUseProgram(program->program()); | |
| 2056 matrix_location = program->vertex_shader().matrix_location(); | |
| 2057 ya_tex_scale_location = program->vertex_shader().ya_tex_scale_location(); | |
| 2058 ya_tex_offset_location = program->vertex_shader().ya_tex_offset_location(); | |
| 2059 uv_tex_scale_location = program->vertex_shader().uv_tex_scale_location(); | |
| 2060 uv_tex_offset_location = program->vertex_shader().uv_tex_offset_location(); | |
| 2061 y_texture_location = program->fragment_shader().y_texture_location(); | |
| 2062 u_texture_location = program->fragment_shader().uv_texture_location(); | |
| 2063 yuv_matrix_location = program->fragment_shader().yuv_matrix_location(); | |
| 2064 yuv_adj_location = program->fragment_shader().yuv_adj_location(); | |
| 2065 ya_clamp_rect_location = | |
| 2066 program->fragment_shader().ya_clamp_rect_location(); | |
| 2067 uv_clamp_rect_location = | |
| 2068 program->fragment_shader().uv_clamp_rect_location(); | |
| 2069 alpha_location = program->fragment_shader().alpha_location(); | |
| 2043 } | 2070 } |
| 2044 | 2071 |
| 2045 gfx::SizeF ya_tex_scale(1.0f, 1.0f); | 2072 gfx::SizeF ya_tex_scale(1.0f, 1.0f); |
| 2046 gfx::SizeF uv_tex_scale(1.0f, 1.0f); | 2073 gfx::SizeF uv_tex_scale(1.0f, 1.0f); |
| 2047 if (sampler != SAMPLER_TYPE_2D_RECT) { | 2074 if (sampler != SAMPLER_TYPE_2D_RECT) { |
| 2048 DCHECK(!quad->ya_tex_size.IsEmpty()); | 2075 DCHECK(!quad->ya_tex_size.IsEmpty()); |
| 2049 DCHECK(!quad->uv_tex_size.IsEmpty()); | 2076 DCHECK(!quad->uv_tex_size.IsEmpty()); |
| 2050 ya_tex_scale = gfx::SizeF(1.0f / quad->ya_tex_size.width(), | 2077 ya_tex_scale = gfx::SizeF(1.0f / quad->ya_tex_size.width(), |
| 2051 1.0f / quad->ya_tex_size.height()); | 2078 1.0f / quad->ya_tex_size.height()); |
| 2052 uv_tex_scale = gfx::SizeF(1.0f / quad->uv_tex_size.width(), | 2079 uv_tex_scale = gfx::SizeF(1.0f / quad->uv_tex_size.width(), |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2088 uv_vertex_tex_scale_x, uv_vertex_tex_scale_y); | 2115 uv_vertex_tex_scale_x, uv_vertex_tex_scale_y); |
| 2089 uv_clamp_rect.Inset(0.5f * uv_tex_scale.width(), | 2116 uv_clamp_rect.Inset(0.5f * uv_tex_scale.width(), |
| 2090 0.5f * uv_tex_scale.height()); | 2117 0.5f * uv_tex_scale.height()); |
| 2091 gl_->Uniform4f(ya_clamp_rect_location, ya_clamp_rect.x(), ya_clamp_rect.y(), | 2118 gl_->Uniform4f(ya_clamp_rect_location, ya_clamp_rect.x(), ya_clamp_rect.y(), |
| 2092 ya_clamp_rect.right(), ya_clamp_rect.bottom()); | 2119 ya_clamp_rect.right(), ya_clamp_rect.bottom()); |
| 2093 gl_->Uniform4f(uv_clamp_rect_location, uv_clamp_rect.x(), uv_clamp_rect.y(), | 2120 gl_->Uniform4f(uv_clamp_rect_location, uv_clamp_rect.x(), uv_clamp_rect.y(), |
| 2094 uv_clamp_rect.right(), uv_clamp_rect.bottom()); | 2121 uv_clamp_rect.right(), uv_clamp_rect.bottom()); |
| 2095 | 2122 |
| 2096 gl_->Uniform1i(y_texture_location, 1); | 2123 gl_->Uniform1i(y_texture_location, 1); |
| 2097 gl_->Uniform1i(u_texture_location, 2); | 2124 gl_->Uniform1i(u_texture_location, 2); |
| 2098 gl_->Uniform1i(v_texture_location, 3); | 2125 if (!use_nv12) |
| 2126 gl_->Uniform1i(v_texture_location, 3); | |
| 2099 if (use_alpha_plane) | 2127 if (use_alpha_plane) |
| 2100 gl_->Uniform1i(a_texture_location, 4); | 2128 gl_->Uniform1i(a_texture_location, 4); |
| 2101 | 2129 |
| 2102 // These values are magic numbers that are used in the transformation from YUV | 2130 // These values are magic numbers that are used in the transformation from YUV |
| 2103 // to RGB color values. They are taken from the following webpage: | 2131 // to RGB color values. They are taken from the following webpage: |
| 2104 // http://www.fourcc.org/fccyvrgb.php | 2132 // http://www.fourcc.org/fccyvrgb.php |
| 2105 float yuv_to_rgb_rec601[9] = { | 2133 float yuv_to_rgb_rec601[9] = { |
| 2106 1.164f, 1.164f, 1.164f, 0.0f, -.391f, 2.018f, 1.596f, -.813f, 0.0f, | 2134 1.164f, 1.164f, 1.164f, 0.0f, -.391f, 2.018f, 1.596f, -.813f, 0.0f, |
| 2107 }; | 2135 }; |
| 2108 float yuv_to_rgb_jpeg[9] = { | 2136 float yuv_to_rgb_jpeg[9] = { |
| (...skipping 1291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3400 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | 3428 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| 3401 VideoYUVProgram* program = &video_yuv_program_[precision][sampler]; | 3429 VideoYUVProgram* program = &video_yuv_program_[precision][sampler]; |
| 3402 if (!program->initialized()) { | 3430 if (!program->initialized()) { |
| 3403 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); | 3431 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); |
| 3404 program->Initialize(output_surface_->context_provider(), precision, | 3432 program->Initialize(output_surface_->context_provider(), precision, |
| 3405 sampler); | 3433 sampler); |
| 3406 } | 3434 } |
| 3407 return program; | 3435 return program; |
| 3408 } | 3436 } |
| 3409 | 3437 |
| 3438 const GLRenderer::VideoNV12Program* GLRenderer::GetVideoNV12Program( | |
|
danakj
2016/04/11 23:28:28
This program should be tested in our unit tests th
| |
| 3439 TexCoordPrecision precision, | |
| 3440 SamplerType sampler) { | |
| 3441 DCHECK_GE(precision, 0); | |
| 3442 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | |
| 3443 DCHECK_GE(sampler, 0); | |
| 3444 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | |
| 3445 VideoNV12Program* program = &video_nv12_program_[precision][sampler]; | |
| 3446 if (!program->initialized()) { | |
| 3447 TRACE_EVENT0("cc", "GLRenderer::videoNV12Program::initialize"); | |
| 3448 program->Initialize(output_surface_->context_provider(), precision, | |
| 3449 sampler); | |
| 3450 } | |
| 3451 return program; | |
| 3452 } | |
| 3453 | |
| 3410 const GLRenderer::VideoYUVAProgram* GLRenderer::GetVideoYUVAProgram( | 3454 const GLRenderer::VideoYUVAProgram* GLRenderer::GetVideoYUVAProgram( |
| 3411 TexCoordPrecision precision, | 3455 TexCoordPrecision precision, |
| 3412 SamplerType sampler) { | 3456 SamplerType sampler) { |
| 3413 DCHECK_GE(precision, 0); | 3457 DCHECK_GE(precision, 0); |
| 3414 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3458 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| 3415 DCHECK_GE(sampler, 0); | 3459 DCHECK_GE(sampler, 0); |
| 3416 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | 3460 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| 3417 VideoYUVAProgram* program = &video_yuva_program_[precision][sampler]; | 3461 VideoYUVAProgram* program = &video_yuva_program_[precision][sampler]; |
| 3418 if (!program->initialized()) { | 3462 if (!program->initialized()) { |
| 3419 TRACE_EVENT0("cc", "GLRenderer::videoYUVAProgram::initialize"); | 3463 TRACE_EVENT0("cc", "GLRenderer::videoYUVAProgram::initialize"); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3453 for (int l = 0; l <= LAST_MASK_VALUE; ++l) { | 3497 for (int l = 0; l <= LAST_MASK_VALUE; ++l) { |
| 3454 render_pass_mask_program_[i][j][k][l].Cleanup(gl_); | 3498 render_pass_mask_program_[i][j][k][l].Cleanup(gl_); |
| 3455 render_pass_mask_program_aa_[i][j][k][l].Cleanup(gl_); | 3499 render_pass_mask_program_aa_[i][j][k][l].Cleanup(gl_); |
| 3456 render_pass_mask_color_matrix_program_aa_[i][j][k][l].Cleanup(gl_); | 3500 render_pass_mask_color_matrix_program_aa_[i][j][k][l].Cleanup(gl_); |
| 3457 render_pass_mask_color_matrix_program_[i][j][k][l].Cleanup(gl_); | 3501 render_pass_mask_color_matrix_program_[i][j][k][l].Cleanup(gl_); |
| 3458 } | 3502 } |
| 3459 } | 3503 } |
| 3460 | 3504 |
| 3461 video_yuv_program_[i][j].Cleanup(gl_); | 3505 video_yuv_program_[i][j].Cleanup(gl_); |
| 3462 video_yuva_program_[i][j].Cleanup(gl_); | 3506 video_yuva_program_[i][j].Cleanup(gl_); |
| 3507 video_nv12_program_[i][j].Cleanup(gl_); | |
| 3463 } | 3508 } |
| 3464 for (int j = 0; j <= LAST_BLEND_MODE; j++) { | 3509 for (int j = 0; j <= LAST_BLEND_MODE; j++) { |
| 3465 render_pass_program_[i][j].Cleanup(gl_); | 3510 render_pass_program_[i][j].Cleanup(gl_); |
| 3466 render_pass_program_aa_[i][j].Cleanup(gl_); | 3511 render_pass_program_aa_[i][j].Cleanup(gl_); |
| 3467 render_pass_color_matrix_program_[i][j].Cleanup(gl_); | 3512 render_pass_color_matrix_program_[i][j].Cleanup(gl_); |
| 3468 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); | 3513 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); |
| 3469 } | 3514 } |
| 3470 | 3515 |
| 3471 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { | 3516 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { |
| 3472 texture_program_[i][j].Cleanup(gl_); | 3517 texture_program_[i][j].Cleanup(gl_); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3599 texture_id = pending_overlay_resources_.back()->texture_id(); | 3644 texture_id = pending_overlay_resources_.back()->texture_id(); |
| 3600 } | 3645 } |
| 3601 | 3646 |
| 3602 context_support_->ScheduleOverlayPlane( | 3647 context_support_->ScheduleOverlayPlane( |
| 3603 overlay.plane_z_order, overlay.transform, texture_id, | 3648 overlay.plane_z_order, overlay.transform, texture_id, |
| 3604 ToNearestRect(overlay.display_rect), overlay.uv_rect); | 3649 ToNearestRect(overlay.display_rect), overlay.uv_rect); |
| 3605 } | 3650 } |
| 3606 } | 3651 } |
| 3607 | 3652 |
| 3608 } // namespace cc | 3653 } // namespace cc |
| OLD | NEW |