blob: c498f8a17809942b757a3fa892503eabf9b28044 [file] [log] [blame]
benvanik@google.com1a233342011-04-28 19:44:39 +00001//
2// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// HandleAllocator.cpp: Implements the gl::HandleAllocator class, which is used
8// to allocate GL handles.
9
10#include "libGLESv2/HandleAllocator.h"
11
12#include "libGLESv2/main.h"
13
14namespace gl
15{
16
17HandleAllocator::HandleAllocator() : mBaseValue(1), mNextValue(1)
18{
19}
20
21HandleAllocator::~HandleAllocator()
22{
23}
24
25void HandleAllocator::setBaseHandle(GLuint value)
26{
27 ASSERT(mBaseValue == mNextValue);
28 mBaseValue = value;
29 mNextValue = value;
30}
31
32GLuint HandleAllocator::allocate()
33{
34 if (mFreeValues.size())
35 {
36 GLuint handle = mFreeValues.back();
37 mFreeValues.pop_back();
38 return handle;
39 }
40 return mNextValue++;
41}
42
43void HandleAllocator::release(GLuint handle)
44{
45 if (handle == mNextValue - 1)
46 {
benvanik@google.com07792e52011-05-05 19:38:32 +000047 // Don't drop below base value
48 if(mNextValue > mBaseValue)
49 {
50 mNextValue--;
51 }
benvanik@google.com1a233342011-04-28 19:44:39 +000052 }
benvanik@google.com07792e52011-05-05 19:38:32 +000053 else
54 {
55 // Only free handles that we own - don't drop below the base value
56 if (handle >= mBaseValue)
57 {
58 mFreeValues.push_back(handle);
59 }
60 }
benvanik@google.com1a233342011-04-28 19:44:39 +000061}
62
63}