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 // This file contains the definition of the FencedAllocator class. | 5 // This file contains the definition of the FencedAllocator class. |
6 | 6 |
7 #ifndef GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ | 7 #ifndef GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ |
8 #define GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ | 8 #define GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ |
9 | 9 |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 22 matching lines...) Expand all Loading... |
33 public: | 33 public: |
34 typedef unsigned int Offset; | 34 typedef unsigned int Offset; |
35 // Invalid offset, returned by Alloc in case of failure. | 35 // Invalid offset, returned by Alloc in case of failure. |
36 static const Offset kInvalidOffset = 0xffffffffU; | 36 static const Offset kInvalidOffset = 0xffffffffU; |
37 | 37 |
38 // Allocation alignment, must be a power of two. | 38 // Allocation alignment, must be a power of two. |
39 static const unsigned int kAllocAlignment = 16; | 39 static const unsigned int kAllocAlignment = 16; |
40 | 40 |
41 // Creates a FencedAllocator. Note that the size of the buffer is passed, but | 41 // Creates a FencedAllocator. Note that the size of the buffer is passed, but |
42 // not its base address: everything is handled as offsets into the buffer. | 42 // not its base address: everything is handled as offsets into the buffer. |
43 FencedAllocator(unsigned int size, | 43 FencedAllocator(unsigned int size, CommandBufferHelper* helper); |
44 CommandBufferHelper *helper, | |
45 const base::Closure& poll_callback); | |
46 | 44 |
47 ~FencedAllocator(); | 45 ~FencedAllocator(); |
48 | 46 |
49 // Allocates a block of memory. If the buffer is out of directly available | 47 // 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 | 48 // memory, this function may wait until memory that was freed "pending a |
51 // token" can be re-used. | 49 // token" can be re-used. |
52 // | 50 // |
53 // Parameters: | 51 // Parameters: |
54 // size: the size of the memory block to allocate. | 52 // size: the size of the memory block to allocate. |
55 // | 53 // |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 BlockIndex WaitForTokenAndFreeBlock(BlockIndex index); | 137 BlockIndex WaitForTokenAndFreeBlock(BlockIndex index); |
140 | 138 |
141 // Allocates a block of memory inside a given block, splitting it in two | 139 // Allocates a block of memory inside a given block, splitting it in two |
142 // (unless that block is of the exact requested size). | 140 // (unless that block is of the exact requested size). |
143 // NOTE: this will invalidate block indices. | 141 // NOTE: this will invalidate block indices. |
144 // Returns the offset of the allocated block (NOTE: this is different from | 142 // Returns the offset of the allocated block (NOTE: this is different from |
145 // the other functions that return a block index). | 143 // the other functions that return a block index). |
146 Offset AllocInBlock(BlockIndex index, unsigned int size); | 144 Offset AllocInBlock(BlockIndex index, unsigned int size); |
147 | 145 |
148 CommandBufferHelper *helper_; | 146 CommandBufferHelper *helper_; |
149 base::Closure poll_callback_; | |
150 Container blocks_; | 147 Container blocks_; |
151 size_t bytes_in_use_; | 148 size_t bytes_in_use_; |
152 | 149 |
153 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocator); | 150 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocator); |
154 }; | 151 }; |
155 | 152 |
156 // This class functions just like FencedAllocator, but its API uses pointers | 153 // This class functions just like FencedAllocator, but its API uses pointers |
157 // instead of offsets. | 154 // instead of offsets. |
158 class FencedAllocatorWrapper { | 155 class FencedAllocatorWrapper { |
159 public: | 156 public: |
160 FencedAllocatorWrapper(unsigned int size, | 157 FencedAllocatorWrapper(unsigned int size, |
161 CommandBufferHelper* helper, | 158 CommandBufferHelper* helper, |
162 const base::Closure& poll_callback, | |
163 void* base) | 159 void* base) |
164 : allocator_(size, helper, poll_callback), | 160 : allocator_(size, helper), base_(base) {} |
165 base_(base) { } | |
166 | 161 |
167 // Allocates a block of memory. If the buffer is out of directly available | 162 // Allocates a block of memory. If the buffer is out of directly available |
168 // memory, this function may wait until memory that was freed "pending a | 163 // memory, this function may wait until memory that was freed "pending a |
169 // token" can be re-used. | 164 // token" can be re-used. |
170 // | 165 // |
171 // Parameters: | 166 // Parameters: |
172 // size: the size of the memory block to allocate. | 167 // size: the size of the memory block to allocate. |
173 // | 168 // |
174 // Returns: | 169 // Returns: |
175 // the pointer to the allocated memory block, or NULL if out of | 170 // the pointer to the allocated memory block, or NULL if out of |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 | 261 |
267 private: | 262 private: |
268 FencedAllocator allocator_; | 263 FencedAllocator allocator_; |
269 void* base_; | 264 void* base_; |
270 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocatorWrapper); | 265 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocatorWrapper); |
271 }; | 266 }; |
272 | 267 |
273 } // namespace gpu | 268 } // namespace gpu |
274 | 269 |
275 #endif // GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ | 270 #endif // GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ |
OLD | NEW |