Chromium Code Reviews| 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 23 matching lines...) Expand all Loading... | |
| 34 #include "cc/output/output_surface.h" | 34 #include "cc/output/output_surface.h" |
| 35 #include "cc/output/render_surface_filters.h" | 35 #include "cc/output/render_surface_filters.h" |
| 36 #include "cc/output/static_geometry_binding.h" | 36 #include "cc/output/static_geometry_binding.h" |
| 37 #include "cc/output/texture_mailbox_deleter.h" | 37 #include "cc/output/texture_mailbox_deleter.h" |
| 38 #include "cc/quads/draw_polygon.h" | 38 #include "cc/quads/draw_polygon.h" |
| 39 #include "cc/quads/picture_draw_quad.h" | 39 #include "cc/quads/picture_draw_quad.h" |
| 40 #include "cc/quads/render_pass.h" | 40 #include "cc/quads/render_pass.h" |
| 41 #include "cc/quads/stream_video_draw_quad.h" | 41 #include "cc/quads/stream_video_draw_quad.h" |
| 42 #include "cc/quads/texture_draw_quad.h" | 42 #include "cc/quads/texture_draw_quad.h" |
| 43 #include "cc/raster/scoped_gpu_raster.h" | 43 #include "cc/raster/scoped_gpu_raster.h" |
| 44 #include "cc/resources/resource_pool.h" | |
| 44 #include "cc/resources/scoped_resource.h" | 45 #include "cc/resources/scoped_resource.h" |
| 45 #include "gpu/GLES2/gl2extchromium.h" | 46 #include "gpu/GLES2/gl2extchromium.h" |
| 46 #include "gpu/command_buffer/client/context_support.h" | 47 #include "gpu/command_buffer/client/context_support.h" |
| 47 #include "gpu/command_buffer/client/gles2_interface.h" | 48 #include "gpu/command_buffer/client/gles2_interface.h" |
| 48 #include "gpu/command_buffer/common/gpu_memory_allocation.h" | 49 #include "gpu/command_buffer/common/gpu_memory_allocation.h" |
| 49 #include "skia/ext/texture_handle.h" | 50 #include "skia/ext/texture_handle.h" |
| 50 #include "third_party/skia/include/core/SkBitmap.h" | 51 #include "third_party/skia/include/core/SkBitmap.h" |
| 51 #include "third_party/skia/include/core/SkColor.h" | 52 #include "third_party/skia/include/core/SkColor.h" |
| 52 #include "third_party/skia/include/core/SkColorFilter.h" | 53 #include "third_party/skia/include/core/SkColorFilter.h" |
| 53 #include "third_party/skia/include/core/SkImage.h" | 54 #include "third_party/skia/include/core/SkImage.h" |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 capabilities_.max_msaa_samples = 0; | 365 capabilities_.max_msaa_samples = 0; |
| 365 else | 366 else |
| 366 capabilities_.max_msaa_samples = context_caps.max_samples; | 367 capabilities_.max_msaa_samples = context_caps.max_samples; |
| 367 | 368 |
| 368 use_sync_query_ = context_caps.sync_query; | 369 use_sync_query_ = context_caps.sync_query; |
| 369 use_blend_equation_advanced_ = context_caps.blend_equation_advanced; | 370 use_blend_equation_advanced_ = context_caps.blend_equation_advanced; |
| 370 use_blend_equation_advanced_coherent_ = | 371 use_blend_equation_advanced_coherent_ = |
| 371 context_caps.blend_equation_advanced_coherent; | 372 context_caps.blend_equation_advanced_coherent; |
| 372 | 373 |
| 373 InitializeSharedObjects(); | 374 InitializeSharedObjects(); |
| 375 | |
| 376 // TODO(erikchen): Fix this to allow the creation of IOSurfaces. | |
| 377 // https://crbug.com/581526. | |
| 378 overlay_resource_pool_ = ResourcePool::CreateForGpuMemoryBufferResources( | |
| 379 resource_provider_, nullptr); | |
| 374 } | 380 } |
| 375 | 381 |
| 376 GLRenderer::~GLRenderer() { | 382 GLRenderer::~GLRenderer() { |
| 377 while (!pending_async_read_pixels_.empty()) { | 383 while (!pending_async_read_pixels_.empty()) { |
| 378 PendingAsyncReadPixels* pending_read = | 384 PendingAsyncReadPixels* pending_read = |
| 379 pending_async_read_pixels_.back().get(); | 385 pending_async_read_pixels_.back().get(); |
| 380 pending_read->finished_read_pixels_callback.Cancel(); | 386 pending_read->finished_read_pixels_callback.Cancel(); |
| 381 pending_async_read_pixels_.pop_back(); | 387 pending_async_read_pixels_.pop_back(); |
| 382 } | 388 } |
| 383 | 389 |
| (...skipping 2405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2789 gl_->ScheduleCALayerInUseQueryCHROMIUM(textures.size(), textures.data()); | 2795 gl_->ScheduleCALayerInUseQueryCHROMIUM(textures.size(), textures.data()); |
| 2790 } | 2796 } |
| 2791 } | 2797 } |
| 2792 } | 2798 } |
| 2793 | 2799 |
| 2794 void GLRenderer::DidReceiveTextureInUseResponses( | 2800 void GLRenderer::DidReceiveTextureInUseResponses( |
| 2795 const gpu::TextureInUseResponses& responses) { | 2801 const gpu::TextureInUseResponses& responses) { |
| 2796 DCHECK(settings_->release_overlay_resources_after_gpu_query); | 2802 DCHECK(settings_->release_overlay_resources_after_gpu_query); |
| 2797 for (const gpu::TextureInUseResponse& response : responses) { | 2803 for (const gpu::TextureInUseResponse& response : responses) { |
| 2798 if (!response.in_use) { | 2804 if (!response.in_use) { |
| 2799 swapped_and_acked_overlay_resources_.erase(response.texture); | 2805 OverlayResourceNoLongerInUse(response.texture); |
| 2800 } | 2806 } |
| 2801 } | 2807 } |
| 2802 } | 2808 } |
| 2803 | 2809 |
| 2804 void GLRenderer::EnforceMemoryPolicy() { | 2810 void GLRenderer::EnforceMemoryPolicy() { |
| 2805 if (!visible()) { | 2811 if (!visible()) { |
| 2806 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources"); | 2812 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources"); |
| 2807 ReleaseRenderPassTextures(); | 2813 ReleaseRenderPassTextures(); |
| 2808 DiscardBackbuffer(); | 2814 DiscardBackbuffer(); |
| 2809 output_surface_->context_provider()->DeleteCachedResources(); | 2815 output_surface_->context_provider()->DeleteCachedResources(); |
| (...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3624 // PrepareSurfaceForPass also clears the surface, which is not desired when | 3630 // PrepareSurfaceForPass also clears the surface, which is not desired when |
| 3625 // restoring. | 3631 // restoring. |
| 3626 SetViewport(); | 3632 SetViewport(); |
| 3627 } | 3633 } |
| 3628 | 3634 |
| 3629 bool GLRenderer::IsContextLost() { | 3635 bool GLRenderer::IsContextLost() { |
| 3630 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR; | 3636 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR; |
| 3631 } | 3637 } |
| 3632 | 3638 |
| 3633 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) { | 3639 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) { |
| 3640 size_t copied_render_pass_count = 0; | |
| 3634 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) { | 3641 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) { |
|
ccameron
2016/07/21 05:31:16
Resource* overlay_resource = nullptr;
| |
| 3642 ResourceId contents_resource_id = ca_layer_overlay.contents_resource_id; | |
| 3643 // Some CALayers require a final round of processing. | |
| 3644 if (ca_layer_overlay.render_pass_id.IsValid()) { | |
| 3645 ResourceId resource_id; | |
| 3646 CopyRenderPassToOverlayResource(ca_layer_overlay.render_pass_id, | |
| 3647 &resource_id); | |
|
ccameron
2016/07/21 05:31:16
CopyRenderPassToOverlayResource now takes a Resour
| |
| 3648 contents_resource_id = resource_id; | |
| 3649 ++copied_render_pass_count; | |
| 3650 } | |
| 3651 | |
| 3635 unsigned texture_id = 0; | 3652 unsigned texture_id = 0; |
| 3636 if (ca_layer_overlay.contents_resource_id) { | 3653 if (contents_resource_id) { |
| 3637 pending_overlay_resources_.push_back( | 3654 pending_overlay_resources_.push_back( |
| 3638 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( | 3655 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( |
| 3639 resource_provider_, ca_layer_overlay.contents_resource_id))); | 3656 resource_provider_, contents_resource_id))); |
| 3640 texture_id = pending_overlay_resources_.back()->texture_id(); | 3657 texture_id = pending_overlay_resources_.back()->texture_id(); |
| 3641 } | 3658 } |
|
ccameron
2016/07/21 05:31:16
At this point it's safe to
if (overlay_resource)
| |
| 3642 GLfloat contents_rect[4] = { | 3659 GLfloat contents_rect[4] = { |
| 3643 ca_layer_overlay.contents_rect.x(), ca_layer_overlay.contents_rect.y(), | 3660 ca_layer_overlay.contents_rect.x(), ca_layer_overlay.contents_rect.y(), |
| 3644 ca_layer_overlay.contents_rect.width(), | 3661 ca_layer_overlay.contents_rect.width(), |
| 3645 ca_layer_overlay.contents_rect.height(), | 3662 ca_layer_overlay.contents_rect.height(), |
| 3646 }; | 3663 }; |
| 3647 GLfloat bounds_rect[4] = { | 3664 GLfloat bounds_rect[4] = { |
| 3648 ca_layer_overlay.bounds_rect.x(), ca_layer_overlay.bounds_rect.y(), | 3665 ca_layer_overlay.bounds_rect.x(), ca_layer_overlay.bounds_rect.y(), |
| 3649 ca_layer_overlay.bounds_rect.width(), | 3666 ca_layer_overlay.bounds_rect.width(), |
| 3650 ca_layer_overlay.bounds_rect.height(), | 3667 ca_layer_overlay.bounds_rect.height(), |
| 3651 }; | 3668 }; |
| 3652 GLboolean is_clipped = ca_layer_overlay.shared_state->is_clipped; | 3669 GLboolean is_clipped = ca_layer_overlay.shared_state->is_clipped; |
| 3653 GLfloat clip_rect[4] = {ca_layer_overlay.shared_state->clip_rect.x(), | 3670 GLfloat clip_rect[4] = {ca_layer_overlay.shared_state->clip_rect.x(), |
| 3654 ca_layer_overlay.shared_state->clip_rect.y(), | 3671 ca_layer_overlay.shared_state->clip_rect.y(), |
| 3655 ca_layer_overlay.shared_state->clip_rect.width(), | 3672 ca_layer_overlay.shared_state->clip_rect.width(), |
| 3656 ca_layer_overlay.shared_state->clip_rect.height()}; | 3673 ca_layer_overlay.shared_state->clip_rect.height()}; |
| 3657 GLint sorting_context_id = | 3674 GLint sorting_context_id = |
| 3658 ca_layer_overlay.shared_state->sorting_context_id; | 3675 ca_layer_overlay.shared_state->sorting_context_id; |
| 3659 GLfloat transform[16]; | 3676 GLfloat transform[16]; |
| 3660 ca_layer_overlay.shared_state->transform.asColMajorf(transform); | 3677 ca_layer_overlay.shared_state->transform.asColMajorf(transform); |
| 3661 unsigned filter = ca_layer_overlay.filter; | 3678 unsigned filter = ca_layer_overlay.filter; |
| 3662 gl_->ScheduleCALayerCHROMIUM( | 3679 gl_->ScheduleCALayerCHROMIUM( |
| 3663 texture_id, contents_rect, ca_layer_overlay.shared_state->opacity, | 3680 texture_id, contents_rect, ca_layer_overlay.shared_state->opacity, |
| 3664 ca_layer_overlay.background_color, ca_layer_overlay.edge_aa_mask, | 3681 ca_layer_overlay.background_color, ca_layer_overlay.edge_aa_mask, |
| 3665 bounds_rect, is_clipped, clip_rect, sorting_context_id, transform, | 3682 bounds_rect, is_clipped, clip_rect, sorting_context_id, transform, |
| 3666 filter); | 3683 filter); |
| 3667 } | 3684 } |
| 3685 | |
| 3686 // Take the number of copied render passes in this frame, and use 3 times that | |
| 3687 // amount as the cache limit. | |
| 3688 overlay_resource_pool_->SetResourceUsageLimits( | |
| 3689 std::numeric_limits<std::size_t>::max(), copied_render_pass_count * 3); | |
| 3668 } | 3690 } |
| 3669 | 3691 |
| 3670 void GLRenderer::ScheduleOverlays(DrawingFrame* frame) { | 3692 void GLRenderer::ScheduleOverlays(DrawingFrame* frame) { |
| 3671 if (frame->overlay_list.empty()) | 3693 if (frame->overlay_list.empty()) |
| 3672 return; | 3694 return; |
| 3673 | 3695 |
| 3674 OverlayCandidateList& overlays = frame->overlay_list; | 3696 OverlayCandidateList& overlays = frame->overlay_list; |
| 3675 for (const OverlayCandidate& overlay : overlays) { | 3697 for (const OverlayCandidate& overlay : overlays) { |
| 3676 unsigned texture_id = 0; | 3698 unsigned texture_id = 0; |
| 3677 if (overlay.use_output_surface_for_resource) { | 3699 if (overlay.use_output_surface_for_resource) { |
| 3678 texture_id = output_surface_->GetOverlayTextureId(); | 3700 texture_id = output_surface_->GetOverlayTextureId(); |
| 3679 DCHECK(texture_id || IsContextLost()); | 3701 DCHECK(texture_id || IsContextLost()); |
| 3680 } else { | 3702 } else { |
| 3681 pending_overlay_resources_.push_back( | 3703 pending_overlay_resources_.push_back( |
| 3682 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( | 3704 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( |
| 3683 resource_provider_, overlay.resource_id))); | 3705 resource_provider_, overlay.resource_id))); |
| 3684 texture_id = pending_overlay_resources_.back()->texture_id(); | 3706 texture_id = pending_overlay_resources_.back()->texture_id(); |
| 3685 } | 3707 } |
| 3686 | 3708 |
| 3687 context_support_->ScheduleOverlayPlane( | 3709 context_support_->ScheduleOverlayPlane( |
| 3688 overlay.plane_z_order, overlay.transform, texture_id, | 3710 overlay.plane_z_order, overlay.transform, texture_id, |
| 3689 ToNearestRect(overlay.display_rect), overlay.uv_rect); | 3711 ToNearestRect(overlay.display_rect), overlay.uv_rect); |
| 3690 } | 3712 } |
| 3691 } | 3713 } |
| 3692 | 3714 |
| 3715 void GLRenderer::OverlayResourceNoLongerInUse(GLuint texture) { | |
| 3716 auto it = swapped_and_acked_overlay_resources_.find(texture); | |
| 3717 if (it != swapped_and_acked_overlay_resources_.end()) { | |
| 3718 overlay_resource_pool_->ReleaseResourceIfFound(it->second->resource_id()); | |
| 3719 swapped_and_acked_overlay_resources_.erase(it); | |
|
ccameron
2016/07/20 22:13:53
(from gl_renderer.h) ...
We can just check for r
erikchen
2016/07/20 23:40:39
I don't think that's a great idea. We'd be maintai
ccameron
2016/07/21 05:31:16
This would now no longer need to do the release.
| |
| 3720 } | |
| 3721 } | |
| 3722 | |
| 3723 void GLRenderer::CopyRenderPassToOverlayResource( | |
| 3724 const RenderPassId& render_pass_id, | |
| 3725 ResourceId* resource_id) { | |
| 3726 ScopedResource* contents_texture = | |
| 3727 render_pass_textures_[render_pass_id].get(); | |
| 3728 DCHECK(contents_texture); | |
| 3729 DCHECK(contents_texture->id()); | |
| 3730 Resource* resource = overlay_resource_pool_->AcquireResource( | |
| 3731 contents_texture->size(), ResourceFormat::RGBA_8888); | |
| 3732 *resource_id = resource->id(); | |
| 3733 ResourceProvider::ScopedWriteLockGL destination(resource_provider_, | |
| 3734 *resource_id, false); | |
| 3735 | |
| 3736 GLuint source_texture = 0; | |
| 3737 std::unique_ptr<ResourceProvider::ScopedReadLockGL> source; | |
| 3738 if (current_framebuffer_lock_ && | |
| 3739 current_framebuffer_lock_->texture_id() == contents_texture->id()) { | |
| 3740 source_texture = current_framebuffer_lock_->texture_id(); | |
| 3741 } else { | |
| 3742 source.reset(new ResourceProvider::ScopedReadLockGL( | |
| 3743 resource_provider_, contents_texture->id())); | |
| 3744 source_texture = source->texture_id(); | |
| 3745 } | |
| 3746 gl_->CopySubTextureCHROMIUM(source_texture, destination.texture_id(), 0, 0, 0, | |
| 3747 0, contents_texture->size().width(), | |
| 3748 contents_texture->size().height(), GL_TRUE, | |
| 3749 GL_FALSE, GL_FALSE); | |
| 3750 } | |
| 3751 | |
| 3693 } // namespace cc | 3752 } // namespace cc |
| OLD | NEW |