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.
7 // HandleAllocator.cpp: Implements the gl::HandleAllocator class, which is used
8 // to allocate GL handles.
10 #include "libGLESv2/HandleAllocator.h"
12 #include "libGLESv2/main.h"
17 HandleAllocator::HandleAllocator() : mBaseValue(1), mNextValue(1)
21 HandleAllocator::~HandleAllocator()
25 void HandleAllocator::setBaseHandle(GLuint value)
27 ASSERT(mBaseValue == mNextValue);
32 GLuint HandleAllocator::allocate()
34 if (mFreeValues.size())
36 GLuint handle = mFreeValues.back();
37 mFreeValues.pop_back();
43 void HandleAllocator::release(GLuint handle)
45 if (handle == mNextValue - 1)
47 // Don't drop below base value
48 if(mNextValue > mBaseValue)
55 // Only free handles that we own - don't drop below the base value
56 if (handle >= mBaseValue)
58 mFreeValues.push_back(handle);