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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 387 } | 387 } |
| 388 | 388 |
| 389 GLRenderer::~GLRenderer() { | 389 GLRenderer::~GLRenderer() { |
| 390 while (!pending_async_read_pixels_.empty()) { | 390 while (!pending_async_read_pixels_.empty()) { |
| 391 PendingAsyncReadPixels* pending_read = | 391 PendingAsyncReadPixels* pending_read = |
| 392 pending_async_read_pixels_.back().get(); | 392 pending_async_read_pixels_.back().get(); |
| 393 pending_read->finished_read_pixels_callback.Cancel(); | 393 pending_read->finished_read_pixels_callback.Cancel(); |
| 394 pending_async_read_pixels_.pop_back(); | 394 pending_async_read_pixels_.pop_back(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 swapped_overlay_resources_.clear(); | |
| 398 CleanupSharedObjects(); | 397 CleanupSharedObjects(); |
| 399 } | 398 } |
| 400 | 399 |
| 401 const RendererCapabilitiesImpl& GLRenderer::Capabilities() const { | 400 const RendererCapabilitiesImpl& GLRenderer::Capabilities() const { |
| 402 return capabilities_; | 401 return capabilities_; |
| 403 } | 402 } |
| 404 | 403 |
| 405 void GLRenderer::DidChangeVisibility() { | 404 void GLRenderer::DidChangeVisibility() { |
| 406 EnforceMemoryPolicy(); | 405 EnforceMemoryPolicy(); |
| 407 | 406 |
| (...skipping 2302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2710 : swap_buffer_rect_.y(), | 2709 : swap_buffer_rect_.y(), |
| 2711 swap_buffer_rect_.width(), swap_buffer_rect_.height()); | 2710 swap_buffer_rect_.width(), swap_buffer_rect_.height()); |
| 2712 } else { | 2711 } else { |
| 2713 // Expand the swap rect to the full surface unless it's empty, and empty | 2712 // Expand the swap rect to the full surface unless it's empty, and empty |
| 2714 // swap is allowed. | 2713 // swap is allowed. |
| 2715 if (!swap_buffer_rect_.IsEmpty() || !capabilities_.allow_empty_swap) { | 2714 if (!swap_buffer_rect_.IsEmpty() || !capabilities_.allow_empty_swap) { |
| 2716 swap_buffer_rect_ = gfx::Rect(surface_size); | 2715 swap_buffer_rect_ = gfx::Rect(surface_size); |
| 2717 } | 2716 } |
| 2718 compositor_frame.gl_frame_data->sub_buffer_rect = swap_buffer_rect_; | 2717 compositor_frame.gl_frame_data->sub_buffer_rect = swap_buffer_rect_; |
| 2719 } | 2718 } |
| 2719 | |
| 2720 swapping_overlay_resources_.push_back(std::move(pending_overlay_resources_)); | |
| 2721 pending_overlay_resources_.clear(); | |
| 2722 | |
| 2720 output_surface_->SwapBuffers(&compositor_frame); | 2723 output_surface_->SwapBuffers(&compositor_frame); |
| 2721 | 2724 |
| 2722 // We always hold onto resources until an extra frame has swapped, to make | |
| 2723 // sure we don't update the buffer while it's being scanned out. | |
| 2724 swapped_overlay_resources_.push_back(std::move(pending_overlay_resources_)); | |
| 2725 pending_overlay_resources_.clear(); | |
| 2726 if (!settings_->release_overlay_resources_on_swap_complete && | |
|
ccameron
2016/05/17 22:40:25
This "!settings_->release_overlay_resources_on_swa
erikchen
2016/05/17 23:22:33
I get it. You wanted me to reuse the *overlay_reso
| |
| 2727 swapped_overlay_resources_.size() > 2) { | |
| 2728 swapped_overlay_resources_.pop_front(); | |
| 2729 } | |
| 2730 swap_buffer_rect_ = gfx::Rect(); | 2725 swap_buffer_rect_ = gfx::Rect(); |
| 2731 } | 2726 } |
| 2732 | 2727 |
| 2733 void GLRenderer::SwapBuffersComplete() { | 2728 void GLRenderer::SwapBuffersComplete() { |
| 2734 if (settings_->release_overlay_resources_on_swap_complete && | 2729 if (swapping_overlay_resources_.empty()) { |
| 2735 !swapped_overlay_resources_.empty()) { | 2730 ReleaseOverlayResources(); |
|
ccameron
2016/05/17 22:40:25
This is easier to read without the early-out.
erikchen
2016/05/17 23:22:33
Done.
| |
| 2736 swapped_overlay_resources_.pop_front(); | 2731 return; |
| 2737 } | 2732 } |
| 2733 | |
| 2734 OverlayResourceLockList& list = swapping_overlay_resources_[0]; | |
| 2735 for (OverlayResourceLock& lock : list) { | |
| 2736 ResourceId resource_id = lock->GetResourceId(); | |
| 2737 | |
| 2738 // Theoretically, there should be a DCHECK here that asserts that the | |
| 2739 // resource is not already in swapped_and_acked_overlay_resources_. However, | |
| 2740 // there are compositor consumers that reuse resources without waiting for | |
| 2741 // them to be returned. | |
|
ccameron
2016/05/17 22:40:25
This comment isn't right -- the renderer is not al
erikchen
2016/05/17 23:22:33
got it.
| |
| 2742 swapped_and_acked_overlay_resources_[resource_id] = std::move(lock); | |
| 2743 } | |
| 2744 list.clear(); | |
| 2745 swapping_overlay_resources_.erase(swapping_overlay_resources_.begin()); | |
| 2746 ReleaseOverlayResources(); | |
|
ccameron
2016/05/17 22:40:25
I'd just move the ReleaseOverlayResources code her
erikchen
2016/05/17 23:22:33
Done.
| |
| 2738 } | 2747 } |
| 2739 | 2748 |
| 2740 void GLRenderer::EnforceMemoryPolicy() { | 2749 void GLRenderer::EnforceMemoryPolicy() { |
| 2741 if (!visible()) { | 2750 if (!visible()) { |
| 2742 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources"); | 2751 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources"); |
| 2743 ReleaseRenderPassTextures(); | 2752 ReleaseRenderPassTextures(); |
| 2744 DiscardBackbuffer(); | 2753 DiscardBackbuffer(); |
| 2745 output_surface_->context_provider()->DeleteCachedResources(); | 2754 output_surface_->context_provider()->DeleteCachedResources(); |
| 2746 gl_->Flush(); | 2755 gl_->Flush(); |
| 2747 } | 2756 } |
| (...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3597 | 3606 |
| 3598 bool GLRenderer::IsContextLost() { | 3607 bool GLRenderer::IsContextLost() { |
| 3599 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR; | 3608 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR; |
| 3600 } | 3609 } |
| 3601 | 3610 |
| 3602 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) { | 3611 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) { |
| 3603 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) { | 3612 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) { |
| 3604 unsigned texture_id = 0; | 3613 unsigned texture_id = 0; |
| 3605 if (ca_layer_overlay.contents_resource_id) { | 3614 if (ca_layer_overlay.contents_resource_id) { |
| 3606 pending_overlay_resources_.push_back( | 3615 pending_overlay_resources_.push_back( |
| 3607 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( | 3616 base::WrapUnique(new ResourceProvider::ScopedReadLockGpuMemoryBuffer( |
| 3608 resource_provider_, ca_layer_overlay.contents_resource_id))); | 3617 resource_provider_, ca_layer_overlay.contents_resource_id))); |
| 3609 texture_id = pending_overlay_resources_.back()->texture_id(); | 3618 texture_id = pending_overlay_resources_.back()->GetTextureId(); |
| 3610 } | 3619 } |
| 3611 GLfloat contents_rect[4] = { | 3620 GLfloat contents_rect[4] = { |
| 3612 ca_layer_overlay.contents_rect.x(), ca_layer_overlay.contents_rect.y(), | 3621 ca_layer_overlay.contents_rect.x(), ca_layer_overlay.contents_rect.y(), |
| 3613 ca_layer_overlay.contents_rect.width(), | 3622 ca_layer_overlay.contents_rect.width(), |
| 3614 ca_layer_overlay.contents_rect.height(), | 3623 ca_layer_overlay.contents_rect.height(), |
| 3615 }; | 3624 }; |
| 3616 GLfloat bounds_rect[4] = { | 3625 GLfloat bounds_rect[4] = { |
| 3617 ca_layer_overlay.bounds_rect.x(), ca_layer_overlay.bounds_rect.y(), | 3626 ca_layer_overlay.bounds_rect.x(), ca_layer_overlay.bounds_rect.y(), |
| 3618 ca_layer_overlay.bounds_rect.width(), | 3627 ca_layer_overlay.bounds_rect.width(), |
| 3619 ca_layer_overlay.bounds_rect.height(), | 3628 ca_layer_overlay.bounds_rect.height(), |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 3640 return; | 3649 return; |
| 3641 | 3650 |
| 3642 OverlayCandidateList& overlays = frame->overlay_list; | 3651 OverlayCandidateList& overlays = frame->overlay_list; |
| 3643 for (const OverlayCandidate& overlay : overlays) { | 3652 for (const OverlayCandidate& overlay : overlays) { |
| 3644 unsigned texture_id = 0; | 3653 unsigned texture_id = 0; |
| 3645 if (overlay.use_output_surface_for_resource) { | 3654 if (overlay.use_output_surface_for_resource) { |
| 3646 texture_id = output_surface_->GetOverlayTextureId(); | 3655 texture_id = output_surface_->GetOverlayTextureId(); |
| 3647 DCHECK(texture_id || IsContextLost()); | 3656 DCHECK(texture_id || IsContextLost()); |
| 3648 } else { | 3657 } else { |
| 3649 pending_overlay_resources_.push_back( | 3658 pending_overlay_resources_.push_back( |
| 3650 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( | 3659 base::WrapUnique(new ResourceProvider::ScopedReadLockGpuMemoryBuffer( |
| 3651 resource_provider_, overlay.resource_id))); | 3660 resource_provider_, overlay.resource_id))); |
| 3652 texture_id = pending_overlay_resources_.back()->texture_id(); | 3661 texture_id = pending_overlay_resources_.back()->GetTextureId(); |
| 3653 } | 3662 } |
| 3654 | 3663 |
| 3655 context_support_->ScheduleOverlayPlane( | 3664 context_support_->ScheduleOverlayPlane( |
| 3656 overlay.plane_z_order, overlay.transform, texture_id, | 3665 overlay.plane_z_order, overlay.transform, texture_id, |
| 3657 ToNearestRect(overlay.display_rect), overlay.uv_rect); | 3666 ToNearestRect(overlay.display_rect), overlay.uv_rect); |
| 3658 } | 3667 } |
| 3659 } | 3668 } |
| 3660 | 3669 |
| 3670 void GLRenderer::ReleaseOverlayResources() { | |
| 3671 auto it = swapped_and_acked_overlay_resources_.begin(); | |
| 3672 while (it != swapped_and_acked_overlay_resources_.end()) { | |
| 3673 if (it->second->GetGpuMemoryBuffer() && | |
| 3674 it->second->GetGpuMemoryBuffer()->IsInUseByMacOSWindowServer()) { | |
| 3675 ++it; | |
| 3676 continue; | |
| 3677 } | |
| 3678 | |
| 3679 it = swapped_and_acked_overlay_resources_.erase(it); | |
| 3680 } | |
| 3681 } | |
| 3682 | |
| 3661 } // namespace cc | 3683 } // namespace cc |
| OLD | NEW |