Chromium Code Reviews| 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 <vector> | 10 #include <vector> |
| 11 #include <map> | |
| 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/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 15 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
| 17 #include "content/common/gpu/gpu_memory_allocation.h" | |
| 16 | 18 |
| 17 class GpuCommandBufferStubBase; | 19 class GpuCommandBufferStubBase; |
| 18 | 20 |
| 19 class CONTENT_EXPORT GpuMemoryManagerClient { | 21 class CONTENT_EXPORT GpuMemoryManagerClient { |
| 20 public: | 22 public: |
| 21 virtual ~GpuMemoryManagerClient() {} | 23 virtual ~GpuMemoryManagerClient() {} |
| 22 | 24 |
| 23 virtual void AppendAllCommandBufferStubs( | 25 virtual void AppendAllCommandBufferStubs( |
| 24 std::vector<GpuCommandBufferStubBase*>& stubs) = 0; | 26 std::vector<GpuCommandBufferStubBase*>& stubs) = 0; |
| 25 }; | 27 }; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 39 enum { | 41 enum { |
| 40 #if defined(OS_ANDROID) | 42 #if defined(OS_ANDROID) |
| 41 kMinimumAllocationForTab = 32 * 1024 * 1024, | 43 kMinimumAllocationForTab = 32 * 1024 * 1024, |
| 42 kMaximumAllocationForTabs = 64 * 1024 * 1024, | 44 kMaximumAllocationForTabs = 64 * 1024 * 1024, |
| 43 #else | 45 #else |
| 44 kMinimumAllocationForTab = 64 * 1024 * 1024, | 46 kMinimumAllocationForTab = 64 * 1024 * 1024, |
| 45 kMaximumAllocationForTabs = 512 * 1024 * 1024 - kMinimumAllocationForTab, | 47 kMaximumAllocationForTabs = 512 * 1024 * 1024 - kMinimumAllocationForTab, |
| 46 #endif | 48 #endif |
| 47 }; | 49 }; |
| 48 | 50 |
| 51 // StubMemoryStat is used to store memory-allocation-related information about | |
| 52 // a GpuCommandBufferStubBase for some time point. | |
| 53 struct StubMemoryStat { | |
| 54 bool visible; | |
| 55 GpuMemoryAllocationRequest requested_allocation; | |
| 56 GpuMemoryAllocation allocation; | |
| 57 }; | |
| 58 | |
| 49 GpuMemoryManager(GpuMemoryManagerClient* client, | 59 GpuMemoryManager(GpuMemoryManagerClient* client, |
| 50 size_t max_surfaces_with_frontbuffer_soft_limit); | 60 size_t max_surfaces_with_frontbuffer_soft_limit); |
| 51 ~GpuMemoryManager(); | 61 ~GpuMemoryManager(); |
| 52 | 62 |
| 53 // 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. |
| 54 // Otherwise PostDelayedTask using a CancelableClosure and allow multiple | 64 // Otherwise PostDelayedTask using a CancelableClosure and allow multiple |
| 55 // 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 |
| 56 // lower priority situations. An immediate schedule manage will cancel any | 66 // lower priority situations. An immediate schedule manage will cancel any |
| 57 // queued delayed manage. | 67 // queued delayed manage. |
| 58 void ScheduleManage(bool immediate); | 68 void ScheduleManage(bool immediate); |
| 59 | 69 |
| 70 // Returns StubMemoryStat's for each GpuCommandBufferStubBase, which were | |
| 71 // assigned during the most recent call to Manage(). | |
| 72 // Useful for tracking the memory-allocation-related presumed state of the | |
| 73 // system, as seen by GpuMemoryManager. | |
| 74 std::map<GpuCommandBufferStubBase*, StubMemoryStat> | |
|
piman
2012/07/18 19:59:58
I suggest returning const std::map<...>& to avoid
| |
| 75 GetStubStatsForLastManage() const { | |
| 76 return stub_memory_stats_; | |
| 77 } | |
| 78 | |
| 79 // Tries to estimate the total available gpu memory for use by | |
| 80 // GpuMemoryManager. Ideally should consider other system applications and | |
| 81 // other internal but non GpuMemoryManager managed sources, etc. | |
| 82 size_t GetAvailableGpuMemory() const; | |
| 83 | |
| 84 // GetPeakAssignedAllocationSum() will return the historical max value for the | |
| 85 // sum of all assigned client allocations (ie, peak system memory allocation). | |
| 86 size_t GetPeakAssignedAllocationSum() const { | |
|
piman
2012/07/18 19:59:58
nit: usually for trivial inline functions that jus
| |
| 87 return peak_assigned_allocation_sum_; | |
| 88 } | |
| 89 | |
| 60 private: | 90 private: |
| 61 friend class GpuMemoryManagerTest; | 91 friend class GpuMemoryManagerTest; |
| 62 void Manage(); | 92 void Manage(); |
| 63 | 93 |
| 64 class CONTENT_EXPORT StubWithSurfaceComparator { | 94 class CONTENT_EXPORT StubWithSurfaceComparator { |
| 65 public: | 95 public: |
| 66 bool operator()(GpuCommandBufferStubBase* lhs, | 96 bool operator()(GpuCommandBufferStubBase* lhs, |
| 67 GpuCommandBufferStubBase* rhs); | 97 GpuCommandBufferStubBase* rhs); |
| 68 }; | 98 }; |
| 69 | 99 |
| 70 GpuMemoryManagerClient* client_; | 100 GpuMemoryManagerClient* client_; |
| 71 | 101 |
| 72 base::CancelableClosure delayed_manage_callback_; | 102 base::CancelableClosure delayed_manage_callback_; |
| 73 bool manage_immediate_scheduled_; | 103 bool manage_immediate_scheduled_; |
| 74 | 104 |
| 75 size_t max_surfaces_with_frontbuffer_soft_limit_; | 105 size_t max_surfaces_with_frontbuffer_soft_limit_; |
| 76 | 106 |
| 107 std::map<GpuCommandBufferStubBase*, StubMemoryStat> stub_memory_stats_; | |
| 108 size_t peak_assigned_allocation_sum_; | |
| 109 | |
| 77 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager); | 110 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager); |
| 78 }; | 111 }; |
| 79 | 112 |
| 80 #endif | 113 #endif |
| 81 | 114 |
| 82 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ | 115 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ |
| OLD | NEW |