summaryrefslogtreecommitdiffstats
path: root/gpu/command_buffer/common/id_allocator.cc
diff options
context:
space:
mode:
authorgman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-03 19:14:10 +0000
committergman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-03 19:14:10 +0000
commit066849e369dae48bf61ae0cf70c9e9acaf9f1045 (patch)
tree479aebcba9d2f1d3b054dc3ea64baa9a7c753f15 /gpu/command_buffer/common/id_allocator.cc
parent0411509f65aae2b1ba684bf87343a14253246de0 (diff)
downloadchromium_src-066849e369dae48bf61ae0cf70c9e9acaf9f1045.zip
chromium_src-066849e369dae48bf61ae0cf70c9e9acaf9f1045.tar.gz
chromium_src-066849e369dae48bf61ae0cf70c9e9acaf9f1045.tar.bz2
Adds support for shared resources.
It's not clear how to test this easily it seems like we an integration test is needed at some point. I did run the conformance tests with share_resources set to true and it rand without crashing. TEST=unit tests BUG=none Review URL: http://codereview.chromium.org/1817002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46264 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu/command_buffer/common/id_allocator.cc')
-rw-r--r--gpu/command_buffer/common/id_allocator.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/gpu/command_buffer/common/id_allocator.cc b/gpu/command_buffer/common/id_allocator.cc
new file mode 100644
index 0000000..22c55e3
--- /dev/null
+++ b/gpu/command_buffer/common/id_allocator.cc
@@ -0,0 +1,35 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file contains the implementation of IdAllocator.
+
+#include "../common/id_allocator.h"
+#include "../common/logging.h"
+
+namespace gpu {
+
+IdAllocator::IdAllocator() {
+}
+
+ResourceId IdAllocator::FindFirstFree() const {
+ ResourceId id = 1;
+ for (ResourceIdSet::const_iterator it = used_ids_.begin();
+ it != used_ids_.end(); ++it) {
+ if ((*it) != id) {
+ return id;
+ }
+ ++id;
+ }
+ return id;
+}
+
+ResourceId IdAllocator::AllocateIDAtOrAbove(ResourceId desired_id) {
+ 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