Commit 9bfb1a58 authored by jbauman's avatar jbauman Committed by Commit bot

Enable partial texture upload support for browser compositor with Surfaces

This requires that previously-used textures be returned to the browser compositor before a commit, so they can be uploaded to. This saves memory by reducing the number of textures that need to be created.

Also avoid releasing old textures from renderers on SubmitFrame, as that can be unnecessarily expensive if both the old and new frames reference the same textures.

BUG=446588,446417,446414

Review URL: https://codereview.chromium.org/843633003

Cr-Commit-Position: refs/heads/master@{#310737}
parent b0a18bb4
...@@ -41,7 +41,8 @@ DelegatingRenderer::DelegatingRenderer(RendererClient* client, ...@@ -41,7 +41,8 @@ DelegatingRenderer::DelegatingRenderer(RendererClient* client,
capabilities_.using_partial_swap = false; capabilities_.using_partial_swap = false;
capabilities_.max_texture_size = resource_provider_->max_texture_size(); capabilities_.max_texture_size = resource_provider_->max_texture_size();
capabilities_.best_texture_format = resource_provider_->best_texture_format(); capabilities_.best_texture_format = resource_provider_->best_texture_format();
capabilities_.allow_partial_texture_updates = false; capabilities_.allow_partial_texture_updates =
output_surface->capabilities().can_force_reclaim_resources;
if (!output_surface_->context_provider()) { if (!output_surface_->context_provider()) {
capabilities_.using_shared_memory_resources = true; capabilities_.using_shared_memory_resources = true;
......
...@@ -64,7 +64,8 @@ class CC_EXPORT OutputSurface { ...@@ -64,7 +64,8 @@ class CC_EXPORT OutputSurface {
draw_and_swap_full_viewport_every_frame(false), draw_and_swap_full_viewport_every_frame(false),
adjust_deadline_for_parent(true), adjust_deadline_for_parent(true),
uses_default_gl_framebuffer(true), uses_default_gl_framebuffer(true),
flipped_output_surface(false) {} flipped_output_surface(false),
can_force_reclaim_resources(false) {}
bool delegated_rendering; bool delegated_rendering;
int max_frames_pending; int max_frames_pending;
bool deferred_gl_initialization; bool deferred_gl_initialization;
...@@ -77,6 +78,9 @@ class CC_EXPORT OutputSurface { ...@@ -77,6 +78,9 @@ class CC_EXPORT OutputSurface {
bool uses_default_gl_framebuffer; bool uses_default_gl_framebuffer;
// Whether this OutputSurface is flipped or not. // Whether this OutputSurface is flipped or not.
bool flipped_output_surface; bool flipped_output_surface;
// Whether ForceReclaimResources can be called to reclaim all resources
// from the OutputSurface.
bool can_force_reclaim_resources;
}; };
const Capabilities& capabilities() const { const Capabilities& capabilities() const {
...@@ -111,6 +115,10 @@ class CC_EXPORT OutputSurface { ...@@ -111,6 +115,10 @@ class CC_EXPORT OutputSurface {
virtual void Reshape(const gfx::Size& size, float scale_factor); virtual void Reshape(const gfx::Size& size, float scale_factor);
virtual gfx::Size SurfaceSize() const; virtual gfx::Size SurfaceSize() const;
// If supported, this causes a ReclaimResources for all resources that are
// currently in use.
virtual void ForceReclaimResources() {}
virtual void BindFramebuffer(); virtual void BindFramebuffer();
// The implementation may destroy or steal the contents of the CompositorFrame // The implementation may destroy or steal the contents of the CompositorFrame
......
...@@ -168,10 +168,16 @@ void Display::SetMemoryPolicy(const ManagedMemoryPolicy& policy) { ...@@ -168,10 +168,16 @@ void Display::SetMemoryPolicy(const ManagedMemoryPolicy& policy) {
client_->SetMemoryPolicy(policy); client_->SetMemoryPolicy(policy);
} }
void Display::OnSurfaceDamaged(SurfaceId surface) { void Display::OnSurfaceDamaged(SurfaceId surface_id) {
if (aggregator_ && if (aggregator_ &&
aggregator_->previous_contained_surfaces().count(surface)) { aggregator_->previous_contained_surfaces().count(surface_id)) {
aggregator_->ReleaseResources(surface); Surface* surface = manager_->GetSurfaceForId(surface_id);
if (surface) {
const CompositorFrame* current_frame = surface->GetEligibleFrame();
if (!current_frame || !current_frame->delegated_frame_data ||
!current_frame->delegated_frame_data->resource_list.size())
aggregator_->ReleaseResources(surface_id);
}
client_->DisplayDamaged(); client_->DisplayDamaged();
} }
} }
......
...@@ -293,6 +293,12 @@ void LayerTreeHostImpl::BeginMainFrameAborted(CommitEarlyOutReason reason) { ...@@ -293,6 +293,12 @@ void LayerTreeHostImpl::BeginMainFrameAborted(CommitEarlyOutReason reason) {
void LayerTreeHostImpl::BeginCommit() { void LayerTreeHostImpl::BeginCommit() {
TRACE_EVENT0("cc", "LayerTreeHostImpl::BeginCommit"); TRACE_EVENT0("cc", "LayerTreeHostImpl::BeginCommit");
// Ensure all textures are returned so partial texture updates can happen
// during the commit. Impl-side-painting doesn't upload during commits, so
// is unaffected.
if (!settings_.impl_side_painting)
output_surface_->ForceReclaimResources();
if (UsePendingTreeForSync()) if (UsePendingTreeForSync())
CreatePendingTree(); CreatePendingTree();
} }
......
...@@ -25,6 +25,7 @@ SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface( ...@@ -25,6 +25,7 @@ SurfaceDisplayOutputSurface::SurfaceDisplayOutputSurface(
allocator_(allocator) { allocator_(allocator) {
capabilities_.delegated_rendering = true; capabilities_.delegated_rendering = true;
capabilities_.max_frames_pending = 1; capabilities_.max_frames_pending = 1;
capabilities_.can_force_reclaim_resources = true;
} }
SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() { SurfaceDisplayOutputSurface::~SurfaceDisplayOutputSurface() {
...@@ -75,6 +76,15 @@ bool SurfaceDisplayOutputSurface::BindToClient( ...@@ -75,6 +76,15 @@ bool SurfaceDisplayOutputSurface::BindToClient(
return display_client_->Initialize(); return display_client_->Initialize();
} }
void SurfaceDisplayOutputSurface::ForceReclaimResources() {
if (!surface_id_.is_null()) {
scoped_ptr<cc::CompositorFrame> empty_frame(new cc::CompositorFrame());
empty_frame->delegated_frame_data.reset(new cc::DelegatedFrameData);
factory_.SubmitFrame(surface_id_, empty_frame.Pass(),
cc::SurfaceFactory::DrawCallback());
}
}
void SurfaceDisplayOutputSurface::ReturnResources( void SurfaceDisplayOutputSurface::ReturnResources(
const cc::ReturnedResourceArray& resources) { const cc::ReturnedResourceArray& resources) {
cc::CompositorFrameAck ack; cc::CompositorFrameAck ack;
......
...@@ -41,6 +41,7 @@ class SurfaceDisplayOutputSurface : public cc::OutputSurface, ...@@ -41,6 +41,7 @@ class SurfaceDisplayOutputSurface : public cc::OutputSurface,
// cc::OutputSurface implementation. // cc::OutputSurface implementation.
void SwapBuffers(cc::CompositorFrame* frame) override; void SwapBuffers(cc::CompositorFrame* frame) override;
bool BindToClient(cc::OutputSurfaceClient* client) override; bool BindToClient(cc::OutputSurfaceClient* client) override;
void ForceReclaimResources() override;
// cc::SurfaceFactoryClient implementation. // cc::SurfaceFactoryClient implementation.
void ReturnResources(const cc::ReturnedResourceArray& resources) override; void ReturnResources(const cc::ReturnedResourceArray& resources) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment