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 IdAllocator. | 5 // This file contains the implementation of IdAllocator. |
6 | 6 |
7 #include "gpu/command_buffer/common/id_allocator.h" | 7 #include "gpu/command_buffer/common/id_allocator.h" |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 | 11 |
12 namespace gpu { | 12 namespace gpu { |
13 | 13 |
14 IdAllocator::IdAllocator() { | 14 IdAllocator::IdAllocator() { |
15 COMPILE_ASSERT(kInvalidResource == 0u, invalid_resource_is_not_zero); | 15 static_assert(kInvalidResource == 0u, "kInvalidResource must be 0"); |
16 // Simplify the code by making sure that lower_bound(id) never | 16 // Simplify the code by making sure that lower_bound(id) never |
17 // returns the beginning of the map, if id is valid (eg != | 17 // returns the beginning of the map, if id is valid (eg != |
18 // kInvalidResource). | 18 // kInvalidResource). |
19 used_ids_.insert(std::make_pair(0u, 0u)); | 19 used_ids_.insert(std::make_pair(0u, 0u)); |
20 } | 20 } |
21 | 21 |
22 IdAllocator::~IdAllocator() {} | 22 IdAllocator::~IdAllocator() {} |
23 | 23 |
24 ResourceId IdAllocator::AllocateID() { | 24 ResourceId IdAllocator::AllocateID() { |
25 return AllocateIDRange(1u); | 25 return AllocateIDRange(1u); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 | 136 |
137 used_ids_.insert(std::make_pair(id, id)); | 137 used_ids_.insert(std::make_pair(id, id)); |
138 return true; | 138 return true; |
139 } | 139 } |
140 | 140 |
141 void IdAllocator::FreeID(ResourceId id) { | 141 void IdAllocator::FreeID(ResourceId id) { |
142 FreeIDRange(id, 1u); | 142 FreeIDRange(id, 1u); |
143 } | 143 } |
144 | 144 |
145 void IdAllocator::FreeIDRange(ResourceId first_id, uint32 range) { | 145 void IdAllocator::FreeIDRange(ResourceId first_id, uint32 range) { |
146 COMPILE_ASSERT(kInvalidResource == 0u, invalid_resource_is_not_zero); | 146 static_assert(kInvalidResource == 0u, "kInvalidResource must be 0"); |
147 | 147 |
148 if (range == 0u || (first_id == 0u && range == 1u)) { | 148 if (range == 0u || (first_id == 0u && range == 1u)) { |
149 return; | 149 return; |
150 } | 150 } |
151 | 151 |
152 if (first_id == 0u) { | 152 if (first_id == 0u) { |
153 first_id++; | 153 first_id++; |
154 range--; | 154 range--; |
155 } | 155 } |
156 | 156 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 if (current->first == id) { | 196 if (current->first == id) { |
197 return true; | 197 return true; |
198 } | 198 } |
199 } | 199 } |
200 | 200 |
201 --current; | 201 --current; |
202 return current->second >= id; | 202 return current->second >= id; |
203 } | 203 } |
204 | 204 |
205 } // namespace gpu | 205 } // namespace gpu |
OLD | NEW |