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 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad), | 538 EnqueueTextureQuad(frame, TextureDrawQuad::MaterialCast(quad), |
539 clip_region); | 539 clip_region); |
540 break; | 540 break; |
541 case DrawQuad::TILED_CONTENT: | 541 case DrawQuad::TILED_CONTENT: |
542 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad), clip_region); | 542 DrawTileQuad(frame, TileDrawQuad::MaterialCast(quad), clip_region); |
543 break; | 543 break; |
544 case DrawQuad::YUV_VIDEO_CONTENT: | 544 case DrawQuad::YUV_VIDEO_CONTENT: |
545 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad), | 545 DrawYUVVideoQuad(frame, YUVVideoDrawQuad::MaterialCast(quad), |
546 clip_region); | 546 clip_region); |
547 break; | 547 break; |
| 548 case DrawQuad::Y_VIDEO_CONTENT: |
| 549 DrawYVideoQuad(frame, YVideoDrawQuad::MaterialCast(quad), clip_region); |
| 550 break; |
548 } | 551 } |
549 } | 552 } |
550 | 553 |
551 // This function does not handle 3D sorting right now, since the debug border | 554 // This function does not handle 3D sorting right now, since the debug border |
552 // quads are just drawn as their original quads and not in split pieces. This | 555 // quads are just drawn as their original quads and not in split pieces. This |
553 // results in some debug border quads drawing over foreground quads. | 556 // results in some debug border quads drawing over foreground quads. |
554 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, | 557 void GLRenderer::DrawDebugBorderQuad(const DrawingFrame* frame, |
555 const DebugBorderDrawQuad* quad) { | 558 const DebugBorderDrawQuad* quad) { |
556 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 559 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
557 | 560 |
(...skipping 1727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2285 GetScaledUVs(quad->visible_rect, clip_region, uvs); | 2288 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
2286 gfx::QuadF region_quad = *clip_region; | 2289 gfx::QuadF region_quad = *clip_region; |
2287 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); | 2290 region_quad.Scale(1.0f / tile_rect.width(), 1.0f / tile_rect.height()); |
2288 region_quad -= gfx::Vector2dF(0.5f, 0.5f); | 2291 region_quad -= gfx::Vector2dF(0.5f, 0.5f); |
2289 DrawQuadGeometryClippedByQuadF( | 2292 DrawQuadGeometryClippedByQuadF( |
2290 frame, quad->shared_quad_state->quad_to_target_transform, tile_rect, | 2293 frame, quad->shared_quad_state->quad_to_target_transform, tile_rect, |
2291 region_quad, matrix_location, uvs); | 2294 region_quad, matrix_location, uvs); |
2292 } | 2295 } |
2293 } | 2296 } |
2294 | 2297 |
| 2298 void GLRenderer::DrawYVideoQuad(const DrawingFrame* frame, |
| 2299 const YVideoDrawQuad* quad, |
| 2300 const gfx::QuadF* clip_region) { |
| 2301 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
| 2302 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
| 2303 gl_, &highp_threshold_cache_, highp_threshold_min_, |
| 2304 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); |
| 2305 |
| 2306 ResourceProvider::ScopedReadLockGL lock(resource_provider_, |
| 2307 quad->resource_id()); |
| 2308 const SamplerType sampler = SamplerTypeFromTextureTarget(lock.target()); |
| 2309 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); |
| 2310 gl_->BindTexture(lock.target(), lock.texture_id()); |
| 2311 |
| 2312 // TODO(astojilj) TextureProgram could also be used - just remember to set |
| 2313 // varying v_alpha. |
| 2314 const VideoYProgram* program = GetVideoYProgram(tex_coord_precision, sampler); |
| 2315 DCHECK(program && (program->initialized() || IsContextLost())); |
| 2316 SetUseProgram(program->program()); |
| 2317 |
| 2318 // Set the uv-transform. |
| 2319 Float4 uv_transform = {{0.0f, 0.0f, 1.0f, 1.0f}}; |
| 2320 if (!clip_region) { |
| 2321 gfx::PointF uv0 = quad->uv_top_left; |
| 2322 gfx::PointF uv1 = quad->uv_bottom_right; |
| 2323 uv_transform = {{uv0.x(), uv0.y(), uv1.x() - uv0.x(), uv1.y() - uv0.y()}}; |
| 2324 } |
| 2325 gfx::Size texture_size = lock.size(); |
| 2326 if (sampler == SAMPLER_TYPE_2D_RECT) { |
| 2327 // Un-normalize the texture coordiantes for rectangle targets. |
| 2328 uv_transform.data[0] *= texture_size.width(); |
| 2329 uv_transform.data[2] *= texture_size.width(); |
| 2330 uv_transform.data[1] *= texture_size.height(); |
| 2331 uv_transform.data[3] *= texture_size.height(); |
| 2332 } |
| 2333 gl_->Uniform4fv(program->vertex_shader().tex_transform_location(), 1, |
| 2334 uv_transform.data); |
| 2335 gl_->Uniform1i(program->fragment_shader().sampler_location(), 0); |
| 2336 gl_->Uniform1f(program->fragment_shader().x_derivative_location(), |
| 2337 1.f / (float)texture_size.width()); |
| 2338 gl_->Uniform1f(program->fragment_shader().y_derivative_location(), |
| 2339 1.f / (float)texture_size.height()); |
| 2340 |
| 2341 if (!clip_region) { |
| 2342 DrawQuadGeometry(frame, quad->shared_quad_state->quad_to_target_transform, |
| 2343 gfx::RectF(quad->rect), |
| 2344 program->vertex_shader().matrix_location()); |
| 2345 } else { |
| 2346 gfx::QuadF region_quad(*clip_region); |
| 2347 region_quad.Scale(1.0f / quad->rect.width(), 1.0f / quad->rect.height()); |
| 2348 region_quad -= gfx::Vector2dF(0.5f, 0.5f); |
| 2349 float uvs[8] = {0}; |
| 2350 GetScaledUVs(quad->visible_rect, clip_region, uvs); |
| 2351 DrawQuadGeometryClippedByQuadF( |
| 2352 frame, quad->shared_quad_state->quad_to_target_transform, |
| 2353 gfx::RectF(quad->rect), region_quad, |
| 2354 program->vertex_shader().matrix_location(), uvs); |
| 2355 } |
| 2356 } |
| 2357 |
2295 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, | 2358 void GLRenderer::DrawStreamVideoQuad(const DrawingFrame* frame, |
2296 const StreamVideoDrawQuad* quad, | 2359 const StreamVideoDrawQuad* quad, |
2297 const gfx::QuadF* clip_region) { | 2360 const gfx::QuadF* clip_region) { |
2298 SetBlendEnabled(quad->ShouldDrawWithBlending()); | 2361 SetBlendEnabled(quad->ShouldDrawWithBlending()); |
2299 | 2362 |
2300 static float gl_matrix[16]; | 2363 static float gl_matrix[16]; |
2301 | 2364 |
2302 DCHECK(capabilities_.using_egl_image); | 2365 DCHECK(capabilities_.using_egl_image); |
2303 | 2366 |
2304 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | 2367 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( |
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3499 &video_yuv_program_[precision][sampler][use_alpha_plane][use_nv12]; | 3562 &video_yuv_program_[precision][sampler][use_alpha_plane][use_nv12]; |
3500 if (!program->initialized()) { | 3563 if (!program->initialized()) { |
3501 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); | 3564 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); |
3502 program->mutable_fragment_shader()->SetFeatures(use_alpha_plane, use_nv12); | 3565 program->mutable_fragment_shader()->SetFeatures(use_alpha_plane, use_nv12); |
3503 program->Initialize(output_surface_->context_provider(), precision, | 3566 program->Initialize(output_surface_->context_provider(), precision, |
3504 sampler); | 3567 sampler); |
3505 } | 3568 } |
3506 return program; | 3569 return program; |
3507 } | 3570 } |
3508 | 3571 |
| 3572 const GLRenderer::VideoYProgram* GLRenderer::GetVideoYProgram( |
| 3573 TexCoordPrecision precision, |
| 3574 SamplerType sampler) { |
| 3575 DCHECK_GE(precision, 0); |
| 3576 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
| 3577 DCHECK_GE(sampler, 0); |
| 3578 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
| 3579 VideoYProgram* program = &video_y_program_[precision][sampler]; |
| 3580 if (!program->initialized()) { |
| 3581 TRACE_EVENT0("cc", "GLRenderer::videoYProgram::initialize"); |
| 3582 program->Initialize(output_surface_->context_provider(), precision, |
| 3583 sampler); |
| 3584 } |
| 3585 return program; |
| 3586 } |
| 3587 |
3509 const GLRenderer::VideoStreamTextureProgram* | 3588 const GLRenderer::VideoStreamTextureProgram* |
3510 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { | 3589 GLRenderer::GetVideoStreamTextureProgram(TexCoordPrecision precision) { |
3511 DCHECK_GE(precision, 0); | 3590 DCHECK_GE(precision, 0); |
3512 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3591 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
3513 VideoStreamTextureProgram* program = | 3592 VideoStreamTextureProgram* program = |
3514 &video_stream_texture_program_[precision]; | 3593 &video_stream_texture_program_[precision]; |
3515 if (!program->initialized()) { | 3594 if (!program->initialized()) { |
3516 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); | 3595 TRACE_EVENT0("cc", "GLRenderer::streamTextureProgram::initialize"); |
3517 program->Initialize(output_surface_->context_provider(), precision, | 3596 program->Initialize(output_surface_->context_provider(), precision, |
3518 SAMPLER_TYPE_EXTERNAL_OES); | 3597 SAMPLER_TYPE_EXTERNAL_OES); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3552 render_pass_program_aa_[i][j].Cleanup(gl_); | 3631 render_pass_program_aa_[i][j].Cleanup(gl_); |
3553 render_pass_color_matrix_program_[i][j].Cleanup(gl_); | 3632 render_pass_color_matrix_program_[i][j].Cleanup(gl_); |
3554 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); | 3633 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); |
3555 } | 3634 } |
3556 | 3635 |
3557 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { | 3636 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { |
3558 texture_program_[i][j].Cleanup(gl_); | 3637 texture_program_[i][j].Cleanup(gl_); |
3559 nonpremultiplied_texture_program_[i][j].Cleanup(gl_); | 3638 nonpremultiplied_texture_program_[i][j].Cleanup(gl_); |
3560 texture_background_program_[i][j].Cleanup(gl_); | 3639 texture_background_program_[i][j].Cleanup(gl_); |
3561 nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_); | 3640 nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_); |
| 3641 video_y_program_[i][j].Cleanup(gl_); |
3562 } | 3642 } |
3563 | 3643 |
3564 video_stream_texture_program_[i].Cleanup(gl_); | 3644 video_stream_texture_program_[i].Cleanup(gl_); |
3565 } | 3645 } |
3566 | 3646 |
3567 debug_border_program_.Cleanup(gl_); | 3647 debug_border_program_.Cleanup(gl_); |
3568 solid_color_program_.Cleanup(gl_); | 3648 solid_color_program_.Cleanup(gl_); |
3569 solid_color_program_aa_.Cleanup(gl_); | 3649 solid_color_program_aa_.Cleanup(gl_); |
3570 | 3650 |
3571 if (offscreen_framebuffer_id_) | 3651 if (offscreen_framebuffer_id_) |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3686 texture_id = pending_overlay_resources_.back()->texture_id(); | 3766 texture_id = pending_overlay_resources_.back()->texture_id(); |
3687 } | 3767 } |
3688 | 3768 |
3689 context_support_->ScheduleOverlayPlane( | 3769 context_support_->ScheduleOverlayPlane( |
3690 overlay.plane_z_order, overlay.transform, texture_id, | 3770 overlay.plane_z_order, overlay.transform, texture_id, |
3691 ToNearestRect(overlay.display_rect), overlay.uv_rect); | 3771 ToNearestRect(overlay.display_rect), overlay.uv_rect); |
3692 } | 3772 } |
3693 } | 3773 } |
3694 | 3774 |
3695 } // namespace cc | 3775 } // namespace cc |
OLD | NEW |