OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 implementation of the FencedAllocator class. | 5 // This file contains the implementation of the FencedAllocator class. |
6 | 6 |
7 #include "gpu/command_buffer/client/fenced_allocator.h" | 7 #include "gpu/command_buffer/client/fenced_allocator.h" |
8 | 8 |
| 9 #include <stdint.h> |
| 10 |
9 #include <algorithm> | 11 #include <algorithm> |
10 | 12 |
11 #include "gpu/command_buffer/client/cmd_buffer_helper.h" | 13 #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
12 | 14 |
13 namespace gpu { | 15 namespace gpu { |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 // Round down to the largest multiple of kAllocAlignment no greater than |size|. | 19 // Round down to the largest multiple of kAllocAlignment no greater than |size|. |
18 unsigned int RoundDown(unsigned int size) { | 20 unsigned int RoundDown(unsigned int size) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 Block &block = blocks_[index]; | 90 Block &block = blocks_[index]; |
89 | 91 |
90 if (block.state == IN_USE) | 92 if (block.state == IN_USE) |
91 bytes_in_use_ -= block.size; | 93 bytes_in_use_ -= block.size; |
92 | 94 |
93 block.state = FREE; | 95 block.state = FREE; |
94 CollapseFreeBlock(index); | 96 CollapseFreeBlock(index); |
95 } | 97 } |
96 | 98 |
97 // Looks for the corresponding block, mark it FREE_PENDING_TOKEN. | 99 // Looks for the corresponding block, mark it FREE_PENDING_TOKEN. |
98 void FencedAllocator::FreePendingToken( | 100 void FencedAllocator::FreePendingToken(FencedAllocator::Offset offset, |
99 FencedAllocator::Offset offset, int32 token) { | 101 int32_t token) { |
100 BlockIndex index = GetBlockByOffset(offset); | 102 BlockIndex index = GetBlockByOffset(offset); |
101 Block &block = blocks_[index]; | 103 Block &block = blocks_[index]; |
102 if (block.state == IN_USE) | 104 if (block.state == IN_USE) |
103 bytes_in_use_ -= block.size; | 105 bytes_in_use_ -= block.size; |
104 block.state = FREE_PENDING_TOKEN; | 106 block.state = FREE_PENDING_TOKEN; |
105 block.token = token; | 107 block.token = token; |
106 } | 108 } |
107 | 109 |
108 // Gets the max of the size of the blocks marked as free. | 110 // Gets the max of the size of the blocks marked as free. |
109 unsigned int FencedAllocator::GetLargestFreeSize() { | 111 unsigned int FencedAllocator::GetLargestFreeSize() { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 // The blocks are in offset order, so we can do a binary search. | 245 // The blocks are in offset order, so we can do a binary search. |
244 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) { | 246 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) { |
245 Block templ = { IN_USE, offset, 0, kUnusedToken }; | 247 Block templ = { IN_USE, offset, 0, kUnusedToken }; |
246 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(), | 248 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(), |
247 templ, OffsetCmp()); | 249 templ, OffsetCmp()); |
248 DCHECK(it != blocks_.end() && it->offset == offset); | 250 DCHECK(it != blocks_.end() && it->offset == offset); |
249 return it-blocks_.begin(); | 251 return it-blocks_.begin(); |
250 } | 252 } |
251 | 253 |
252 } // namespace gpu | 254 } // namespace gpu |
OLD | NEW |