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 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 FlushTextureQuadCache(SHARED_BINDING); | 519 FlushTextureQuadCache(SHARED_BINDING); |
520 } | 520 } |
521 | 521 |
522 switch (quad->material) { | 522 switch (quad->material) { |
523 case DrawQuad::INVALID: | 523 case DrawQuad::INVALID: |
524 NOTREACHED(); | 524 NOTREACHED(); |
525 break; | 525 break; |
526 case DrawQuad::DEBUG_BORDER: | 526 case DrawQuad::DEBUG_BORDER: |
527 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); | 527 DrawDebugBorderQuad(frame, DebugBorderDrawQuad::MaterialCast(quad)); |
528 break; | 528 break; |
529 case DrawQuad::IO_SURFACE_CONTENT: | |
530 DrawIOSurfaceQuad(frame, IOSurfaceDrawQuad::MaterialCast(quad), | |
531 clip_region); | |
532 break; | |
533 case DrawQuad::PICTURE_CONTENT: | 529 case DrawQuad::PICTURE_CONTENT: |
534 // PictureDrawQuad should only be used for resourceless software draws. | 530 // PictureDrawQuad should only be used for resourceless software draws. |
535 NOTREACHED(); | 531 NOTREACHED(); |
536 break; | 532 break; |
537 case DrawQuad::RENDER_PASS: | 533 case DrawQuad::RENDER_PASS: |
538 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad), | 534 DrawRenderPassQuad(frame, RenderPassDrawQuad::MaterialCast(quad), |
539 clip_region); | 535 clip_region); |
540 break; | 536 break; |
541 case DrawQuad::SOLID_COLOR: | 537 case DrawQuad::SOLID_COLOR: |
542 DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad), | 538 DrawSolidColorQuad(frame, SolidColorDrawQuad::MaterialCast(quad), |
(...skipping 1930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2473 uv[4] = scaled_region.p3().x() + 0.5f; | 2469 uv[4] = scaled_region.p3().x() + 0.5f; |
2474 uv[5] = scaled_region.p3().y() + 0.5f; | 2470 uv[5] = scaled_region.p3().y() + 0.5f; |
2475 uv[6] = scaled_region.p4().x() + 0.5f; | 2471 uv[6] = scaled_region.p4().x() + 0.5f; |
2476 uv[7] = scaled_region.p4().y() + 0.5f; | 2472 uv[7] = scaled_region.p4().y() + 0.5f; |
2477 PrepareGeometry(CLIPPED_BINDING); | 2473 PrepareGeometry(CLIPPED_BINDING); |
2478 clipped_geometry_->InitializeCustomQuadWithUVs(scaled_region, uv); | 2474 clipped_geometry_->InitializeCustomQuadWithUVs(scaled_region, uv); |
2479 FlushTextureQuadCache(CLIPPED_BINDING); | 2475 FlushTextureQuadCache(CLIPPED_BINDING); |
2480 } | 2476 } |
2481 } | 2477 } |
2482 | 2478 |
2483 void GLRenderer::DrawIOSurfaceQuad(const DrawingFrame* frame, | |
2484 const IOSurfaceDrawQuad* quad, | |
2485 const gfx::QuadF* clip_region) { | |
2486 SetBlendEnabled(quad->ShouldDrawWithBlending()); | |
2487 | |
2488 TexCoordPrecision tex_coord_precision = TexCoordPrecisionRequired( | |
2489 gl_, &highp_threshold_cache_, highp_threshold_min_, | |
2490 quad->shared_quad_state->visible_quad_layer_rect.bottom_right()); | |
2491 | |
2492 TexTransformTextureProgramBinding binding; | |
2493 binding.Set(GetTextureIOSurfaceProgram(tex_coord_precision)); | |
2494 | |
2495 SetUseProgram(binding.program_id); | |
2496 gl_->Uniform1i(binding.sampler_location, 0); | |
2497 if (quad->orientation == IOSurfaceDrawQuad::FLIPPED) { | |
2498 gl_->Uniform4f( | |
2499 binding.tex_transform_location, 0, quad->io_surface_size.height(), | |
2500 quad->io_surface_size.width(), quad->io_surface_size.height() * -1.0f); | |
2501 } else { | |
2502 gl_->Uniform4f(binding.tex_transform_location, 0, 0, | |
2503 quad->io_surface_size.width(), | |
2504 quad->io_surface_size.height()); | |
2505 } | |
2506 | |
2507 const float vertex_opacity[] = {quad->shared_quad_state->opacity, | |
2508 quad->shared_quad_state->opacity, | |
2509 quad->shared_quad_state->opacity, | |
2510 quad->shared_quad_state->opacity}; | |
2511 gl_->Uniform1fv(binding.vertex_opacity_location, 4, vertex_opacity); | |
2512 | |
2513 ResourceProvider::ScopedReadLockGL lock(resource_provider_, | |
2514 quad->io_surface_resource_id()); | |
2515 DCHECK_EQ(GL_TEXTURE0, GetActiveTextureUnit(gl_)); | |
2516 gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, lock.texture_id()); | |
2517 | |
2518 if (!clip_region) { | |
2519 DrawQuadGeometry(frame, quad->shared_quad_state->quad_to_target_transform, | |
2520 gfx::RectF(quad->rect), binding.matrix_location); | |
2521 } else { | |
2522 float uvs[8] = {0}; | |
2523 GetScaledUVs(quad->visible_rect, clip_region, uvs); | |
2524 DrawQuadGeometryClippedByQuadF( | |
2525 frame, quad->shared_quad_state->quad_to_target_transform, | |
2526 gfx::RectF(quad->rect), *clip_region, binding.matrix_location, uvs); | |
2527 } | |
2528 | |
2529 gl_->BindTexture(GL_TEXTURE_RECTANGLE_ARB, 0); | |
2530 } | |
2531 | |
2532 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { | 2479 void GLRenderer::FinishDrawingFrame(DrawingFrame* frame) { |
2533 if (use_sync_query_) { | 2480 if (use_sync_query_) { |
2534 DCHECK(current_sync_query_); | 2481 DCHECK(current_sync_query_); |
2535 current_sync_query_->End(); | 2482 current_sync_query_->End(); |
2536 pending_sync_queries_.push_back(std::move(current_sync_query_)); | 2483 pending_sync_queries_.push_back(std::move(current_sync_query_)); |
2537 } | 2484 } |
2538 | 2485 |
2539 current_framebuffer_lock_ = nullptr; | 2486 current_framebuffer_lock_ = nullptr; |
2540 swap_buffer_rect_.Union(frame->root_damage_rect); | 2487 swap_buffer_rect_.Union(frame->root_damage_rect); |
2541 | 2488 |
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3405 &nonpremultiplied_texture_background_program_[precision][sampler]; | 3352 &nonpremultiplied_texture_background_program_[precision][sampler]; |
3406 if (!program->initialized()) { | 3353 if (!program->initialized()) { |
3407 TRACE_EVENT0("cc", | 3354 TRACE_EVENT0("cc", |
3408 "GLRenderer::NonPremultipliedTextureProgram::Initialize"); | 3355 "GLRenderer::NonPremultipliedTextureProgram::Initialize"); |
3409 program->Initialize(output_surface_->context_provider(), precision, | 3356 program->Initialize(output_surface_->context_provider(), precision, |
3410 sampler); | 3357 sampler); |
3411 } | 3358 } |
3412 return program; | 3359 return program; |
3413 } | 3360 } |
3414 | 3361 |
3415 const GLRenderer::TextureProgram* GLRenderer::GetTextureIOSurfaceProgram( | |
3416 TexCoordPrecision precision) { | |
3417 DCHECK_GE(precision, 0); | |
3418 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | |
3419 TextureProgram* program = &texture_io_surface_program_[precision]; | |
3420 if (!program->initialized()) { | |
3421 TRACE_EVENT0("cc", "GLRenderer::textureIOSurfaceProgram::initialize"); | |
3422 program->Initialize(output_surface_->context_provider(), precision, | |
3423 SAMPLER_TYPE_2D_RECT); | |
3424 } | |
3425 return program; | |
3426 } | |
3427 | |
3428 const GLRenderer::VideoYUVProgram* GLRenderer::GetVideoYUVProgram( | 3362 const GLRenderer::VideoYUVProgram* GLRenderer::GetVideoYUVProgram( |
3429 TexCoordPrecision precision, | 3363 TexCoordPrecision precision, |
3430 SamplerType sampler) { | 3364 SamplerType sampler) { |
3431 DCHECK_GE(precision, 0); | 3365 DCHECK_GE(precision, 0); |
3432 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); | 3366 DCHECK_LE(precision, LAST_TEX_COORD_PRECISION); |
3433 DCHECK_GE(sampler, 0); | 3367 DCHECK_GE(sampler, 0); |
3434 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); | 3368 DCHECK_LE(sampler, LAST_SAMPLER_TYPE); |
3435 VideoYUVProgram* program = &video_yuv_program_[precision][sampler]; | 3369 VideoYUVProgram* program = &video_yuv_program_[precision][sampler]; |
3436 if (!program->initialized()) { | 3370 if (!program->initialized()) { |
3437 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); | 3371 TRACE_EVENT0("cc", "GLRenderer::videoYUVProgram::initialize"); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3518 render_pass_color_matrix_program_[i][j].Cleanup(gl_); | 3452 render_pass_color_matrix_program_[i][j].Cleanup(gl_); |
3519 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); | 3453 render_pass_color_matrix_program_aa_[i][j].Cleanup(gl_); |
3520 } | 3454 } |
3521 | 3455 |
3522 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { | 3456 for (int j = 0; j <= LAST_SAMPLER_TYPE; ++j) { |
3523 texture_program_[i][j].Cleanup(gl_); | 3457 texture_program_[i][j].Cleanup(gl_); |
3524 nonpremultiplied_texture_program_[i][j].Cleanup(gl_); | 3458 nonpremultiplied_texture_program_[i][j].Cleanup(gl_); |
3525 texture_background_program_[i][j].Cleanup(gl_); | 3459 texture_background_program_[i][j].Cleanup(gl_); |
3526 nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_); | 3460 nonpremultiplied_texture_background_program_[i][j].Cleanup(gl_); |
3527 } | 3461 } |
3528 texture_io_surface_program_[i].Cleanup(gl_); | |
3529 | 3462 |
3530 video_stream_texture_program_[i].Cleanup(gl_); | 3463 video_stream_texture_program_[i].Cleanup(gl_); |
3531 } | 3464 } |
3532 | 3465 |
3533 debug_border_program_.Cleanup(gl_); | 3466 debug_border_program_.Cleanup(gl_); |
3534 solid_color_program_.Cleanup(gl_); | 3467 solid_color_program_.Cleanup(gl_); |
3535 solid_color_program_aa_.Cleanup(gl_); | 3468 solid_color_program_aa_.Cleanup(gl_); |
3536 | 3469 |
3537 if (offscreen_framebuffer_id_) | 3470 if (offscreen_framebuffer_id_) |
3538 gl_->DeleteFramebuffers(1, &offscreen_framebuffer_id_); | 3471 gl_->DeleteFramebuffers(1, &offscreen_framebuffer_id_); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3652 texture_id = pending_overlay_resources_.back()->texture_id(); | 3585 texture_id = pending_overlay_resources_.back()->texture_id(); |
3653 } | 3586 } |
3654 | 3587 |
3655 context_support_->ScheduleOverlayPlane( | 3588 context_support_->ScheduleOverlayPlane( |
3656 overlay.plane_z_order, overlay.transform, texture_id, | 3589 overlay.plane_z_order, overlay.transform, texture_id, |
3657 ToNearestRect(overlay.display_rect), overlay.uv_rect); | 3590 ToNearestRect(overlay.display_rect), overlay.uv_rect); |
3658 } | 3591 } |
3659 } | 3592 } |
3660 | 3593 |
3661 } // namespace cc | 3594 } // namespace cc |
OLD | NEW |