| 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 RingBuffer class. | 5 // This file contains the implementation of the RingBuffer class. |
| 6 | 6 |
| 7 #include "gpu/command_buffer/client/ring_buffer.h" | 7 #include "gpu/command_buffer/client/ring_buffer.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 DCHECK(block.state == IN_USE) | 96 DCHECK(block.state == IN_USE) |
| 97 << "block that corresponds to offset already freed"; | 97 << "block that corresponds to offset already freed"; |
| 98 block.token = token; | 98 block.token = token; |
| 99 block.state = FREE_PENDING_TOKEN; | 99 block.state = FREE_PENDING_TOKEN; |
| 100 return; | 100 return; |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 NOTREACHED() << "attempt to free non-existant block"; | 103 NOTREACHED() << "attempt to free non-existant block"; |
| 104 } | 104 } |
| 105 | 105 |
| 106 void RingBuffer::DiscardBlock(void* pointer) { |
| 107 Offset offset = GetOffset(pointer); |
| 108 offset -= base_offset_; |
| 109 DCHECK(!blocks_.empty()) << "no allocations to free"; |
| 110 for (Container::reverse_iterator it = blocks_.rbegin(); |
| 111 it != blocks_.rend(); |
| 112 ++it) { |
| 113 Block& block = *it; |
| 114 if (block.offset == offset) { |
| 115 DCHECK(block.state == IN_USE) |
| 116 << "block that corresponds to offset already freed"; |
| 117 |
| 118 // Mark this as padding and let the FreeOldestBlock() logic handle |
| 119 // updating all the various offsets. |
| 120 block.state = PADDING; |
| 121 return; |
| 122 } |
| 123 } |
| 124 NOTREACHED() << "attempt to free non-existant block"; |
| 125 } |
| 126 |
| 106 unsigned int RingBuffer::GetLargestFreeSizeNoWaiting() { | 127 unsigned int RingBuffer::GetLargestFreeSizeNoWaiting() { |
| 107 unsigned int last_token_read = helper_->last_token_read(); | 128 unsigned int last_token_read = helper_->last_token_read(); |
| 108 while (!blocks_.empty()) { | 129 while (!blocks_.empty()) { |
| 109 Block& block = blocks_.front(); | 130 Block& block = blocks_.front(); |
| 110 if (block.token > last_token_read || block.state == IN_USE) break; | 131 if (block.token > last_token_read || block.state == IN_USE) break; |
| 111 FreeOldestBlock(); | 132 FreeOldestBlock(); |
| 112 } | 133 } |
| 113 if (free_offset_ == in_use_offset_) { | 134 if (free_offset_ == in_use_offset_) { |
| 114 if (blocks_.empty()) { | 135 if (blocks_.empty()) { |
| 115 // The entire buffer is free. | 136 // The entire buffer is free. |
| 116 DCHECK_EQ(free_offset_, 0u); | 137 DCHECK_EQ(free_offset_, 0u); |
| 117 return size_; | 138 return size_; |
| 118 } else { | 139 } else { |
| 119 // The entire buffer is in use. | 140 // The entire buffer is in use. |
| 120 return 0; | 141 return 0; |
| 121 } | 142 } |
| 122 } else if (free_offset_ > in_use_offset_) { | 143 } else if (free_offset_ > in_use_offset_) { |
| 123 // It's free from free_offset_ to size_ and from 0 to in_use_offset_ | 144 // It's free from free_offset_ to size_ and from 0 to in_use_offset_ |
| 124 return std::max(size_ - free_offset_, in_use_offset_); | 145 return std::max(size_ - free_offset_, in_use_offset_); |
| 125 } else { | 146 } else { |
| 126 // It's free from free_offset_ -> in_use_offset_; | 147 // It's free from free_offset_ -> in_use_offset_; |
| 127 return in_use_offset_ - free_offset_; | 148 return in_use_offset_ - free_offset_; |
| 128 } | 149 } |
| 129 } | 150 } |
| 130 | 151 |
| 131 } // namespace gpu | 152 } // namespace gpu |
| OLD | NEW |