Chromium Code Reviews| Index: content/common/gpu/gpu_memory_manager.cc |
| diff --git a/content/common/gpu/gpu_memory_manager.cc b/content/common/gpu/gpu_memory_manager.cc |
| index 10883287bcc803ef7c16f44f85ed54d58757154b..886ded3e7c208e40c8f2cf8423ec2c2182962df7 100644 |
| --- a/content/common/gpu/gpu_memory_manager.cc |
| +++ b/content/common/gpu/gpu_memory_manager.cc |
| @@ -9,10 +9,13 @@ |
| #include <algorithm> |
| #include "base/bind.h" |
| +#include "base/command_line.h" |
| #include "base/debug/trace_event.h" |
| #include "base/message_loop.h" |
| +#include "base/string_number_conversions.h" |
| #include "content/common/gpu/gpu_command_buffer_stub.h" |
| #include "content/common/gpu/gpu_memory_allocation.h" |
| +#include "gpu/command_buffer/service/gpu_switches.h" |
| namespace { |
| @@ -29,25 +32,6 @@ bool IsInSameContextShareGroupAsAnyOf( |
| return false; |
| } |
| -#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( |
| GpuMemoryManager::StubMemoryStatMap* stub_memory_stats, |
| const std::vector<GpuCommandBufferStubBase*>& stubs, |
| @@ -65,14 +49,49 @@ void AssignMemoryAllocations( |
| } |
| +#if defined(OS_ANDROID) |
| +size_t GpuMemoryManager::CalculateBonusMemoryAllocationBasedOnSize( |
| + gfx::Size size) const { |
| + const int viewportMultiplier = 16; |
|
greggman
2012/07/31 00:30:41
style: constants are kCamelCase
ccameron
2012/07/31 00:52:49
Done. This was a copy-paste of the function (movi
|
| + 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 < GetMinimumTabAllocation()) |
| + limit = GetMinimumTabAllocation(); |
| + else if (limit > GetAvailableGpuMemory()) |
| + limit = GetAvailableGpuMemory(); |
| + return limit - GetMinimumTabAllocation(); |
| +} |
| +#endif |
| + |
| GpuMemoryManager::GpuMemoryManager(GpuMemoryManagerClient* client, |
| size_t max_surfaces_with_frontbuffer_soft_limit) |
| : client_(client), |
| manage_immediate_scheduled_(false), |
| max_surfaces_with_frontbuffer_soft_limit_( |
| max_surfaces_with_frontbuffer_soft_limit), |
| + bytes_available_gpu_memory_(0), |
| bytes_allocated_current_(0), |
| bytes_allocated_historical_max_(0) { |
| + CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| + if (command_line->HasSwitch(switches::kForceGpuMemAvailableMb)) { |
| + base::StringToSizeT( |
| + command_line->GetSwitchValueASCII(switches::kForceGpuMemAvailableMb), |
| + &bytes_available_gpu_memory_); |
| + bytes_available_gpu_memory_ *= 1024 * 1024; |
| + } |
| + else { |
|
greggman
2012/07/31 00:30:41
style: open an close braces go on same line for 'e
ccameron
2012/07/31 00:52:49
Done. There was another instance of this later in
|
| +#if defined(OS_ANDROID) |
| + bytes_available_gpu_memory_ = 64 * 1024 * 1024; |
| +#else |
| + bytes_available_gpu_memory_ = 448 * 1024 * 1024; |
| +#endif |
| + } |
| } |
| GpuMemoryManager::~GpuMemoryManager() { |
| @@ -112,11 +131,6 @@ void GpuMemoryManager::ScheduleManage(bool immediate) { |
| } |
| } |
| -size_t GpuMemoryManager::GetAvailableGpuMemory() const { |
| - // TODO(mmocny): Implement this with real system figures. |
| - return kMaximumAllocationForTabs; |
| -} |
| - |
| void GpuMemoryManager::TrackMemoryAllocatedChange(size_t old_size, |
| size_t new_size) |
| { |
| @@ -241,10 +255,10 @@ void GpuMemoryManager::Manage() { |
| 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; |
| - if (base_allocation_size < kMaximumAllocationForTabs && |
| + size_t base_allocation_size = GetMinimumTabAllocation() * num_stubs_need_mem; |
| + if (base_allocation_size < GetAvailableGpuMemory() && |
| !stubs_with_surface_foreground.empty()) |
| - bonus_allocation = (kMaximumAllocationForTabs - base_allocation_size) / |
| + bonus_allocation = (GetAvailableGpuMemory() - base_allocation_size) / |
| stubs_with_surface_foreground.size(); |
|
greggman
2012/07/31 00:30:41
style: indent? i'm not 100% sure this is wrong. It
ccameron
2012/07/31 00:52:49
Done. Lined up with the =, since that seems most
|
| #else |
| // On android, calculate bonus allocation based on surface size. |
| @@ -259,7 +273,7 @@ void GpuMemoryManager::Manage() { |
| AssignMemoryAllocations( |
| &stub_memory_stats_for_last_manage_, |
| stubs_with_surface_foreground, |
| - GpuMemoryAllocation(kMinimumAllocationForTab + bonus_allocation, |
| + GpuMemoryAllocation(GetMinimumTabAllocation() + bonus_allocation, |
| GpuMemoryAllocation::kHasFrontbuffer | |
| GpuMemoryAllocation::kHasBackbuffer), |
| true); |
| @@ -279,14 +293,14 @@ void GpuMemoryManager::Manage() { |
| AssignMemoryAllocations( |
| &stub_memory_stats_for_last_manage_, |
| stubs_without_surface_foreground, |
| - GpuMemoryAllocation(kMinimumAllocationForTab, |
| + GpuMemoryAllocation(GetMinimumTabAllocation(), |
| GpuMemoryAllocation::kHasNoBuffers), |
| true); |
| AssignMemoryAllocations( |
| &stub_memory_stats_for_last_manage_, |
| stubs_without_surface_background, |
| - GpuMemoryAllocation(kMinimumAllocationForTab, |
| + GpuMemoryAllocation(GetMinimumTabAllocation(), |
| GpuMemoryAllocation::kHasNoBuffers), |
| false); |
| @@ -295,14 +309,6 @@ void GpuMemoryManager::Manage() { |
| stubs_without_surface_hibernated, |
| GpuMemoryAllocation(0, GpuMemoryAllocation::kHasNoBuffers), |
| false); |
| - |
| - size_t assigned_allocation_sum = 0; |
| - for (StubMemoryStatMap::iterator it = |
| - stub_memory_stats_for_last_manage_.begin(); |
| - it != stub_memory_stats_for_last_manage_.end(); |
| - ++it) { |
| - assigned_allocation_sum += it->second.allocation.gpu_resource_size_in_bytes; |
| - } |
| } |
| #endif |