Index: gpu/command_buffer/common/id_allocator.cc |
diff --git a/gpu/command_buffer/common/id_allocator.cc b/gpu/command_buffer/common/id_allocator.cc |
index 6b2c0e4bc5cab7cb9945ad8ddc1d2d825161fd1e..68f79720b1de2000718b9c7d90fc21c0dca624a5 100644 |
--- a/gpu/command_buffer/common/id_allocator.cc |
+++ b/gpu/command_buffer/common/id_allocator.cc |
@@ -9,7 +9,35 @@ |
namespace gpu { |
-IdAllocator::IdAllocator() { |
+IdAllocator::IdAllocator() {} |
+ |
+IdAllocator::~IdAllocator() {} |
+ |
+ResourceId IdAllocator::AllocateID() { |
+ ResourceId id = FindFirstFree(); |
+ MarkAsUsed(id); |
+ return id; |
+} |
+ |
+ResourceId IdAllocator::AllocateIDAtOrAbove(ResourceId desired_id) { |
+ GPU_DCHECK_LT(static_cast<ResourceId>(used_ids_.size()), |
+ static_cast<ResourceId>(-1)); |
+ for (; InUse(desired_id); ++desired_id) {} |
+ MarkAsUsed(desired_id); |
+ return desired_id; |
+} |
+ |
+bool IdAllocator::MarkAsUsed(ResourceId id) { |
+ std::pair<ResourceIdSet::iterator, bool> result = used_ids_.insert(id); |
+ return result.second; |
+} |
+ |
+void IdAllocator::FreeID(ResourceId id) { |
+ used_ids_.erase(id); |
+} |
+ |
+bool IdAllocator::InUse(ResourceId id) const { |
+ return id == kInvalidResource || used_ids_.find(id) != used_ids_.end(); |
} |
ResourceId IdAllocator::FindFirstFree() const { |
@@ -24,12 +52,4 @@ ResourceId IdAllocator::FindFirstFree() const { |
return id; |
} |
-ResourceId IdAllocator::AllocateIDAtOrAbove(ResourceId desired_id) { |
- GPU_DCHECK_LT(static_cast<ResourceId>(used_ids_.size()), |
- static_cast<ResourceId>(-1)); |
- for (; InUse(desired_id); ++desired_id) {} |
- MarkAsUsed(desired_id); |
- return desired_id; |
-} |
- |
} // namespace gpu |