michael@0: #include "precompiled.h" michael@0: // michael@0: // Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: // HandleAllocator.cpp: Implements the gl::HandleAllocator class, which is used michael@0: // to allocate GL handles. michael@0: michael@0: #include "libGLESv2/HandleAllocator.h" michael@0: michael@0: #include "libGLESv2/main.h" michael@0: michael@0: namespace gl michael@0: { michael@0: michael@0: HandleAllocator::HandleAllocator() : mBaseValue(1), mNextValue(1) michael@0: { michael@0: } michael@0: michael@0: HandleAllocator::~HandleAllocator() michael@0: { michael@0: } michael@0: michael@0: void HandleAllocator::setBaseHandle(GLuint value) michael@0: { michael@0: ASSERT(mBaseValue == mNextValue); michael@0: mBaseValue = value; michael@0: mNextValue = value; michael@0: } michael@0: michael@0: GLuint HandleAllocator::allocate() michael@0: { michael@0: if (mFreeValues.size()) michael@0: { michael@0: GLuint handle = mFreeValues.back(); michael@0: mFreeValues.pop_back(); michael@0: return handle; michael@0: } michael@0: return mNextValue++; michael@0: } michael@0: michael@0: void HandleAllocator::release(GLuint handle) michael@0: { michael@0: if (handle == mNextValue - 1) michael@0: { michael@0: // Don't drop below base value michael@0: if(mNextValue > mBaseValue) michael@0: { michael@0: mNextValue--; michael@0: } michael@0: } michael@0: else michael@0: { michael@0: // Only free handles that we own - don't drop below the base value michael@0: if (handle >= mBaseValue) michael@0: { michael@0: mFreeValues.push_back(handle); michael@0: } michael@0: } michael@0: } michael@0: michael@0: }