| 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 14 matching lines...) Expand all Loading... |
| 25 ~(FencedAllocator::kAllocAlignment - 1); | 25 ~(FencedAllocator::kAllocAlignment - 1); |
| 26 } | 26 } |
| 27 | 27 |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 #ifndef _MSC_VER | 30 #ifndef _MSC_VER |
| 31 const FencedAllocator::Offset FencedAllocator::kInvalidOffset; | 31 const FencedAllocator::Offset FencedAllocator::kInvalidOffset; |
| 32 const unsigned int FencedAllocator::kAllocAlignment; | 32 const unsigned int FencedAllocator::kAllocAlignment; |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 FencedAllocator::FencedAllocator(unsigned int size, | 35 FencedAllocator::FencedAllocator(unsigned int size, CommandBufferHelper* helper) |
| 36 CommandBufferHelper* helper, | 36 : helper_(helper), bytes_in_use_(0) { |
| 37 const base::Closure& poll_callback) | |
| 38 : helper_(helper), | |
| 39 poll_callback_(poll_callback), | |
| 40 bytes_in_use_(0) { | |
| 41 Block block = { FREE, 0, RoundDown(size), kUnusedToken }; | 37 Block block = { FREE, 0, RoundDown(size), kUnusedToken }; |
| 42 blocks_.push_back(block); | 38 blocks_.push_back(block); |
| 43 } | 39 } |
| 44 | 40 |
| 45 FencedAllocator::~FencedAllocator() { | 41 FencedAllocator::~FencedAllocator() { |
| 46 // Free blocks pending tokens. | 42 // Free blocks pending tokens. |
| 47 for (unsigned int i = 0; i < blocks_.size(); ++i) { | 43 for (unsigned int i = 0; i < blocks_.size(); ++i) { |
| 48 if (blocks_[i].state == FREE_PENDING_TOKEN) { | 44 if (blocks_[i].state == FREE_PENDING_TOKEN) { |
| 49 i = WaitForTokenAndFreeBlock(i); | 45 i = WaitForTokenAndFreeBlock(i); |
| 50 } | 46 } |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 BlockIndex index) { | 205 BlockIndex index) { |
| 210 Block &block = blocks_[index]; | 206 Block &block = blocks_[index]; |
| 211 DCHECK_EQ(block.state, FREE_PENDING_TOKEN); | 207 DCHECK_EQ(block.state, FREE_PENDING_TOKEN); |
| 212 helper_->WaitForToken(block.token); | 208 helper_->WaitForToken(block.token); |
| 213 block.state = FREE; | 209 block.state = FREE; |
| 214 return CollapseFreeBlock(index); | 210 return CollapseFreeBlock(index); |
| 215 } | 211 } |
| 216 | 212 |
| 217 // Frees any blocks pending a token for which the token has been read. | 213 // Frees any blocks pending a token for which the token has been read. |
| 218 void FencedAllocator::FreeUnused() { | 214 void FencedAllocator::FreeUnused() { |
| 219 // Free any potential blocks that has its lifetime handled outside. | |
| 220 poll_callback_.Run(); | |
| 221 | |
| 222 for (unsigned int i = 0; i < blocks_.size();) { | 215 for (unsigned int i = 0; i < blocks_.size();) { |
| 223 Block& block = blocks_[i]; | 216 Block& block = blocks_[i]; |
| 224 if (block.state == FREE_PENDING_TOKEN && | 217 if (block.state == FREE_PENDING_TOKEN && |
| 225 helper_->HasTokenPassed(block.token)) { | 218 helper_->HasTokenPassed(block.token)) { |
| 226 block.state = FREE; | 219 block.state = FREE; |
| 227 i = CollapseFreeBlock(i); | 220 i = CollapseFreeBlock(i); |
| 228 } else { | 221 } else { |
| 229 ++i; | 222 ++i; |
| 230 } | 223 } |
| 231 } | 224 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 255 // The blocks are in offset order, so we can do a binary search. | 248 // The blocks are in offset order, so we can do a binary search. |
| 256 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) { | 249 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) { |
| 257 Block templ = { IN_USE, offset, 0, kUnusedToken }; | 250 Block templ = { IN_USE, offset, 0, kUnusedToken }; |
| 258 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(), | 251 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(), |
| 259 templ, OffsetCmp()); | 252 templ, OffsetCmp()); |
| 260 DCHECK(it != blocks_.end() && it->offset == offset); | 253 DCHECK(it != blocks_.end() && it->offset == offset); |
| 261 return it-blocks_.begin(); | 254 return it-blocks_.begin(); |
| 262 } | 255 } |
| 263 | 256 |
| 264 } // namespace gpu | 257 } // namespace gpu |
| OLD | NEW |