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

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 review 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"
16 #include "content/common/content_export.h" 17 #include "content/common/content_export.h"
17 #include "content/common/gpu/gpu_memory_allocation.h" 18 #include "content/common/gpu/gpu_memory_allocation.h"
19 #include "content/public/common/gpu_memory_stats.h"
18 #include "ui/gfx/size.h" 20 #include "ui/gfx/size.h"
19 21
20 class GpuCommandBufferStubBase; 22 class GpuCommandBufferStubBase;
23 class GpuMemoryTrackingGroup;
21 24
22 #if defined(COMPILER_GCC) 25 #if defined(COMPILER_GCC)
23 namespace BASE_HASH_NAMESPACE { 26 namespace BASE_HASH_NAMESPACE {
24 template<> 27 template<>
25 struct hash<GpuCommandBufferStubBase*> { 28 struct hash<GpuCommandBufferStubBase*> {
26 size_t operator()(GpuCommandBufferStubBase* ptr) const { 29 size_t operator()(GpuCommandBufferStubBase* ptr) const {
27 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); 30 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
28 } 31 }
29 }; 32 };
30 } // namespace BASE_HASH_NAMESPACE 33 } // namespace BASE_HASH_NAMESPACE
(...skipping 25 matching lines...) Expand all
56 size_t max_surfaces_with_frontbuffer_soft_limit); 59 size_t max_surfaces_with_frontbuffer_soft_limit);
57 ~GpuMemoryManager(); 60 ~GpuMemoryManager();
58 61
59 // Schedule a Manage() call. If immediate is true, we PostTask without delay. 62 // Schedule a Manage() call. If immediate is true, we PostTask without delay.
60 // Otherwise PostDelayedTask using a CancelableClosure and allow multiple 63 // Otherwise PostDelayedTask using a CancelableClosure and allow multiple
61 // delayed calls to "queue" up. This way, we do not spam clients in certain 64 // 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 65 // lower priority situations. An immediate schedule manage will cancel any
63 // queued delayed manage. 66 // queued delayed manage.
64 void ScheduleManage(bool immediate); 67 void ScheduleManage(bool immediate);
65 68
69 // Retrieve GPU Resource consumption statistics for the task manager
70 void GetVideoMemoryUsageStats(
71 content::GPUVideoMemoryUsageStats& video_memory_usage_stats) const;
72
73 // Add and remove structures to track context groups' memory consumption
74 void AddTrackingGroup(GpuMemoryTrackingGroup* tracking_group);
75 void RemoveTrackingGroup(GpuMemoryTrackingGroup* tracking_group);
76
66 // Returns StubMemoryStat's for each GpuCommandBufferStubBase, which were 77 // Returns StubMemoryStat's for each GpuCommandBufferStubBase, which were
67 // assigned during the most recent call to Manage(). 78 // assigned during the most recent call to Manage().
68 // Useful for tracking the memory-allocation-related presumed state of the 79 // Useful for tracking the memory-allocation-related presumed state of the
69 // system, as seen by GpuMemoryManager. 80 // system, as seen by GpuMemoryManager.
70 typedef base::hash_map<GpuCommandBufferStubBase*, StubMemoryStat> 81 typedef base::hash_map<GpuCommandBufferStubBase*, StubMemoryStat>
71 StubMemoryStatMap; 82 StubMemoryStatMap;
72 const StubMemoryStatMap& stub_memory_stats_for_last_manage() const { 83 const StubMemoryStatMap& stub_memory_stats_for_last_manage() const {
73 return stub_memory_stats_for_last_manage_; 84 return stub_memory_stats_for_last_manage_;
74 } 85 }
75 86
76 // Track a change in memory allocated by any context 87 // Track a change in memory allocated by any context
77 void TrackMemoryAllocatedChange(size_t old_size, size_t new_size); 88 void TrackMemoryAllocatedChange(size_t old_size, size_t new_size);
78 89
79 private: 90 private:
80 friend class GpuMemoryManagerTest; 91 friend class GpuMemoryManagerTest;
81 92
82 void Manage(); 93 void Manage();
83 94
95 // The context groups' tracking structures
96 std::set<GpuMemoryTrackingGroup*> tracking_groups_;
97
84 size_t CalculateBonusMemoryAllocationBasedOnSize(gfx::Size size) const; 98 size_t CalculateBonusMemoryAllocationBasedOnSize(gfx::Size size) const;
85 99
86 size_t GetAvailableGpuMemory() const { 100 size_t GetAvailableGpuMemory() const {
87 return bytes_available_gpu_memory_; 101 return bytes_available_gpu_memory_;
88 } 102 }
89 103
90 // The minimum non-zero amount of memory that a tab may be assigned 104 // The minimum non-zero amount of memory that a tab may be assigned
91 size_t GetMinimumTabAllocation() const { 105 size_t GetMinimumTabAllocation() const {
92 #if defined(OS_ANDROID) 106 #if defined(OS_ANDROID)
93 return 32 * 1024 * 1024; 107 return 32 * 1024 * 1024;
(...skipping 23 matching lines...) Expand all
117 // The current total memory usage, and historical maximum memory usage 131 // The current total memory usage, and historical maximum memory usage
118 size_t bytes_allocated_current_; 132 size_t bytes_allocated_current_;
119 size_t bytes_allocated_historical_max_; 133 size_t bytes_allocated_historical_max_;
120 134
121 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager); 135 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager);
122 }; 136 };
123 137
124 #endif 138 #endif
125 139
126 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ 140 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698