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