From e6e1fc29a59fcffde631d6acd2853e2c7a24cea7 Mon Sep 17 00:00:00 2001 From: "ccameron@chromium.org" Date: Fri, 25 Jan 2013 01:38:06 +0000 Subject: Elide unnecessary IPCs and MakeCurrents from GpuMemoryManager Sending a new memory policy is not free -- it will invoke a MakeCurrent if changing the surface allocation, and it will invoke an IPC to send the policy to the renderer. Don't do these if there is no change being sent. BUG= Review URL: https://chromiumcodereview.appspot.com/12038075 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@178723 0039d316-1c4b-4281-b951-d872f2087c98 --- content/common/gpu/gpu_command_buffer_stub.cc | 28 +++++++++++++++++++-------- content/common/gpu/gpu_command_buffer_stub.h | 4 ++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/content/common/gpu/gpu_command_buffer_stub.cc b/content/common/gpu/gpu_command_buffer_stub.cc index a0a79bc..a8bb1c5 100644 --- a/content/common/gpu/gpu_command_buffer_stub.cc +++ b/content/common/gpu/gpu_command_buffer_stub.cc @@ -119,6 +119,7 @@ GpuCommandBufferStub::GpuCommandBufferStub( surface_id_(surface_id), software_(software), last_flush_count_(0), + last_memory_allocation_valid_(false), parent_stub_for_initialization_(), parent_texture_for_initialization_(0), watchdog_(watchdog), @@ -865,14 +866,25 @@ gpu::gles2::MemoryTracker* GpuCommandBufferStub::GetMemoryTracker() const { void GpuCommandBufferStub::SetMemoryAllocation( const GpuMemoryAllocation& allocation) { - Send(new GpuCommandBufferMsg_SetMemoryAllocation( - route_id_, allocation.renderer_allocation)); - // This can be called outside of OnMessageReceived, so the context needs to be - // made current before calling methods on the surface. - if (!surface_ || !MakeCurrent()) - return; - surface_->SetFrontbufferAllocation( - allocation.browser_allocation.suggest_have_frontbuffer); + if (!last_memory_allocation_valid_ || + !allocation.renderer_allocation.Equals( + last_memory_allocation_.renderer_allocation)) { + Send(new GpuCommandBufferMsg_SetMemoryAllocation( + route_id_, allocation.renderer_allocation)); + } + + if (!last_memory_allocation_valid_ || + !allocation.browser_allocation.Equals( + last_memory_allocation_.browser_allocation)) { + // This can be called outside of OnMessageReceived, so the context needs + // to be made current before calling methods on the surface. + if (surface_ && MakeCurrent()) + surface_->SetFrontbufferAllocation( + allocation.browser_allocation.suggest_have_frontbuffer); + } + + last_memory_allocation_valid_ = true; + last_memory_allocation_ = allocation; } } // namespace content diff --git a/content/common/gpu/gpu_command_buffer_stub.h b/content/common/gpu/gpu_command_buffer_stub.h index c133ecc..eff5511c 100644 --- a/content/common/gpu/gpu_command_buffer_stub.h +++ b/content/common/gpu/gpu_command_buffer_stub.h @@ -220,6 +220,10 @@ class GpuCommandBufferStub scoped_refptr surface_; scoped_ptr memory_manager_client_state_; + // The last memory allocation received from the GpuMemoryManager (used to + // elide redundant work). + bool last_memory_allocation_valid_; + GpuMemoryAllocation last_memory_allocation_; // SetParent may be called before Initialize, in which case we need to keep // around the parent stub, so that Initialize can set the parent correctly. -- cgit v1.1