summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsohan.jyoti <sohan.jyoti@samsung.com>2015-10-05 01:23:34 -0700
committerCommit bot <commit-bot@chromium.org>2015-10-05 08:24:15 +0000
commit127a06b45820e30f78079814557cfacd038d6167 (patch)
tree2f273febca0134df221b475ba786a868d0483d42
parentc0a885a08ad8844e1c7852c4d98e24542bc2966b (diff)
downloadchromium_src-127a06b45820e30f78079814557cfacd038d6167.zip
chromium_src-127a06b45820e30f78079814557cfacd038d6167.tar.gz
chromium_src-127a06b45820e30f78079814557cfacd038d6167.tar.bz2
Move gpu memory calculations to Compositor.
This moves gpu memory policy code from gpumemorymanager to renderer compositor. It will be useful for renderer to use off screen context. BUG=526196 CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel Review URL: https://codereview.chromium.org/1324413003 Cr-Commit-Position: refs/heads/master@{#352301}
-rw-r--r--android_webview/browser/aw_render_thread_context_provider.cc5
-rw-r--r--android_webview/browser/aw_render_thread_context_provider.h3
-rw-r--r--blimp/client/compositor/blimp_context_provider.cc6
-rw-r--r--blimp/client/compositor/blimp_context_provider.h3
-rw-r--r--cc/output/context_provider.h7
-rw-r--r--cc/output/output_surface.cc4
-rw-r--r--cc/output/output_surface_unittest.cc31
-rw-r--r--cc/raster/tile_task_worker_pool_perftest.cc2
-rw-r--r--cc/test/test_context_provider.cc14
-rw-r--r--cc/test/test_context_provider.h5
-rw-r--r--cc/test/test_in_process_context_provider.cc3
-rw-r--r--cc/test/test_in_process_context_provider.h3
-rw-r--r--cc/tiles/tile_manager_unittest.cc16
-rw-r--r--cc/trees/layer_tree_host_impl.cc15
-rw-r--r--cc/trees/layer_tree_settings.cc5
-rw-r--r--cc/trees/layer_tree_settings.h2
-rw-r--r--components/mus/public/cpp/context_provider.h3
-rw-r--r--components/mus/surfaces/surfaces_context_provider.h3
-rw-r--r--content/browser/android/in_process/context_provider_in_process.cc5
-rw-r--r--content/browser/android/in_process/context_provider_in_process.h3
-rw-r--r--content/browser/android/in_process/synchronous_compositor_context_provider.cc5
-rw-r--r--content/browser/android/in_process/synchronous_compositor_context_provider.h4
-rw-r--r--content/common/gpu/client/command_buffer_proxy_impl.cc19
-rw-r--r--content/common/gpu/client/command_buffer_proxy_impl.h7
-rw-r--r--content/common/gpu/client/context_provider_command_buffer.cc30
-rw-r--r--content/common/gpu/client/context_provider_command_buffer.h5
-rw-r--r--content/common/gpu/gpu_command_buffer_stub.cc41
-rw-r--r--content/common/gpu/gpu_command_buffer_stub.h9
-rw-r--r--content/common/gpu/gpu_memory_manager.cc111
-rw-r--r--content/common/gpu/gpu_memory_manager.h6
-rw-r--r--content/common/gpu/gpu_memory_manager_client.h4
-rw-r--r--content/common/gpu/gpu_memory_manager_unittest.cc217
-rw-r--r--content/common/gpu/gpu_messages.h9
-rw-r--r--content/renderer/gpu/render_widget_compositor.cc84
-rw-r--r--content/renderer/gpu/render_widget_compositor.h3
-rw-r--r--ui/compositor/test/in_process_context_provider.cc5
-rw-r--r--ui/compositor/test/in_process_context_provider.h3
37 files changed, 113 insertions, 587 deletions
diff --git a/android_webview/browser/aw_render_thread_context_provider.cc b/android_webview/browser/aw_render_thread_context_provider.cc
index e928975..3ead8ec 100644
--- a/android_webview/browser/aw_render_thread_context_provider.cc
+++ b/android_webview/browser/aw_render_thread_context_provider.cc
@@ -181,11 +181,6 @@ void AwRenderThreadContextProvider::SetLostContextCallback(
lost_context_callback_ = lost_context_callback;
}
-void AwRenderThreadContextProvider::SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback) {
- // There's no memory manager for the in-process implementation.
-}
-
void AwRenderThreadContextProvider::OnLostContext() {
DCHECK(main_thread_checker_.CalledOnValidThread());
diff --git a/android_webview/browser/aw_render_thread_context_provider.h b/android_webview/browser/aw_render_thread_context_provider.h
index 24c1463..41a7a6c 100644
--- a/android_webview/browser/aw_render_thread_context_provider.h
+++ b/android_webview/browser/aw_render_thread_context_provider.h
@@ -49,9 +49,6 @@ class AwRenderThreadContextProvider : public cc::ContextProvider {
bool DestroyedOnMainThread() override;
void SetLostContextCallback(
const LostContextCallback& lost_context_callback) override;
- void SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback)
- override;
void OnLostContext();
diff --git a/blimp/client/compositor/blimp_context_provider.cc b/blimp/client/compositor/blimp_context_provider.cc
index 8d33884..213655e 100644
--- a/blimp/client/compositor/blimp_context_provider.cc
+++ b/blimp/client/compositor/blimp_context_provider.cc
@@ -163,12 +163,6 @@ void BlimpContextProvider::SetLostContextCallback(
lost_context_callback_ = lost_context_callback;
}
-void BlimpContextProvider::SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback) {
- // There's no memory manager for the in-process implementation.
- // TODO(dtrainor): Figure out if we need a memory manager for Blimp.
-}
-
void BlimpContextProvider::OnLostContext() {
DCHECK(context_thread_checker_.CalledOnValidThread());
diff --git a/blimp/client/compositor/blimp_context_provider.h b/blimp/client/compositor/blimp_context_provider.h
index 922ae4d..d54d984 100644
--- a/blimp/client/compositor/blimp_context_provider.h
+++ b/blimp/client/compositor/blimp_context_provider.h
@@ -37,9 +37,6 @@ class BlimpContextProvider : public cc::ContextProvider {
bool DestroyedOnMainThread() override;
void SetLostContextCallback(
const LostContextCallback& lost_context_callback) override;
- void SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback)
- override;
protected:
explicit BlimpContextProvider(gfx::AcceleratedWidget widget);
diff --git a/cc/output/context_provider.h b/cc/output/context_provider.h
index 47eff20..64fd233 100644
--- a/cc/output/context_provider.h
+++ b/cc/output/context_provider.h
@@ -104,13 +104,6 @@ class ContextProvider : public base::RefCountedThreadSafe<ContextProvider> {
virtual void SetLostContextCallback(
const LostContextCallback& lost_context_callback) = 0;
- // Sets a callback to be called when the memory policy changes. This should be
- // called from the same thread that the context is bound to.
- typedef base::Callback<void(const ManagedMemoryPolicy& policy)>
- MemoryPolicyChangedCallback;
- virtual void SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback) = 0;
-
protected:
friend class base::RefCountedThreadSafe<ContextProvider>;
virtual ~ContextProvider() {}
diff --git a/cc/output/output_surface.cc b/cc/output/output_surface.cc
index 38b1346..e7c4e93 100644
--- a/cc/output/output_surface.cc
+++ b/cc/output/output_surface.cc
@@ -216,8 +216,6 @@ bool OutputSurface::BindToClient(OutputSurfaceClient* client) {
if (success) {
context_provider_->SetLostContextCallback(base::Bind(
&OutputSurface::DidLoseOutputSurface, base::Unretained(this)));
- context_provider_->SetMemoryPolicyChangedCallback(
- base::Bind(&OutputSurface::SetMemoryPolicy, base::Unretained(this)));
}
}
@@ -365,8 +363,6 @@ void OutputSurface::DetachFromClientInternal() {
if (context_provider_.get()) {
context_provider_->SetLostContextCallback(
ContextProvider::LostContextCallback());
- context_provider_->SetMemoryPolicyChangedCallback(
- ContextProvider::MemoryPolicyChangedCallback());
}
context_provider_ = nullptr;
client_ = nullptr;
diff --git a/cc/output/output_surface_unittest.cc b/cc/output/output_surface_unittest.cc
index 6337332..b09ead4 100644
--- a/cc/output/output_surface_unittest.cc
+++ b/cc/output/output_surface_unittest.cc
@@ -152,37 +152,6 @@ TEST(OutputSurfaceTest, ClientPointerIndicatesWorkerBindToClientFailure) {
EXPECT_FALSE(output_surface.HasClient());
}
-TEST(OutputSurfaceTest, MemoryAllocation) {
- scoped_refptr<TestContextProvider> context_provider =
- TestContextProvider::Create();
-
- TestOutputSurface output_surface(context_provider);
-
- FakeOutputSurfaceClient client;
- EXPECT_TRUE(output_surface.BindToClient(&client));
-
- ManagedMemoryPolicy policy(0);
- policy.bytes_limit_when_visible = 1234;
- policy.priority_cutoff_when_visible =
- gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY;
-
- context_provider->SetMemoryAllocation(policy);
- EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible);
- EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_REQUIRED_ONLY,
- client.memory_policy().priority_cutoff_when_visible);
-
- policy.priority_cutoff_when_visible =
- gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING;
- context_provider->SetMemoryAllocation(policy);
- EXPECT_EQ(gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
- client.memory_policy().priority_cutoff_when_visible);
-
- // 0 bytes limit should be ignored.
- policy.bytes_limit_when_visible = 0;
- context_provider->SetMemoryAllocation(policy);
- EXPECT_EQ(1234u, client.memory_policy().bytes_limit_when_visible);
-}
-
TEST(OutputSurfaceTest, SoftwareOutputDeviceBackbufferManagement) {
TestSoftwareOutputDevice* software_output_device =
new TestSoftwareOutputDevice();
diff --git a/cc/raster/tile_task_worker_pool_perftest.cc b/cc/raster/tile_task_worker_pool_perftest.cc
index 2605064..7540897 100644
--- a/cc/raster/tile_task_worker_pool_perftest.cc
+++ b/cc/raster/tile_task_worker_pool_perftest.cc
@@ -100,8 +100,6 @@ class PerfContextProvider : public ContextProvider {
void DeleteCachedResources() override {}
bool DestroyedOnMainThread() override { return false; }
void SetLostContextCallback(const LostContextCallback& cb) override {}
- void SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& cb) override {}
private:
~PerfContextProvider() override {}
diff --git a/cc/test/test_context_provider.cc b/cc/test/test_context_provider.cc
index 5e43ee3..c943aad 100644
--- a/cc/test/test_context_provider.cc
+++ b/cc/test/test_context_provider.cc
@@ -185,13 +185,6 @@ TestWebGraphicsContext3D* TestContextProvider::UnboundTestContext3d() {
return context3d_.get();
}
-void TestContextProvider::SetMemoryAllocation(
- const ManagedMemoryPolicy& policy) {
- if (memory_policy_changed_callback_.is_null())
- return;
- memory_policy_changed_callback_.Run(policy);
-}
-
void TestContextProvider::SetLostContextCallback(
const LostContextCallback& cb) {
DCHECK(context_thread_checker_.CalledOnValidThread());
@@ -199,13 +192,6 @@ void TestContextProvider::SetLostContextCallback(
lost_context_callback_ = cb;
}
-void TestContextProvider::SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& cb) {
- DCHECK(context_thread_checker_.CalledOnValidThread());
- DCHECK(memory_policy_changed_callback_.is_null() || cb.is_null());
- memory_policy_changed_callback_ = cb;
-}
-
void TestContextProvider::SetMaxTransferBufferUsageBytes(
size_t max_transfer_buffer_usage_bytes) {
context3d_->SetMaxTransferBufferUsageBytes(max_transfer_buffer_usage_bytes);
diff --git a/cc/test/test_context_provider.h b/cc/test/test_context_provider.h
index 3ff9092..994587c 100644
--- a/cc/test/test_context_provider.h
+++ b/cc/test/test_context_provider.h
@@ -44,8 +44,6 @@ class TestContextProvider : public ContextProvider {
void DeleteCachedResources() override;
bool DestroyedOnMainThread() override;
void SetLostContextCallback(const LostContextCallback& cb) override;
- void SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& cb) override;
TestWebGraphicsContext3D* TestContext3d();
@@ -57,8 +55,6 @@ class TestContextProvider : public ContextProvider {
TestContextSupport* support() { return &support_; }
- void SetMemoryAllocation(const ManagedMemoryPolicy& policy);
-
void SetMaxTransferBufferUsageBytes(size_t max_transfer_buffer_usage_bytes);
protected:
@@ -83,7 +79,6 @@ class TestContextProvider : public ContextProvider {
base::Lock context_lock_;
LostContextCallback lost_context_callback_;
- MemoryPolicyChangedCallback memory_policy_changed_callback_;
skia::RefPtr<class GrContext> gr_context_;
base::WeakPtrFactory<TestContextProvider> weak_ptr_factory_;
diff --git a/cc/test/test_in_process_context_provider.cc b/cc/test/test_in_process_context_provider.cc
index 79d53d2..011a70e 100644
--- a/cc/test/test_in_process_context_provider.cc
+++ b/cc/test/test_in_process_context_provider.cc
@@ -168,7 +168,4 @@ bool TestInProcessContextProvider::DestroyedOnMainThread() { return false; }
void TestInProcessContextProvider::SetLostContextCallback(
const LostContextCallback& lost_context_callback) {}
-void TestInProcessContextProvider::SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback) {}
-
} // namespace cc
diff --git a/cc/test/test_in_process_context_provider.h b/cc/test/test_in_process_context_provider.h
index efea712..79e7cc4 100644
--- a/cc/test/test_in_process_context_provider.h
+++ b/cc/test/test_in_process_context_provider.h
@@ -41,9 +41,6 @@ class TestInProcessContextProvider : public ContextProvider {
bool DestroyedOnMainThread() override;
void SetLostContextCallback(
const LostContextCallback& lost_context_callback) override;
- void SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback)
- override;
protected:
friend class base::RefCountedThreadSafe<TestInProcessContextProvider>;
diff --git a/cc/tiles/tile_manager_unittest.cc b/cc/tiles/tile_manager_unittest.cc
index e68ea1f..0a0cb60 100644
--- a/cc/tiles/tile_manager_unittest.cc
+++ b/cc/tiles/tile_manager_unittest.cc
@@ -1363,6 +1363,22 @@ TEST_F(TileManagerTilePriorityQueueTest,
host_impl_.resource_pool()->ReleaseResource(resource, 0);
}
+TEST_F(TileManagerTilePriorityQueueTest, DefaultMemoryPolicy) {
+ const gfx::Size layer_bounds(1000, 1000);
+ host_impl_.SetViewportSize(layer_bounds);
+ SetupDefaultTrees(layer_bounds);
+
+ host_impl_.tile_manager()->PrepareTiles(host_impl_.global_tile_state());
+
+ // 64MB is the default mem limit.
+ EXPECT_EQ(67108864u,
+ host_impl_.global_tile_state().hard_memory_limit_in_bytes);
+ EXPECT_EQ(TileMemoryLimitPolicy::ALLOW_ANYTHING,
+ host_impl_.global_tile_state().memory_limit_policy);
+ EXPECT_EQ(ManagedMemoryPolicy::kDefaultNumResourcesLimit,
+ host_impl_.global_tile_state().num_resources_limit);
+}
+
TEST_F(TileManagerTilePriorityQueueTest, RasterQueueAllUsesCorrectTileBounds) {
// Verify that we use the real tile bounds when advancing phases during the
// tile iteration.
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
index ab75b9c..807ec03f 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -129,16 +129,6 @@ void DidVisibilityChange(LayerTreeHostImpl* id, bool visible) {
TRACE_EVENT_ASYNC_END0("cc", "LayerTreeHostImpl::SetVisible", id);
}
-size_t GetDefaultMemoryAllocationLimit() {
- // TODO(ccameron): (http://crbug.com/137094) This 64MB default is a straggler
- // from the old texture manager and is just to give us a default memory
- // allocation before we get a callback from the GPU memory manager. We
- // should probaby either:
- // - wait for the callback before rendering anything instead
- // - push this into the GPU memory manager somehow.
- return 64 * 1024 * 1024;
-}
-
} // namespace
LayerTreeHostImpl::FrameData::FrameData()
@@ -187,10 +177,7 @@ LayerTreeHostImpl::LayerTreeHostImpl(
tile_priorities_dirty_(false),
settings_(settings),
visible_(true),
- cached_managed_memory_policy_(
- GetDefaultMemoryAllocationLimit(),
- gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
- ManagedMemoryPolicy::kDefaultNumResourcesLimit),
+ cached_managed_memory_policy_(settings.memory_policy_),
is_synchronous_single_threaded_(!proxy->HasImplThread() &&
!settings.single_thread_proxy_scheduler),
// Must be initialized after is_synchronous_single_threaded_ and proxy_.
diff --git a/cc/trees/layer_tree_settings.cc b/cc/trees/layer_tree_settings.cc
index 414abb3..c079ef9 100644
--- a/cc/trees/layer_tree_settings.cc
+++ b/cc/trees/layer_tree_settings.cc
@@ -69,7 +69,10 @@ LayerTreeSettings::LayerTreeSettings()
image_decode_tasks_enabled(false),
use_compositor_animation_timelines(false),
wait_for_beginframe_interval(true),
- max_staging_buffer_usage_in_bytes(32 * 1024 * 1024) {}
+ max_staging_buffer_usage_in_bytes(32 * 1024 * 1024),
+ memory_policy_(64 * 1024 * 1024,
+ gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING,
+ ManagedMemoryPolicy::kDefaultNumResourcesLimit) {}
LayerTreeSettings::~LayerTreeSettings() {}
diff --git a/cc/trees/layer_tree_settings.h b/cc/trees/layer_tree_settings.h
index f6656d5..95a8c80 100644
--- a/cc/trees/layer_tree_settings.h
+++ b/cc/trees/layer_tree_settings.h
@@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "cc/base/cc_export.h"
#include "cc/debug/layer_tree_debug_state.h"
+#include "cc/output/managed_memory_policy.h"
#include "cc/output/renderer_settings.h"
#include "cc/scheduler/scheduler_settings.h"
#include "third_party/skia/include/core/SkColor.h"
@@ -84,6 +85,7 @@ class CC_EXPORT LayerTreeSettings {
bool use_compositor_animation_timelines;
bool wait_for_beginframe_interval;
int max_staging_buffer_usage_in_bytes;
+ ManagedMemoryPolicy memory_policy_;
LayerTreeDebugState initial_debug_state;
diff --git a/components/mus/public/cpp/context_provider.h b/components/mus/public/cpp/context_provider.h
index c07532e..abccb1b 100644
--- a/components/mus/public/cpp/context_provider.h
+++ b/components/mus/public/cpp/context_provider.h
@@ -32,9 +32,6 @@ class ContextProvider : public cc::ContextProvider {
bool DestroyedOnMainThread() override;
void SetLostContextCallback(
const LostContextCallback& lost_context_callback) override {}
- void SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback)
- override {}
protected:
friend class base::RefCountedThreadSafe<ContextProvider>;
diff --git a/components/mus/surfaces/surfaces_context_provider.h b/components/mus/surfaces/surfaces_context_provider.h
index 37cdfab..a3352d9 100644
--- a/components/mus/surfaces/surfaces_context_provider.h
+++ b/components/mus/surfaces/surfaces_context_provider.h
@@ -51,9 +51,6 @@ class SurfacesContextProvider : public cc::ContextProvider,
bool DestroyedOnMainThread() override;
void SetLostContextCallback(
const LostContextCallback& lost_context_callback) override;
- void SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback)
- override {}
void SetupLock() override;
base::Lock* GetLock() override;
diff --git a/content/browser/android/in_process/context_provider_in_process.cc b/content/browser/android/in_process/context_provider_in_process.cc
index 5fea00f..3299769 100644
--- a/content/browser/android/in_process/context_provider_in_process.cc
+++ b/content/browser/android/in_process/context_provider_in_process.cc
@@ -203,9 +203,4 @@ void ContextProviderInProcess::SetLostContextCallback(
lost_context_callback_ = lost_context_callback;
}
-void ContextProviderInProcess::SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback) {
- // There's no memory manager for the in-process implementation.
-}
-
} // namespace content
diff --git a/content/browser/android/in_process/context_provider_in_process.h b/content/browser/android/in_process/context_provider_in_process.h
index b2b2ba8..805fd9e 100644
--- a/content/browser/android/in_process/context_provider_in_process.h
+++ b/content/browser/android/in_process/context_provider_in_process.h
@@ -56,9 +56,6 @@ class ContextProviderInProcess
bool DestroyedOnMainThread() override;
void SetLostContextCallback(
const LostContextCallback& lost_context_callback) override;
- void SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback)
- override;
void OnLostContext();
void InitializeCapabilities();
diff --git a/content/browser/android/in_process/synchronous_compositor_context_provider.cc b/content/browser/android/in_process/synchronous_compositor_context_provider.cc
index ccdd993..59f5dd2 100644
--- a/content/browser/android/in_process/synchronous_compositor_context_provider.cc
+++ b/content/browser/android/in_process/synchronous_compositor_context_provider.cc
@@ -13,9 +13,4 @@ SynchronousCompositorContextProvider::SynchronousCompositorContextProvider(
SynchronousCompositorContextProvider::~SynchronousCompositorContextProvider() {}
-void SynchronousCompositorContextProvider::SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback) {
- // Intentional no-op.
-}
-
} // namespace content
diff --git a/content/browser/android/in_process/synchronous_compositor_context_provider.h b/content/browser/android/in_process/synchronous_compositor_context_provider.h
index 5a692a6..2251273 100644
--- a/content/browser/android/in_process/synchronous_compositor_context_provider.h
+++ b/content/browser/android/in_process/synchronous_compositor_context_provider.h
@@ -18,10 +18,6 @@ class SynchronousCompositorContextProvider
scoped_ptr<WebGraphicsContext3DCommandBufferImpl> context3d,
CommandBufferContextType type);
- void SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback)
- override;
-
private:
~SynchronousCompositorContextProvider() override;
};
diff --git a/content/common/gpu/client/command_buffer_proxy_impl.cc b/content/common/gpu/client/command_buffer_proxy_impl.cc
index 17ecca2..fc0cb83 100644
--- a/content/common/gpu/client/command_buffer_proxy_impl.cc
+++ b/content/common/gpu/client/command_buffer_proxy_impl.cc
@@ -68,8 +68,6 @@ bool CommandBufferProxyImpl::OnMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(CommandBufferProxyImpl, message)
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_Destroyed, OnDestroyed);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_ConsoleMsg, OnConsoleMessage);
- IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SetMemoryAllocation,
- OnSetMemoryAllocation);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalSyncPointAck,
OnSignalSyncPointAck);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SwapBuffersCompleted,
@@ -128,17 +126,6 @@ void CommandBufferProxyImpl::OnConsoleMessage(
}
}
-void CommandBufferProxyImpl::SetMemoryAllocationChangedCallback(
- const MemoryAllocationChangedCallback& callback) {
- CheckLock();
- if (last_state_.error != gpu::error::kNoError)
- return;
-
- memory_allocation_changed_callback_ = callback;
- Send(new GpuCommandBufferMsg_SetClientHasMemoryAllocationChangedCallback(
- route_id_, !memory_allocation_changed_callback_.is_null()));
-}
-
void CommandBufferProxyImpl::AddDeletionObserver(DeletionObserver* observer) {
CheckLock();
deletion_observers_.AddObserver(observer);
@@ -150,12 +137,6 @@ void CommandBufferProxyImpl::RemoveDeletionObserver(
deletion_observers_.RemoveObserver(observer);
}
-void CommandBufferProxyImpl::OnSetMemoryAllocation(
- const gpu::MemoryAllocation& allocation) {
- if (!memory_allocation_changed_callback_.is_null())
- memory_allocation_changed_callback_.Run(allocation);
-}
-
void CommandBufferProxyImpl::OnSignalSyncPointAck(uint32 id) {
SignalTaskMap::iterator it = signal_tasks_.find(id);
DCHECK(it != signal_tasks_.end());
diff --git a/content/common/gpu/client/command_buffer_proxy_impl.h b/content/common/gpu/client/command_buffer_proxy_impl.h
index 978d255..98f8ed7 100644
--- a/content/common/gpu/client/command_buffer_proxy_impl.h
+++ b/content/common/gpu/client/command_buffer_proxy_impl.h
@@ -127,10 +127,6 @@ class CommandBufferProxyImpl
bool ProduceFrontBuffer(const gpu::Mailbox& mailbox);
void SetContextLostCallback(const base::Closure& callback);
- typedef base::Callback<void(const gpu::MemoryAllocation&)>
- MemoryAllocationChangedCallback;
- void SetMemoryAllocationChangedCallback(
- const MemoryAllocationChangedCallback& callback);
void AddDeletionObserver(DeletionObserver* observer);
void RemoveDeletionObserver(DeletionObserver* observer);
@@ -186,7 +182,6 @@ class CommandBufferProxyImpl
void OnDestroyed(gpu::error::ContextLostReason reason,
gpu::error::Error error);
void OnConsoleMessage(const GPUCommandBufferConsoleMessage& message);
- void OnSetMemoryAllocation(const gpu::MemoryAllocation& allocation);
void OnSignalSyncPointAck(uint32 id);
void OnSwapBuffersCompleted(const std::vector<ui::LatencyInfo>& latency_info,
gfx::SwapResult result);
@@ -222,8 +217,6 @@ class CommandBufferProxyImpl
base::Closure context_lost_callback_;
- MemoryAllocationChangedCallback memory_allocation_changed_callback_;
-
GpuConsoleMessageCallback console_message_callback_;
// Tasks to be invoked in SignalSyncPoint responses.
diff --git a/content/common/gpu/client/context_provider_command_buffer.cc b/content/common/gpu/client/context_provider_command_buffer.cc
index f7b2c85..c215dba 100644
--- a/content/common/gpu/client/context_provider_command_buffer.cc
+++ b/content/common/gpu/client/context_provider_command_buffer.cc
@@ -63,11 +63,8 @@ ContextProviderCommandBuffer::~ContextProviderCommandBuffer() {
base::AutoLock lock(main_thread_lock_);
// Destroy references to the context3d_ before leaking it.
- if (context3d_->GetCommandBufferProxy()) {
+ if (context3d_->GetCommandBufferProxy())
context3d_->GetCommandBufferProxy()->SetLock(nullptr);
- context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback(
- CommandBufferProxyImpl::MemoryAllocationChangedCallback());
- }
lost_context_callback_proxy_.reset();
}
@@ -193,16 +190,6 @@ void ContextProviderCommandBuffer::OnLostContext() {
gr_context_->OnLostContext();
}
-void ContextProviderCommandBuffer::OnMemoryAllocationChanged(
- const gpu::MemoryAllocation& allocation) {
- DCHECK(context_thread_checker_.CalledOnValidThread());
-
- if (memory_policy_changed_callback_.is_null())
- return;
-
- memory_policy_changed_callback_.Run(cc::ManagedMemoryPolicy(allocation));
-}
-
void ContextProviderCommandBuffer::InitializeCapabilities() {
Capabilities caps;
caps.gpu = context3d_->GetImplementation()->capabilities();
@@ -230,19 +217,4 @@ void ContextProviderCommandBuffer::SetLostContextCallback(
lost_context_callback_ = lost_context_callback;
}
-void ContextProviderCommandBuffer::SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback) {
- DCHECK(context_thread_checker_.CalledOnValidThread());
- DCHECK(memory_policy_changed_callback_.is_null() ||
- memory_policy_changed_callback.is_null());
- memory_policy_changed_callback_ = memory_policy_changed_callback;
-
- if (!memory_policy_changed_callback_.is_null()) {
- DCHECK(context3d_->GetCommandBufferProxy());
- context3d_->GetCommandBufferProxy()->SetMemoryAllocationChangedCallback(
- base::Bind(&ContextProviderCommandBuffer::OnMemoryAllocationChanged,
- base::Unretained(this)));
- }
-}
-
} // namespace content
diff --git a/content/common/gpu/client/context_provider_command_buffer.h b/content/common/gpu/client/context_provider_command_buffer.h
index 1e0d23f..b2080b4 100644
--- a/content/common/gpu/client/context_provider_command_buffer.h
+++ b/content/common/gpu/client/context_provider_command_buffer.h
@@ -48,9 +48,6 @@ class CONTENT_EXPORT ContextProviderCommandBuffer
bool DestroyedOnMainThread() override;
void SetLostContextCallback(
const LostContextCallback& lost_context_callback) override;
- void SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback)
- override;
protected:
ContextProviderCommandBuffer(
@@ -59,7 +56,6 @@ class CONTENT_EXPORT ContextProviderCommandBuffer
~ContextProviderCommandBuffer() override;
void OnLostContext();
- void OnMemoryAllocationChanged(const gpu::MemoryAllocation& allocation);
private:
void InitializeCapabilities();
@@ -75,7 +71,6 @@ class CONTENT_EXPORT ContextProviderCommandBuffer
std::string debug_name_;
LostContextCallback lost_context_callback_;
- MemoryPolicyChangedCallback memory_policy_changed_callback_;
base::Lock main_thread_lock_;
bool destroyed_;
diff --git a/content/common/gpu/gpu_command_buffer_stub.cc b/content/common/gpu/gpu_command_buffer_stub.cc
index eb8e8ff..6f49445 100644
--- a/content/common/gpu/gpu_command_buffer_stub.cc
+++ b/content/common/gpu/gpu_command_buffer_stub.cc
@@ -205,7 +205,6 @@ GpuCommandBufferStub::GpuCommandBufferStub(
route_id_(route_id),
offscreen_(offscreen),
last_flush_count_(0),
- last_memory_allocation_valid_(false),
watchdog_(watchdog),
waiting_for_sync_point_(false),
previous_processed_num_(0),
@@ -278,9 +277,7 @@ bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) {
message.type() != GpuCommandBufferMsg_RegisterTransferBuffer::ID &&
message.type() != GpuCommandBufferMsg_DestroyTransferBuffer::ID &&
message.type() != GpuCommandBufferMsg_RetireSyncPoint::ID &&
- message.type() != GpuCommandBufferMsg_SignalSyncPoint::ID &&
- message.type() !=
- GpuCommandBufferMsg_SetClientHasMemoryAllocationChangedCallback::ID) {
+ message.type() != GpuCommandBufferMsg_SignalSyncPoint::ID) {
if (!MakeCurrent())
return false;
have_context = true;
@@ -317,9 +314,6 @@ bool GpuCommandBufferStub::OnMessageReceived(const IPC::Message& message) {
OnSignalSyncPoint)
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_SignalQuery,
OnSignalQuery)
- IPC_MESSAGE_HANDLER(
- GpuCommandBufferMsg_SetClientHasMemoryAllocationChangedCallback,
- OnSetClientHasMemoryAllocationChangedCallback)
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateImage, OnCreateImage);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_DestroyImage, OnDestroyImage);
IPC_MESSAGE_HANDLER(GpuCommandBufferMsg_CreateStreamTexture,
@@ -477,8 +471,6 @@ void GpuCommandBufferStub::Destroy() {
}
}
- memory_manager_client_state_.reset();
-
while (!sync_points_.empty())
OnRetireSyncPoint(sync_points_.front());
@@ -924,10 +916,9 @@ void GpuCommandBufferStub::OnCreateVideoEncoder(
// self-delete during destruction of this stub.
}
+// TODO(sohanjg): cleanup this and the client side too.
void GpuCommandBufferStub::OnSetSurfaceVisible(bool visible) {
TRACE_EVENT0("gpu", "GpuCommandBufferStub::OnSetSurfaceVisible");
- if (memory_manager_client_state_)
- memory_manager_client_state_->SetVisible(visible);
}
void GpuCommandBufferStub::AddSyncPoint(uint32 sync_point, bool retire) {
@@ -1022,22 +1013,6 @@ void GpuCommandBufferStub::OnSignalQuery(uint32 query_id, uint32 id) {
OnSignalSyncPointAck(id);
}
-
-void GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback(
- bool has_callback) {
- TRACE_EVENT0(
- "gpu",
- "GpuCommandBufferStub::OnSetClientHasMemoryAllocationChangedCallback");
- if (has_callback) {
- if (!memory_manager_client_state_) {
- memory_manager_client_state_.reset(
- GetMemoryManager()->CreateClientState(this, !offscreen_, true));
- }
- } else {
- memory_manager_client_state_.reset();
- }
-}
-
void GpuCommandBufferStub::OnCreateImage(int32 id,
gfx::GpuMemoryBufferHandle handle,
gfx::Size size,
@@ -1143,18 +1118,6 @@ gpu::gles2::MemoryTracker* GpuCommandBufferStub::GetMemoryTracker() const {
return context_group_->memory_tracker();
}
-void GpuCommandBufferStub::SetMemoryAllocation(
- const gpu::MemoryAllocation& allocation) {
- if (!last_memory_allocation_valid_ ||
- !allocation.Equals(last_memory_allocation_)) {
- Send(new GpuCommandBufferMsg_SetMemoryAllocation(
- route_id_, allocation));
- }
-
- last_memory_allocation_valid_ = true;
- last_memory_allocation_ = allocation;
-}
-
void GpuCommandBufferStub::SuggestHaveFrontBuffer(
bool suggest_have_frontbuffer) {
// This can be called outside of OnMessageReceived, so the context needs
diff --git a/content/common/gpu/gpu_command_buffer_stub.h b/content/common/gpu/gpu_command_buffer_stub.h
index 83025c8..8e854df 100644
--- a/content/common/gpu/gpu_command_buffer_stub.h
+++ b/content/common/gpu/gpu_command_buffer_stub.h
@@ -98,7 +98,6 @@ class GpuCommandBufferStub
// GpuMemoryManagerClient implementation:
gfx::Size GetSurfaceSize() const override;
gpu::gles2::MemoryTracker* GetMemoryTracker() const override;
- void SetMemoryAllocation(const gpu::MemoryAllocation& allocation) override;
void SuggestHaveFrontBuffer(bool suggest_have_frontbuffer) override;
bool GetTotalGpuMemory(uint64* bytes) override;
@@ -203,8 +202,6 @@ class GpuCommandBufferStub
void OnSignalSyncPointAck(uint32 id);
void OnSignalQuery(uint32 query, uint32 id);
- void OnSetClientHasMemoryAllocationChangedCallback(bool has_callback);
-
void OnCreateImage(int32 id,
gfx::GpuMemoryBufferHandle handle,
gfx::Size size,
@@ -268,12 +265,6 @@ class GpuCommandBufferStub
scoped_ptr<gpu::SyncPointClient> sync_point_client_;
scoped_refptr<gfx::GLSurface> surface_;
- scoped_ptr<GpuMemoryManagerClientState> memory_manager_client_state_;
- // The last memory allocation received from the GpuMemoryManager (used to
- // elide redundant work).
- bool last_memory_allocation_valid_;
- gpu::MemoryAllocation last_memory_allocation_;
-
GpuWatchdog* watchdog_;
base::ObserverList<DestructionObserver> destruction_observers_;
diff --git a/content/common/gpu/gpu_memory_manager.cc b/content/common/gpu/gpu_memory_manager.cc
index 6cae8e0..755fe2a 100644
--- a/content/common/gpu/gpu_memory_manager.cc
+++ b/content/common/gpu/gpu_memory_manager.cc
@@ -59,57 +59,6 @@ GpuMemoryManager::~GpuMemoryManager() {
DCHECK(!bytes_allocated_unmanaged_current_);
}
-void GpuMemoryManager::UpdateAvailableGpuMemory() {
- // If the value was overridden on the command line, use the specified value.
- static bool client_hard_limit_bytes_overridden =
- base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kForceGpuMemAvailableMb);
- if (client_hard_limit_bytes_overridden) {
- base::StringToUint64(
- base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
- switches::kForceGpuMemAvailableMb),
- &client_hard_limit_bytes_);
- client_hard_limit_bytes_ *= 1024 * 1024;
- return;
- }
-
-#if defined(OS_ANDROID)
- // On non-Android, we use an operating system query when possible.
- // We do not have a reliable concept of multiple GPUs existing in
- // a system, so just be safe and go with the minimum encountered.
- uint64 bytes_min = 0;
-
- // Only use the clients that are visible, because otherwise the set of clients
- // we are querying could become extremely large.
- for (ClientStateList::const_iterator it = clients_visible_mru_.begin();
- it != clients_visible_mru_.end();
- ++it) {
- const GpuMemoryManagerClientState* client_state = *it;
- if (!client_state->has_surface_)
- continue;
- if (!client_state->visible_)
- continue;
-
- uint64 bytes = 0;
- if (client_state->client_->GetTotalGpuMemory(&bytes)) {
- if (!bytes_min || bytes < bytes_min)
- bytes_min = bytes;
- }
- }
-
- client_hard_limit_bytes_ = bytes_min;
- // Clamp the observed value to a specific range on Android.
- client_hard_limit_bytes_ = std::max(client_hard_limit_bytes_,
- static_cast<uint64>(8 * 1024 * 1024));
- client_hard_limit_bytes_ = std::min(client_hard_limit_bytes_,
- static_cast<uint64>(256 * 1024 * 1024));
-#else
- // Ignore what the system said and give all clients the same maximum
- // allocation on desktop platforms.
- client_hard_limit_bytes_ = 512 * 1024 * 1024;
-#endif
-}
-
void GpuMemoryManager::ScheduleManage(
ScheduleManageTime schedule_manage_time) {
if (disable_schedule_manage_)
@@ -251,74 +200,14 @@ void GpuMemoryManager::Manage() {
manage_immediate_scheduled_ = false;
delayed_manage_callback_.Cancel();
- // Update the amount of GPU memory available on the system.
- UpdateAvailableGpuMemory();
-
// Determine which clients are "hibernated" (which determines the
// distribution of frontbuffers and memory among clients that don't have
// surfaces).
SetClientsHibernatedState();
- // Assign memory allocations to clients that have surfaces.
- AssignSurfacesAllocations();
-
- // Assign memory allocations to clients that don't have surfaces.
- AssignNonSurfacesAllocations();
-
SendUmaStatsToBrowser();
}
-void GpuMemoryManager::AssignSurfacesAllocations() {
- // Send that allocation to the clients.
- ClientStateList clients = clients_visible_mru_;
- clients.insert(clients.end(),
- clients_nonvisible_mru_.begin(),
- clients_nonvisible_mru_.end());
- for (ClientStateList::const_iterator it = clients.begin();
- it != clients.end();
- ++it) {
- GpuMemoryManagerClientState* client_state = *it;
-
- // Populate and send the allocation to the client
- MemoryAllocation allocation;
- allocation.bytes_limit_when_visible = client_hard_limit_bytes_;
-#if defined(OS_ANDROID)
- // On Android, because there is only one visible tab at any time, allow
- // that renderer to cache as much as it can.
- allocation.priority_cutoff_when_visible =
- MemoryAllocation::CUTOFF_ALLOW_EVERYTHING;
-#else
- // On desktop platforms, instruct the renderers to cache only a smaller
- // set, to play nice with other renderers and other applications. If this
- // if not done, then the system can become unstable.
- // http://crbug.com/145600 (Linux)
- // http://crbug.com/141377 (Mac)
- allocation.priority_cutoff_when_visible =
- MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE;
-#endif
-
- client_state->client_->SetMemoryAllocation(allocation);
- client_state->client_->SuggestHaveFrontBuffer(!client_state->hibernated_);
- }
-}
-
-void GpuMemoryManager::AssignNonSurfacesAllocations() {
- for (ClientStateList::const_iterator it = clients_nonsurface_.begin();
- it != clients_nonsurface_.end();
- ++it) {
- GpuMemoryManagerClientState* client_state = *it;
- MemoryAllocation allocation;
-
- if (!client_state->hibernated_) {
- allocation.bytes_limit_when_visible = client_hard_limit_bytes_;
- allocation.priority_cutoff_when_visible =
- MemoryAllocation::CUTOFF_ALLOW_EVERYTHING;
- }
-
- client_state->client_->SetMemoryAllocation(allocation);
- }
-}
-
void GpuMemoryManager::SetClientsHibernatedState() const {
// Re-set all tracking groups as being hibernated.
for (TrackingGroupMap::const_iterator it = tracking_groups_.begin();
diff --git a/content/common/gpu/gpu_memory_manager.h b/content/common/gpu/gpu_memory_manager.h
index 01967d6..b92c953 100644
--- a/content/common/gpu/gpu_memory_manager.h
+++ b/content/common/gpu/gpu_memory_manager.h
@@ -112,12 +112,6 @@ class CONTENT_EXPORT GpuMemoryManager :
void Manage();
void SetClientsHibernatedState() const;
- void AssignSurfacesAllocations();
- void AssignNonSurfacesAllocations();
-
- // Update the amount of GPU memory we think we have in the system, based
- // on what the stubs' contexts report.
- void UpdateAvailableGpuMemory();
// Send memory usage stats to the browser process.
void SendUmaStatsToBrowser();
diff --git a/content/common/gpu/gpu_memory_manager_client.h b/content/common/gpu/gpu_memory_manager_client.h
index 0c6c7d0..ae06053 100644
--- a/content/common/gpu/gpu_memory_manager_client.h
+++ b/content/common/gpu/gpu_memory_manager_client.h
@@ -30,10 +30,6 @@ class CONTENT_EXPORT GpuMemoryManagerClient {
// Returns the memory tracker for this stub.
virtual gpu::gles2::MemoryTracker* GetMemoryTracker() const = 0;
- // Sets buffer usage depending on Memory Allocation
- virtual void SetMemoryAllocation(
- const gpu::MemoryAllocation& allocation) = 0;
-
virtual void SuggestHaveFrontBuffer(bool suggest_have_frontbuffer) = 0;
// Returns in bytes the total amount of GPU memory for the GPU which this
diff --git a/content/common/gpu/gpu_memory_manager_unittest.cc b/content/common/gpu/gpu_memory_manager_unittest.cc
index 567ee25..c2fb527 100644
--- a/content/common/gpu/gpu_memory_manager_unittest.cc
+++ b/content/common/gpu/gpu_memory_manager_unittest.cc
@@ -107,11 +107,6 @@ class FakeClient : public GpuMemoryManagerClient {
memory_tracker_ = NULL;
}
- void SetMemoryAllocation(const MemoryAllocation& alloc) override {
- allocation_ = alloc;
- ClientAssignmentCollector::AddClientStat(this, alloc);
- }
-
void SuggestHaveFrontBuffer(bool suggest_have_frontbuffer) override {
suggest_have_frontbuffer_ = suggest_have_frontbuffer;
}
@@ -192,216 +187,4 @@ class GpuMemoryManagerTest : public testing::Test {
GpuMemoryManager memmgr_;
};
-// Test GpuMemoryManager::Manage basic functionality.
-// Expect memory allocation to set suggest_have_frontbuffer/backbuffer
-// according to visibility and last used time for stubs with surface.
-// Expect memory allocation to be shared according to share groups for stubs
-// without a surface.
-TEST_F(GpuMemoryManagerTest, TestManageBasicFunctionality) {
- // Test stubs with surface.
- FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true),
- stub2(&memmgr_, GenerateUniqueSurfaceId(), false);
-
- Manage();
- EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
-
- // Test stubs without surface, with share group of 1 stub.
- FakeClient stub3(&memmgr_, &stub1), stub4(&memmgr_, &stub2);
-
- Manage();
- EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_));
-
- // Test stub without surface, with share group of multiple stubs.
- FakeClient stub5(&memmgr_ , &stub2);
-
- Manage();
- EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_));
-}
-
-// Test GpuMemoryManager::Manage functionality: changing visibility.
-// Expect memory allocation to set suggest_have_frontbuffer/backbuffer
-// according to visibility and last used time for stubs with surface.
-// Expect memory allocation to be shared according to share groups for stubs
-// without a surface.
-TEST_F(GpuMemoryManagerTest, TestManageChangingVisibility) {
- FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true),
- stub2(&memmgr_, GenerateUniqueSurfaceId(), false);
-
- FakeClient stub3(&memmgr_, &stub1), stub4(&memmgr_, &stub2);
- FakeClient stub5(&memmgr_ , &stub2);
-
- Manage();
- EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_));
-
- stub1.SetVisible(false);
- stub2.SetVisible(true);
-
- Manage();
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_));
-}
-
-// Test GpuMemoryManager::Manage functionality: Test more than threshold number
-// of visible stubs.
-// Expect all allocations to continue to have frontbuffer.
-TEST_F(GpuMemoryManagerTest, TestManageManyVisibleStubs) {
- FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true),
- stub2(&memmgr_, GenerateUniqueSurfaceId(), true),
- stub3(&memmgr_, GenerateUniqueSurfaceId(), true),
- stub4(&memmgr_, GenerateUniqueSurfaceId(), true);
-
- FakeClient stub5(&memmgr_ , &stub1), stub6(&memmgr_ , &stub2);
- FakeClient stub7(&memmgr_ , &stub2);
-
- Manage();
- EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub3.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub4.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub5.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub6.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub7.allocation_));
-}
-
-// Test GpuMemoryManager::Manage functionality: Test more than threshold number
-// of not visible stubs.
-// Expect the stubs surpassing the threshold to not have a backbuffer.
-TEST_F(GpuMemoryManagerTest, TestManageManyNotVisibleStubs) {
- FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true),
- stub2(&memmgr_, GenerateUniqueSurfaceId(), true),
- stub3(&memmgr_, GenerateUniqueSurfaceId(), true),
- stub4(&memmgr_, GenerateUniqueSurfaceId(), true);
- stub4.SetVisible(false);
- stub3.SetVisible(false);
- stub2.SetVisible(false);
- stub1.SetVisible(false);
-
- FakeClient stub5(&memmgr_ , &stub1), stub6(&memmgr_ , &stub4);
- FakeClient stub7(&memmgr_ , &stub1);
-
- Manage();
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub3.allocation_));
- EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub4.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub5.allocation_));
- EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub6.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_));
-}
-
-// Test GpuMemoryManager::Manage functionality: Test changing the last used
-// time of stubs when doing so causes change in which stubs surpass threshold.
-// Expect frontbuffer to be dropped for the older stub.
-TEST_F(GpuMemoryManagerTest, TestManageChangingLastUsedTime) {
- FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), true),
- stub2(&memmgr_, GenerateUniqueSurfaceId(), true),
- stub3(&memmgr_, GenerateUniqueSurfaceId(), true),
- stub4(&memmgr_, GenerateUniqueSurfaceId(), true);
-
- FakeClient stub5(&memmgr_ , &stub3), stub6(&memmgr_ , &stub4);
- FakeClient stub7(&memmgr_ , &stub3);
-
- // Make stub4 be the least-recently-used client
- stub4.SetVisible(false);
- stub3.SetVisible(false);
- stub2.SetVisible(false);
- stub1.SetVisible(false);
-
- Manage();
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub3.allocation_));
- EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub4.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub5.allocation_));
- EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub6.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub7.allocation_));
-
- // Make stub3 become the least-recently-used client.
- stub2.SetVisible(true);
- stub2.SetVisible(false);
- stub4.SetVisible(true);
- stub4.SetVisible(false);
-
- Manage();
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
- EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub3.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub4.allocation_));
- EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub5.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub6.allocation_));
- EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub7.allocation_));
-}
-
-// Test GpuMemoryManager::Manage functionality: Test changing importance of
-// enough stubs so that every stub in share group crosses threshold.
-// Expect memory allocation of the stubs without surface to share memory
-// allocation with the most visible stub in share group.
-TEST_F(GpuMemoryManagerTest, TestManageChangingImportanceShareGroup) {
- FakeClient stub_ignore_a(&memmgr_, GenerateUniqueSurfaceId(), true),
- stub_ignore_b(&memmgr_, GenerateUniqueSurfaceId(), false),
- stub_ignore_c(&memmgr_, GenerateUniqueSurfaceId(), false);
- FakeClient stub1(&memmgr_, GenerateUniqueSurfaceId(), false),
- stub2(&memmgr_, GenerateUniqueSurfaceId(), false);
-
- FakeClient stub3(&memmgr_, &stub2), stub4(&memmgr_, &stub2);
-
- // stub1 and stub2 keep their non-hibernated state because they're
- // either visible or the 2 most recently used clients (through the
- // first three checks).
- stub1.SetVisible(true);
- stub2.SetVisible(true);
- Manage();
- EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub1.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub3.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_));
-
- stub1.SetVisible(false);
- Manage();
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceYes(stub2.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_));
- EXPECT_TRUE(IsAllocationForegroundForSurfaceNo(stub4.allocation_));
-
- stub2.SetVisible(false);
- Manage();
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub1.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_));
-
- // stub_ignore_b will cause stub1 to become hibernated (because
- // stub_ignore_a, stub_ignore_b, and stub2 are all non-hibernated and more
- // important).
- stub_ignore_b.SetVisible(true);
- stub_ignore_b.SetVisible(false);
- Manage();
- EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceYes(stub2.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub3.allocation_));
- EXPECT_TRUE(IsAllocationBackgroundForSurfaceNo(stub4.allocation_));
-
- // stub_ignore_c will cause stub2 to become hibernated (because
- // stub_ignore_a, stub_ignore_b, and stub_ignore_c are all non-hibernated
- // and more important).
- stub_ignore_c.SetVisible(true);
- stub_ignore_c.SetVisible(false);
- Manage();
- EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub1.allocation_));
- EXPECT_TRUE(IsAllocationHibernatedForSurfaceYes(stub2.allocation_));
- EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub3.allocation_));
- EXPECT_TRUE(IsAllocationHibernatedForSurfaceNo(stub4.allocation_));
-}
-
} // namespace content
diff --git a/content/common/gpu/gpu_messages.h b/content/common/gpu/gpu_messages.h
index fa37750..c586453 100644
--- a/content/common/gpu/gpu_messages.h
+++ b/content/common/gpu/gpu_messages.h
@@ -598,15 +598,6 @@ IPC_MESSAGE_ROUTED2(GpuCommandBufferMsg_UpdateVSyncParameters,
// Send to stub on surface visibility change.
IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_SetSurfaceVisible, bool /* visible */)
-// Sent to proxy when the gpu memory manager changes its memory allocation.
-IPC_MESSAGE_ROUTED1(GpuCommandBufferMsg_SetMemoryAllocation,
- gpu::MemoryAllocation /* allocation */)
-
-// Sent to stub when proxy is assigned a memory allocation changed callback.
-IPC_MESSAGE_ROUTED1(
- GpuCommandBufferMsg_SetClientHasMemoryAllocationChangedCallback,
- bool /* has_callback */)
-
// Inserts a sync point into the channel. This is handled on the IO thread, so
// can be expected to be reasonably fast, but the sync point is actually
// retired in order with respect to the other calls. The sync point is shared
diff --git a/content/renderer/gpu/render_widget_compositor.cc b/content/renderer/gpu/render_widget_compositor.cc
index a38703a..c82b3b1 100644
--- a/content/renderer/gpu/render_widget_compositor.cc
+++ b/content/renderer/gpu/render_widget_compositor.cc
@@ -41,6 +41,7 @@
#include "content/public/common/content_switches.h"
#include "content/renderer/input/input_handler_manager.h"
#include "gpu/command_buffer/client/gles2_interface.h"
+#include "gpu/command_buffer/service/gpu_switches.h"
#include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallback.h"
#include "third_party/WebKit/public/platform/WebLayoutAndPaintAsyncCallback.h"
#include "third_party/WebKit/public/platform/WebSize.h"
@@ -458,6 +459,9 @@ void RenderWidgetCompositor::Initialize() {
if (base::SysInfo::IsLowEndDevice())
settings.max_staging_buffer_usage_in_bytes /= 4;
+ cc::ManagedMemoryPolicy current = settings.memory_policy_;
+ settings.memory_policy_ = GetGpuMemoryPolicy(current);
+
scoped_refptr<base::SingleThreadTaskRunner> compositor_thread_task_runner =
compositor_deps_->GetCompositorImplThreadTaskRunner();
scoped_refptr<base::SingleThreadTaskRunner>
@@ -1007,4 +1011,84 @@ void RenderWidgetCompositor::SetSurfaceIdNamespace(
layer_tree_host_->set_surface_id_namespace(surface_id_namespace);
}
+cc::ManagedMemoryPolicy RenderWidgetCompositor::GetGpuMemoryPolicy(
+ const cc::ManagedMemoryPolicy& policy) {
+ cc::ManagedMemoryPolicy actual = policy;
+ actual.bytes_limit_when_visible = 0;
+
+ // If the value was overridden on the command line, use the specified value.
+ static bool client_hard_limit_bytes_overridden =
+ base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kForceGpuMemAvailableMb);
+ if (client_hard_limit_bytes_overridden) {
+ if (base::StringToSizeT(
+ base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kForceGpuMemAvailableMb),
+ &actual.bytes_limit_when_visible))
+ actual.bytes_limit_when_visible *= 1024 * 1024;
+ return actual;
+ }
+
+#if defined(OS_ANDROID)
+ // We can't query available GPU memory from the system on Android.
+ // Physical memory is also mis-reported sometimes (eg. Nexus 10 reports
+ // 1262MB when it actually has 2GB, while Razr M has 1GB but only reports
+ // 128MB java heap size). First we estimate physical memory using both.
+ size_t dalvik_mb = base::SysInfo::DalvikHeapSizeMB();
+ size_t physical_mb = base::SysInfo::AmountOfPhysicalMemoryMB();
+ size_t physical_memory_mb = 0;
+ if (dalvik_mb >= 256)
+ physical_memory_mb = dalvik_mb * 4;
+ else
+ physical_memory_mb = std::max(dalvik_mb * 4, (physical_mb * 4) / 3);
+
+ // Now we take a default of 1/8th of memory on high-memory devices,
+ // and gradually scale that back for low-memory devices (to be nicer
+ // to other apps so they don't get killed). Examples:
+ // Nexus 4/10(2GB) 256MB (normally 128MB)
+ // Droid Razr M(1GB) 114MB (normally 57MB)
+ // Galaxy Nexus(1GB) 100MB (normally 50MB)
+ // Xoom(1GB) 100MB (normally 50MB)
+ // Nexus S(low-end) 8MB (normally 8MB)
+ // Note that the compositor now uses only some of this memory for
+ // pre-painting and uses the rest only for 'emergencies'.
+ if (actual.bytes_limit_when_visible == 0) {
+ // NOTE: Non-low-end devices use only 50% of these limits,
+ // except during 'emergencies' where 100% can be used.
+ if (!base::SysInfo::IsLowEndDevice()) {
+ if (physical_memory_mb >= 1536)
+ actual.bytes_limit_when_visible = physical_memory_mb / 8; // >192MB
+ else if (physical_memory_mb >= 1152)
+ actual.bytes_limit_when_visible = physical_memory_mb / 8; // >144MB
+ else if (physical_memory_mb >= 768)
+ actual.bytes_limit_when_visible = physical_memory_mb / 10; // >76MB
+ else
+ actual.bytes_limit_when_visible = physical_memory_mb / 12; // <64MB
+ } else {
+ // Low-end devices have 512MB or less memory by definition
+ // so we hard code the limit rather than relying on the heuristics
+ // above. Low-end devices use 4444 textures so we can use a lower limit.
+ actual.bytes_limit_when_visible = 8;
+ }
+ actual.bytes_limit_when_visible =
+ actual.bytes_limit_when_visible * 1024 * 1024;
+ // Clamp the observed value to a specific range on Android.
+ actual.bytes_limit_when_visible = std::max(
+ actual.bytes_limit_when_visible, static_cast<size_t>(8 * 1024 * 1024));
+ actual.bytes_limit_when_visible =
+ std::min(actual.bytes_limit_when_visible,
+ static_cast<size_t>(256 * 1024 * 1024));
+ }
+ actual.priority_cutoff_when_visible =
+ gpu::MemoryAllocation::CUTOFF_ALLOW_EVERYTHING;
+#else
+ // Ignore what the system said and give all clients the same maximum
+ // allocation on desktop platforms.
+ actual.bytes_limit_when_visible = 512 * 1024 * 1024;
+ actual.priority_cutoff_when_visible =
+ gpu::MemoryAllocation::CUTOFF_ALLOW_NICE_TO_HAVE;
+#endif
+ return actual;
+}
+
} // namespace content
diff --git a/content/renderer/gpu/render_widget_compositor.h b/content/renderer/gpu/render_widget_compositor.h
index cf29630..6e8b8fd 100644
--- a/content/renderer/gpu/render_widget_compositor.h
+++ b/content/renderer/gpu/render_widget_compositor.h
@@ -10,6 +10,7 @@
#include "base/time/time.h"
#include "base/values.h"
#include "cc/input/top_controls_state.h"
+#include "cc/output/managed_memory_policy.h"
#include "cc/output/swap_promise.h"
#include "cc/trees/layer_tree_host_client.h"
#include "cc/trees/layer_tree_host_single_thread_client.h"
@@ -78,6 +79,8 @@ class CONTENT_EXPORT RenderWidgetCompositor
bool SendMessageToMicroBenchmark(int id, scoped_ptr<base::Value> value);
void StartCompositor();
void SetSurfaceIdNamespace(uint32_t surface_id_namespace);
+ cc::ManagedMemoryPolicy GetGpuMemoryPolicy(
+ const cc::ManagedMemoryPolicy& policy);
// WebLayerTreeView implementation.
void setRootLayer(const blink::WebLayer& layer) override;
diff --git a/ui/compositor/test/in_process_context_provider.cc b/ui/compositor/test/in_process_context_provider.cc
index 76cd19d..92fbf3a 100644
--- a/ui/compositor/test/in_process_context_provider.cc
+++ b/ui/compositor/test/in_process_context_provider.cc
@@ -212,11 +212,6 @@ void InProcessContextProvider::SetLostContextCallback(
lost_context_callback_ = lost_context_callback;
}
-void InProcessContextProvider::SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback) {
- // There's no memory manager for the in-process implementation.
-}
-
void InProcessContextProvider::OnLostContext() {
DCHECK(context_thread_checker_.CalledOnValidThread());
{
diff --git a/ui/compositor/test/in_process_context_provider.h b/ui/compositor/test/in_process_context_provider.h
index 628eaec..b728041 100644
--- a/ui/compositor/test/in_process_context_provider.h
+++ b/ui/compositor/test/in_process_context_provider.h
@@ -53,9 +53,6 @@ class InProcessContextProvider : public cc::ContextProvider {
bool DestroyedOnMainThread() override;
void SetLostContextCallback(
const LostContextCallback& lost_context_callback) override;
- void SetMemoryPolicyChangedCallback(
- const MemoryPolicyChangedCallback& memory_policy_changed_callback)
- override;
private:
InProcessContextProvider(