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> |
| 11 |
10 #include <vector> | 12 #include <vector> |
11 | 13 |
12 #include "base/bind.h" | 14 #include "base/bind.h" |
13 #include "base/logging.h" | 15 #include "base/logging.h" |
14 #include "gpu/command_buffer/common/types.h" | 16 #include "base/macros.h" |
15 #include "gpu/gpu_export.h" | 17 #include "gpu/gpu_export.h" |
16 | 18 |
17 namespace gpu { | 19 namespace gpu { |
18 class CommandBufferHelper; | 20 class CommandBufferHelper; |
19 | 21 |
20 // FencedAllocator provides a mechanism to manage allocations within a fixed | 22 // FencedAllocator provides a mechanism to manage allocations within a fixed |
21 // block of memory (storing the book-keeping externally). Furthermore this | 23 // block of memory (storing the book-keeping externally). Furthermore this |
22 // class allows to free data "pending" the passage of a command buffer token, | 24 // 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 | 25 // that is, the memory won't be reused until the command buffer has processed |
24 // that token. | 26 // that token. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 IN_USE, | 96 IN_USE, |
95 FREE, | 97 FREE, |
96 FREE_PENDING_TOKEN | 98 FREE_PENDING_TOKEN |
97 }; | 99 }; |
98 | 100 |
99 // Book-keeping sturcture that describes a block of memory. | 101 // Book-keeping sturcture that describes a block of memory. |
100 struct Block { | 102 struct Block { |
101 State state; | 103 State state; |
102 Offset offset; | 104 Offset offset; |
103 unsigned int size; | 105 unsigned int size; |
104 int32 token; // token to wait for in the FREE_PENDING_TOKEN case. | 106 int32_t token; // token to wait for in the FREE_PENDING_TOKEN case. |
105 }; | 107 }; |
106 | 108 |
107 // Comparison functor for memory block sorting. | 109 // Comparison functor for memory block sorting. |
108 class OffsetCmp { | 110 class OffsetCmp { |
109 public: | 111 public: |
110 bool operator() (const Block &left, const Block &right) { | 112 bool operator() (const Block &left, const Block &right) { |
111 return left.offset < right.offset; | 113 return left.offset < right.offset; |
112 } | 114 } |
113 }; | 115 }; |
114 | 116 |
115 typedef std::vector<Block> Container; | 117 typedef std::vector<Block> Container; |
116 typedef unsigned int BlockIndex; | 118 typedef unsigned int BlockIndex; |
117 | 119 |
118 static const int32 kUnusedToken = 0; | 120 static const int32_t kUnusedToken = 0; |
119 | 121 |
120 // Gets the index of a memory block, given its offset. | 122 // Gets the index of a memory block, given its offset. |
121 BlockIndex GetBlockByOffset(Offset offset); | 123 BlockIndex GetBlockByOffset(Offset offset); |
122 | 124 |
123 // Collapse a free block with its neighbours if they are free. Returns the | 125 // Collapse a free block with its neighbours if they are free. Returns the |
124 // index of the collapsed block. | 126 // index of the collapsed block. |
125 // NOTE: this will invalidate block indices. | 127 // NOTE: this will invalidate block indices. |
126 BlockIndex CollapseFreeBlock(BlockIndex index); | 128 BlockIndex CollapseFreeBlock(BlockIndex index); |
127 | 129 |
128 // Waits for a FREE_PENDING_TOKEN block to be usable, and free it. Returns | 130 // Waits for a FREE_PENDING_TOKEN block to be usable, and free it. Returns |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 257 |
256 private: | 258 private: |
257 FencedAllocator allocator_; | 259 FencedAllocator allocator_; |
258 void* base_; | 260 void* base_; |
259 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocatorWrapper); | 261 DISALLOW_IMPLICIT_CONSTRUCTORS(FencedAllocatorWrapper); |
260 }; | 262 }; |
261 | 263 |
262 } // namespace gpu | 264 } // namespace gpu |
263 | 265 |
264 #endif // GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ | 266 #endif // GPU_COMMAND_BUFFER_CLIENT_FENCED_ALLOCATOR_H_ |
OLD | NEW |