summaryrefslogtreecommitdiffstats
path: root/content/common/gpu
diff options
context:
space:
mode:
authormmocny@chromium.org <mmocny@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-04 15:40:13 +0000
committermmocny@chromium.org <mmocny@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-04 15:40:13 +0000
commit1d56e96465de6da2deaabb75160d8fc9f281d63a (patch)
treefc51246df0b366ee7bf8084e6fe36b8ac2c7776d /content/common/gpu
parent38a53866a1037af0cbf2604b587840c16e518462 (diff)
downloadchromium_src-1d56e96465de6da2deaabb75160d8fc9f281d63a.zip
chromium_src-1d56e96465de6da2deaabb75160d8fc9f281d63a.tar.gz
chromium_src-1d56e96465de6da2deaabb75160d8fc9f281d63a.tar.bz2
GpuMemoryManager should limit memory allocations based on viewport size for android.
On android, we identify devices with low system memory via viewport size. WK ContentTextureManager previously used viewport size information to select texture allocation limits. Now that GpuMemoryManager is assigning these limits, that logic needed to move here. BUG=123382 TEST=content_unittest.GpuMemoryManagerTest and Manual Review URL: http://codereview.chromium.org/10274009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135351 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/common/gpu')
-rw-r--r--content/common/gpu/gpu_command_buffer_stub.cc6
-rw-r--r--content/common/gpu/gpu_command_buffer_stub.h5
-rw-r--r--content/common/gpu/gpu_memory_manager.cc35
-rw-r--r--content/common/gpu/gpu_memory_manager_unittest.cc6
-rw-r--r--content/common/gpu/image_transport_surface.cc4
5 files changed, 52 insertions, 4 deletions
diff --git a/content/common/gpu/gpu_command_buffer_stub.cc b/content/common/gpu/gpu_command_buffer_stub.cc
index 5424287..ce31401 100644
--- a/content/common/gpu/gpu_command_buffer_stub.cc
+++ b/content/common/gpu/gpu_command_buffer_stub.cc
@@ -623,6 +623,12 @@ void GpuCommandBufferStub::RemoveDestructionObserver(
destruction_observers_.RemoveObserver(observer);
}
+gfx::Size GpuCommandBufferStub::GetSurfaceSize() const {
+ if (!surface_)
+ return gfx::Size();
+ return surface_->GetSize();
+}
+
bool GpuCommandBufferStub::IsInSameContextShareGroup(
const GpuCommandBufferStubBase& other) const {
return context_group_ ==
diff --git a/content/common/gpu/gpu_command_buffer_stub.h b/content/common/gpu/gpu_command_buffer_stub.h
index 6a589fd..abbd455 100644
--- a/content/common/gpu/gpu_command_buffer_stub.h
+++ b/content/common/gpu/gpu_command_buffer_stub.h
@@ -67,6 +67,8 @@ class CONTENT_EXPORT GpuCommandBufferStubBase {
virtual bool has_surface_state() const = 0;
virtual const SurfaceState& surface_state() const = 0;
+ virtual gfx::Size GetSurfaceSize() const = 0;
+
virtual bool IsInSameContextShareGroup(
const GpuCommandBufferStubBase& other) const = 0;
@@ -120,6 +122,9 @@ class GpuCommandBufferStub
virtual const GpuCommandBufferStubBase::SurfaceState& surface_state() const
OVERRIDE;
+ // Returns surface size.
+ virtual gfx::Size GetSurfaceSize() const OVERRIDE;
+
// Returns true iff |other| is in the same context share group as this stub.
virtual bool IsInSameContextShareGroup(
const GpuCommandBufferStubBase& other) const OVERRIDE;
diff --git a/content/common/gpu/gpu_memory_manager.cc b/content/common/gpu/gpu_memory_manager.cc
index d174098..4219ca3 100644
--- a/content/common/gpu/gpu_memory_manager.cc
+++ b/content/common/gpu/gpu_memory_manager.cc
@@ -26,7 +26,27 @@ bool IsInSameContextShareGroupAsAnyOf(
return false;
}
-void AssignMemoryAllocations(std::vector<GpuCommandBufferStubBase*>& stubs,
+#if defined(OS_ANDROID)
+size_t CalculateBonusMemoryAllocationBasedOnSize(gfx::Size size) {
+ const int viewportMultiplier = 16;
+ const unsigned int componentsPerPixel = 4; // GraphicsContext3D::RGBA
+ const unsigned int bytesPerComponent = 1; // sizeof(GC3Dubyte)
+
+ if (size.IsEmpty())
+ return 0;
+
+ size_t limit = viewportMultiplier * size.width() * size.height() *
+ componentsPerPixel * bytesPerComponent;
+ if (limit < GpuMemoryManager::kMinimumAllocationForTab)
+ limit = GpuMemoryManager::kMinimumAllocationForTab;
+ else if (limit > GpuMemoryManager::kMaximumAllocationForTabs)
+ limit = GpuMemoryManager::kMaximumAllocationForTabs;
+ return limit - GpuMemoryManager::kMinimumAllocationForTab;
+}
+#endif
+
+void AssignMemoryAllocations(
+ std::vector<GpuCommandBufferStubBase*>& stubs,
GpuMemoryAllocation allocation) {
for (std::vector<GpuCommandBufferStubBase*>::iterator it = stubs.begin();
it != stubs.end(); ++it) {
@@ -162,17 +182,24 @@ void GpuMemoryManager::Manage() {
stubs_without_surface_hibernated.push_back(stub);
}
- // Calculate memory allocation size in bytes given to each stub, by sharing
- // global limit equally among those that need it.
+ size_t bonus_allocation = 0;
+#if !defined(OS_ANDROID)
+ // Calculate bonus allocation by splitting remainder of global limit equally
+ // after giving out the minimum to those that need it.
size_t num_stubs_need_mem = stubs_with_surface_foreground.size() +
stubs_without_surface_foreground.size() +
stubs_without_surface_background.size();
size_t base_allocation_size = kMinimumAllocationForTab * num_stubs_need_mem;
- size_t bonus_allocation = 0;
if (base_allocation_size < kMaximumAllocationForTabs &&
!stubs_with_surface_foreground.empty())
bonus_allocation = (kMaximumAllocationForTabs - base_allocation_size) /
stubs_with_surface_foreground.size();
+#else
+ // On android, calculate bonus allocation based on surface size.
+ if (!stubs_with_surface_foreground.empty())
+ bonus_allocation = CalculateBonusMemoryAllocationBasedOnSize(
+ stubs_with_surface_foreground[0]->GetSurfaceSize());
+#endif
// Now give out allocations to everyone.
AssignMemoryAllocations(stubs_with_surface_foreground,
diff --git a/content/common/gpu/gpu_memory_manager_unittest.cc b/content/common/gpu/gpu_memory_manager_unittest.cc
index 3e56203..cc52780 100644
--- a/content/common/gpu/gpu_memory_manager_unittest.cc
+++ b/content/common/gpu/gpu_memory_manager_unittest.cc
@@ -33,6 +33,9 @@ class FakeCommandBufferStub : public GpuCommandBufferStubBase {
return surface_state_;
}
+ virtual gfx::Size GetSurfaceSize() const {
+ return gfx::Size();
+ }
virtual bool IsInSameContextShareGroup(
const GpuCommandBufferStubBase& stub) const {
return false;
@@ -64,6 +67,9 @@ class FakeCommandBufferStubWithoutSurface : public GpuCommandBufferStubBase {
return *surface_state_;
}
+ virtual gfx::Size GetSurfaceSize() const {
+ return gfx::Size();
+ }
virtual bool IsInSameContextShareGroup(
const GpuCommandBufferStubBase& stub) const {
return std::find(share_group_.begin(),
diff --git a/content/common/gpu/image_transport_surface.cc b/content/common/gpu/image_transport_surface.cc
index e1fadf6..d7640ba 100644
--- a/content/common/gpu/image_transport_surface.cc
+++ b/content/common/gpu/image_transport_surface.cc
@@ -224,6 +224,10 @@ void ImageTransportHelper::Resize(gfx::Size size) {
surface_->OnResize(size);
+#if defined(OS_ANDROID)
+ manager_->gpu_memory_manager()->ScheduleManage();
+#endif
+
#if defined(OS_WIN)
Decoder()->MakeCurrent();
SetSwapInterval();