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

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

Issue 268063002: Remove command_buffer/common/types.h. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 6 years, 7 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 <stdint.h>
9
8 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/macros.h"
9 #include "base/memory/scoped_vector.h" 12 #include "base/memory/scoped_vector.h"
10 #include "gpu/command_buffer/client/fenced_allocator.h" 13 #include "gpu/command_buffer/client/fenced_allocator.h"
11 #include "gpu/command_buffer/common/buffer.h" 14 #include "gpu/command_buffer/common/buffer.h"
12 #include "gpu/command_buffer/common/types.h"
13 #include "gpu/gpu_export.h" 15 #include "gpu/gpu_export.h"
14 16
15 namespace gpu { 17 namespace gpu {
16 18
17 class CommandBufferHelper; 19 class CommandBufferHelper;
18 20
19 // Manages a shared memory segment. 21 // Manages a shared memory segment.
20 class GPU_EXPORT MemoryChunk { 22 class GPU_EXPORT MemoryChunk {
21 public: 23 public:
22 MemoryChunk(int32 shm_id, 24 MemoryChunk(int32_t shm_id,
23 scoped_refptr<gpu::Buffer> shm, 25 scoped_refptr<gpu::Buffer> shm,
24 CommandBufferHelper* helper, 26 CommandBufferHelper* helper,
25 const base::Closure& poll_callback); 27 const base::Closure& poll_callback);
26 ~MemoryChunk(); 28 ~MemoryChunk();
27 29
28 // Gets the size of the largest free block that is available without waiting. 30 // Gets the size of the largest free block that is available without waiting.
29 unsigned int GetLargestFreeSizeWithoutWaiting() { 31 unsigned int GetLargestFreeSizeWithoutWaiting() {
30 return allocator_.GetLargestFreeSize(); 32 return allocator_.GetLargestFreeSize();
31 } 33 }
32 34
33 // Gets the size of the largest free block that can be allocated if the 35 // Gets the size of the largest free block that can be allocated if the
34 // caller can wait. 36 // caller can wait.
35 unsigned int GetLargestFreeSizeWithWaiting() { 37 unsigned int GetLargestFreeSizeWithWaiting() {
36 return allocator_.GetLargestFreeOrPendingSize(); 38 return allocator_.GetLargestFreeOrPendingSize();
37 } 39 }
38 40
39 // Gets the size of the chunk. 41 // Gets the size of the chunk.
40 unsigned int GetSize() const { 42 unsigned int GetSize() const {
41 return static_cast<unsigned int>(shm_->size()); 43 return static_cast<unsigned int>(shm_->size());
42 } 44 }
43 45
44 // The shared memory id for this chunk. 46 // The shared memory id for this chunk.
45 int32 shm_id() const { 47 int32_t shm_id() const {
46 return shm_id_; 48 return shm_id_;
47 } 49 }
48 50
49 // Allocates a block of memory. If the buffer is out of directly available 51 // Allocates a block of memory. If the buffer is out of directly available
50 // memory, this function may wait until memory that was freed "pending a 52 // memory, this function may wait until memory that was freed "pending a
51 // token" can be re-used. 53 // token" can be re-used.
52 // 54 //
53 // Parameters: 55 // Parameters:
54 // size: the size of the memory block to allocate. 56 // size: the size of the memory block to allocate.
55 // 57 //
(...skipping 30 matching lines...) Expand all
86 88
87 // Frees any blocks whose tokens have passed. 89 // Frees any blocks whose tokens have passed.
88 void FreeUnused() { 90 void FreeUnused() {
89 allocator_.FreeUnused(); 91 allocator_.FreeUnused();
90 } 92 }
91 93
92 // Returns true if pointer is in the range of this block. 94 // Returns true if pointer is in the range of this block.
93 bool IsInChunk(void* pointer) const { 95 bool IsInChunk(void* pointer) const {
94 return pointer >= shm_->memory() && 96 return pointer >= shm_->memory() &&
95 pointer < 97 pointer <
96 reinterpret_cast<const int8*>(shm_->memory()) + shm_->size(); 98 reinterpret_cast<const int8_t*>(shm_->memory()) + shm_->size();
97 } 99 }
98 100
99 // Returns true of any memory in this chunk is in use. 101 // Returns true of any memory in this chunk is in use.
100 bool InUse() { 102 bool InUse() {
101 return allocator_.InUse(); 103 return allocator_.InUse();
102 } 104 }
103 105
104 size_t bytes_in_use() const { 106 size_t bytes_in_use() const {
105 return allocator_.bytes_in_use(); 107 return allocator_.bytes_in_use();
106 } 108 }
107 109
108 private: 110 private:
109 int32 shm_id_; 111 int32_t shm_id_;
110 scoped_refptr<gpu::Buffer> shm_; 112 scoped_refptr<gpu::Buffer> shm_;
111 FencedAllocatorWrapper allocator_; 113 FencedAllocatorWrapper allocator_;
112 114
113 DISALLOW_COPY_AND_ASSIGN(MemoryChunk); 115 DISALLOW_COPY_AND_ASSIGN(MemoryChunk);
114 }; 116 };
115 117
116 // Manages MemoryChunks. 118 // Manages MemoryChunks.
117 class GPU_EXPORT MappedMemoryManager { 119 class GPU_EXPORT MappedMemoryManager {
118 public: 120 public:
119 enum MemoryLimit { 121 enum MemoryLimit {
(...skipping 17 matching lines...) Expand all
137 } 139 }
138 140
139 // Allocates a block of memory 141 // Allocates a block of memory
140 // Parameters: 142 // Parameters:
141 // size: size of memory to allocate. 143 // size: size of memory to allocate.
142 // shm_id: pointer to variable to receive the shared memory id. 144 // shm_id: pointer to variable to receive the shared memory id.
143 // shm_offset: pointer to variable to receive the shared memory offset. 145 // shm_offset: pointer to variable to receive the shared memory offset.
144 // Returns: 146 // Returns:
145 // pointer to allocated block of memory. NULL if failure. 147 // pointer to allocated block of memory. NULL if failure.
146 void* Alloc( 148 void* Alloc(
147 unsigned int size, int32* shm_id, unsigned int* shm_offset); 149 unsigned int size, int32_t* shm_id, unsigned int* shm_offset);
148 150
149 // Frees a block of memory. 151 // Frees a block of memory.
150 // 152 //
151 // Parameters: 153 // Parameters:
152 // pointer: the pointer to the memory block to free. 154 // pointer: the pointer to the memory block to free.
153 void Free(void* pointer); 155 void Free(void* pointer);
154 156
155 // Frees a block of memory, pending the passage of a token. That memory won't 157 // Frees a block of memory, pending the passage of a token. That memory won't
156 // be re-allocated until the token has passed through the command stream. 158 // be re-allocated until the token has passed through the command stream.
157 // 159 //
158 // Parameters: 160 // Parameters:
159 // pointer: the pointer to the memory block to free. 161 // pointer: the pointer to the memory block to free.
160 // token: the token value to wait for before re-using the memory. 162 // token: the token value to wait for before re-using the memory.
161 void FreePendingToken(void* pointer, int32 token); 163 void FreePendingToken(void* pointer, int32_t token);
162 164
163 // Free Any Shared memory that is not in use. 165 // Free Any Shared memory that is not in use.
164 void FreeUnused(); 166 void FreeUnused();
165 167
166 // Used for testing 168 // Used for testing
167 size_t num_chunks() const { 169 size_t num_chunks() const {
168 return chunks_.size(); 170 return chunks_.size();
169 } 171 }
170 172
171 size_t bytes_in_use() const { 173 size_t bytes_in_use() const {
(...skipping 21 matching lines...) Expand all
193 size_t allocated_memory_; 195 size_t allocated_memory_;
194 size_t max_free_bytes_; 196 size_t max_free_bytes_;
195 197
196 DISALLOW_COPY_AND_ASSIGN(MappedMemoryManager); 198 DISALLOW_COPY_AND_ASSIGN(MappedMemoryManager);
197 }; 199 };
198 200
199 } // namespace gpu 201 } // namespace gpu
200 202
201 #endif // GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_ 203 #endif // GPU_COMMAND_BUFFER_CLIENT_MAPPED_MEMORY_H_
202 204
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698