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 212b50d0ed90656e91aa3155a9d7695638f7ca89..9d8f54003aae57814a15da89368374d0f8f5560b 100644 |
| --- a/content/common/gpu/gpu_memory_manager.cc |
| +++ b/content/common/gpu/gpu_memory_manager.cc |
| @@ -48,11 +48,16 @@ size_t CalculateBonusMemoryAllocationBasedOnSize(gfx::Size size) { |
| #endif |
| void AssignMemoryAllocations( |
| + std::map<GpuCommandBufferStubBase*, GpuMemoryManager::StubMemoryStat>& |
| + stub_memory_stats, |
|
piman
2012/07/18 19:59:58
nit: Passing parameters by non-const references is
|
| std::vector<GpuCommandBufferStubBase*>& stubs, |
| - GpuMemoryAllocation allocation) { |
| + GpuMemoryAllocation allocation, |
| + bool visible) { |
| for (std::vector<GpuCommandBufferStubBase*>::iterator it = stubs.begin(); |
| it != stubs.end(); ++it) { |
| (*it)->SetMemoryAllocation(allocation); |
| + stub_memory_stats[*it].allocation = allocation; |
| + stub_memory_stats[*it].visible = visible; |
| } |
| } |
| @@ -63,7 +68,8 @@ GpuMemoryManager::GpuMemoryManager(GpuMemoryManagerClient* client, |
| : client_(client), |
| manage_immediate_scheduled_(false), |
| max_surfaces_with_frontbuffer_soft_limit_( |
| - max_surfaces_with_frontbuffer_soft_limit) { |
| + max_surfaces_with_frontbuffer_soft_limit), |
| + peak_assigned_allocation_sum_(0) { |
| } |
| GpuMemoryManager::~GpuMemoryManager() { |
| @@ -103,6 +109,11 @@ void GpuMemoryManager::ScheduleManage(bool immediate) { |
| } |
| } |
| +size_t GpuMemoryManager::GetAvailableGpuMemory() const { |
| + // TODO(mmocny): Implement this with real system figures. |
| + return kMaximumAllocationForTabs; |
| +} |
| + |
| // The current Manage algorithm simply classifies contexts (stubs) into |
| // "foreground", "background", or "hibernated" categories. |
| // For each of these three categories, there are predefined memory allocation |
| @@ -216,28 +227,52 @@ void GpuMemoryManager::Manage() { |
| stubs_with_surface_foreground[0]->GetSurfaceSize()); |
| #endif |
| + stub_memory_stats_.clear(); |
| + |
| // Now give out allocations to everyone. |
| - AssignMemoryAllocations(stubs_with_surface_foreground, |
| + AssignMemoryAllocations(stub_memory_stats_, |
|
piman
2012/07/18 19:59:58
nit: correct style is either
Function(param1,
|
| + stubs_with_surface_foreground, |
| GpuMemoryAllocation(kMinimumAllocationForTab + bonus_allocation, |
| GpuMemoryAllocation::kHasFrontbuffer | |
| - GpuMemoryAllocation::kHasBackbuffer)); |
| + GpuMemoryAllocation::kHasBackbuffer), |
| + true); |
| - AssignMemoryAllocations(stubs_with_surface_background, |
| - GpuMemoryAllocation(0, GpuMemoryAllocation::kHasFrontbuffer)); |
| + AssignMemoryAllocations(stub_memory_stats_, |
| + stubs_with_surface_background, |
| + GpuMemoryAllocation(0, GpuMemoryAllocation::kHasFrontbuffer), |
| + false); |
| - AssignMemoryAllocations(stubs_with_surface_hibernated, |
| - GpuMemoryAllocation(0, GpuMemoryAllocation::kHasNoBuffers)); |
| + AssignMemoryAllocations(stub_memory_stats_, |
| + stubs_with_surface_hibernated, |
| + GpuMemoryAllocation(0, GpuMemoryAllocation::kHasNoBuffers), |
| + false); |
| - AssignMemoryAllocations(stubs_without_surface_foreground, |
| + AssignMemoryAllocations(stub_memory_stats_, |
| + stubs_without_surface_foreground, |
| GpuMemoryAllocation(kMinimumAllocationForTab, |
| - GpuMemoryAllocation::kHasNoBuffers)); |
| + GpuMemoryAllocation::kHasNoBuffers), |
| + true); |
| - AssignMemoryAllocations(stubs_without_surface_background, |
| + AssignMemoryAllocations(stub_memory_stats_, |
| + stubs_without_surface_background, |
| GpuMemoryAllocation(kMinimumAllocationForTab, |
| - GpuMemoryAllocation::kHasNoBuffers)); |
| + GpuMemoryAllocation::kHasNoBuffers), |
| + false); |
| + |
| + AssignMemoryAllocations(stub_memory_stats_, |
| + stubs_without_surface_hibernated, |
| + GpuMemoryAllocation(0, GpuMemoryAllocation::kHasNoBuffers), |
| + false); |
| + |
| + size_t assigned_allocation_sum = 0; |
| + for (std::map<GpuCommandBufferStubBase*, StubMemoryStat>::iterator |
| + it = stub_memory_stats_.begin(); it != stub_memory_stats_.end(); ++it) { |
|
piman
2012/07/18 19:59:58
nit: The typedef I suggest will help you here, but
|
| + assigned_allocation_sum += it->second.allocation.gpu_resource_size_in_bytes; |
| + } |
| + |
| + if (assigned_allocation_sum > peak_assigned_allocation_sum_) |
| + peak_assigned_allocation_sum_ = assigned_allocation_sum; |
|
piman
2012/07/18 19:59:58
nit: unnecessary empty line.
|
| - AssignMemoryAllocations(stubs_without_surface_hibernated, |
| - GpuMemoryAllocation(0, GpuMemoryAllocation::kHasNoBuffers)); |
| } |
| #endif |