Chromium Code Reviews| Index: gpu/command_buffer/client/ring_buffer.cc |
| diff --git a/gpu/command_buffer/client/ring_buffer.cc b/gpu/command_buffer/client/ring_buffer.cc |
| index 835f430d3df62e7ffdfb3b0c6df58c175dd7536e..201c15354fa1c19d5e5f42175d18b8c06e2253e8 100644 |
| --- a/gpu/command_buffer/client/ring_buffer.cc |
| +++ b/gpu/command_buffer/client/ring_buffer.cc |
| @@ -29,8 +29,11 @@ RingBuffer::~RingBuffer() { |
| void RingBuffer::FreeOldestBlock() { |
| GPU_DCHECK(!blocks_.empty()) << "no free blocks"; |
| Block& block = blocks_.front(); |
| - GPU_DCHECK(block.valid) << "attempt to allocate more than maximum memory"; |
| - helper_->WaitForToken(block.token); |
| + GPU_DCHECK(block.state != IN_USE) |
| + << "attempt to allocate more than maximum memory"; |
| + if (block.state == FREE_PENDING_TOKEN) { |
| + helper_->WaitForToken(block.token); |
| + } |
| in_use_offset_ += block.size; |
| if (in_use_offset_ == size_) { |
| in_use_offset_ = 0; |
| @@ -45,7 +48,7 @@ void RingBuffer::FreeOldestBlock() { |
| RingBuffer::Offset RingBuffer::Alloc(unsigned int size) { |
| GPU_DCHECK_LE(size, size_) << "attempt to allocate more than maximum memory"; |
| - GPU_DCHECK(blocks_.empty() || blocks_.back().valid) |
| + GPU_DCHECK(blocks_.empty() || blocks_.back().state != IN_USE) |
| << "Attempt to alloc another block before freeing the previous."; |
| // Similarly to malloc, an allocation of 0 allocates at least 1 byte, to |
| // return different pointers every time. |
| @@ -56,8 +59,14 @@ RingBuffer::Offset RingBuffer::Alloc(unsigned int size) { |
| FreeOldestBlock(); |
| } |
| + if (size + free_offset_ > size_) { |
| + //Add padding to fill space before wrapping around |
|
piman
2011/05/03 16:30:20
1 space after //
|
| + blocks_.push_back(Block(free_offset_, size_ - free_offset_, PADDING)); |
| + free_offset_ = 0; |
| + } |
| + |
| Offset offset = free_offset_; |
| - blocks_.push_back(Block(offset, size)); |
| + blocks_.push_back(Block(offset, size, IN_USE)); |
| free_offset_ += size; |
| if (free_offset_ == size_) { |
| free_offset_ = 0; |
| @@ -74,10 +83,10 @@ void RingBuffer::FreePendingToken(RingBuffer::Offset offset, |
| ++it) { |
| Block& block = *it; |
| if (block.offset == offset) { |
| - GPU_DCHECK(!block.valid) |
| + GPU_DCHECK(block.state == IN_USE) |
| << "block that corresponds to offset already freed"; |
| block.token = token; |
| - block.valid = true; |
| + block.state = FREE_PENDING_TOKEN; |
| return; |
| } |
| } |
| @@ -97,8 +106,8 @@ unsigned int RingBuffer::GetLargestFreeSizeNoWaiting() { |
| return 0; |
| } |
| } else if (free_offset_ > in_use_offset_) { |
| - // It's free from free_offset_ to size_ |
| - return size_ - free_offset_; |
| + // It's free from free_offset_ to size_ and from 0 to in_use_offset_ |
| + return std::max(size_ - free_offset_, in_use_offset_); |
| } else { |
| // It's free from free_offset_ -> in_use_offset_; |
| return in_use_offset_ - free_offset_; |