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

Side by Side Diff: gpu/command_buffer/client/mapped_memory.h

Issue 23130004: Enforce a memory limit on MappedMemoryManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More code review feedback incorporated Created 7 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
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 GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ 5 #ifndef GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_
6 #define GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ 6 #define GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_
7 7
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "gpu/command_buffer/client/fenced_allocator.h" 9 #include "gpu/command_buffer/client/fenced_allocator.h"
10 #include "gpu/command_buffer/common/buffer.h" 10 #include "gpu/command_buffer/common/buffer.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 // Frees a block of memory, pending the passage of a token. That memory won't 72 // Frees a block of memory, pending the passage of a token. That memory won't
73 // be re-allocated until the token has passed through the command stream. 73 // be re-allocated until the token has passed through the command stream.
74 // 74 //
75 // Parameters: 75 // Parameters:
76 // pointer: the pointer to the memory block to free. 76 // pointer: the pointer to the memory block to free.
77 // token: the token value to wait for before re-using the memory. 77 // token: the token value to wait for before re-using the memory.
78 void FreePendingToken(void* pointer, unsigned int token) { 78 void FreePendingToken(void* pointer, unsigned int token) {
79 allocator_.FreePendingToken(pointer, token); 79 allocator_.FreePendingToken(pointer, token);
80 } 80 }
81 81
82 // Frees any blocks who's tokens have passed. 82 // Frees any blocks whose tokens have passed.
83 void FreeUnused() { 83 void FreeUnused() {
84 allocator_.FreeUnused(); 84 allocator_.FreeUnused();
85 } 85 }
86 86
87 // Returns true if pointer is in the range of this block. 87 // Returns true if pointer is in the range of this block.
88 bool IsInChunk(void* pointer) const { 88 bool IsInChunk(void* pointer) const {
89 return pointer >= shm_.ptr && 89 return pointer >= shm_.ptr &&
90 pointer < reinterpret_cast<const int8*>(shm_.ptr) + shm_.size; 90 pointer < reinterpret_cast<const int8*>(shm_.ptr) + shm_.size;
91 } 91 }
92 92
93 // Returns true of any memory in this chuck is in use. 93 // Returns true of any memory in this chunk is in use.
94 bool InUse() { 94 bool InUse() {
95 return allocator_.InUse(); 95 return allocator_.InUse();
96 } 96 }
97 97
98 private: 98 private:
99 int32 shm_id_; 99 int32 shm_id_;
100 gpu::Buffer shm_; 100 gpu::Buffer shm_;
101 FencedAllocatorWrapper allocator_; 101 FencedAllocatorWrapper allocator_;
102 102
103 DISALLOW_COPY_AND_ASSIGN(MemoryChunk); 103 DISALLOW_COPY_AND_ASSIGN(MemoryChunk);
104 }; 104 };
105 105
106 // Manages MemoryChucks. 106 // Manages MemoryChunks.
107 class GPU_EXPORT MappedMemoryManager { 107 class GPU_EXPORT MappedMemoryManager {
108 public: 108 public:
109 enum MemoryLimit {
110 kNoLimit = 0,
111 };
112
109 explicit MappedMemoryManager(CommandBufferHelper* helper); 113 explicit MappedMemoryManager(CommandBufferHelper* helper);
114 MappedMemoryManager(CommandBufferHelper* helper,
115 size_t memory_limit);
110 116
111 ~MappedMemoryManager(); 117 ~MappedMemoryManager();
112 118
113 unsigned int chunk_size_multiple() const { 119 unsigned int chunk_size_multiple() const {
114 return chunk_size_multiple_; 120 return chunk_size_multiple_;
115 } 121 }
116 122
117 void set_chunk_size_multiple(unsigned int multiple) { 123 void set_chunk_size_multiple(unsigned int multiple) {
118 chunk_size_multiple_ = multiple; 124 chunk_size_multiple_ = multiple;
119 } 125 }
(...skipping 19 matching lines...) Expand all
139 // 145 //
140 // Parameters: 146 // Parameters:
141 // pointer: the pointer to the memory block to free. 147 // pointer: the pointer to the memory block to free.
142 // token: the token value to wait for before re-using the memory. 148 // token: the token value to wait for before re-using the memory.
143 void FreePendingToken(void* pointer, int32 token); 149 void FreePendingToken(void* pointer, int32 token);
144 150
145 // Free Any Shared memory that is not in use. 151 // Free Any Shared memory that is not in use.
146 void FreeUnused(); 152 void FreeUnused();
147 153
148 // Used for testing 154 // Used for testing
149 size_t num_chunks() { 155 size_t num_chunks() const {
150 return chunks_.size(); 156 return chunks_.size();
151 } 157 }
152 158
159 // Used for testing
160 size_t allocated_memory() const {
161 return allocated_memory_;
162 }
163
153 private: 164 private:
154 typedef ScopedVector<MemoryChunk> MemoryChunkVector; 165 typedef ScopedVector<MemoryChunk> MemoryChunkVector;
155 166
156 // size a chunk is rounded up to. 167 // size a chunk is rounded up to.
157 unsigned int chunk_size_multiple_; 168 unsigned int chunk_size_multiple_;
158 CommandBufferHelper* helper_; 169 CommandBufferHelper* helper_;
159 MemoryChunkVector chunks_; 170 MemoryChunkVector chunks_;
171 size_t allocated_memory_;
172 size_t memory_limit_;
160 173
161 DISALLOW_COPY_AND_ASSIGN(MappedMemoryManager); 174 DISALLOW_COPY_AND_ASSIGN(MappedMemoryManager);
162 }; 175 };
163 176
164 } // namespace gpu 177 } // namespace gpu
165 178
166 #endif // GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ 179 #endif // GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_
167 180
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698