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 #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 <set> |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 void RemoveClient(GpuMemoryManagerClient* client); | 70 void RemoveClient(GpuMemoryManagerClient* client); |
71 void SetClientVisible(GpuMemoryManagerClient* client, bool visible); | 71 void SetClientVisible(GpuMemoryManagerClient* client, bool visible); |
72 void SetClientManagedMemoryStats(GpuMemoryManagerClient* client, | 72 void SetClientManagedMemoryStats(GpuMemoryManagerClient* client, |
73 const GpuManagedMemoryStats& stats); | 73 const GpuManagedMemoryStats& stats); |
74 | 74 |
75 // Add and remove structures to track context groups' memory consumption | 75 // Add and remove structures to track context groups' memory consumption |
76 void AddTrackingGroup(GpuMemoryTrackingGroup* tracking_group); | 76 void AddTrackingGroup(GpuMemoryTrackingGroup* tracking_group); |
77 void RemoveTrackingGroup(GpuMemoryTrackingGroup* tracking_group); | 77 void RemoveTrackingGroup(GpuMemoryTrackingGroup* tracking_group); |
78 | 78 |
79 // Track a change in memory allocated by any context | 79 // Track a change in memory allocated by any context |
80 void TrackMemoryAllocatedChange(size_t old_size, size_t new_size); | 80 void TrackMemoryAllocatedChange( |
| 81 size_t old_size, |
| 82 size_t new_size, |
| 83 gpu::gles2::MemoryTracker::Pool tracking_pool); |
81 | 84 |
82 private: | 85 private: |
83 friend class GpuMemoryManagerTest; | 86 friend class GpuMemoryManagerTest; |
84 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, | 87 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, |
85 ComparatorTests); | 88 ComparatorTests); |
86 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, | 89 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, |
87 TestManageBasicFunctionality); | 90 TestManageBasicFunctionality); |
88 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, | 91 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, |
89 TestManageChangingVisibility); | 92 TestManageChangingVisibility); |
90 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, | 93 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 size_t GetMaximumTabAllocation() const; | 171 size_t GetMaximumTabAllocation() const; |
169 size_t GetMinimumTabAllocation() const; | 172 size_t GetMinimumTabAllocation() const; |
170 | 173 |
171 // Get a reasonable memory limit from a viewport's surface area. | 174 // Get a reasonable memory limit from a viewport's surface area. |
172 static size_t CalcAvailableFromViewportArea(int viewport_area); | 175 static size_t CalcAvailableFromViewportArea(int viewport_area); |
173 static size_t CalcAvailableFromGpuTotal(size_t total_gpu_memory); | 176 static size_t CalcAvailableFromGpuTotal(size_t total_gpu_memory); |
174 | 177 |
175 // Send memory usage stats to the browser process. | 178 // Send memory usage stats to the browser process. |
176 void SendUmaStatsToBrowser(); | 179 void SendUmaStatsToBrowser(); |
177 | 180 |
| 181 // Get the current number of bytes allocated. |
| 182 size_t GetCurrentUsage() const { |
| 183 return bytes_allocated_managed_current_ + |
| 184 bytes_allocated_unmanaged_current_; |
| 185 } |
| 186 |
178 // Interfaces for testing | 187 // Interfaces for testing |
179 void TestingSetClientVisible(GpuMemoryManagerClient* client, bool visible); | 188 void TestingSetClientVisible(GpuMemoryManagerClient* client, bool visible); |
180 void TestingSetClientLastUsedTime(GpuMemoryManagerClient* client, | 189 void TestingSetClientLastUsedTime(GpuMemoryManagerClient* client, |
181 base::TimeTicks last_used_time); | 190 base::TimeTicks last_used_time); |
182 void TestingSetClientHasSurface(GpuMemoryManagerClient* client, | 191 void TestingSetClientHasSurface(GpuMemoryManagerClient* client, |
183 bool has_surface); | 192 bool has_surface); |
184 bool TestingCompareClients(GpuMemoryManagerClient* lhs, | 193 bool TestingCompareClients(GpuMemoryManagerClient* lhs, |
185 GpuMemoryManagerClient* rhs) const; | 194 GpuMemoryManagerClient* rhs) const; |
186 void TestingDisableScheduleManage() { disable_schedule_manage_ = true; } | 195 void TestingDisableScheduleManage() { disable_schedule_manage_ = true; } |
187 void TestingSetAvailableGpuMemory(size_t bytes) { | 196 void TestingSetAvailableGpuMemory(size_t bytes) { |
(...skipping 21 matching lines...) Expand all Loading... |
209 | 218 |
210 // The maximum amount of memory that may be allocated for GPU resources | 219 // The maximum amount of memory that may be allocated for GPU resources |
211 size_t bytes_available_gpu_memory_; | 220 size_t bytes_available_gpu_memory_; |
212 bool bytes_available_gpu_memory_overridden_; | 221 bool bytes_available_gpu_memory_overridden_; |
213 | 222 |
214 // The maximum amount of memory that can be allocated for GPU resources | 223 // The maximum amount of memory that can be allocated for GPU resources |
215 // in backgrounded renderers. | 224 // in backgrounded renderers. |
216 size_t bytes_backgrounded_available_gpu_memory_; | 225 size_t bytes_backgrounded_available_gpu_memory_; |
217 | 226 |
218 // The current total memory usage, and historical maximum memory usage | 227 // The current total memory usage, and historical maximum memory usage |
219 size_t bytes_allocated_current_; | 228 size_t bytes_allocated_managed_current_; |
220 size_t bytes_allocated_managed_visible_; | 229 size_t bytes_allocated_managed_visible_; |
221 size_t bytes_allocated_managed_backgrounded_; | 230 size_t bytes_allocated_managed_backgrounded_; |
| 231 size_t bytes_allocated_unmanaged_current_; |
222 size_t bytes_allocated_historical_max_; | 232 size_t bytes_allocated_historical_max_; |
223 | 233 |
224 // The number of browser windows that exist. If we ever receive a | 234 // The number of browser windows that exist. If we ever receive a |
225 // GpuMsg_SetVideoMemoryWindowCount, then we use this to compute memory | 235 // GpuMsg_SetVideoMemoryWindowCount, then we use this to compute memory |
226 // budgets, instead of doing more complicated stub-based calculations. | 236 // budgets, instead of doing more complicated stub-based calculations. |
227 bool window_count_has_been_received_; | 237 bool window_count_has_been_received_; |
228 uint32 window_count_; | 238 uint32 window_count_; |
229 | 239 |
230 // Used to disable automatic changes to Manage() in testing. | 240 // Used to disable automatic changes to Manage() in testing. |
231 bool disable_schedule_manage_; | 241 bool disable_schedule_manage_; |
(...skipping 19 matching lines...) Expand all Loading... |
251 // context is currently rendering on. Returns false if no extension exists | 261 // context is currently rendering on. Returns false if no extension exists |
252 // to get the exact amount of GPU memory. | 262 // to get the exact amount of GPU memory. |
253 virtual bool GetTotalGpuMemory(size_t* bytes) = 0; | 263 virtual bool GetTotalGpuMemory(size_t* bytes) = 0; |
254 }; | 264 }; |
255 | 265 |
256 } // namespace content | 266 } // namespace content |
257 | 267 |
258 #endif | 268 #endif |
259 | 269 |
260 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ | 270 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ |
OLD | NEW |