Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: cc/output/gl_renderer.cc

Issue 1984873002: Add logic to ResourceProvider to correctly lock GpuMemoryBuffer Resources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(); 397 swapped_overlay_resources_.clear();
398 ReleaseGpuMemoryBufferResources();
399
398 CleanupSharedObjects(); 400 CleanupSharedObjects();
399 } 401 }
400 402
401 const RendererCapabilitiesImpl& GLRenderer::Capabilities() const { 403 const RendererCapabilitiesImpl& GLRenderer::Capabilities() const {
402 return capabilities_; 404 return capabilities_;
403 } 405 }
404 406
405 void GLRenderer::DidChangeVisibility() { 407 void GLRenderer::DidChangeVisibility() {
406 EnforceMemoryPolicy(); 408 EnforceMemoryPolicy();
407 409
(...skipping 2312 matching lines...) Expand 10 before | Expand all | Expand 10 after
2720 output_surface_->SwapBuffers(&compositor_frame); 2722 output_surface_->SwapBuffers(&compositor_frame);
2721 2723
2722 // We always hold onto resources until an extra frame has swapped, to make 2724 // 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. 2725 // sure we don't update the buffer while it's being scanned out.
2724 swapped_overlay_resources_.push_back(std::move(pending_overlay_resources_)); 2726 swapped_overlay_resources_.push_back(std::move(pending_overlay_resources_));
2725 pending_overlay_resources_.clear(); 2727 pending_overlay_resources_.clear();
2726 if (!settings_->release_overlay_resources_on_swap_complete && 2728 if (!settings_->release_overlay_resources_on_swap_complete &&
2727 swapped_overlay_resources_.size() > 2) { 2729 swapped_overlay_resources_.size() > 2) {
2728 swapped_overlay_resources_.pop_front(); 2730 swapped_overlay_resources_.pop_front();
2729 } 2731 }
2732
2733 // Make the assumption that by the time a second SwapBuffers has come in, the
2734 // resources in |pending_gmb_resources_| have been received, processed, (and
2735 // possibly displayed) by the Window Server.
2736 if (!pending_gmb_resources_.empty()) {
2737 in_use_gmb_resources_.push_back(std::move(pending_gmb_resources_));
2738 pending_gmb_resources_.clear();
2739 }
2740 ReleaseGpuMemoryBufferResources();
2741
2730 swap_buffer_rect_ = gfx::Rect(); 2742 swap_buffer_rect_ = gfx::Rect();
2731 } 2743 }
2732 2744
2733 void GLRenderer::SwapBuffersComplete() { 2745 void GLRenderer::SwapBuffersComplete() {
2734 if (settings_->release_overlay_resources_on_swap_complete && 2746 if (settings_->release_overlay_resources_on_swap_complete &&
2735 !swapped_overlay_resources_.empty()) { 2747 !swapped_overlay_resources_.empty()) {
2736 swapped_overlay_resources_.pop_front(); 2748 swapped_overlay_resources_.pop_front();
2737 } 2749 }
2738 } 2750 }
2739 2751
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
3596 } 3608 }
3597 3609
3598 bool GLRenderer::IsContextLost() { 3610 bool GLRenderer::IsContextLost() {
3599 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR; 3611 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR;
3600 } 3612 }
3601 3613
3602 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) { 3614 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) {
3603 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) { 3615 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) {
3604 unsigned texture_id = 0; 3616 unsigned texture_id = 0;
3605 if (ca_layer_overlay.contents_resource_id) { 3617 if (ca_layer_overlay.contents_resource_id) {
3606 pending_overlay_resources_.push_back( 3618 pending_gmb_resources_.push_back(
3607 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( 3619 base::WrapUnique(new ResourceProvider::ScopedReadLockGpuMemoryBuffer(
3608 resource_provider_, ca_layer_overlay.contents_resource_id))); 3620 resource_provider_, ca_layer_overlay.contents_resource_id)));
3609 texture_id = pending_overlay_resources_.back()->texture_id(); 3621 texture_id = pending_gmb_resources_.back()->texture_id();
3610 } 3622 }
3611 GLfloat contents_rect[4] = { 3623 GLfloat contents_rect[4] = {
3612 ca_layer_overlay.contents_rect.x(), ca_layer_overlay.contents_rect.y(), 3624 ca_layer_overlay.contents_rect.x(), ca_layer_overlay.contents_rect.y(),
3613 ca_layer_overlay.contents_rect.width(), 3625 ca_layer_overlay.contents_rect.width(),
3614 ca_layer_overlay.contents_rect.height(), 3626 ca_layer_overlay.contents_rect.height(),
3615 }; 3627 };
3616 GLfloat bounds_rect[4] = { 3628 GLfloat bounds_rect[4] = {
3617 ca_layer_overlay.bounds_rect.x(), ca_layer_overlay.bounds_rect.y(), 3629 ca_layer_overlay.bounds_rect.x(), ca_layer_overlay.bounds_rect.y(),
3618 ca_layer_overlay.bounds_rect.width(), 3630 ca_layer_overlay.bounds_rect.width(),
3619 ca_layer_overlay.bounds_rect.height(), 3631 ca_layer_overlay.bounds_rect.height(),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
3651 resource_provider_, overlay.resource_id))); 3663 resource_provider_, overlay.resource_id)));
3652 texture_id = pending_overlay_resources_.back()->texture_id(); 3664 texture_id = pending_overlay_resources_.back()->texture_id();
3653 } 3665 }
3654 3666
3655 context_support_->ScheduleOverlayPlane( 3667 context_support_->ScheduleOverlayPlane(
3656 overlay.plane_z_order, overlay.transform, texture_id, 3668 overlay.plane_z_order, overlay.transform, texture_id,
3657 ToNearestRect(overlay.display_rect), overlay.uv_rect); 3669 ToNearestRect(overlay.display_rect), overlay.uv_rect);
3658 } 3670 }
3659 } 3671 }
3660 3672
3673 void GLRenderer::ReleaseGpuMemoryBufferResources() {
3674 // Remove resources that are no longer in use by the Window Server.
3675 for (auto& resources_vector : in_use_gmb_resources_) {
3676 resources_vector.erase(
3677 std::remove_if(
3678 resources_vector.begin(), resources_vector.end(),
3679 [](std::unique_ptr<ResourceProvider::ScopedReadLockGpuMemoryBuffer>&
3680 lock) { return !lock->IsInUseByMacOSWindowServer(); }),
3681 resources_vector.end());
3682 }
3683
3684 // Remove vectors that are empty.
3685 in_use_gmb_resources_.erase(
3686 std::remove_if(in_use_gmb_resources_.begin(), in_use_gmb_resources_.end(),
3687 [](GmbResourceLockList& list) { return list.empty(); }),
3688 in_use_gmb_resources_.end());
3689 }
3690
3661 } // namespace cc 3691 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698