| 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 <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 blocks_.push_back(block); | 43 blocks_.push_back(block); |
| 44 } | 44 } |
| 45 | 45 |
| 46 FencedAllocator::~FencedAllocator() { | 46 FencedAllocator::~FencedAllocator() { |
| 47 // Free blocks pending tokens. | 47 // Free blocks pending tokens. |
| 48 for (unsigned int i = 0; i < blocks_.size(); ++i) { | 48 for (unsigned int i = 0; i < blocks_.size(); ++i) { |
| 49 if (blocks_[i].state == FREE_PENDING_TOKEN) { | 49 if (blocks_[i].state == FREE_PENDING_TOKEN) { |
| 50 i = WaitForTokenAndFreeBlock(i); | 50 i = WaitForTokenAndFreeBlock(i); |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 // These checks are not valid if the service has crashed or lost the context. | 53 |
| 54 // DCHECK_EQ(blocks_.size(), 1u); | 54 DCHECK_EQ(blocks_.size(), 1u); |
| 55 // DCHECK_EQ(blocks_[0].state, FREE); | 55 DCHECK_EQ(blocks_[0].state, FREE); |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Looks for a non-allocated block that is big enough. Search in the FREE | 58 // Looks for a non-allocated block that is big enough. Search in the FREE |
| 59 // blocks first (for direct usage), first-fit, then in the FREE_PENDING_TOKEN | 59 // blocks first (for direct usage), first-fit, then in the FREE_PENDING_TOKEN |
| 60 // blocks, waiting for them. The current implementation isn't smart about | 60 // blocks, waiting for them. The current implementation isn't smart about |
| 61 // optimizing what to wait for, just looks inside the block in order (first-fit | 61 // optimizing what to wait for, just looks inside the block in order (first-fit |
| 62 // as well). | 62 // as well). |
| 63 FencedAllocator::Offset FencedAllocator::Alloc(unsigned int size) { | 63 FencedAllocator::Offset FencedAllocator::Alloc(unsigned int size) { |
| 64 // size of 0 is not allowed because it would be inconsistent to only sometimes | 64 // size of 0 is not allowed because it would be inconsistent to only sometimes |
| 65 // have it succeed. Example: Alloc(SizeOfBuffer), Alloc(0). | 65 // have it succeed. Example: Alloc(SizeOfBuffer), Alloc(0). |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 // The blocks are in offset order, so we can do a binary search. | 244 // The blocks are in offset order, so we can do a binary search. |
| 245 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) { | 245 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) { |
| 246 Block templ = { IN_USE, offset, 0, kUnusedToken }; | 246 Block templ = { IN_USE, offset, 0, kUnusedToken }; |
| 247 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(), | 247 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(), |
| 248 templ, OffsetCmp()); | 248 templ, OffsetCmp()); |
| 249 DCHECK(it != blocks_.end() && it->offset == offset); | 249 DCHECK(it != blocks_.end() && it->offset == offset); |
| 250 return it-blocks_.begin(); | 250 return it-blocks_.begin(); |
| 251 } | 251 } |
| 252 | 252 |
| 253 } // namespace gpu | 253 } // namespace gpu |
| OLD | NEW |