Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: gpu/command_buffer/client/fenced_allocator.cc

Issue 11419280: Make FencedAlloctor fail on size = 0. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | gpu/command_buffer/client/fenced_allocator_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "../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 21 matching lines...) Expand all
32 // GPU_DCHECK_EQ(blocks_.size(), 1u); 32 // GPU_DCHECK_EQ(blocks_.size(), 1u);
33 // GPU_DCHECK_EQ(blocks_[0].state, FREE); 33 // GPU_DCHECK_EQ(blocks_[0].state, FREE);
34 } 34 }
35 35
36 // Looks for a non-allocated block that is big enough. Search in the FREE 36 // Looks for a non-allocated block that is big enough. Search in the FREE
37 // blocks first (for direct usage), first-fit, then in the FREE_PENDING_TOKEN 37 // blocks first (for direct usage), first-fit, then in the FREE_PENDING_TOKEN
38 // blocks, waiting for them. The current implementation isn't smart about 38 // blocks, waiting for them. The current implementation isn't smart about
39 // optimizing what to wait for, just looks inside the block in order (first-fit 39 // optimizing what to wait for, just looks inside the block in order (first-fit
40 // as well). 40 // as well).
41 FencedAllocator::Offset FencedAllocator::Alloc(unsigned int size) { 41 FencedAllocator::Offset FencedAllocator::Alloc(unsigned int size) {
42 // Similarly to malloc, an allocation of 0 allocates at least 1 byte, to 42 // size of 0 is not allowed because it would be inconsistent to only sometimes
43 // return different pointers every time. 43 // have it succeed. Example: Alloc(SizeOfBuffer), Alloc(0).
44 if (size == 0) size = 1; 44 if (size == 0) {
45 return kInvalidOffset;
46 }
45 47
46 // Try first to allocate in a free block. 48 // Try first to allocate in a free block.
47 for (unsigned int i = 0; i < blocks_.size(); ++i) { 49 for (unsigned int i = 0; i < blocks_.size(); ++i) {
48 Block &block = blocks_[i]; 50 Block &block = blocks_[i];
49 if (block.state == FREE && block.size >= size) { 51 if (block.state == FREE && block.size >= size) {
50 return AllocInBlock(i, size); 52 return AllocInBlock(i, size);
51 } 53 }
52 } 54 }
53 55
54 // No free block is available. Look for blocks pending tokens, and wait for 56 // No free block is available. Look for blocks pending tokens, and wait for
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 // The blocks are in offset order, so we can do a binary search. 205 // The blocks are in offset order, so we can do a binary search.
204 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) { 206 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) {
205 Block templ = { IN_USE, offset, 0, kUnusedToken }; 207 Block templ = { IN_USE, offset, 0, kUnusedToken };
206 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(), 208 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(),
207 templ, OffsetCmp()); 209 templ, OffsetCmp());
208 GPU_DCHECK(it != blocks_.end() && it->offset == offset); 210 GPU_DCHECK(it != blocks_.end() && it->offset == offset);
209 return it-blocks_.begin(); 211 return it-blocks_.begin();
210 } 212 }
211 213
212 } // namespace gpu 214 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | gpu/command_buffer/client/fenced_allocator_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698