Chromium Code Reviews| Index: gpu/command_buffer/client/fenced_allocator.cc |
| diff --git a/gpu/command_buffer/client/fenced_allocator.cc b/gpu/command_buffer/client/fenced_allocator.cc |
| index 6eb9ab3a1485df189a4f804ed4e7a06201011c8e..5c84c62443992a262a5676e4a43f1cf914746453 100644 |
| --- a/gpu/command_buffer/client/fenced_allocator.cc |
| +++ b/gpu/command_buffer/client/fenced_allocator.cc |
| @@ -5,7 +5,9 @@ |
| // This file contains the implementation of the FencedAllocator class. |
| #include "gpu/command_buffer/client/fenced_allocator.h" |
| + |
|
no sievers
2013/08/20 02:46:54
nit: whitespace change
kaanb
2013/08/20 22:15:46
Whitespace is advised per the style guide:
http://
|
| #include <algorithm> |
| + |
| #include "gpu/command_buffer/client/cmd_buffer_helper.h" |
| namespace gpu { |
| @@ -33,7 +35,8 @@ const FencedAllocator::Offset FencedAllocator::kInvalidOffset; |
| FencedAllocator::FencedAllocator(unsigned int size, |
| CommandBufferHelper *helper) |
| - : helper_(helper) { |
| + : helper_(helper), |
| + bytes_in_use_(0) { |
| Block block = { FREE, 0, RoundDown(size), kUnusedToken }; |
| blocks_.push_back(block); |
| } |
| @@ -90,6 +93,10 @@ FencedAllocator::Offset FencedAllocator::Alloc(unsigned int size) { |
| void FencedAllocator::Free(FencedAllocator::Offset offset) { |
| BlockIndex index = GetBlockByOffset(offset); |
| GPU_DCHECK_NE(blocks_[index].state, FREE); |
| + |
| + if (blocks_[index].state == IN_USE) |
|
piman
2013/08/20 02:56:16
nit: only do map lookup once (like in FreePendingT
kaanb
2013/08/20 22:15:46
Done.
|
| + bytes_in_use_ -= blocks_[index].size; |
| + |
| blocks_[index].state = FREE; |
| CollapseFreeBlock(index); |
| } |
| @@ -99,6 +106,8 @@ void FencedAllocator::FreePendingToken( |
| FencedAllocator::Offset offset, int32 token) { |
| BlockIndex index = GetBlockByOffset(offset); |
| Block &block = blocks_[index]; |
| + if (block.state == IN_USE) |
| + bytes_in_use_ -= block.size; |
| block.state = FREE_PENDING_TOKEN; |
| block.token = token; |
| } |
| @@ -212,10 +221,12 @@ FencedAllocator::Offset FencedAllocator::AllocInBlock(BlockIndex index, |
| GPU_DCHECK_EQ(block.state, FREE); |
| Offset offset = block.offset; |
| if (block.size == size) { |
| + bytes_in_use_ += size; |
| block.state = IN_USE; |
| return offset; |
| } |
| Block newblock = { FREE, offset + size, block.size - size, kUnusedToken}; |
| + bytes_in_use_ += size; |
|
piman
2013/08/20 02:56:16
nit: factor this to before the if?
kaanb
2013/08/20 22:15:46
Done.
|
| block.state = IN_USE; |
| block.size = size; |
| // this is the last thing being done because it may invalidate block; |