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

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

Issue 2015923003: Reland of 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
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/resources/resource_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 }
2720 output_surface_->SwapBuffers(&compositor_frame); 2719
2720 swapping_overlay_resources_.push_back(std::move(pending_overlay_resources_));
2721 pending_overlay_resources_.clear();
2721 2722
2722 // We always hold onto resources until an extra frame has swapped, to make 2723 // 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 // 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 && 2725 if (!settings_->release_overlay_resources_on_swap_complete &&
2727 swapped_overlay_resources_.size() > 2) { 2726 swapping_overlay_resources_.size() > 2) {
2728 swapped_overlay_resources_.pop_front(); 2727 swapping_overlay_resources_.pop_front();
2729 } 2728 }
2729
2730 output_surface_->SwapBuffers(&compositor_frame);
2731
2730 swap_buffer_rect_ = gfx::Rect(); 2732 swap_buffer_rect_ = gfx::Rect();
2731 } 2733 }
2732 2734
2733 void GLRenderer::SwapBuffersComplete() { 2735 void GLRenderer::SwapBuffersComplete() {
2734 if (settings_->release_overlay_resources_on_swap_complete && 2736 // On OS X, the logic in this block moves resources into
2735 !swapped_overlay_resources_.empty()) { 2737 // |swapped_and_acked_overlay_resources_|, and then erases resources from
2736 swapped_overlay_resources_.pop_front(); 2738 // |swapped_and_acked_overlay_resources_| that are no longer in use by the
2739 // Window Server. On other platforms, since resources are never in use by the
2740 // Window Server, this is equivalent to just erasing all resources from the
2741 // first element of |swapping_overlay_resources_|.
2742 if (settings_->release_overlay_resources_on_swap_complete) {
2743 // Move resources known to be acked into
2744 // |swapped_and_acked_overlay_resources_|.
2745 if (!swapping_overlay_resources_.empty()) {
2746 for (OverlayResourceLock& lock : swapping_overlay_resources_.front()) {
2747 swapped_and_acked_overlay_resources_[lock->GetResourceId()] =
2748 std::move(lock);
2749 }
2750 swapping_overlay_resources_.pop_front();
2751 }
2752
2753 // Release resources that are no longer in use by the Window Server.
2754 auto it = swapped_and_acked_overlay_resources_.begin();
2755 while (it != swapped_and_acked_overlay_resources_.end()) {
2756 if (it->second->GetGpuMemoryBuffer() &&
2757 it->second->GetGpuMemoryBuffer()->IsInUseByMacOSWindowServer()) {
2758 ++it;
2759 continue;
2760 }
2761
2762 it = swapped_and_acked_overlay_resources_.erase(it);
2763 }
2737 } 2764 }
2738 } 2765 }
2739 2766
2740 void GLRenderer::EnforceMemoryPolicy() { 2767 void GLRenderer::EnforceMemoryPolicy() {
2741 if (!visible()) { 2768 if (!visible()) {
2742 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources"); 2769 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources");
2743 ReleaseRenderPassTextures(); 2770 ReleaseRenderPassTextures();
2744 DiscardBackbuffer(); 2771 DiscardBackbuffer();
2745 output_surface_->context_provider()->DeleteCachedResources(); 2772 output_surface_->context_provider()->DeleteCachedResources();
2746 gl_->Flush(); 2773 gl_->Flush();
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
3597 3624
3598 bool GLRenderer::IsContextLost() { 3625 bool GLRenderer::IsContextLost() {
3599 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR; 3626 return gl_->GetGraphicsResetStatusKHR() != GL_NO_ERROR;
3600 } 3627 }
3601 3628
3602 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) { 3629 void GLRenderer::ScheduleCALayers(DrawingFrame* frame) {
3603 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) { 3630 for (const CALayerOverlay& ca_layer_overlay : frame->ca_layer_overlay_list) {
3604 unsigned texture_id = 0; 3631 unsigned texture_id = 0;
3605 if (ca_layer_overlay.contents_resource_id) { 3632 if (ca_layer_overlay.contents_resource_id) {
3606 pending_overlay_resources_.push_back( 3633 pending_overlay_resources_.push_back(
3607 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( 3634 base::WrapUnique(new ResourceProvider::ScopedReadLockGpuMemoryBuffer(
3608 resource_provider_, ca_layer_overlay.contents_resource_id))); 3635 resource_provider_, ca_layer_overlay.contents_resource_id)));
3609 texture_id = pending_overlay_resources_.back()->texture_id(); 3636 texture_id = pending_overlay_resources_.back()->GetTextureId();
3610 } 3637 }
3611 GLfloat contents_rect[4] = { 3638 GLfloat contents_rect[4] = {
3612 ca_layer_overlay.contents_rect.x(), ca_layer_overlay.contents_rect.y(), 3639 ca_layer_overlay.contents_rect.x(), ca_layer_overlay.contents_rect.y(),
3613 ca_layer_overlay.contents_rect.width(), 3640 ca_layer_overlay.contents_rect.width(),
3614 ca_layer_overlay.contents_rect.height(), 3641 ca_layer_overlay.contents_rect.height(),
3615 }; 3642 };
3616 GLfloat bounds_rect[4] = { 3643 GLfloat bounds_rect[4] = {
3617 ca_layer_overlay.bounds_rect.x(), ca_layer_overlay.bounds_rect.y(), 3644 ca_layer_overlay.bounds_rect.x(), ca_layer_overlay.bounds_rect.y(),
3618 ca_layer_overlay.bounds_rect.width(), 3645 ca_layer_overlay.bounds_rect.width(),
3619 ca_layer_overlay.bounds_rect.height(), 3646 ca_layer_overlay.bounds_rect.height(),
(...skipping 20 matching lines...) Expand all
3640 return; 3667 return;
3641 3668
3642 OverlayCandidateList& overlays = frame->overlay_list; 3669 OverlayCandidateList& overlays = frame->overlay_list;
3643 for (const OverlayCandidate& overlay : overlays) { 3670 for (const OverlayCandidate& overlay : overlays) {
3644 unsigned texture_id = 0; 3671 unsigned texture_id = 0;
3645 if (overlay.use_output_surface_for_resource) { 3672 if (overlay.use_output_surface_for_resource) {
3646 texture_id = output_surface_->GetOverlayTextureId(); 3673 texture_id = output_surface_->GetOverlayTextureId();
3647 DCHECK(texture_id || IsContextLost()); 3674 DCHECK(texture_id || IsContextLost());
3648 } else { 3675 } else {
3649 pending_overlay_resources_.push_back( 3676 pending_overlay_resources_.push_back(
3650 base::WrapUnique(new ResourceProvider::ScopedReadLockGL( 3677 base::WrapUnique(new ResourceProvider::ScopedReadLockGpuMemoryBuffer(
3651 resource_provider_, overlay.resource_id))); 3678 resource_provider_, overlay.resource_id)));
3652 texture_id = pending_overlay_resources_.back()->texture_id(); 3679 texture_id = pending_overlay_resources_.back()->GetTextureId();
3653 } 3680 }
3654 3681
3655 context_support_->ScheduleOverlayPlane( 3682 context_support_->ScheduleOverlayPlane(
3656 overlay.plane_z_order, overlay.transform, texture_id, 3683 overlay.plane_z_order, overlay.transform, texture_id,
3657 ToNearestRect(overlay.display_rect), overlay.uv_rect); 3684 ToNearestRect(overlay.display_rect), overlay.uv_rect);
3658 } 3685 }
3659 } 3686 }
3660 3687
3661 } // namespace cc 3688 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.h ('k') | cc/resources/resource_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698