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