| 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 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad), | 592 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad), |
| 593 clip_region); | 593 clip_region); |
| 594 break; | 594 break; |
| 595 case DrawQuad::TILED_CONTENT: | 595 case DrawQuad::TILED_CONTENT: |
| 596 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad), clip_region); | 596 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad), clip_region); |
| 597 break; | 597 break; |
| 598 case DrawQuad::YUV_VIDEO_CONTENT: | 598 case DrawQuad::YUV_VIDEO_CONTENT: |
| 599 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad), | 599 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad), |
| 600 clip_region); | 600 clip_region); |
| 601 break; | 601 break; |
| 602 case DrawQuad::Y_VIDEO_CONTENT: |
| 603 DrawYVideoQuad(frame, YVideoDrawQuad::MaterialCast(quad), clip_region); |
| 604 break; |
| 602 } | 605 } |
| 603 } | 606 } |
| 604 | 607 |
| 605 // This function does not handle 3D sorting right now, since the debug border | 608 // This function does not handle 3D sorting right now, since the debug border |
| 606 // quads are just drawn as their original quads and not in split pieces. This | 609 // quads are just drawn as their original quads and not in split pieces. This |
| 607 // results in some debug border quads drawing over foreground quads. | 610 // results in some debug border quads drawing over foreground quads. |
| 608 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, | 611 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, |
| 609 const DebugBorderDrawQuad* quad) { | 612 const DebugBorderDrawQuad* quad) { |
| 610 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 613 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 611 | 614 |
| (...skipping 1824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2436 GetScaledUVs(quad->visible_rect, clip_region, uvs); | 2439 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
| 2437 gfx::QuadF region_quad = *clip_region; | 2440 gfx::QuadF region_quad = *clip_region; |
| 2438 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); | 2441 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); |
| 2439 region_quad -= gfx::Vector2dF(0.5f, 0.5f); | 2442 region_quad -= gfx::Vector2dF(0.5f, 0.5f); |
| 2440 DrawQuadGeometryClippedByQuadF( | 2443 DrawQuadGeometryClippedByQuadF( |
| 2441 frame, quad->shared_quad_state->quad_to_target_transform, tile_rect, | 2444 frame, quad->shared_quad_state->quad_to_target_transform, tile_rect, |
| 2442 region_quad, matrix_location, uvs); | 2445 region_quad, matrix_location, uvs); |
| 2443 } | 2446 } |
| 2444 } | 2447 } |
| 2445 | 2448 |
| 2449 void GLRenderer::DrawYVideoQuad(const DrawingFrame* frame, |
| 2450 const YVideoDrawQuad* quad, |
| 2451 const gfx::QuadF* clip_region) { |
| 2452 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 2453 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2454 gl_, &highp_threshold_cache_, highp_threshold_min_, |
| 2455 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); |
| 2456 |
| 2457 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 2458 quad->resource_id()); |
| 2459 const SamplerType sampler = SamplerTypeFromTextureTarget(lock.target()); |
| 2460 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
| 2461 gl_->BindTexture(lock.target(), lock.texture_id()); |
| 2462 |
| 2463 const VideoYProgram* program = GetVideoYProgram(tex_coord_precision, sampler); |
| 2464 DCHECK(program && (program->initialized() || IsContextLost())); |
| 2465 SetUseProgram(program->program()); |
| 2466 |
| 2467 // Set the uv-transform. |
| 2468 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}}; |
| 2469 if (!clip_region) { |
| 2470 gfx::PointF uv0 = quad->uv_top_left; |
| 2471 gfx::PointF uv1 = quad->uv_bottom_right; |
| 2472 uv_transform = {{uv0.x(), uv0.y(), uv1.x() - uv0.x(), uv1.y() - uv0.y()}}; |
| 2473 } |
| 2474 gfx::Size texture_size = lock.size(); |
| 2475 if (sampler == SAMPLER_TYPE_2D_RECT) { |
| 2476 // Un-normalize the texture coordiantes for rectangle targets. |
| 2477 uv_transform.data[0] *= texture_size.width(); |
| 2478 uv_transform.data[2] *= texture_size.width(); |
| 2479 uv_transform.data[1] *= texture_size.height(); |
| 2480 uv_transform.data[3] *= texture_size.height(); |
| 2481 } |
| 2482 gl_->Uniform4fv(program->vertex_shader().tex_transform_location(), 1, |
| 2483 uv_transform.data); |
| 2484 gl_->Uniform1i(program->fragment_shader().sampler_location(), 0); |
| 2485 gl_->Uniform1f(program->fragment_shader().x_derivative_location(), |
| 2486 1.f / (float)texture_size.width()); |
| 2487 gl_->Uniform1f(program->fragment_shader().y_derivative_location(), |
| 2488 1.f / (float)texture_size.height()); |
| 2489 |
| 2490 if (!clip_region) { |
| 2491 DrawQuadGeometry(frame->projection_matrix, |
| 2492 quad->shared_quad_state->quad_to_target_transform, |
| 2493 gfx::RectF(quad->rect), |
| 2494 program->vertex_shader().matrix_location()); |
| 2495 } else { |
| 2496 gfx::QuadF region_quad(*clip_region); |
| 2497 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); |
| 2498 region_quad -= gfx::Vector2dF(0.5f, 0.5f); |
| 2499 float uvs[8] = {0}; |
| 2500 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
| 2501 DrawQuadGeometryClippedByQuadF( |
| 2502 frame, quad->shared_quad_state->quad_to_target_transform, |
| 2503 gfx::RectF(quad->rect), region_quad, |
| 2504 program->vertex_shader().matrix_location(), uvs); |
| 2505 } |
| 2506 } |
| 2507 |
| 2446 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, | 2508 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, |
| 2447 const StreamVideoDrawQuad* quad, | 2509 const StreamVideoDrawQuad* quad, |
| 2448 const gfx::QuadF* clip_region) { | 2510 const gfx::QuadF* clip_region) { |
| 2449 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 2511 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 2450 | 2512 |
| 2451 static float gl_matrix[16]; | 2513 static float gl_matrix[16]; |
| 2452 | 2514 |
| 2453 DCHECK(output_surface_->context_provider() | 2515 DCHECK(output_surface_->context_provider() |
| 2454 ->ContextCapabilities() | 2516 ->ContextCapabilities() |
| 2455 .egl_image_external); | 2517 .egl_image_external); |
| (...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3636 if (!program->initialized()) { | 3698 if (!program->initialized()) { |
| 3637 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); | 3699 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); |
| 3638 program->mutable_fragment_shader()->SetFeatures(use_alpha_plane, use_nv12, | 3700 program->mutable_fragment_shader()->SetFeatures(use_alpha_plane, use_nv12, |
| 3639 use_color_lut); | 3701 use_color_lut); |
| 3640 program->Initialize(output_surface_->context_provider(), precision, | 3702 program->Initialize(output_surface_->context_provider(), precision, |
| 3641 sampler); | 3703 sampler); |
| 3642 } | 3704 } |
| 3643 return program; | 3705 return program; |
| 3644 } | 3706 } |
| 3645 | 3707 |
| 3708 const GLRenderer::VideoYProgram* GLRenderer::GetVideoYProgram( |
| 3709 TexCoordPrecision precision, |
| 3710 SamplerType sampler) { |
| 3711 DCHECK_GE(precision, 0); |
| 3712 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| 3713 DCHECK_GE(sampler, 0); |
| 3714 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| 3715 VideoYProgram* program = &video_y_program_[precision][sampler]; |
| 3716 if (!program->initialized()) { |
| 3717 TRACE_EVENT0("cc", "GLRenderer::videoYProgram::initialize"); |
| 3718 program->Initialize(output_surface_->context_provider(), precision, |
| 3719 sampler); |
| 3720 } |
| 3721 return program; |
| 3722 } |
| 3723 |
| 3646 const GLRenderer::VideoStreamTextureProgram* | 3724 const GLRenderer::VideoStreamTextureProgram* |
| 3647 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { | 3725 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { |
| 3648 DCHECK_GE(precision, 0); | 3726 DCHECK_GE(precision, 0); |
| 3649 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3727 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| 3650 VideoStreamTextureProgram* program = | 3728 VideoStreamTextureProgram* program = |
| 3651 &video_stream_texture_program_[precision]; | 3729 &video_stream_texture_program_[precision]; |
| 3652 if (!program->initialized()) { | 3730 if (!program->initialized()) { |
| 3653 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); | 3731 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); |
| 3654 program->Initialize(output_surface_->context_provider(), precision, | 3732 program->Initialize(output_surface_->context_provider(), precision, |
| 3655 SAMPLER_TYPE_EXTERNAL_OES); | 3733 SAMPLER_TYPE_EXTERNAL_OES); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3691 render_pass_program_aa_[i][j].Cleanup(gl_); | 3769 render_pass_program_aa_[i][j].Cleanup(gl_); |
| 3692 render_pass_color_matrix_program_[i][j].Cleanup(gl_); | 3770 render_pass_color_matrix_program_[i][j].Cleanup(gl_); |
| 3693 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); | 3771 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); |
| 3694 } | 3772 } |
| 3695 | 3773 |
| 3696 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { | 3774 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { |
| 3697 texture_program_[i][j].Cleanup(gl_); | 3775 texture_program_[i][j].Cleanup(gl_); |
| 3698 nonpremultiplied_texture_program_[i][j].Cleanup(gl_); | 3776 nonpremultiplied_texture_program_[i][j].Cleanup(gl_); |
| 3699 texture_background_program_[i][j].Cleanup(gl_); | 3777 texture_background_program_[i][j].Cleanup(gl_); |
| 3700 nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_); | 3778 nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_); |
| 3779 video_y_program_[i][j].Cleanup(gl_); |
| 3701 } | 3780 } |
| 3702 | 3781 |
| 3703 video_stream_texture_program_[i].Cleanup(gl_); | 3782 video_stream_texture_program_[i].Cleanup(gl_); |
| 3704 } | 3783 } |
| 3705 | 3784 |
| 3706 debug_border_program_.Cleanup(gl_); | 3785 debug_border_program_.Cleanup(gl_); |
| 3707 solid_color_program_.Cleanup(gl_); | 3786 solid_color_program_.Cleanup(gl_); |
| 3708 solid_color_program_aa_.Cleanup(gl_); | 3787 solid_color_program_aa_.Cleanup(gl_); |
| 3709 | 3788 |
| 3710 if (offscreen_framebuffer_id_) | 3789 if (offscreen_framebuffer_id_) |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4035 | 4114 |
| 4036 gl_->ScheduleCALayerSharedStateCHROMIUM( | 4115 gl_->ScheduleCALayerSharedStateCHROMIUM( |
| 4037 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect, | 4116 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect, |
| 4038 sorting_context_id, gl_transform); | 4117 sorting_context_id, gl_transform); |
| 4039 gl_->ScheduleCALayerCHROMIUM( | 4118 gl_->ScheduleCALayerCHROMIUM( |
| 4040 texture_id, contents_rect, ca_layer_overlay->background_color, | 4119 texture_id, contents_rect, ca_layer_overlay->background_color, |
| 4041 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); | 4120 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); |
| 4042 } | 4121 } |
| 4043 | 4122 |
| 4044 } // namespace cc | 4123 } // namespace cc |
| OLD | NEW |