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

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

Issue 216673006: Revert 260177 "By keeping track of transfer buffer usage (both s..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 9 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
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/bind.h"
9 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
10 #include "gpu/command_buffer/client/fenced_allocator.h" 9 #include "gpu/command_buffer/client/fenced_allocator.h"
11 #include "gpu/command_buffer/common/buffer.h" 10 #include "gpu/command_buffer/common/buffer.h"
12 #include "gpu/command_buffer/common/types.h" 11 #include "gpu/command_buffer/common/types.h"
13 #include "gpu/gpu_export.h" 12 #include "gpu/gpu_export.h"
14 13
15 namespace gpu { 14 namespace gpu {
16 15
17 class CommandBufferHelper; 16 class CommandBufferHelper;
18 17
19 // Manages a shared memory segment. 18 // Manages a shared memory segment.
20 class GPU_EXPORT MemoryChunk { 19 class GPU_EXPORT MemoryChunk {
21 public: 20 public:
22 MemoryChunk(int32 shm_id, 21 MemoryChunk(int32 shm_id,
23 scoped_refptr<gpu::Buffer> shm, 22 scoped_refptr<gpu::Buffer> shm,
24 CommandBufferHelper* helper, 23 CommandBufferHelper* helper);
25 const base::Closure& poll_callback);
26 ~MemoryChunk(); 24 ~MemoryChunk();
27 25
28 // Gets the size of the largest free block that is available without waiting. 26 // Gets the size of the largest free block that is available without waiting.
29 unsigned int GetLargestFreeSizeWithoutWaiting() { 27 unsigned int GetLargestFreeSizeWithoutWaiting() {
30 return allocator_.GetLargestFreeSize(); 28 return allocator_.GetLargestFreeSize();
31 } 29 }
32 30
33 // Gets the size of the largest free block that can be allocated if the 31 // Gets the size of the largest free block that can be allocated if the
34 // caller can wait. 32 // caller can wait.
35 unsigned int GetLargestFreeSizeWithWaiting() { 33 unsigned int GetLargestFreeSizeWithWaiting() {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // Manages MemoryChunks. 114 // Manages MemoryChunks.
117 class GPU_EXPORT MappedMemoryManager { 115 class GPU_EXPORT MappedMemoryManager {
118 public: 116 public:
119 enum MemoryLimit { 117 enum MemoryLimit {
120 kNoLimit = 0, 118 kNoLimit = 0,
121 }; 119 };
122 120
123 // |unused_memory_reclaim_limit|: When exceeded this causes pending memory 121 // |unused_memory_reclaim_limit|: When exceeded this causes pending memory
124 // to be reclaimed before allocating more memory. 122 // to be reclaimed before allocating more memory.
125 MappedMemoryManager(CommandBufferHelper* helper, 123 MappedMemoryManager(CommandBufferHelper* helper,
126 const base::Closure& poll_callback,
127 size_t unused_memory_reclaim_limit); 124 size_t unused_memory_reclaim_limit);
128 125
129 ~MappedMemoryManager(); 126 ~MappedMemoryManager();
130 127
131 unsigned int chunk_size_multiple() const { 128 unsigned int chunk_size_multiple() const {
132 return chunk_size_multiple_; 129 return chunk_size_multiple_;
133 } 130 }
134 131
135 void set_chunk_size_multiple(unsigned int multiple) { 132 void set_chunk_size_multiple(unsigned int multiple) {
136 chunk_size_multiple_ = multiple; 133 chunk_size_multiple_ = multiple;
(...skipping 24 matching lines...) Expand all
161 void FreePendingToken(void* pointer, int32 token); 158 void FreePendingToken(void* pointer, int32 token);
162 159
163 // Free Any Shared memory that is not in use. 160 // Free Any Shared memory that is not in use.
164 void FreeUnused(); 161 void FreeUnused();
165 162
166 // Used for testing 163 // Used for testing
167 size_t num_chunks() const { 164 size_t num_chunks() const {
168 return chunks_.size(); 165 return chunks_.size();
169 } 166 }
170 167
171 size_t bytes_in_use() const {
172 size_t bytes_in_use = 0;
173 for (size_t ii = 0; ii < chunks_.size(); ++ii) {
174 MemoryChunk* chunk = chunks_[ii];
175 bytes_in_use += chunk->bytes_in_use();
176 }
177 return bytes_in_use;
178 }
179
180 // Used for testing 168 // Used for testing
181 size_t allocated_memory() const { 169 size_t allocated_memory() const {
182 return allocated_memory_; 170 return allocated_memory_;
183 } 171 }
184 172
185 private: 173 private:
186 typedef ScopedVector<MemoryChunk> MemoryChunkVector; 174 typedef ScopedVector<MemoryChunk> MemoryChunkVector;
187 175
188 // size a chunk is rounded up to. 176 // size a chunk is rounded up to.
189 unsigned int chunk_size_multiple_; 177 unsigned int chunk_size_multiple_;
190 CommandBufferHelper* helper_; 178 CommandBufferHelper* helper_;
191 base::Closure poll_callback_;
192 MemoryChunkVector chunks_; 179 MemoryChunkVector chunks_;
193 size_t allocated_memory_; 180 size_t allocated_memory_;
194 size_t max_free_bytes_; 181 size_t max_free_bytes_;
195 182
196 DISALLOW_COPY_AND_ASSIGN(MappedMemoryManager); 183 DISALLOW_COPY_AND_ASSIGN(MappedMemoryManager);
197 }; 184 };
198 185
199 } // namespace gpu 186 } // namespace gpu
200 187
201 #endif // GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ 188 #endif // GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_
202 189
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698