• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2002 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.h: Defines the gl::HandleAllocator class, which is used to
8 // allocate GL handles.
9 
10 #ifndef LIBANGLE_HANDLEALLOCATOR_H_
11 #define LIBANGLE_HANDLEALLOCATOR_H_
12 
13 #include "common/angleutils.h"
14 
15 #include "angle_gl.h"
16 
17 namespace gl
18 {
19 
20 class HandleAllocator final : angle::NonCopyable
21 {
22   public:
23     // Maximum handle = MAX_UINT-1
24     HandleAllocator();
25     // Specify maximum handle value. Used for testing.
26     HandleAllocator(GLuint maximumHandleValue);
27 
28     ~HandleAllocator();
29 
30     void setBaseHandle(GLuint value);
31 
32     GLuint allocate();
33     void release(GLuint handle);
34     void reserve(GLuint handle);
35     void reset();
36 
37     void enableLogging(bool enabled);
38 
39   private:
40     GLuint mBaseValue;
41     GLuint mNextValue;
42     typedef std::vector<GLuint> HandleList;
43     HandleList mFreeValues;
44 
45     // Represents an inclusive range [begin, end]
46     struct HandleRange
47     {
HandleRangeHandleRange48         HandleRange(GLuint beginIn, GLuint endIn) : begin(beginIn), end(endIn) {}
49 
50         GLuint begin;
51         GLuint end;
52     };
53 
54     struct HandleRangeComparator;
55 
56     // The freelist consists of never-allocated handles, stored
57     // as ranges, and handles that were previously allocated and
58     // released, stored in a heap.
59     std::vector<HandleRange> mUnallocatedList;
60     std::vector<GLuint> mReleasedList;
61 
62     bool mLoggingEnabled;
63 };
64 
65 }  // namespace gl
66 
67 #endif  // LIBANGLE_HANDLEALLOCATOR_H_
68