Home | History | Annotate | Download | only in libGLESv2
      1 //
      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 
     14 namespace gl
     15 {
     16 
     17 HandleAllocator::HandleAllocator() : mBaseValue(1), mNextValue(1)
     18 {
     19 }
     20 
     21 HandleAllocator::~HandleAllocator()
     22 {
     23 }
     24 
     25 void HandleAllocator::setBaseHandle(GLuint value)
     26 {
     27     ASSERT(mBaseValue == mNextValue);
     28     mBaseValue = value;
     29     mNextValue = value;
     30 }
     31 
     32 GLuint 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 
     43 void HandleAllocator::release(GLuint handle)
     44 {
     45     if (handle == mNextValue - 1)
     46     {
     47         // Don't drop below base value
     48         if(mNextValue > mBaseValue)
     49         {
     50             mNextValue--;
     51         }
     52     }
     53     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     }
     61 }
     62 
     63 }
     64