Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: content/common/gpu/gpu_memory_manager.cc

Issue 10801014: Add GetStubStats and related functions in GpuMemoryManager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Diff from master instead of local branch Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
(...skipping 30 matching lines...) Expand all
41 componentsPerPixel * bytesPerComponent; 41 componentsPerPixel * bytesPerComponent;
42 if (limit < GpuMemoryManager::kMinimumAllocationForTab) 42 if (limit < GpuMemoryManager::kMinimumAllocationForTab)
43 limit = GpuMemoryManager::kMinimumAllocationForTab; 43 limit = GpuMemoryManager::kMinimumAllocationForTab;
44 else if (limit > GpuMemoryManager::kMaximumAllocationForTabs) 44 else if (limit > GpuMemoryManager::kMaximumAllocationForTabs)
45 limit = GpuMemoryManager::kMaximumAllocationForTabs; 45 limit = GpuMemoryManager::kMaximumAllocationForTabs;
46 return limit - GpuMemoryManager::kMinimumAllocationForTab; 46 return limit - GpuMemoryManager::kMinimumAllocationForTab;
47 } 47 }
48 #endif 48 #endif
49 49
50 void AssignMemoryAllocations( 50 void AssignMemoryAllocations(
51 std::map<GpuCommandBufferStubBase*, GpuMemoryManager::StubMemoryStat>&
52 stub_memory_stats,
piman 2012/07/18 19:59:58 nit: Passing parameters by non-const references is
51 std::vector<GpuCommandBufferStubBase*>& stubs, 53 std::vector<GpuCommandBufferStubBase*>& stubs,
52 GpuMemoryAllocation allocation) { 54 GpuMemoryAllocation allocation,
55 bool visible) {
53 for (std::vector<GpuCommandBufferStubBase*>::iterator it = stubs.begin(); 56 for (std::vector<GpuCommandBufferStubBase*>::iterator it = stubs.begin();
54 it != stubs.end(); ++it) { 57 it != stubs.end(); ++it) {
55 (*it)->SetMemoryAllocation(allocation); 58 (*it)->SetMemoryAllocation(allocation);
59 stub_memory_stats[*it].allocation = allocation;
60 stub_memory_stats[*it].visible = visible;
56 } 61 }
57 } 62 }
58 63
59 } 64 }
60 65
61 GpuMemoryManager::GpuMemoryManager(GpuMemoryManagerClient* client, 66 GpuMemoryManager::GpuMemoryManager(GpuMemoryManagerClient* client,
62 size_t max_surfaces_with_frontbuffer_soft_limit) 67 size_t max_surfaces_with_frontbuffer_soft_limit)
63 : client_(client), 68 : client_(client),
64 manage_immediate_scheduled_(false), 69 manage_immediate_scheduled_(false),
65 max_surfaces_with_frontbuffer_soft_limit_( 70 max_surfaces_with_frontbuffer_soft_limit_(
66 max_surfaces_with_frontbuffer_soft_limit) { 71 max_surfaces_with_frontbuffer_soft_limit),
72 peak_assigned_allocation_sum_(0) {
67 } 73 }
68 74
69 GpuMemoryManager::~GpuMemoryManager() { 75 GpuMemoryManager::~GpuMemoryManager() {
70 } 76 }
71 77
72 bool GpuMemoryManager::StubWithSurfaceComparator::operator()( 78 bool GpuMemoryManager::StubWithSurfaceComparator::operator()(
73 GpuCommandBufferStubBase* lhs, 79 GpuCommandBufferStubBase* lhs,
74 GpuCommandBufferStubBase* rhs) { 80 GpuCommandBufferStubBase* rhs) {
75 DCHECK(lhs->has_surface_state() && rhs->has_surface_state()); 81 DCHECK(lhs->has_surface_state() && rhs->has_surface_state());
76 const GpuCommandBufferStubBase::SurfaceState& lhs_ss = lhs->surface_state(); 82 const GpuCommandBufferStubBase::SurfaceState& lhs_ss = lhs->surface_state();
(...skipping 19 matching lines...) Expand all
96 return; 102 return;
97 delayed_manage_callback_.Reset(base::Bind(&GpuMemoryManager::Manage, 103 delayed_manage_callback_.Reset(base::Bind(&GpuMemoryManager::Manage,
98 AsWeakPtr())); 104 AsWeakPtr()));
99 MessageLoop::current()->PostDelayedTask( 105 MessageLoop::current()->PostDelayedTask(
100 FROM_HERE, 106 FROM_HERE,
101 delayed_manage_callback_.callback(), 107 delayed_manage_callback_.callback(),
102 base::TimeDelta::FromMilliseconds(kDelayedScheduleManageTimeoutMs)); 108 base::TimeDelta::FromMilliseconds(kDelayedScheduleManageTimeoutMs));
103 } 109 }
104 } 110 }
105 111
112 size_t GpuMemoryManager::GetAvailableGpuMemory() const {
113 // TODO(mmocny): Implement this with real system figures.
114 return kMaximumAllocationForTabs;
115 }
116
106 // The current Manage algorithm simply classifies contexts (stubs) into 117 // The current Manage algorithm simply classifies contexts (stubs) into
107 // "foreground", "background", or "hibernated" categories. 118 // "foreground", "background", or "hibernated" categories.
108 // For each of these three categories, there are predefined memory allocation 119 // For each of these three categories, there are predefined memory allocation
109 // limits and front/backbuffer states. 120 // limits and front/backbuffer states.
110 // 121 //
111 // Stubs may or may not have a surfaces, and the rules are different for each. 122 // Stubs may or may not have a surfaces, and the rules are different for each.
112 // 123 //
113 // The rules for categorizing contexts with a surface are: 124 // The rules for categorizing contexts with a surface are:
114 // 1. Foreground: All visible surfaces. 125 // 1. Foreground: All visible surfaces.
115 // * Must have both front and back buffer. 126 // * Must have both front and back buffer.
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 !stubs_with_surface_foreground.empty()) 220 !stubs_with_surface_foreground.empty())
210 bonus_allocation = (kMaximumAllocationForTabs - base_allocation_size) / 221 bonus_allocation = (kMaximumAllocationForTabs - base_allocation_size) /
211 stubs_with_surface_foreground.size(); 222 stubs_with_surface_foreground.size();
212 #else 223 #else
213 // On android, calculate bonus allocation based on surface size. 224 // On android, calculate bonus allocation based on surface size.
214 if (!stubs_with_surface_foreground.empty()) 225 if (!stubs_with_surface_foreground.empty())
215 bonus_allocation = CalculateBonusMemoryAllocationBasedOnSize( 226 bonus_allocation = CalculateBonusMemoryAllocationBasedOnSize(
216 stubs_with_surface_foreground[0]->GetSurfaceSize()); 227 stubs_with_surface_foreground[0]->GetSurfaceSize());
217 #endif 228 #endif
218 229
230 stub_memory_stats_.clear();
231
219 // Now give out allocations to everyone. 232 // Now give out allocations to everyone.
220 AssignMemoryAllocations(stubs_with_surface_foreground, 233 AssignMemoryAllocations(stub_memory_stats_,
piman 2012/07/18 19:59:58 nit: correct style is either Function(param1,
234 stubs_with_surface_foreground,
221 GpuMemoryAllocation(kMinimumAllocationForTab + bonus_allocation, 235 GpuMemoryAllocation(kMinimumAllocationForTab + bonus_allocation,
222 GpuMemoryAllocation::kHasFrontbuffer | 236 GpuMemoryAllocation::kHasFrontbuffer |
223 GpuMemoryAllocation::kHasBackbuffer)); 237 GpuMemoryAllocation::kHasBackbuffer),
238 true);
224 239
225 AssignMemoryAllocations(stubs_with_surface_background, 240 AssignMemoryAllocations(stub_memory_stats_,
226 GpuMemoryAllocation(0, GpuMemoryAllocation::kHasFrontbuffer)); 241 stubs_with_surface_background,
242 GpuMemoryAllocation(0, GpuMemoryAllocation::kHasFrontbuffer),
243 false);
227 244
228 AssignMemoryAllocations(stubs_with_surface_hibernated, 245 AssignMemoryAllocations(stub_memory_stats_,
229 GpuMemoryAllocation(0, GpuMemoryAllocation::kHasNoBuffers)); 246 stubs_with_surface_hibernated,
247 GpuMemoryAllocation(0, GpuMemoryAllocation::kHasNoBuffers),
248 false);
230 249
231 AssignMemoryAllocations(stubs_without_surface_foreground, 250 AssignMemoryAllocations(stub_memory_stats_,
251 stubs_without_surface_foreground,
232 GpuMemoryAllocation(kMinimumAllocationForTab, 252 GpuMemoryAllocation(kMinimumAllocationForTab,
233 GpuMemoryAllocation::kHasNoBuffers)); 253 GpuMemoryAllocation::kHasNoBuffers),
254 true);
234 255
235 AssignMemoryAllocations(stubs_without_surface_background, 256 AssignMemoryAllocations(stub_memory_stats_,
257 stubs_without_surface_background,
236 GpuMemoryAllocation(kMinimumAllocationForTab, 258 GpuMemoryAllocation(kMinimumAllocationForTab,
237 GpuMemoryAllocation::kHasNoBuffers)); 259 GpuMemoryAllocation::kHasNoBuffers),
260 false);
238 261
239 AssignMemoryAllocations(stubs_without_surface_hibernated, 262 AssignMemoryAllocations(stub_memory_stats_,
240 GpuMemoryAllocation(0, GpuMemoryAllocation::kHasNoBuffers)); 263 stubs_without_surface_hibernated,
264 GpuMemoryAllocation(0, GpuMemoryAllocation::kHasNoBuffers),
265 false);
266
267 size_t assigned_allocation_sum = 0;
268 for (std::map<GpuCommandBufferStubBase*, StubMemoryStat>::iterator
269 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
270 assigned_allocation_sum += it->second.allocation.gpu_resource_size_in_bytes;
271 }
272
273 if (assigned_allocation_sum > peak_assigned_allocation_sum_)
274 peak_assigned_allocation_sum_ = assigned_allocation_sum;
275
piman 2012/07/18 19:59:58 nit: unnecessary empty line.
241 } 276 }
242 277
243 #endif 278 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698