| 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 |
| 11 namespace gpu { | 11 namespace gpu { |
| 12 | 12 |
| 13 #ifndef _MSC_VER | 13 #ifndef _MSC_VER |
| 14 const FencedAllocator::Offset FencedAllocator::kInvalidOffset; | 14 const FencedAllocator::Offset FencedAllocator::kInvalidOffset; |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 FencedAllocator::FencedAllocator(unsigned int size, |
| 18 CommandBufferHelper *helper) |
| 19 : helper_(helper) { |
| 20 Block block = { FREE, 0, size, kUnusedToken }; |
| 21 blocks_.push_back(block); |
| 22 } |
| 23 |
| 17 FencedAllocator::~FencedAllocator() { | 24 FencedAllocator::~FencedAllocator() { |
| 18 // Free blocks pending tokens. | 25 // Free blocks pending tokens. |
| 19 for (unsigned int i = 0; i < blocks_.size(); ++i) { | 26 for (unsigned int i = 0; i < blocks_.size(); ++i) { |
| 20 if (blocks_[i].state == FREE_PENDING_TOKEN) { | 27 if (blocks_[i].state == FREE_PENDING_TOKEN) { |
| 21 i = WaitForTokenAndFreeBlock(i); | 28 i = WaitForTokenAndFreeBlock(i); |
| 22 } | 29 } |
| 23 } | 30 } |
| 24 // These checks are not valid if the service has crashed or lost the context. | 31 // These checks are not valid if the service has crashed or lost the context. |
| 25 // GPU_DCHECK_EQ(blocks_.size(), 1u); | 32 // GPU_DCHECK_EQ(blocks_.size(), 1u); |
| 26 // GPU_DCHECK_EQ(blocks_[0].state, FREE); | 33 // GPU_DCHECK_EQ(blocks_[0].state, FREE); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // The blocks are in offset order, so we can do a binary search. | 199 // The blocks are in offset order, so we can do a binary search. |
| 193 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) { | 200 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) { |
| 194 Block templ = { IN_USE, offset, 0, kUnusedToken }; | 201 Block templ = { IN_USE, offset, 0, kUnusedToken }; |
| 195 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(), | 202 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(), |
| 196 templ, OffsetCmp()); | 203 templ, OffsetCmp()); |
| 197 GPU_DCHECK(it != blocks_.end() && it->offset == offset); | 204 GPU_DCHECK(it != blocks_.end() && it->offset == offset); |
| 198 return it-blocks_.begin(); | 205 return it-blocks_.begin(); |
| 199 } | 206 } |
| 200 | 207 |
| 201 } // namespace gpu | 208 } // namespace gpu |
| OLD | NEW |