| 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 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/cancelable_callback.h" | 13 #include "base/cancelable_callback.h" |
| 14 #include "base/hash_tables.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 |
| 21 #if defined(COMPILER_GCC) |
| 22 namespace BASE_HASH_NAMESPACE { |
| 23 template<> |
| 24 struct hash<GpuCommandBufferStubBase*> { |
| 25 size_t operator()(GpuCommandBufferStubBase* ptr) const { |
| 26 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); |
| 27 } |
| 28 }; |
| 29 } // namespace BASE_HASH_NAMESPACE |
| 30 #endif // COMPILER |
| 31 |
| 19 class CONTENT_EXPORT GpuMemoryManagerClient { | 32 class CONTENT_EXPORT GpuMemoryManagerClient { |
| 20 public: | 33 public: |
| 21 virtual ~GpuMemoryManagerClient() {} | 34 virtual ~GpuMemoryManagerClient() {} |
| 22 | 35 |
| 23 virtual void AppendAllCommandBufferStubs( | 36 virtual void AppendAllCommandBufferStubs( |
| 24 std::vector<GpuCommandBufferStubBase*>& stubs) = 0; | 37 std::vector<GpuCommandBufferStubBase*>& stubs) = 0; |
| 25 }; | 38 }; |
| 26 | 39 |
| 27 class CONTENT_EXPORT GpuMemoryManager : | 40 class CONTENT_EXPORT GpuMemoryManager : |
| 28 public base::SupportsWeakPtr<GpuMemoryManager> { | 41 public base::SupportsWeakPtr<GpuMemoryManager> { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 39 enum { | 52 enum { |
| 40 #if defined(OS_ANDROID) | 53 #if defined(OS_ANDROID) |
| 41 kMinimumAllocationForTab = 32 * 1024 * 1024, | 54 kMinimumAllocationForTab = 32 * 1024 * 1024, |
| 42 kMaximumAllocationForTabs = 64 * 1024 * 1024, | 55 kMaximumAllocationForTabs = 64 * 1024 * 1024, |
| 43 #else | 56 #else |
| 44 kMinimumAllocationForTab = 64 * 1024 * 1024, | 57 kMinimumAllocationForTab = 64 * 1024 * 1024, |
| 45 kMaximumAllocationForTabs = 512 * 1024 * 1024 - kMinimumAllocationForTab, | 58 kMaximumAllocationForTabs = 512 * 1024 * 1024 - kMinimumAllocationForTab, |
| 46 #endif | 59 #endif |
| 47 }; | 60 }; |
| 48 | 61 |
| 62 // StubMemoryStat is used to store memory-allocation-related information about |
| 63 // a GpuCommandBufferStubBase for some time point. |
| 64 struct StubMemoryStat { |
| 65 bool visible; |
| 66 GpuMemoryAllocationRequest requested_allocation; |
| 67 GpuMemoryAllocation allocation; |
| 68 }; |
| 69 |
| 49 GpuMemoryManager(GpuMemoryManagerClient* client, | 70 GpuMemoryManager(GpuMemoryManagerClient* client, |
| 50 size_t max_surfaces_with_frontbuffer_soft_limit); | 71 size_t max_surfaces_with_frontbuffer_soft_limit); |
| 51 ~GpuMemoryManager(); | 72 ~GpuMemoryManager(); |
| 52 | 73 |
| 53 // Schedule a Manage() call. If immediate is true, we PostTask without delay. | 74 // Schedule a Manage() call. If immediate is true, we PostTask without delay. |
| 54 // Otherwise PostDelayedTask using a CancelableClosure and allow multiple | 75 // Otherwise PostDelayedTask using a CancelableClosure and allow multiple |
| 55 // delayed calls to "queue" up. This way, we do not spam clients in certain | 76 // 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 | 77 // lower priority situations. An immediate schedule manage will cancel any |
| 57 // queued delayed manage. | 78 // queued delayed manage. |
| 58 void ScheduleManage(bool immediate); | 79 void ScheduleManage(bool immediate); |
| 59 | 80 |
| 81 // Returns StubMemoryStat's for each GpuCommandBufferStubBase, which were |
| 82 // assigned during the most recent call to Manage(). |
| 83 // Useful for tracking the memory-allocation-related presumed state of the |
| 84 // system, as seen by GpuMemoryManager. |
| 85 typedef base::hash_map<GpuCommandBufferStubBase*, StubMemoryStat> |
| 86 StubMemoryStatMap; |
| 87 const StubMemoryStatMap& stub_memory_stats_for_last_manage() const { |
| 88 return stub_memory_stats_for_last_manage_; |
| 89 } |
| 90 |
| 91 // Tries to estimate the total available gpu memory for use by |
| 92 // GpuMemoryManager. Ideally should consider other system applications and |
| 93 // other internal but non GpuMemoryManager managed sources, etc. |
| 94 size_t GetAvailableGpuMemory() const; |
| 95 |
| 96 // GetPeakAssignedAllocationSum() will return the historical max value for the |
| 97 // sum of all assigned client allocations (ie, peak system memory allocation). |
| 98 size_t peak_assigned_allocation_sum() const { |
| 99 return peak_assigned_allocation_sum_; |
| 100 } |
| 101 |
| 60 private: | 102 private: |
| 61 friend class GpuMemoryManagerTest; | 103 friend class GpuMemoryManagerTest; |
| 62 void Manage(); | 104 void Manage(); |
| 63 | 105 |
| 64 class CONTENT_EXPORT StubWithSurfaceComparator { | 106 class CONTENT_EXPORT StubWithSurfaceComparator { |
| 65 public: | 107 public: |
| 66 bool operator()(GpuCommandBufferStubBase* lhs, | 108 bool operator()(GpuCommandBufferStubBase* lhs, |
| 67 GpuCommandBufferStubBase* rhs); | 109 GpuCommandBufferStubBase* rhs); |
| 68 }; | 110 }; |
| 69 | 111 |
| 70 GpuMemoryManagerClient* client_; | 112 GpuMemoryManagerClient* client_; |
| 71 | 113 |
| 72 base::CancelableClosure delayed_manage_callback_; | 114 base::CancelableClosure delayed_manage_callback_; |
| 73 bool manage_immediate_scheduled_; | 115 bool manage_immediate_scheduled_; |
| 74 | 116 |
| 75 size_t max_surfaces_with_frontbuffer_soft_limit_; | 117 size_t max_surfaces_with_frontbuffer_soft_limit_; |
| 76 | 118 |
| 119 StubMemoryStatMap stub_memory_stats_for_last_manage_; |
| 120 size_t peak_assigned_allocation_sum_; |
| 121 |
| 77 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager); | 122 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager); |
| 78 }; | 123 }; |
| 79 | 124 |
| 80 #endif | 125 #endif |
| 81 | 126 |
| 82 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ | 127 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ |
| OLD | NEW |