| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "../client/fenced_allocator.h" | 7 #include "../client/fenced_allocator.h" |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include "../client/cmd_buffer_helper.h" | 9 #include "../client/cmd_buffer_helper.h" |
| 10 | 10 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 if (next.offset <= current.offset) | 123 if (next.offset <= current.offset) |
| 124 return false; | 124 return false; |
| 125 if (next.offset != current.offset + current.size) | 125 if (next.offset != current.offset + current.size) |
| 126 return false; | 126 return false; |
| 127 if (current.state == FREE && next.state == FREE) | 127 if (current.state == FREE && next.state == FREE) |
| 128 return false; | 128 return false; |
| 129 } | 129 } |
| 130 return true; | 130 return true; |
| 131 } | 131 } |
| 132 | 132 |
| 133 bool FencedAllocator::InUse() { |
| 134 return blocks_.size() != 1 || blocks_[0].state != FREE; |
| 135 } |
| 136 |
| 133 // Collapse the block to the next one, then to the previous one. Provided the | 137 // Collapse the block to the next one, then to the previous one. Provided the |
| 134 // structure is consistent, those are the only blocks eligible for collapse. | 138 // structure is consistent, those are the only blocks eligible for collapse. |
| 135 FencedAllocator::BlockIndex FencedAllocator::CollapseFreeBlock( | 139 FencedAllocator::BlockIndex FencedAllocator::CollapseFreeBlock( |
| 136 BlockIndex index) { | 140 BlockIndex index) { |
| 137 if (index + 1 < blocks_.size()) { | 141 if (index + 1 < blocks_.size()) { |
| 138 Block &next = blocks_[index + 1]; | 142 Block &next = blocks_[index + 1]; |
| 139 if (next.state == FREE) { | 143 if (next.state == FREE) { |
| 140 blocks_[index].size += next.size; | 144 blocks_[index].size += next.size; |
| 141 blocks_.erase(blocks_.begin() + index + 1); | 145 blocks_.erase(blocks_.begin() + index + 1); |
| 142 } | 146 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 // The blocks are in offset order, so we can do a binary search. | 203 // The blocks are in offset order, so we can do a binary search. |
| 200 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) { | 204 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) { |
| 201 Block templ = { IN_USE, offset, 0, kUnusedToken }; | 205 Block templ = { IN_USE, offset, 0, kUnusedToken }; |
| 202 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(), | 206 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(), |
| 203 templ, OffsetCmp()); | 207 templ, OffsetCmp()); |
| 204 GPU_DCHECK(it != blocks_.end() && it->offset == offset); | 208 GPU_DCHECK(it != blocks_.end() && it->offset == offset); |
| 205 return it-blocks_.begin(); | 209 return it-blocks_.begin(); |
| 206 } | 210 } |
| 207 | 211 |
| 208 } // namespace gpu | 212 } // namespace gpu |
| OLD | NEW |