| 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> |
| 11 #include <limits> | 11 #include <limits> |
| 12 #include <memory> | 12 #include <memory> |
| 13 #include <set> | 13 #include <set> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/macros.h" | 18 #include "base/macros.h" |
| 19 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
| 20 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 23 #include "base/threading/thread_task_runner_handle.h" |
| 23 #include "base/trace_event/trace_event.h" | 24 #include "base/trace_event/trace_event.h" |
| 24 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 25 #include "cc/base/container_util.h" | 26 #include "cc/base/container_util.h" |
| 26 #include "cc/base/math_util.h" | 27 #include "cc/base/math_util.h" |
| 27 #include "cc/output/compositor_frame.h" | 28 #include "cc/output/compositor_frame.h" |
| 28 #include "cc/output/compositor_frame_metadata.h" | 29 #include "cc/output/compositor_frame_metadata.h" |
| 29 #include "cc/output/context_provider.h" | 30 #include "cc/output/context_provider.h" |
| 30 #include "cc/output/copy_output_request.h" | 31 #include "cc/output/copy_output_request.h" |
| 31 #include "cc/output/dynamic_geometry_binding.h" | 32 #include "cc/output/dynamic_geometry_binding.h" |
| 32 #include "cc/output/gl_frame_data.h" | 33 #include "cc/output/gl_frame_data.h" |
| 33 #include "cc/output/layer_quad.h" | 34 #include "cc/output/layer_quad.h" |
| 34 #include "cc/output/output_surface.h" | 35 #include "cc/output/output_surface.h" |
| 35 #include "cc/output/render_surface_filters.h" | 36 #include "cc/output/render_surface_filters.h" |
| 36 #include "cc/output/static_geometry_binding.h" | 37 #include "cc/output/static_geometry_binding.h" |
| 37 #include "cc/output/texture_mailbox_deleter.h" | 38 #include "cc/output/texture_mailbox_deleter.h" |
| 38 #include "cc/quads/draw_polygon.h" | 39 #include "cc/quads/draw_polygon.h" |
| 39 #include "cc/quads/picture_draw_quad.h" | 40 #include "cc/quads/picture_draw_quad.h" |
| 40 #include "cc/quads/render_pass.h" | 41 #include "cc/quads/render_pass.h" |
| 41 #include "cc/quads/stream_video_draw_quad.h" | 42 #include "cc/quads/stream_video_draw_quad.h" |
| 42 #include "cc/quads/texture_draw_quad.h" | 43 #include "cc/quads/texture_draw_quad.h" |
| 43 #include "cc/raster/scoped_gpu_raster.h" | 44 #include "cc/raster/scoped_gpu_raster.h" |
| 45 #include "cc/resources/resource_pool.h" |
| 44 #include "cc/resources/scoped_resource.h" | 46 #include "cc/resources/scoped_resource.h" |
| 45 #include "gpu/GLES2/gl2extchromium.h" | 47 #include "gpu/GLES2/gl2extchromium.h" |
| 46 #include "gpu/command_buffer/client/context_support.h" | 48 #include "gpu/command_buffer/client/context_support.h" |
| 47 #include "gpu/command_buffer/client/gles2_interface.h" | 49 #include "gpu/command_buffer/client/gles2_interface.h" |
| 48 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 50 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 49 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 51 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
| 50 #include "skia/ext/texture_handle.h" | 52 #include "skia/ext/texture_handle.h" |
| 51 #include "third_party/skia/include/core/SkBitmap.h" | 53 #include "third_party/skia/include/core/SkBitmap.h" |
| 52 #include "third_party/skia/include/core/SkColor.h" | 54 #include "third_party/skia/include/core/SkColor.h" |
| 53 #include "third_party/skia/include/core/SkColorFilter.h" | 55 #include "third_party/skia/include/core/SkColorFilter.h" |
| (...skipping 3578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3632 // restoring. | 3634 // restoring. |
| 3633 SetViewport(); | 3635 SetViewport(); |
| 3634 } | 3636 } |
| 3635 | 3637 |
| 3636 bool GLRenderer::IsContextLost() { | 3638 bool GLRenderer::IsContextLost() { |
| 3637 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR; | 3639 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR; |
| 3638 } | 3640 } |
| 3639 | 3641 |
| 3640 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) { | 3642 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) { |
| 3641 scoped_refptr<CALayerOverlaySharedState> shared_state; | 3643 scoped_refptr<CALayerOverlaySharedState> shared_state; |
| 3644 size_t copied_render_pass_count = 0; |
| 3642 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) { | 3645 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) { |
| 3646 if (!overlay_resource_pool_) { |
| 3647 overlay_resource_pool_ = ResourcePool::CreateForGpuMemoryBufferResources( |
| 3648 resource_provider_, base::ThreadTaskRunnerHandle::Get().get()); |
| 3649 } |
| 3650 |
| 3651 ResourceId contents_resource_id = ca_layer_overlay.contents_resource_id; |
| 3652 Resource* resource = nullptr; |
| 3653 // Some CALayers require a final round of processing. |
| 3654 if (ca_layer_overlay.render_pass_id.IsValid()) { |
| 3655 CopyRenderPassToOverlayResource(ca_layer_overlay.render_pass_id, |
| 3656 &resource); |
| 3657 contents_resource_id = resource->id(); |
| 3658 ++copied_render_pass_count; |
| 3659 } |
| 3660 |
| 3643 unsigned texture_id = 0; | 3661 unsigned texture_id = 0; |
| 3644 if (ca_layer_overlay.contents_resource_id) { | 3662 if (contents_resource_id) { |
| 3645 pending_overlay_resources_.push_back( | 3663 pending_overlay_resources_.push_back( |
| 3646 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( | 3664 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( |
| 3647 resource_provider_, ca_layer_overlay.contents_resource_id))); | 3665 resource_provider_, contents_resource_id))); |
| 3648 texture_id = pending_overlay_resources_.back()->texture_id(); | 3666 texture_id = pending_overlay_resources_.back()->texture_id(); |
| 3667 |
| 3668 if (resource) { |
| 3669 // Once a resource is released, it is marked as "busy". It will be |
| 3670 // available for reuse after the ScopedReadLockGL is destroyed. |
| 3671 overlay_resource_pool_->ReleaseResource(resource); |
| 3672 } |
| 3649 } | 3673 } |
| 3650 GLfloat contents_rect[4] = { | 3674 GLfloat contents_rect[4] = { |
| 3651 ca_layer_overlay.contents_rect.x(), ca_layer_overlay.contents_rect.y(), | 3675 ca_layer_overlay.contents_rect.x(), ca_layer_overlay.contents_rect.y(), |
| 3652 ca_layer_overlay.contents_rect.width(), | 3676 ca_layer_overlay.contents_rect.width(), |
| 3653 ca_layer_overlay.contents_rect.height(), | 3677 ca_layer_overlay.contents_rect.height(), |
| 3654 }; | 3678 }; |
| 3655 GLfloat bounds_rect[4] = { | 3679 GLfloat bounds_rect[4] = { |
| 3656 ca_layer_overlay.bounds_rect.x(), ca_layer_overlay.bounds_rect.y(), | 3680 ca_layer_overlay.bounds_rect.x(), ca_layer_overlay.bounds_rect.y(), |
| 3657 ca_layer_overlay.bounds_rect.width(), | 3681 ca_layer_overlay.bounds_rect.width(), |
| 3658 ca_layer_overlay.bounds_rect.height(), | 3682 ca_layer_overlay.bounds_rect.height(), |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3691 effect.drop_shadow_color = | 3715 effect.drop_shadow_color = |
| 3692 static_cast<GLuint>(filter_effect.drop_shadow_color); | 3716 static_cast<GLuint>(filter_effect.drop_shadow_color); |
| 3693 } | 3717 } |
| 3694 | 3718 |
| 3695 gl_->ScheduleCALayerFilterEffectsCHROMIUM(effects.size(), effects.data()); | 3719 gl_->ScheduleCALayerFilterEffectsCHROMIUM(effects.size(), effects.data()); |
| 3696 } | 3720 } |
| 3697 gl_->ScheduleCALayerCHROMIUM( | 3721 gl_->ScheduleCALayerCHROMIUM( |
| 3698 texture_id, contents_rect, ca_layer_overlay.background_color, | 3722 texture_id, contents_rect, ca_layer_overlay.background_color, |
| 3699 ca_layer_overlay.edge_aa_mask, bounds_rect, filter); | 3723 ca_layer_overlay.edge_aa_mask, bounds_rect, filter); |
| 3700 } | 3724 } |
| 3725 |
| 3726 // Take the number of copied render passes in this frame, and use 3 times that |
| 3727 // amount as the cache limit. |
| 3728 if (overlay_resource_pool_) { |
| 3729 overlay_resource_pool_->SetResourceUsageLimits( |
| 3730 std::numeric_limits<std::size_t>::max(), copied_render_pass_count * 3); |
| 3731 } |
| 3701 } | 3732 } |
| 3702 | 3733 |
| 3703 void GLRenderer::ScheduleOverlays(DrawingFrame* frame) { | 3734 void GLRenderer::ScheduleOverlays(DrawingFrame* frame) { |
| 3704 if (frame->overlay_list.empty()) | 3735 if (frame->overlay_list.empty()) |
| 3705 return; | 3736 return; |
| 3706 | 3737 |
| 3707 OverlayCandidateList& overlays = frame->overlay_list; | 3738 OverlayCandidateList& overlays = frame->overlay_list; |
| 3708 for (const OverlayCandidate& overlay : overlays) { | 3739 for (const OverlayCandidate& overlay : overlays) { |
| 3709 unsigned texture_id = 0; | 3740 unsigned texture_id = 0; |
| 3710 if (overlay.use_output_surface_for_resource) { | 3741 if (overlay.use_output_surface_for_resource) { |
| 3711 texture_id = output_surface_->GetOverlayTextureId(); | 3742 texture_id = output_surface_->GetOverlayTextureId(); |
| 3712 DCHECK(texture_id || IsContextLost()); | 3743 DCHECK(texture_id || IsContextLost()); |
| 3713 } else { | 3744 } else { |
| 3714 pending_overlay_resources_.push_back( | 3745 pending_overlay_resources_.push_back( |
| 3715 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( | 3746 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( |
| 3716 resource_provider_, overlay.resource_id))); | 3747 resource_provider_, overlay.resource_id))); |
| 3717 texture_id = pending_overlay_resources_.back()->texture_id(); | 3748 texture_id = pending_overlay_resources_.back()->texture_id(); |
| 3718 } | 3749 } |
| 3719 | 3750 |
| 3720 context_support_->ScheduleOverlayPlane( | 3751 context_support_->ScheduleOverlayPlane( |
| 3721 overlay.plane_z_order, overlay.transform, texture_id, | 3752 overlay.plane_z_order, overlay.transform, texture_id, |
| 3722 ToNearestRect(overlay.display_rect), overlay.uv_rect); | 3753 ToNearestRect(overlay.display_rect), overlay.uv_rect); |
| 3723 } | 3754 } |
| 3724 } | 3755 } |
| 3725 | 3756 |
| 3757 void GLRenderer::CopyRenderPassToOverlayResource( |
| 3758 const RenderPassId& render_pass_id, |
| 3759 Resource** resource) { |
| 3760 ScopedResource* contents_texture = |
| 3761 render_pass_textures_[render_pass_id].get(); |
| 3762 DCHECK(contents_texture); |
| 3763 DCHECK(contents_texture->id()); |
| 3764 // TODO(erikchen): Fix this to allow the creation of IOSurfaces. |
| 3765 // https://crbug.com/581526. |
| 3766 *resource = overlay_resource_pool_->AcquireResource( |
| 3767 contents_texture->size(), ResourceFormat::RGBA_8888); |
| 3768 ResourceProvider::ScopedWriteLockGL destination(resource_provider_, |
| 3769 (*resource)->id(), false); |
| 3770 |
| 3771 GLuint source_texture = 0; |
| 3772 std::unique_ptr<ResourceProvider::ScopedReadLockGL> source; |
| 3773 if (current_framebuffer_lock_ && |
| 3774 current_framebuffer_lock_->texture_id() == contents_texture->id()) { |
| 3775 source_texture = current_framebuffer_lock_->texture_id(); |
| 3776 } else { |
| 3777 source.reset(new ResourceProvider::ScopedReadLockGL( |
| 3778 resource_provider_, contents_texture->id())); |
| 3779 source_texture = source->texture_id(); |
| 3780 } |
| 3781 gl_->CopySubTextureCHROMIUM(source_texture, destination.texture_id(), 0, 0, 0, |
| 3782 0, contents_texture->size().width(), |
| 3783 contents_texture->size().height(), GL_TRUE, |
| 3784 GL_FALSE, GL_FALSE); |
| 3785 } |
| 3786 |
| 3726 } // namespace cc | 3787 } // namespace cc |
| OLD | NEW |