OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
3 * All rights reserved. | 3 * All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 16 matching lines...) Expand all Loading... |
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 */ | 30 */ |
31 | 31 |
32 | 32 |
33 // This file contains the implementation of IdAllocator. | 33 // This file contains the implementation of IdAllocator. |
34 | 34 |
35 #include "gpu/command_buffer/client/id_allocator.h" | 35 #include "gpu/command_buffer/client/id_allocator.h" |
36 | 36 |
37 namespace command_buffer { | 37 namespace gpu { |
38 | 38 |
39 IdAllocator::IdAllocator() : bitmap_(1) { bitmap_[0] = 0; } | 39 IdAllocator::IdAllocator() : bitmap_(1) { bitmap_[0] = 0; } |
40 | 40 |
41 static const unsigned int kBitsPerUint32 = sizeof(Uint32) * 8; // NOLINT | 41 static const unsigned int kBitsPerUint32 = sizeof(Uint32) * 8; // NOLINT |
42 | 42 |
43 // Looks for the first non-full entry, and return the first free bit in that | 43 // Looks for the first non-full entry, and return the first free bit in that |
44 // entry. If all the entries are full, it will return the first bit of an entry | 44 // entry. If all the entries are full, it will return the first bit of an entry |
45 // that would be appended, but doesn't actually append that entry to the vector. | 45 // that would be appended, but doesn't actually append that entry to the vector. |
46 unsigned int IdAllocator::FindFirstFree() const { | 46 unsigned int IdAllocator::FindFirstFree() const { |
47 size_t size = bitmap_.size(); | 47 size_t size = bitmap_.size(); |
(...skipping 27 matching lines...) Expand all Loading... |
75 | 75 |
76 // Gets the bit from the proper entry. This doesn't resize the vector, just | 76 // Gets the bit from the proper entry. This doesn't resize the vector, just |
77 // returns false if the bit is beyond the last entry. | 77 // returns false if the bit is beyond the last entry. |
78 bool IdAllocator::GetBit(unsigned int bit) const { | 78 bool IdAllocator::GetBit(unsigned int bit) const { |
79 size_t size = bitmap_.size(); | 79 size_t size = bitmap_.size(); |
80 if (bit / kBitsPerUint32 >= size) return false; | 80 if (bit / kBitsPerUint32 >= size) return false; |
81 Uint32 mask = 1U << (bit % kBitsPerUint32); | 81 Uint32 mask = 1U << (bit % kBitsPerUint32); |
82 return (bitmap_[bit / kBitsPerUint32] & mask) != 0; | 82 return (bitmap_[bit / kBitsPerUint32] & mask) != 0; |
83 } | 83 } |
84 | 84 |
85 } // namespace command_buffer | 85 } // namespace gpu |
OLD | NEW |