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

Side by Side Diff: content/common/gpu/gpu_memory_manager.h

Issue 10823092: Add a flag to specify the amount of total GPU memory available. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unnecessary #if-ANDROID lines 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
« no previous file with comments | « no previous file | content/common/gpu/gpu_memory_manager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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/hash_tables.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "content/common/content_export.h" 16 #include "content/common/content_export.h"
17 #include "content/common/gpu/gpu_memory_allocation.h" 17 #include "content/common/gpu/gpu_memory_allocation.h"
18 #include "ui/gfx/size.h"
18 19
19 class GpuCommandBufferStubBase; 20 class GpuCommandBufferStubBase;
20 21
21 #if defined(COMPILER_GCC) 22 #if defined(COMPILER_GCC)
22 namespace BASE_HASH_NAMESPACE { 23 namespace BASE_HASH_NAMESPACE {
23 template<> 24 template<>
24 struct hash<GpuCommandBufferStubBase*> { 25 struct hash<GpuCommandBufferStubBase*> {
25 size_t operator()(GpuCommandBufferStubBase* ptr) const { 26 size_t operator()(GpuCommandBufferStubBase* ptr) const {
26 return hash<size_t>()(reinterpret_cast<size_t>(ptr)); 27 return hash<size_t>()(reinterpret_cast<size_t>(ptr));
27 } 28 }
28 }; 29 };
29 } // namespace BASE_HASH_NAMESPACE 30 } // namespace BASE_HASH_NAMESPACE
30 #endif // COMPILER 31 #endif // COMPILER
31 32
32 class CONTENT_EXPORT GpuMemoryManagerClient { 33 class CONTENT_EXPORT GpuMemoryManagerClient {
33 public: 34 public:
34 virtual ~GpuMemoryManagerClient() {} 35 virtual ~GpuMemoryManagerClient() {}
35 36
36 virtual void AppendAllCommandBufferStubs( 37 virtual void AppendAllCommandBufferStubs(
37 std::vector<GpuCommandBufferStubBase*>& stubs) = 0; 38 std::vector<GpuCommandBufferStubBase*>& stubs) = 0;
38 }; 39 };
39 40
40 class CONTENT_EXPORT GpuMemoryManager : 41 class CONTENT_EXPORT GpuMemoryManager :
41 public base::SupportsWeakPtr<GpuMemoryManager> { 42 public base::SupportsWeakPtr<GpuMemoryManager> {
42 public: 43 public:
43 enum { kDefaultMaxSurfacesWithFrontbufferSoftLimit = 8 }; 44 enum { kDefaultMaxSurfacesWithFrontbufferSoftLimit = 8 };
44 45
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 46
62 // StubMemoryStat is used to store memory-allocation-related information about 47 // StubMemoryStat is used to store memory-allocation-related information about
63 // a GpuCommandBufferStubBase for some time point. 48 // a GpuCommandBufferStubBase for some time point.
64 struct StubMemoryStat { 49 struct StubMemoryStat {
65 bool visible; 50 bool visible;
66 GpuMemoryAllocationRequest requested_allocation; 51 GpuMemoryAllocationRequest requested_allocation;
67 GpuMemoryAllocation allocation; 52 GpuMemoryAllocation allocation;
68 }; 53 };
69 54
70 GpuMemoryManager(GpuMemoryManagerClient* client, 55 GpuMemoryManager(GpuMemoryManagerClient* client,
(...skipping 10 matching lines...) Expand all
81 // Returns StubMemoryStat's for each GpuCommandBufferStubBase, which were 66 // Returns StubMemoryStat's for each GpuCommandBufferStubBase, which were
82 // assigned during the most recent call to Manage(). 67 // assigned during the most recent call to Manage().
83 // Useful for tracking the memory-allocation-related presumed state of the 68 // Useful for tracking the memory-allocation-related presumed state of the
84 // system, as seen by GpuMemoryManager. 69 // system, as seen by GpuMemoryManager.
85 typedef base::hash_map<GpuCommandBufferStubBase*, StubMemoryStat> 70 typedef base::hash_map<GpuCommandBufferStubBase*, StubMemoryStat>
86 StubMemoryStatMap; 71 StubMemoryStatMap;
87 const StubMemoryStatMap& stub_memory_stats_for_last_manage() const { 72 const StubMemoryStatMap& stub_memory_stats_for_last_manage() const {
88 return stub_memory_stats_for_last_manage_; 73 return stub_memory_stats_for_last_manage_;
89 } 74 }
90 75
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 76 // Track a change in memory allocated by any context
97 void TrackMemoryAllocatedChange(size_t old_size, size_t new_size); 77 void TrackMemoryAllocatedChange(size_t old_size, size_t new_size);
98 78
99
100 private: 79 private:
101 friend class GpuMemoryManagerTest; 80 friend class GpuMemoryManagerTest;
81
102 void Manage(); 82 void Manage();
103 83
84 size_t CalculateBonusMemoryAllocationBasedOnSize(gfx::Size size) const;
85
86 size_t GetAvailableGpuMemory() const {
87 return bytes_available_gpu_memory_;
88 }
89
90 // The minimum non-zero amount of memory that a tab may be assigned
91 size_t GetMinimumTabAllocation() const {
92 #if defined(OS_ANDROID)
93 return 32 * 1024 * 1024;
94 #else
95 return 64 * 1024 * 1024;
96 #endif
97 }
98
104 class CONTENT_EXPORT StubWithSurfaceComparator { 99 class CONTENT_EXPORT StubWithSurfaceComparator {
105 public: 100 public:
106 bool operator()(GpuCommandBufferStubBase* lhs, 101 bool operator()(GpuCommandBufferStubBase* lhs,
107 GpuCommandBufferStubBase* rhs); 102 GpuCommandBufferStubBase* rhs);
108 }; 103 };
109 104
110 GpuMemoryManagerClient* client_; 105 GpuMemoryManagerClient* client_;
111 106
112 base::CancelableClosure delayed_manage_callback_; 107 base::CancelableClosure delayed_manage_callback_;
113 bool manage_immediate_scheduled_; 108 bool manage_immediate_scheduled_;
114 109
115 size_t max_surfaces_with_frontbuffer_soft_limit_; 110 size_t max_surfaces_with_frontbuffer_soft_limit_;
116 111
117 StubMemoryStatMap stub_memory_stats_for_last_manage_; 112 StubMemoryStatMap stub_memory_stats_for_last_manage_;
118 113
114 // The maximum amount of memory that may be allocated for GPU resources
115 size_t bytes_available_gpu_memory_;
116
119 // The current total memory usage, and historical maximum memory usage 117 // The current total memory usage, and historical maximum memory usage
120 size_t bytes_allocated_current_; 118 size_t bytes_allocated_current_;
121 size_t bytes_allocated_historical_max_; 119 size_t bytes_allocated_historical_max_;
122 120
123 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager); 121 DISALLOW_COPY_AND_ASSIGN(GpuMemoryManager);
124 }; 122 };
125 123
126 #endif 124 #endif
127 125
128 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_ 126 #endif // CONTENT_COMMON_GPU_GPU_MEMORY_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | content/common/gpu/gpu_memory_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698