Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/gpu/gpu_memory_manager.h" | 5 #include "content/common/gpu/gpu_memory_manager.h" |
| 6 | 6 |
| 7 #if defined(ENABLE_GPU) | 7 #if defined(ENABLE_GPU) |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "content/common/gpu/gpu_command_buffer_stub.h" | 13 #include "content/common/gpu/gpu_command_buffer_stub.h" |
| 14 #include "content/common/gpu/gpu_memory_allocation.h" | 14 #include "content/common/gpu/gpu_memory_allocation.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 bool IsInSameContextShareGroupAsAnyOf( | 18 bool IsInSameContextShareGroupAsAnyOf( |
| 19 const GpuCommandBufferStubBase* stub, | 19 const GpuCommandBufferStubBase* stub, |
| 20 const std::vector<GpuCommandBufferStubBase*>& stubs) { | 20 const std::vector<GpuCommandBufferStubBase*>& stubs) { |
| 21 for (std::vector<GpuCommandBufferStubBase*>::const_iterator it = | 21 for (std::vector<GpuCommandBufferStubBase*>::const_iterator it = |
| 22 stubs.begin(); it != stubs.end(); ++it) { | 22 stubs.begin(); it != stubs.end(); ++it) { |
| 23 if (stub->IsInSameContextShareGroup(**it)) | 23 if (stub->IsInSameContextShareGroup(**it)) |
| 24 return true; | 24 return true; |
| 25 } | 25 } |
| 26 return false; | 26 return false; |
| 27 } | 27 } |
| 28 | 28 |
| 29 void AssignMemoryAllocations(std::vector<GpuCommandBufferStubBase*>& stubs, | 29 #if defined(OS_ANDROID) |
| 30 size_t CalculateBonusMemoryAllocationBasedOnSize(gfx::Size size) { | |
| 31 const int viewportMultiplier = 16; | |
| 32 unsigned int componentsPerPixel = 4; // GraphicsContext3D::RGBA | |
|
jonathan.backer
2012/05/04 14:25:28
const
| |
| 33 unsigned int bytesPerComponent = 1; // sizeof(GC3Dubyte) | |
| 34 | |
| 35 if (size.IsEmpty()) | |
| 36 return 0; | |
| 37 | |
| 38 size_t limit = viewportMultiplier * size.width() * size.height() * | |
| 39 componentsPerPixel * bytesPerComponent; | |
| 40 if (limit < GpuMemoryManager::kMinimumAllocationForTab) | |
| 41 limit = GpuMemoryManager::kMinimumAllocationForTab; | |
| 42 else if (limit > GpuMemoryManager::kMaximumAllocationForTabs) | |
| 43 limit = GpuMemoryManager::kMaximumAllocationForTabs; | |
| 44 return limit - GpuMemoryManager::kMinimumAllocationForTab; | |
| 45 } | |
| 46 #endif | |
| 47 | |
| 48 void AssignMemoryAllocations( | |
| 49 std::vector<GpuCommandBufferStubBase*>& stubs, | |
| 30 GpuMemoryAllocation allocation) { | 50 GpuMemoryAllocation allocation) { |
| 31 for (std::vector<GpuCommandBufferStubBase*>::iterator it = stubs.begin(); | 51 for (std::vector<GpuCommandBufferStubBase*>::iterator it = stubs.begin(); |
| 32 it != stubs.end(); ++it) { | 52 it != stubs.end(); ++it) { |
| 33 (*it)->SetMemoryAllocation(allocation); | 53 (*it)->SetMemoryAllocation(allocation); |
| 34 } | 54 } |
| 35 } | 55 } |
| 36 | 56 |
| 37 } | 57 } |
| 38 | 58 |
| 39 GpuMemoryManager::GpuMemoryManager(GpuMemoryManagerClient* client, | 59 GpuMemoryManager::GpuMemoryManager(GpuMemoryManagerClient* client, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 // of surface stubs which are in the same context share group. | 175 // of surface stubs which are in the same context share group. |
| 156 if (IsInSameContextShareGroupAsAnyOf(stub, stubs_with_surface_foreground)) | 176 if (IsInSameContextShareGroupAsAnyOf(stub, stubs_with_surface_foreground)) |
| 157 stubs_without_surface_foreground.push_back(stub); | 177 stubs_without_surface_foreground.push_back(stub); |
| 158 else if (IsInSameContextShareGroupAsAnyOf( | 178 else if (IsInSameContextShareGroupAsAnyOf( |
| 159 stub, stubs_with_surface_background)) | 179 stub, stubs_with_surface_background)) |
| 160 stubs_without_surface_background.push_back(stub); | 180 stubs_without_surface_background.push_back(stub); |
| 161 else | 181 else |
| 162 stubs_without_surface_hibernated.push_back(stub); | 182 stubs_without_surface_hibernated.push_back(stub); |
| 163 } | 183 } |
| 164 | 184 |
| 165 // Calculate memory allocation size in bytes given to each stub, by sharing | 185 size_t bonus_allocation = 0; |
| 166 // global limit equally among those that need it. | 186 #if !defined(OS_ANDROID) |
| 187 // Calculate bonus allocation by splitting remainder of global limit equally | |
| 188 // after giving out the minimum to those that need it. | |
| 167 size_t num_stubs_need_mem = stubs_with_surface_foreground.size() + | 189 size_t num_stubs_need_mem = stubs_with_surface_foreground.size() + |
| 168 stubs_without_surface_foreground.size() + | 190 stubs_without_surface_foreground.size() + |
| 169 stubs_without_surface_background.size(); | 191 stubs_without_surface_background.size(); |
| 170 size_t base_allocation_size = kMinimumAllocationForTab * num_stubs_need_mem; | 192 size_t base_allocation_size = kMinimumAllocationForTab * num_stubs_need_mem; |
| 171 size_t bonus_allocation = 0; | |
| 172 if (base_allocation_size < kMaximumAllocationForTabs && | 193 if (base_allocation_size < kMaximumAllocationForTabs && |
| 173 !stubs_with_surface_foreground.empty()) | 194 !stubs_with_surface_foreground.empty()) |
| 174 bonus_allocation = (kMaximumAllocationForTabs - base_allocation_size) / | 195 bonus_allocation = (kMaximumAllocationForTabs - base_allocation_size) / |
| 175 stubs_with_surface_foreground.size(); | 196 stubs_with_surface_foreground.size(); |
| 197 #else | |
| 198 // On android, calculate bonus allocation based on surface size. | |
| 199 if (!stubs_with_surface_foreground.empty()) | |
| 200 bonus_allocation = CalculateBonusMemoryAllocationBasedOnSize( | |
| 201 stubs_with_surface_foreground[0]->GetSurfaceSize()); | |
| 202 #endif | |
| 176 | 203 |
| 177 // Now give out allocations to everyone. | 204 // Now give out allocations to everyone. |
| 178 AssignMemoryAllocations(stubs_with_surface_foreground, | 205 AssignMemoryAllocations(stubs_with_surface_foreground, |
| 179 GpuMemoryAllocation(kMinimumAllocationForTab + bonus_allocation, | 206 GpuMemoryAllocation(kMinimumAllocationForTab + bonus_allocation, |
| 180 GpuMemoryAllocation::kHasFrontbuffer | | 207 GpuMemoryAllocation::kHasFrontbuffer | |
| 181 GpuMemoryAllocation::kHasBackbuffer)); | 208 GpuMemoryAllocation::kHasBackbuffer)); |
| 182 | 209 |
| 183 AssignMemoryAllocations(stubs_with_surface_background, | 210 AssignMemoryAllocations(stubs_with_surface_background, |
| 184 GpuMemoryAllocation(0, GpuMemoryAllocation::kHasFrontbuffer)); | 211 GpuMemoryAllocation(0, GpuMemoryAllocation::kHasFrontbuffer)); |
| 185 | 212 |
| 186 AssignMemoryAllocations(stubs_with_surface_hibernated, | 213 AssignMemoryAllocations(stubs_with_surface_hibernated, |
| 187 GpuMemoryAllocation(0, GpuMemoryAllocation::kHasNoBuffers)); | 214 GpuMemoryAllocation(0, GpuMemoryAllocation::kHasNoBuffers)); |
| 188 | 215 |
| 189 AssignMemoryAllocations(stubs_without_surface_foreground, | 216 AssignMemoryAllocations(stubs_without_surface_foreground, |
| 190 GpuMemoryAllocation(kMinimumAllocationForTab, | 217 GpuMemoryAllocation(kMinimumAllocationForTab, |
| 191 GpuMemoryAllocation::kHasNoBuffers)); | 218 GpuMemoryAllocation::kHasNoBuffers)); |
| 192 | 219 |
| 193 AssignMemoryAllocations(stubs_without_surface_background, | 220 AssignMemoryAllocations(stubs_without_surface_background, |
| 194 GpuMemoryAllocation(kMinimumAllocationForTab, | 221 GpuMemoryAllocation(kMinimumAllocationForTab, |
| 195 GpuMemoryAllocation::kHasNoBuffers)); | 222 GpuMemoryAllocation::kHasNoBuffers)); |
| 196 | 223 |
| 197 AssignMemoryAllocations(stubs_without_surface_hibernated, | 224 AssignMemoryAllocations(stubs_without_surface_hibernated, |
| 198 GpuMemoryAllocation(0, GpuMemoryAllocation::kHasNoBuffers)); | 225 GpuMemoryAllocation(0, GpuMemoryAllocation::kHasNoBuffers)); |
| 199 } | 226 } |
| 200 | 227 |
| 201 #endif | 228 #endif |
| OLD | NEW |