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 1834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2446 GetScaledUVs(quad->visible_rect, clip_region, uvs); | 2449 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
2447 gfx::QuadF region_quad = *clip_region; | 2450 gfx::QuadF region_quad = *clip_region; |
2448 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); | 2451 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); |
2449 region_quad -= gfx::Vector2dF(0.5f, 0.5f); | 2452 region_quad -= gfx::Vector2dF(0.5f, 0.5f); |
2450 DrawQuadGeometryClippedByQuadF( | 2453 DrawQuadGeometryClippedByQuadF( |
2451 frame, quad->shared_quad_state->quad_to_target_transform, tile_rect, | 2454 frame, quad->shared_quad_state->quad_to_target_transform, tile_rect, |
2452 region_quad, matrix_location, uvs); | 2455 region_quad, matrix_location, uvs); |
2453 } | 2456 } |
2454 } | 2457 } |
2455 | 2458 |
| 2459 void GLRenderer::DrawYVideoQuad(const DrawingFrame* frame, |
| 2460 const YVideoDrawQuad* quad, |
| 2461 const gfx::QuadF* clip_region) { |
| 2462 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 2463 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2464 gl_, &highp_threshold_cache_, highp_threshold_min_, |
| 2465 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); |
| 2466 |
| 2467 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 2468 quad->resource_id()); |
| 2469 const SamplerType sampler = SamplerTypeFromTextureTarget(lock.target()); |
| 2470 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
| 2471 gl_->BindTexture(lock.target(), lock.texture_id()); |
| 2472 |
| 2473 const VideoYProgram* program = GetVideoYProgram(tex_coord_precision, sampler); |
| 2474 DCHECK(program && (program->initialized() || IsContextLost())); |
| 2475 SetUseProgram(program->program()); |
| 2476 |
| 2477 // Set the uv-transform. |
| 2478 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}}; |
| 2479 if (!clip_region) { |
| 2480 gfx::PointF uv0 = quad->uv_top_left; |
| 2481 gfx::PointF uv1 = quad->uv_bottom_right; |
| 2482 uv_transform = {{uv0.x(), uv0.y(), uv1.x() - uv0.x(), uv1.y() - uv0.y()}}; |
| 2483 } |
| 2484 gfx::Size texture_size = lock.size(); |
| 2485 if (sampler == SAMPLER_TYPE_2D_RECT) { |
| 2486 // Un-normalize the texture coordiantes for rectangle targets. |
| 2487 uv_transform.data[0] *= texture_size.width(); |
| 2488 uv_transform.data[2] *= texture_size.width(); |
| 2489 uv_transform.data[1] *= texture_size.height(); |
| 2490 uv_transform.data[3] *= texture_size.height(); |
| 2491 } |
| 2492 gl_->Uniform4fv(program->vertex_shader().tex_transform_location(), 1, |
| 2493 uv_transform.data); |
| 2494 gl_->Uniform1i(program->fragment_shader().sampler_location(), 0); |
| 2495 gl_->Uniform1f(program->fragment_shader().x_derivative_location(), |
| 2496 1.f / (float)texture_size.width()); |
| 2497 gl_->Uniform1f(program->fragment_shader().y_derivative_location(), |
| 2498 1.f / (float)texture_size.height()); |
| 2499 |
| 2500 if (!clip_region) { |
| 2501 DrawQuadGeometry(frame->projection_matrix, |
| 2502 quad->shared_quad_state->quad_to_target_transform, |
| 2503 gfx::RectF(quad->rect), |
| 2504 program->vertex_shader().matrix_location()); |
| 2505 } else { |
| 2506 gfx::QuadF region_quad(*clip_region); |
| 2507 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); |
| 2508 region_quad -= gfx::Vector2dF(0.5f, 0.5f); |
| 2509 float uvs[8] = {0}; |
| 2510 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
| 2511 DrawQuadGeometryClippedByQuadF( |
| 2512 frame, quad->shared_quad_state->quad_to_target_transform, |
| 2513 gfx::RectF(quad->rect), region_quad, |
| 2514 program->vertex_shader().matrix_location(), uvs); |
| 2515 } |
| 2516 } |
| 2517 |
2456 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, | 2518 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, |
2457 const StreamVideoDrawQuad* quad, | 2519 const StreamVideoDrawQuad* quad, |
2458 const gfx::QuadF* clip_region) { | 2520 const gfx::QuadF* clip_region) { |
2459 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 2521 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
2460 | 2522 |
2461 static float gl_matrix[16]; | 2523 static float gl_matrix[16]; |
2462 | 2524 |
2463 DCHECK(output_surface_->context_provider() | 2525 DCHECK(output_surface_->context_provider() |
2464 ->ContextCapabilities() | 2526 ->ContextCapabilities() |
2465 .egl_image_external); | 2527 .egl_image_external); |
(...skipping 1179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3645 if (!program->initialized()) { | 3707 if (!program->initialized()) { |
3646 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); | 3708 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); |
3647 program->mutable_fragment_shader()->SetFeatures(use_alpha_plane, use_nv12, | 3709 program->mutable_fragment_shader()->SetFeatures(use_alpha_plane, use_nv12, |
3648 use_color_lut); | 3710 use_color_lut); |
3649 program->Initialize(output_surface_->context_provider(), precision, | 3711 program->Initialize(output_surface_->context_provider(), precision, |
3650 sampler); | 3712 sampler); |
3651 } | 3713 } |
3652 return program; | 3714 return program; |
3653 } | 3715 } |
3654 | 3716 |
| 3717 const GLRenderer::VideoYProgram* GLRenderer::GetVideoYProgram( |
| 3718 TexCoordPrecision precision, |
| 3719 SamplerType sampler) { |
| 3720 DCHECK_GE(precision, 0); |
| 3721 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| 3722 DCHECK_GE(sampler, 0); |
| 3723 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| 3724 VideoYProgram* program = &video_y_program_[precision][sampler]; |
| 3725 if (!program->initialized()) { |
| 3726 TRACE_EVENT0("cc", "GLRenderer::videoYProgram::initialize"); |
| 3727 program->Initialize(output_surface_->context_provider(), precision, |
| 3728 sampler); |
| 3729 } |
| 3730 return program; |
| 3731 } |
| 3732 |
3655 const GLRenderer::VideoStreamTextureProgram* | 3733 const GLRenderer::VideoStreamTextureProgram* |
3656 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { | 3734 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { |
3657 DCHECK_GE(precision, 0); | 3735 DCHECK_GE(precision, 0); |
3658 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3736 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
3659 VideoStreamTextureProgram* program = | 3737 VideoStreamTextureProgram* program = |
3660 &video_stream_texture_program_[precision]; | 3738 &video_stream_texture_program_[precision]; |
3661 if (!program->initialized()) { | 3739 if (!program->initialized()) { |
3662 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); | 3740 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); |
3663 program->Initialize(output_surface_->context_provider(), precision, | 3741 program->Initialize(output_surface_->context_provider(), precision, |
3664 SAMPLER_TYPE_EXTERNAL_OES); | 3742 SAMPLER_TYPE_EXTERNAL_OES); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3700 render_pass_program_aa_[i][j].Cleanup(gl_); | 3778 render_pass_program_aa_[i][j].Cleanup(gl_); |
3701 render_pass_color_matrix_program_[i][j].Cleanup(gl_); | 3779 render_pass_color_matrix_program_[i][j].Cleanup(gl_); |
3702 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); | 3780 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); |
3703 } | 3781 } |
3704 | 3782 |
3705 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { | 3783 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { |
3706 texture_program_[i][j].Cleanup(gl_); | 3784 texture_program_[i][j].Cleanup(gl_); |
3707 nonpremultiplied_texture_program_[i][j].Cleanup(gl_); | 3785 nonpremultiplied_texture_program_[i][j].Cleanup(gl_); |
3708 texture_background_program_[i][j].Cleanup(gl_); | 3786 texture_background_program_[i][j].Cleanup(gl_); |
3709 nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_); | 3787 nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_); |
| 3788 video_y_program_[i][j].Cleanup(gl_); |
3710 } | 3789 } |
3711 | 3790 |
3712 video_stream_texture_program_[i].Cleanup(gl_); | 3791 video_stream_texture_program_[i].Cleanup(gl_); |
3713 } | 3792 } |
3714 | 3793 |
3715 debug_border_program_.Cleanup(gl_); | 3794 debug_border_program_.Cleanup(gl_); |
3716 solid_color_program_.Cleanup(gl_); | 3795 solid_color_program_.Cleanup(gl_); |
3717 solid_color_program_aa_.Cleanup(gl_); | 3796 solid_color_program_aa_.Cleanup(gl_); |
3718 | 3797 |
3719 if (offscreen_framebuffer_id_) | 3798 if (offscreen_framebuffer_id_) |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4044 | 4123 |
4045 gl_->ScheduleCALayerSharedStateCHROMIUM( | 4124 gl_->ScheduleCALayerSharedStateCHROMIUM( |
4046 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect, | 4125 ca_layer_overlay->shared_state->opacity, is_clipped, clip_rect, |
4047 sorting_context_id, gl_transform); | 4126 sorting_context_id, gl_transform); |
4048 gl_->ScheduleCALayerCHROMIUM( | 4127 gl_->ScheduleCALayerCHROMIUM( |
4049 texture_id, contents_rect, ca_layer_overlay->background_color, | 4128 texture_id, contents_rect, ca_layer_overlay->background_color, |
4050 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); | 4129 ca_layer_overlay->edge_aa_mask, bounds_rect, filter); |
4051 } | 4130 } |
4052 | 4131 |
4053 } // namespace cc | 4132 } // namespace cc |
OLD | NEW |