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 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 void GetVideoMemoryUsageStats( | 56 void GetVideoMemoryUsageStats( |
57 content::GPUVideoMemoryUsageStats* video_memory_usage_stats) const; | 57 content::GPUVideoMemoryUsageStats* video_memory_usage_stats) const; |
58 | 58 |
59 GpuMemoryManagerClientState* CreateClientState( | 59 GpuMemoryManagerClientState* CreateClientState( |
60 GpuMemoryManagerClient* client, bool has_surface, bool visible); | 60 GpuMemoryManagerClient* client, bool has_surface, bool visible); |
61 | 61 |
62 GpuMemoryTrackingGroup* CreateTrackingGroup( | 62 GpuMemoryTrackingGroup* CreateTrackingGroup( |
63 base::ProcessId pid, gpu::gles2::MemoryTracker* memory_tracker); | 63 base::ProcessId pid, gpu::gles2::MemoryTracker* memory_tracker); |
64 | 64 |
65 uint64 GetClientMemoryUsage(const GpuMemoryManagerClient* client) const; | 65 uint64 GetClientMemoryUsage(const GpuMemoryManagerClient* client) const; |
66 uint64 GetMaximumClientAllocation() const { | 66 |
67 return client_hard_limit_bytes_; | 67 // The maximum and minimum amount of memory that a client may be assigned. |
| 68 uint64 GetMaximumClientAllocation() const; |
| 69 uint64 GetMinimumClientAllocation() const { |
| 70 return bytes_minimum_per_client_; |
68 } | 71 } |
69 | 72 |
70 private: | 73 private: |
71 friend class GpuMemoryManagerTest; | 74 friend class GpuMemoryManagerTest; |
72 friend class GpuMemoryTrackingGroup; | 75 friend class GpuMemoryTrackingGroup; |
73 friend class GpuMemoryManagerClientState; | 76 friend class GpuMemoryManagerClientState; |
74 | 77 |
75 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, | 78 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, |
76 TestManageBasicFunctionality); | 79 TestManageBasicFunctionality); |
77 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, | 80 FRIEND_TEST_ALL_PREFIXES(GpuMemoryManagerTest, |
(...skipping 30 matching lines...) Expand all Loading... |
108 typedef std::map<gpu::gles2::MemoryTracker*, GpuMemoryTrackingGroup*> | 111 typedef std::map<gpu::gles2::MemoryTracker*, GpuMemoryTrackingGroup*> |
109 TrackingGroupMap; | 112 TrackingGroupMap; |
110 | 113 |
111 typedef std::list<GpuMemoryManagerClientState*> ClientStateList; | 114 typedef std::list<GpuMemoryManagerClientState*> ClientStateList; |
112 | 115 |
113 void Manage(); | 116 void Manage(); |
114 void SetClientsHibernatedState() const; | 117 void SetClientsHibernatedState() const; |
115 void AssignSurfacesAllocations(); | 118 void AssignSurfacesAllocations(); |
116 void AssignNonSurfacesAllocations(); | 119 void AssignNonSurfacesAllocations(); |
117 | 120 |
| 121 // Math helper function to compute the maximum value of cap such that |
| 122 // sum_i min(bytes[i], cap) <= bytes_sum_limit |
| 123 static uint64 ComputeCap(std::vector<uint64> bytes, uint64 bytes_sum_limit); |
| 124 |
| 125 // Compute the allocation for clients when visible and not visible. |
| 126 void ComputeVisibleSurfacesAllocations(); |
| 127 void DistributeRemainingMemoryToVisibleSurfaces(); |
| 128 |
| 129 // Compute the budget for a client. Allow at most bytes_above_required_cap |
| 130 // bytes above client_state's required level. Allow at most |
| 131 // bytes_above_minimum_cap bytes above client_state's minimum level. Allow |
| 132 // at most bytes_overall_cap bytes total. |
| 133 uint64 ComputeClientAllocationWhenVisible( |
| 134 GpuMemoryManagerClientState* client_state, |
| 135 uint64 bytes_above_required_cap, |
| 136 uint64 bytes_above_minimum_cap, |
| 137 uint64 bytes_overall_cap); |
| 138 |
118 // Update the amount of GPU memory we think we have in the system, based | 139 // Update the amount of GPU memory we think we have in the system, based |
119 // on what the stubs' contexts report. | 140 // on what the stubs' contexts report. |
120 void UpdateAvailableGpuMemory(); | 141 void UpdateAvailableGpuMemory(); |
| 142 void UpdateUnmanagedMemoryLimits(); |
| 143 |
| 144 // The amount of video memory which is available for allocation. |
| 145 uint64 GetAvailableGpuMemory() const; |
| 146 |
| 147 // Minimum value of available GPU memory, no matter how little the GPU |
| 148 // reports. This is the default value. |
| 149 uint64 GetDefaultAvailableGpuMemory() const; |
| 150 |
| 151 // Maximum cap on total GPU memory, no matter how much the GPU reports. |
| 152 uint64 GetMaximumTotalGpuMemory() const; |
| 153 |
| 154 // The default amount of memory that a client is assigned, if it has not |
| 155 // reported any memory usage stats yet. |
| 156 uint64 GetDefaultClientAllocation() const { |
| 157 return bytes_default_per_client_; |
| 158 } |
| 159 |
| 160 static uint64 CalcAvailableFromGpuTotal(uint64 total_gpu_memory); |
121 | 161 |
122 // Send memory usage stats to the browser process. | 162 // Send memory usage stats to the browser process. |
123 void SendUmaStatsToBrowser(); | 163 void SendUmaStatsToBrowser(); |
124 | 164 |
125 // Get the current number of bytes allocated. | 165 // Get the current number of bytes allocated. |
126 uint64 GetCurrentUsage() const { | 166 uint64 GetCurrentUsage() const { |
127 return bytes_allocated_managed_current_ + | 167 return bytes_allocated_managed_current_ + |
128 bytes_allocated_unmanaged_current_; | 168 bytes_allocated_unmanaged_current_; |
129 } | 169 } |
130 | 170 |
(...skipping 15 matching lines...) Expand all Loading... |
146 void OnDestroyClientState(GpuMemoryManagerClientState* client); | 186 void OnDestroyClientState(GpuMemoryManagerClientState* client); |
147 | 187 |
148 // Add or remove a client from its clients list (visible, nonvisible, or | 188 // Add or remove a client from its clients list (visible, nonvisible, or |
149 // nonsurface). When adding the client, add it to the front of the list. | 189 // nonsurface). When adding the client, add it to the front of the list. |
150 void AddClientToList(GpuMemoryManagerClientState* client_state); | 190 void AddClientToList(GpuMemoryManagerClientState* client_state); |
151 void RemoveClientFromList(GpuMemoryManagerClientState* client_state); | 191 void RemoveClientFromList(GpuMemoryManagerClientState* client_state); |
152 ClientStateList* GetClientList(GpuMemoryManagerClientState* client_state); | 192 ClientStateList* GetClientList(GpuMemoryManagerClientState* client_state); |
153 | 193 |
154 // Interfaces for testing | 194 // Interfaces for testing |
155 void TestingDisableScheduleManage() { disable_schedule_manage_ = true; } | 195 void TestingDisableScheduleManage() { disable_schedule_manage_ = true; } |
| 196 void TestingSetAvailableGpuMemory(uint64 bytes) { |
| 197 bytes_available_gpu_memory_ = bytes; |
| 198 bytes_available_gpu_memory_overridden_ = true; |
| 199 } |
| 200 |
| 201 void TestingSetMinimumClientAllocation(uint64 bytes) { |
| 202 bytes_minimum_per_client_ = bytes; |
| 203 } |
| 204 |
| 205 void TestingSetDefaultClientAllocation(uint64 bytes) { |
| 206 bytes_default_per_client_ = bytes; |
| 207 } |
| 208 |
| 209 void TestingSetUnmanagedLimitStep(uint64 bytes) { |
| 210 bytes_unmanaged_limit_step_ = bytes; |
| 211 } |
156 | 212 |
157 GpuChannelManager* channel_manager_; | 213 GpuChannelManager* channel_manager_; |
158 | 214 |
159 // A list of all visible and nonvisible clients, in most-recently-used | 215 // A list of all visible and nonvisible clients, in most-recently-used |
160 // order (most recently used is first). | 216 // order (most recently used is first). |
161 ClientStateList clients_visible_mru_; | 217 ClientStateList clients_visible_mru_; |
162 ClientStateList clients_nonvisible_mru_; | 218 ClientStateList clients_nonvisible_mru_; |
163 | 219 |
164 // A list of all clients that don't have a surface. | 220 // A list of all clients that don't have a surface. |
165 ClientStateList clients_nonsurface_; | 221 ClientStateList clients_nonsurface_; |
166 | 222 |
167 // All context groups' tracking structures | 223 // All context groups' tracking structures |
168 TrackingGroupMap tracking_groups_; | 224 TrackingGroupMap tracking_groups_; |
169 | 225 |
170 base::CancelableClosure delayed_manage_callback_; | 226 base::CancelableClosure delayed_manage_callback_; |
171 bool manage_immediate_scheduled_; | 227 bool manage_immediate_scheduled_; |
172 bool disable_schedule_manage_; | |
173 | 228 |
174 uint64 max_surfaces_with_frontbuffer_soft_limit_; | 229 uint64 max_surfaces_with_frontbuffer_soft_limit_; |
175 | 230 |
176 // The maximum amount of memory that may be allocated for a single client. | 231 // The priority cutoff used for all renderers. |
177 uint64 client_hard_limit_bytes_; | 232 gpu::MemoryAllocation::PriorityCutoff priority_cutoff_; |
| 233 |
| 234 // The maximum amount of memory that may be allocated for GPU resources |
| 235 uint64 bytes_available_gpu_memory_; |
| 236 bool bytes_available_gpu_memory_overridden_; |
| 237 |
| 238 // The minimum and default allocations for a single client. |
| 239 uint64 bytes_minimum_per_client_; |
| 240 uint64 bytes_default_per_client_; |
178 | 241 |
179 // The current total memory usage, and historical maximum memory usage | 242 // The current total memory usage, and historical maximum memory usage |
180 uint64 bytes_allocated_managed_current_; | 243 uint64 bytes_allocated_managed_current_; |
181 uint64 bytes_allocated_unmanaged_current_; | 244 uint64 bytes_allocated_unmanaged_current_; |
182 uint64 bytes_allocated_historical_max_; | 245 uint64 bytes_allocated_historical_max_; |
183 | 246 |
| 247 // If bytes_allocated_unmanaged_current_ leaves the interval [low_, high_), |
| 248 // then ScheduleManage to take the change into account. |
| 249 uint64 bytes_allocated_unmanaged_high_; |
| 250 uint64 bytes_allocated_unmanaged_low_; |
| 251 |
| 252 // Update bytes_allocated_unmanaged_low/high_ in intervals of step_. |
| 253 uint64 bytes_unmanaged_limit_step_; |
| 254 |
| 255 // Used to disable automatic changes to Manage() in testing. |
| 256 bool disable_schedule_manage_; |
| 257 |
184 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager); | 258 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager); |
185 }; | 259 }; |
186 | 260 |
187 } // namespace content | 261 } // namespace content |
188 | 262 |
189 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ | 263 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ |
OLD | NEW |