1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/angle/src/libGLESv2/HandleAllocator.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +#include "precompiled.h" 1.5 +// 1.6 +// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved. 1.7 +// Use of this source code is governed by a BSD-style license that can be 1.8 +// found in the LICENSE file. 1.9 +// 1.10 + 1.11 +// HandleAllocator.cpp: Implements the gl::HandleAllocator class, which is used 1.12 +// to allocate GL handles. 1.13 + 1.14 +#include "libGLESv2/HandleAllocator.h" 1.15 + 1.16 +#include "libGLESv2/main.h" 1.17 + 1.18 +namespace gl 1.19 +{ 1.20 + 1.21 +HandleAllocator::HandleAllocator() : mBaseValue(1), mNextValue(1) 1.22 +{ 1.23 +} 1.24 + 1.25 +HandleAllocator::~HandleAllocator() 1.26 +{ 1.27 +} 1.28 + 1.29 +void HandleAllocator::setBaseHandle(GLuint value) 1.30 +{ 1.31 + ASSERT(mBaseValue == mNextValue); 1.32 + mBaseValue = value; 1.33 + mNextValue = value; 1.34 +} 1.35 + 1.36 +GLuint HandleAllocator::allocate() 1.37 +{ 1.38 + if (mFreeValues.size()) 1.39 + { 1.40 + GLuint handle = mFreeValues.back(); 1.41 + mFreeValues.pop_back(); 1.42 + return handle; 1.43 + } 1.44 + return mNextValue++; 1.45 +} 1.46 + 1.47 +void HandleAllocator::release(GLuint handle) 1.48 +{ 1.49 + if (handle == mNextValue - 1) 1.50 + { 1.51 + // Don't drop below base value 1.52 + if(mNextValue > mBaseValue) 1.53 + { 1.54 + mNextValue--; 1.55 + } 1.56 + } 1.57 + else 1.58 + { 1.59 + // Only free handles that we own - don't drop below the base value 1.60 + if (handle >= mBaseValue) 1.61 + { 1.62 + mFreeValues.push_back(handle); 1.63 + } 1.64 + } 1.65 +} 1.66 + 1.67 +}