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> |
(...skipping 24 matching lines...) Expand all Loading... |
35 | 35 |
36 virtual void AppendAllCommandBufferStubs( | 36 virtual void AppendAllCommandBufferStubs( |
37 std::vector<GpuCommandBufferStubBase*>& stubs) = 0; | 37 std::vector<GpuCommandBufferStubBase*>& stubs) = 0; |
38 }; | 38 }; |
39 | 39 |
40 class CONTENT_EXPORT GpuMemoryManager : | 40 class CONTENT_EXPORT GpuMemoryManager : |
41 public base::SupportsWeakPtr<GpuMemoryManager> { | 41 public base::SupportsWeakPtr<GpuMemoryManager> { |
42 public: | 42 public: |
43 enum { kDefaultMaxSurfacesWithFrontbufferSoftLimit = 8 }; | 43 enum { kDefaultMaxSurfacesWithFrontbufferSoftLimit = 8 }; |
44 | 44 |
45 // These are predefined values (in bytes) for | |
46 // GpuMemoryAllocation::gpuResourceSizeInBytes. | |
47 // Maximum Allocation for all tabs is a soft limit that can be exceeded | |
48 // during the time it takes for renderers to respect new allocations, | |
49 // including when switching tabs or opening a new window. | |
50 // To alleviate some pressure, we decrease our desired limit by "one tabs' | |
51 // worth" of memory. | |
52 enum { | |
53 #if defined(OS_ANDROID) | |
54 kMinimumAllocationForTab = 32 * 1024 * 1024, | |
55 kMaximumAllocationForTabs = 64 * 1024 * 1024, | |
56 #else | |
57 kMinimumAllocationForTab = 64 * 1024 * 1024, | |
58 kMaximumAllocationForTabs = 512 * 1024 * 1024 - kMinimumAllocationForTab, | |
59 #endif | |
60 }; | |
61 | 45 |
62 // StubMemoryStat is used to store memory-allocation-related information about | 46 // StubMemoryStat is used to store memory-allocation-related information about |
63 // a GpuCommandBufferStubBase for some time point. | 47 // a GpuCommandBufferStubBase for some time point. |
64 struct StubMemoryStat { | 48 struct StubMemoryStat { |
65 bool visible; | 49 bool visible; |
66 GpuMemoryAllocationRequest requested_allocation; | 50 GpuMemoryAllocationRequest requested_allocation; |
67 GpuMemoryAllocation allocation; | 51 GpuMemoryAllocation allocation; |
68 }; | 52 }; |
69 | 53 |
70 GpuMemoryManager(GpuMemoryManagerClient* client, | 54 GpuMemoryManager(GpuMemoryManagerClient* client, |
(...skipping 10 matching lines...) Expand all Loading... |
81 // Returns StubMemoryStat's for each GpuCommandBufferStubBase, which were | 65 // Returns StubMemoryStat's for each GpuCommandBufferStubBase, which were |
82 // assigned during the most recent call to Manage(). | 66 // assigned during the most recent call to Manage(). |
83 // Useful for tracking the memory-allocation-related presumed state of the | 67 // Useful for tracking the memory-allocation-related presumed state of the |
84 // system, as seen by GpuMemoryManager. | 68 // system, as seen by GpuMemoryManager. |
85 typedef base::hash_map<GpuCommandBufferStubBase*, StubMemoryStat> | 69 typedef base::hash_map<GpuCommandBufferStubBase*, StubMemoryStat> |
86 StubMemoryStatMap; | 70 StubMemoryStatMap; |
87 const StubMemoryStatMap& stub_memory_stats_for_last_manage() const { | 71 const StubMemoryStatMap& stub_memory_stats_for_last_manage() const { |
88 return stub_memory_stats_for_last_manage_; | 72 return stub_memory_stats_for_last_manage_; |
89 } | 73 } |
90 | 74 |
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 // Track a change in memory allocated by any context | 75 // Track a change in memory allocated by any context |
97 void TrackMemoryAllocatedChange(size_t old_size, size_t new_size); | 76 void TrackMemoryAllocatedChange(size_t old_size, size_t new_size); |
98 | 77 |
99 | |
100 private: | 78 private: |
101 friend class GpuMemoryManagerTest; | 79 friend class GpuMemoryManagerTest; |
| 80 |
102 void Manage(); | 81 void Manage(); |
103 | 82 |
| 83 #if defined(OS_ANDROID) |
| 84 size_t CalculateBonusMemoryAllocationBasedOnSize(gfx::Size size) const; |
| 85 #endif |
| 86 |
| 87 size_t GetAvailableGpuMemory() const { |
| 88 return bytes_available_gpu_memory_; |
| 89 } |
| 90 |
| 91 // The minimum non-zero amount of memory that a tab may be assigned |
| 92 size_t GetMinimumTabAllocation() const { |
| 93 #if defined(OS_ANDROID) |
| 94 return 32 * 1024 * 1024; |
| 95 #else |
| 96 return 64 * 1024 * 1024; |
| 97 #endif |
| 98 } |
| 99 |
104 class CONTENT_EXPORT StubWithSurfaceComparator { | 100 class CONTENT_EXPORT StubWithSurfaceComparator { |
105 public: | 101 public: |
106 bool operator()(GpuCommandBufferStubBase* lhs, | 102 bool operator()(GpuCommandBufferStubBase* lhs, |
107 GpuCommandBufferStubBase* rhs); | 103 GpuCommandBufferStubBase* rhs); |
108 }; | 104 }; |
109 | 105 |
110 GpuMemoryManagerClient* client_; | 106 GpuMemoryManagerClient* client_; |
111 | 107 |
112 base::CancelableClosure delayed_manage_callback_; | 108 base::CancelableClosure delayed_manage_callback_; |
113 bool manage_immediate_scheduled_; | 109 bool manage_immediate_scheduled_; |
114 | 110 |
115 size_t max_surfaces_with_frontbuffer_soft_limit_; | 111 size_t max_surfaces_with_frontbuffer_soft_limit_; |
116 | 112 |
117 StubMemoryStatMap stub_memory_stats_for_last_manage_; | 113 StubMemoryStatMap stub_memory_stats_for_last_manage_; |
118 | 114 |
| 115 // The maximum amount of memory that may be allocated for GPU resources |
| 116 size_t bytes_available_gpu_memory_; |
| 117 |
119 // The current total memory usage, and historical maximum memory usage | 118 // The current total memory usage, and historical maximum memory usage |
120 size_t bytes_allocated_current_; | 119 size_t bytes_allocated_current_; |
121 size_t bytes_allocated_historical_max_; | 120 size_t bytes_allocated_historical_max_; |
122 | 121 |
123 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager); | 122 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager); |
124 }; | 123 }; |
125 | 124 |
126 #endif | 125 #endif |
127 | 126 |
128 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ | 127 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ |
OLD | NEW |