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

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

Issue 10854076: Add GPU memory tab to the task manager. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporate taskman feedback Created 8 years, 4 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 #ifndef CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ 5 #ifndef CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_
6 #define CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ 6 #define CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_
7 7
8 #if defined(ENABLE_GPU) 8 #if defined(ENABLE_GPU)
9 9
10 #include <set>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/basictypes.h" 13 #include "base/basictypes.h"
13 #include "base/cancelable_callback.h" 14 #include "base/cancelable_callback.h"
14 #include "base/hash_tables.h" 15 #include "base/hash_tables.h"
15 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
17 #include "base/process.h"
16 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
17 #include "content/common/gpu/gpu_memory_allocation.h" 19 #include "content/common/gpu/gpu_memory_allocation.h"
20 #include "content/public/common/gpu_info.h"
18 #include "ui/gfx/size.h" 21 #include "ui/gfx/size.h"
19 22
20 class GpuCommandBufferStubBase; 23 class GpuCommandBufferStubBase;
24 class GpuMemoryTrackingGroup;
21 25
22 #if defined(COMPILER_GCC) 26 #if defined(COMPILER_GCC)
23 namespace BASE_HASH_NAMESPACE { 27 namespace BASE_HASH_NAMESPACE {
24 template<> 28 template<>
25 struct hash<GpuCommandBufferStubBase*> { 29 struct hash<GpuCommandBufferStubBase*> {
26 size_t operator()(GpuCommandBufferStubBase* ptr) const { 30 size_t operator()(GpuCommandBufferStubBase* ptr) const {
27 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); 31 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
28 } 32 }
29 }; 33 };
30 } // namespace BASE_HASH_NAMESPACE 34 } // namespace BASE_HASH_NAMESPACE
(...skipping 25 matching lines...) Expand all
56 size_t max_surfaces_with_frontbuffer_soft_limit); 60 size_t max_surfaces_with_frontbuffer_soft_limit);
57 ~GpuMemoryManager(); 61 ~GpuMemoryManager();
58 62
59 // Schedule a Manage() call. If immediate is true, we PostTask without delay. 63 // Schedule a Manage() call. If immediate is true, we PostTask without delay.
60 // Otherwise PostDelayedTask using a CancelableClosure and allow multiple 64 // Otherwise PostDelayedTask using a CancelableClosure and allow multiple
61 // delayed calls to "queue" up. This way, we do not spam clients in certain 65 // delayed calls to "queue" up. This way, we do not spam clients in certain
62 // lower priority situations. An immediate schedule manage will cancel any 66 // lower priority situations. An immediate schedule manage will cancel any
63 // queued delayed manage. 67 // queued delayed manage.
64 void ScheduleManage(bool immediate); 68 void ScheduleManage(bool immediate);
65 69
70 // Retrieve GPU Resource consumption statistics for the task manager
71 void GetVidmemUsageStats(
72 content::GPUVidmemUsageStats& vidmem_usage_stats) const;
73
74 // Add and remove structures to track context groups' memory consumption
75 void AddTrackingGroup(GpuMemoryTrackingGroup* tracking_group);
76 void RemoveTrackingGroup(GpuMemoryTrackingGroup* tracking_group);
77
66 // Returns StubMemoryStat's for each GpuCommandBufferStubBase, which were 78 // Returns StubMemoryStat's for each GpuCommandBufferStubBase, which were
67 // assigned during the most recent call to Manage(). 79 // assigned during the most recent call to Manage().
68 // Useful for tracking the memory-allocation-related presumed state of the 80 // Useful for tracking the memory-allocation-related presumed state of the
69 // system, as seen by GpuMemoryManager. 81 // system, as seen by GpuMemoryManager.
70 typedef base::hash_map<GpuCommandBufferStubBase*, StubMemoryStat> 82 typedef base::hash_map<GpuCommandBufferStubBase*, StubMemoryStat>
71 StubMemoryStatMap; 83 StubMemoryStatMap;
72 const StubMemoryStatMap& stub_memory_stats_for_last_manage() const { 84 const StubMemoryStatMap& stub_memory_stats_for_last_manage() const {
73 return stub_memory_stats_for_last_manage_; 85 return stub_memory_stats_for_last_manage_;
74 } 86 }
75 87
76 // Track a change in memory allocated by any context 88 // Track a change in memory allocated by any context
77 void TrackMemoryAllocatedChange(size_t old_size, size_t new_size); 89 void TrackMemoryAllocatedChange(size_t old_size, size_t new_size);
78 90
79 private: 91 private:
80 friend class GpuMemoryManagerTest; 92 friend class GpuMemoryManagerTest;
81 93
82 void Manage(); 94 void Manage();
83 95
96 // The context groups' tracking structures
97 std::set<GpuMemoryTrackingGroup*> tracking_groups_;
98
84 size_t CalculateBonusMemoryAllocationBasedOnSize(gfx::Size size) const; 99 size_t CalculateBonusMemoryAllocationBasedOnSize(gfx::Size size) const;
85 100
86 size_t GetAvailableGpuMemory() const { 101 size_t GetAvailableGpuMemory() const {
87 return bytes_available_gpu_memory_; 102 return bytes_available_gpu_memory_;
88 } 103 }
89 104
90 // The minimum non-zero amount of memory that a tab may be assigned 105 // The minimum non-zero amount of memory that a tab may be assigned
91 size_t GetMinimumTabAllocation() const { 106 size_t GetMinimumTabAllocation() const {
92 #if defined(OS_ANDROID) 107 #if defined(OS_ANDROID)
93 return 32 * 1024 * 1024; 108 return 32 * 1024 * 1024;
(...skipping 20 matching lines...) Expand all
114 // The maximum amount of memory that may be allocated for GPU resources 129 // The maximum amount of memory that may be allocated for GPU resources
115 size_t bytes_available_gpu_memory_; 130 size_t bytes_available_gpu_memory_;
116 131
117 // The current total memory usage, and historical maximum memory usage 132 // The current total memory usage, and historical maximum memory usage
118 size_t bytes_allocated_current_; 133 size_t bytes_allocated_current_;
119 size_t bytes_allocated_historical_max_; 134 size_t bytes_allocated_historical_max_;
120 135
121 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager); 136 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager);
122 }; 137 };
123 138
139 // All decoders in a context group point to a single GpuMemoryTrackingGroup,
140 // which tracks GPU resource consumption for the entire context group.
141 class GpuMemoryTrackingGroup {
jam 2012/08/17 18:31:05 nit: put this in a separate file
ccameron 2012/08/17 20:52:55 Moved to gpu_memory_tracking.h. I still have the
142 public:
143 GpuMemoryTrackingGroup(base::ProcessId pid, GpuMemoryManager* memory_manager)
144 : pid_(pid),
145 size_(0),
146 memory_manager_(memory_manager) {
147 memory_manager_->AddTrackingGroup(this);
148 }
149 ~GpuMemoryTrackingGroup() {
150 memory_manager_->RemoveTrackingGroup(this);
151 }
152 void TrackMemoryAllocatedChange(size_t old_size, size_t new_size) {
153 if (old_size < new_size) {
154 size_t delta = new_size - old_size;
155 size_ += delta;
156 }
157 if (new_size < old_size) {
158 size_t delta = old_size - new_size;
159 DCHECK(size_ >= delta);
160 size_ -= delta;
161 }
162 memory_manager_->TrackMemoryAllocatedChange(old_size, new_size);
163 }
164 base::ProcessId GetPid() const {
165 return pid_;
166 }
167 size_t GetSize() const {
168 return size_;
169 }
170
171 private:
172 base::ProcessId pid_;
173 size_t size_;
174 GpuMemoryManager* memory_manager_;
175 };
176
124 #endif 177 #endif
125 178
126 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ 179 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698