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

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

Issue 2162193002: Add logic to GLRenderer to support RenderPassDrawQuad copying. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up. Created 4 years, 5 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 2778 matching lines...) Expand 10 before | Expand all | Expand 10 after
2789 gl_->ScheduleCALayerInUseQueryCHROMIUM(textures.size(), textures.data()); 2789 gl_->ScheduleCALayerInUseQueryCHROMIUM(textures.size(), textures.data());
2790 } 2790 }
2791 } 2791 }
2792 } 2792 }
2793 2793
2794 void GLRenderer::DidReceiveTextureInUseResponses( 2794 void GLRenderer::DidReceiveTextureInUseResponses(
2795 const gpu::TextureInUseResponses& responses) { 2795 const gpu::TextureInUseResponses& responses) {
2796 DCHECK(settings_->release_overlay_resources_after_gpu_query); 2796 DCHECK(settings_->release_overlay_resources_after_gpu_query);
2797 for (const gpu::TextureInUseResponse& response : responses) { 2797 for (const gpu::TextureInUseResponse& response : responses) {
2798 if (!response.in_use) { 2798 if (!response.in_use) {
2799 swapped_and_acked_overlay_resources_.erase(response.texture); 2799 OverlayResourceNoLongerInUse(response.texture);
2800 } 2800 }
2801 } 2801 }
2802 } 2802 }
2803 2803
2804 void GLRenderer::EnforceMemoryPolicy() { 2804 void GLRenderer::EnforceMemoryPolicy() {
2805 if (!visible()) { 2805 if (!visible()) {
2806 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources"); 2806 TRACE_EVENT0("cc", "GLRenderer::EnforceMemoryPolicy dropping resources");
2807 ReleaseRenderPassTextures(); 2807 ReleaseRenderPassTextures();
2808 DiscardBackbuffer(); 2808 DiscardBackbuffer();
2809 output_surface_->context_provider()->DeleteCachedResources(); 2809 output_surface_->context_provider()->DeleteCachedResources();
(...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after
3683 resource_provider_, overlay.resource_id))); 3683 resource_provider_, overlay.resource_id)));
3684 texture_id = pending_overlay_resources_.back()->texture_id(); 3684 texture_id = pending_overlay_resources_.back()->texture_id();
3685 } 3685 }
3686 3686
3687 context_support_->ScheduleOverlayPlane( 3687 context_support_->ScheduleOverlayPlane(
3688 overlay.plane_z_order, overlay.transform, texture_id, 3688 overlay.plane_z_order, overlay.transform, texture_id,
3689 ToNearestRect(overlay.display_rect), overlay.uv_rect); 3689 ToNearestRect(overlay.display_rect), overlay.uv_rect);
3690 } 3690 }
3691 } 3691 }
3692 3692
3693 void GLRenderer::OverlayResourceNoLongerInUse(GLuint texture) {
3694 auto it = swapped_and_acked_overlay_resources_.find(texture);
3695 std::vector<ResourceId> resource_ids;
3696 if (it != swapped_and_acked_overlay_resources_.end()) {
3697 resource_ids.push_back(it->second->resource_id());
3698 swapped_and_acked_overlay_resources_.erase(it);
3699 }
3700 ReleaseIOSurfaces(resource_ids);
3701 }
3702
3703 ResourceId GLRenderer::CreateOrReuseIOSurface(const gfx::Size& size) {
3704 DCHECK(settings_->release_overlay_resources_after_gpu_query);
3705 for (auto it = free_iosurfaces_.begin(); it != free_iosurfaces_.end(); ++it) {
3706 if ((*it)->size() == size) {
3707 ResourceId id = (*it)->id();
3708 in_use_iosurfaces_.emplace_back(std::move(*it));
3709 free_iosurfaces_.erase(it);
3710 return id;
3711 }
3712 }
3713
3714 // TODO(erikchen): Update ScopedResouce to support IOSurface creation. This
3715 // code doesn't actually make an IOSurface. https://crbug.com/581526.
3716 std::unique_ptr<ScopedResource> resource =
3717 ScopedResource::Create(resource_provider_);
3718 resource->AllocateWithGpuMemoryBuffer(size, ResourceFormat::RGBA_8888);
3719 ResourceId id = resource->id();
3720 in_use_iosurfaces_.emplace_back(std::move(resource));
3721 return id;
3722 }
3723
3724 void GLRenderer::DeleteIOSurfacesOverCacheLimit() {
3725 if (free_iosurfaces_.size() > iosurface_limit_) {
3726 size_t num_to_erase = free_iosurfaces_.size() - iosurface_limit_;
3727 free_iosurfaces_.erase(free_iosurfaces_.begin(),
3728 free_iosurfaces_.begin() + num_to_erase);
3729 }
3730 }
3731
3732 bool GLRenderer::CopyRenderPassDrawQuadToIOSurface(
3733 const RenderPassDrawQuad* quad,
3734 ResourceId* resource_id) {
3735 ScopedResource* contents_texture =
3736 render_pass_textures_[quad->render_pass_id].get();
3737 DCHECK(contents_texture);
3738 DCHECK(contents_texture->id());
3739 *resource_id = CreateOrReuseIOSurface(contents_texture->size());
3740 ResourceProvider::ScopedWriteLockGL destination(resource_provider_,
3741 *resource_id, false);
3742
3743 GLuint source_texture = 0;
3744 std::unique_ptr<ResourceProvider::ScopedReadLockGL> source;
3745 if (current_framebuffer_lock_ &&
3746 current_framebuffer_lock_->texture_id() == contents_texture->id()) {
3747 source_texture = current_framebuffer_lock_->texture_id();
3748 } else {
3749 source.reset(new ResourceProvider::ScopedReadLockGL(
3750 resource_provider_, contents_texture->id()));
3751 source_texture = source->texture_id();
3752 }
3753 gl_->CopySubTextureCHROMIUM(source_texture, destination.texture_id(), 0, 0, 0,
3754 0, contents_texture->size().width(),
3755 contents_texture->size().height(), GL_TRUE,
3756 GL_FALSE, GL_FALSE);
3757 return true;
3758 }
3759
3760 void GLRenderer::ReleaseIOSurfaces(const std::vector<ResourceId>& resources) {
3761 if (in_use_iosurfaces_.empty() || resources.empty())
3762 return;
3763
3764 // Move all IOSurfaces that match resources to the end of in_use_iosurfaces_.
3765 for (auto it = in_use_iosurfaces_.rbegin(); it != in_use_iosurfaces_.rend();
3766 ++it) {
3767 if (std::find(resources.begin(), resources.end(), (*it)->id()) !=
3768 resources.end()) {
3769 free_iosurfaces_.emplace_back(std::move(*it));
3770 in_use_iosurfaces_.erase(std::next(it).base());
3771 }
3772 }
3773
3774 DeleteIOSurfacesOverCacheLimit();
3775 }
3776
3777 void GLRenderer::UpdateCopyCountForFrame(size_t count) {
3778 // Keep two frames worth of cached IOSurfaces.
3779 iosurface_limit_ = count * 2;
3780 DeleteIOSurfacesOverCacheLimit();
3781 }
3782
3693 } // namespace cc 3783 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698