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 <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/bind.h" | |
13 #include "base/logging.h" | 12 #include "base/logging.h" |
14 #include "gpu/command_buffer/common/types.h" | 13 #include "gpu/command_buffer/common/types.h" |
15 #include "gpu/gpu_export.h" | 14 #include "gpu/gpu_export.h" |
16 | 15 |
17 namespace gpu { | 16 namespace gpu { |
18 class CommandBufferHelper; | 17 class CommandBufferHelper; |
19 | 18 |
20 // FencedAllocator provides a mechanism to manage allocations within a fixed | 19 // FencedAllocator provides a mechanism to manage allocations within a fixed |
21 // block of memory (storing the book-keeping externally). Furthermore this | 20 // block of memory (storing the book-keeping externally). Furthermore this |
22 // class allows to free data "pending" the passage of a command buffer token, | 21 // class allows to free data "pending" the passage of a command buffer token, |
23 // that is, the memory won't be reused until the command buffer has processed | 22 // that is, the memory won't be reused until the command buffer has processed |
24 // that token. | 23 // that token. |
25 // | 24 // |
26 // NOTE: Although this class is intended to be used in the command buffer | 25 // NOTE: Although this class is intended to be used in the command buffer |
27 // environment which is multi-process, this class isn't "thread safe", because | 26 // environment which is multi-process, this class isn't "thread safe", because |
28 // it isn't meant to be shared across modules. It is thread-compatible though | 27 // it isn't meant to be shared across modules. It is thread-compatible though |
29 // (see http://www.corp.google.com/eng/doc/cpp_primer.html#thread_safety). | 28 // (see http://www.corp.google.com/eng/doc/cpp_primer.html#thread_safety). |
30 class GPU_EXPORT FencedAllocator { | 29 class GPU_EXPORT FencedAllocator { |
31 public: | 30 public: |
32 typedef unsigned int Offset; | 31 typedef unsigned int Offset; |
33 // Invalid offset, returned by Alloc in case of failure. | 32 // Invalid offset, returned by Alloc in case of failure. |
34 static const Offset kInvalidOffset = 0xffffffffU; | 33 static const Offset kInvalidOffset = 0xffffffffU; |
35 | 34 |
36 // Creates a FencedAllocator. Note that the size of the buffer is passed, but | 35 // Creates a FencedAllocator. Note that the size of the buffer is passed, but |
37 // not its base address: everything is handled as offsets into the buffer. | 36 // not its base address: everything is handled as offsets into the buffer. |
38 FencedAllocator(unsigned int size, | 37 FencedAllocator(unsigned int size, |
39 CommandBufferHelper *helper, | 38 CommandBufferHelper *helper); |
40 const base::Closure& poll_callback); | |
41 | 39 |
42 ~FencedAllocator(); | 40 ~FencedAllocator(); |
43 | 41 |
44 // Allocates a block of memory. If the buffer is out of directly available | 42 // Allocates a block of memory. If the buffer is out of directly available |
45 // memory, this function may wait until memory that was freed "pending a | 43 // memory, this function may wait until memory that was freed "pending a |
46 // token" can be re-used. | 44 // token" can be re-used. |
47 // | 45 // |
48 // Parameters: | 46 // Parameters: |
49 // size: the size of the memory block to allocate. | 47 // size: the size of the memory block to allocate. |
50 // | 48 // |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 BlockIndex WaitForTokenAndFreeBlock(BlockIndex index); | 129 BlockIndex WaitForTokenAndFreeBlock(BlockIndex index); |
132 | 130 |
133 // Allocates a block of memory inside a given block, splitting it in two | 131 // Allocates a block of memory inside a given block, splitting it in two |
134 // (unless that block is of the exact requested size). | 132 // (unless that block is of the exact requested size). |
135 // NOTE: this will invalidate block indices. | 133 // NOTE: this will invalidate block indices. |
136 // Returns the offset of the allocated block (NOTE: this is different from | 134 // Returns the offset of the allocated block (NOTE: this is different from |
137 // the other functions that return a block index). | 135 // the other functions that return a block index). |
138 Offset AllocInBlock(BlockIndex index, unsigned int size); | 136 Offset AllocInBlock(BlockIndex index, unsigned int size); |
139 | 137 |
140 CommandBufferHelper *helper_; | 138 CommandBufferHelper *helper_; |
141 base::Closure poll_callback_; | |
142 Container blocks_; | 139 Container blocks_; |
143 size_t bytes_in_use_; | 140 size_t bytes_in_use_; |
144 | 141 |
145 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocator); | 142 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocator); |
146 }; | 143 }; |
147 | 144 |
148 // This class functions just like FencedAllocator, but its API uses pointers | 145 // This class functions just like FencedAllocator, but its API uses pointers |
149 // instead of offsets. | 146 // instead of offsets. |
150 class FencedAllocatorWrapper { | 147 class FencedAllocatorWrapper { |
151 public: | 148 public: |
152 FencedAllocatorWrapper(unsigned int size, | 149 FencedAllocatorWrapper(unsigned int size, |
153 CommandBufferHelper* helper, | 150 CommandBufferHelper* helper, |
154 const base::Closure& poll_callback, | |
155 void* base) | 151 void* base) |
156 : allocator_(size, helper, poll_callback), | 152 : allocator_(size, helper), |
157 base_(base) { } | 153 base_(base) { } |
158 | 154 |
159 // Allocates a block of memory. If the buffer is out of directly available | 155 // Allocates a block of memory. If the buffer is out of directly available |
160 // memory, this function may wait until memory that was freed "pending a | 156 // memory, this function may wait until memory that was freed "pending a |
161 // token" can be re-used. | 157 // token" can be re-used. |
162 // | 158 // |
163 // Parameters: | 159 // Parameters: |
164 // size: the size of the memory block to allocate. | 160 // size: the size of the memory block to allocate. |
165 // | 161 // |
166 // Returns: | 162 // Returns: |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 251 |
256 private: | 252 private: |
257 FencedAllocator allocator_; | 253 FencedAllocator allocator_; |
258 void* base_; | 254 void* base_; |
259 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocatorWrapper); | 255 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocatorWrapper); |
260 }; | 256 }; |
261 | 257 |
262 } // namespace gpu | 258 } // namespace gpu |
263 | 259 |
264 #endif // GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ | 260 #endif // GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ |
OLD | NEW |