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

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

Issue 734063004: Update from https://crrev.com/304418 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « gpu/command_buffer/client/fenced_allocator.h ('k') | gpu/command_buffer/client/mapped_memory.h » ('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 "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
11 #include "gpu/command_buffer/client/cmd_buffer_helper.h" 11 #include "gpu/command_buffer/client/cmd_buffer_helper.h"
12 12
13 namespace gpu { 13 namespace gpu {
14 14
15 namespace { 15 namespace {
16 16
17 // Allocation alignment, must be a power of two.
18 const unsigned int kAllocAlignment = 16;
19
20 // Round down to the largest multiple of kAllocAlignment no greater than |size|. 17 // Round down to the largest multiple of kAllocAlignment no greater than |size|.
21 unsigned int RoundDown(unsigned int size) { 18 unsigned int RoundDown(unsigned int size) {
22 return size & ~(kAllocAlignment - 1); 19 return size & ~(FencedAllocator::kAllocAlignment - 1);
23 } 20 }
24 21
25 // Round up to the smallest multiple of kAllocAlignment no smaller than |size|. 22 // Round up to the smallest multiple of kAllocAlignment no smaller than |size|.
26 unsigned int RoundUp(unsigned int size) { 23 unsigned int RoundUp(unsigned int size) {
27 return (size + (kAllocAlignment - 1)) & ~(kAllocAlignment - 1); 24 return (size + (FencedAllocator::kAllocAlignment - 1)) &
25 ~(FencedAllocator::kAllocAlignment - 1);
28 } 26 }
29 27
30 } // namespace 28 } // namespace
31 29
32 #ifndef _MSC_VER 30 #ifndef _MSC_VER
33 const FencedAllocator::Offset FencedAllocator::kInvalidOffset; 31 const FencedAllocator::Offset FencedAllocator::kInvalidOffset;
32 const unsigned int FencedAllocator::kAllocAlignment;
34 #endif 33 #endif
35 34
36 FencedAllocator::FencedAllocator(unsigned int size, 35 FencedAllocator::FencedAllocator(unsigned int size,
37 CommandBufferHelper* helper, 36 CommandBufferHelper* helper,
38 const base::Closure& poll_callback) 37 const base::Closure& poll_callback)
39 : helper_(helper), 38 : helper_(helper),
40 poll_callback_(poll_callback), 39 poll_callback_(poll_callback),
41 bytes_in_use_(0) { 40 bytes_in_use_(0) {
42 Block block = { FREE, 0, RoundDown(size), kUnusedToken }; 41 Block block = { FREE, 0, RoundDown(size), kUnusedToken };
43 blocks_.push_back(block); 42 blocks_.push_back(block);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 // The blocks are in offset order, so we can do a binary search. 243 // The blocks are in offset order, so we can do a binary search.
245 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) { 244 FencedAllocator::BlockIndex FencedAllocator::GetBlockByOffset(Offset offset) {
246 Block templ = { IN_USE, offset, 0, kUnusedToken }; 245 Block templ = { IN_USE, offset, 0, kUnusedToken };
247 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(), 246 Container::iterator it = std::lower_bound(blocks_.begin(), blocks_.end(),
248 templ, OffsetCmp()); 247 templ, OffsetCmp());
249 DCHECK(it != blocks_.end() && it->offset == offset); 248 DCHECK(it != blocks_.end() && it->offset == offset);
250 return it-blocks_.begin(); 249 return it-blocks_.begin();
251 } 250 }
252 251
253 } // namespace gpu 252 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/client/fenced_allocator.h ('k') | gpu/command_buffer/client/mapped_memory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698