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 // HandleRangeAllocator.h: Defines the gl::HandleRangeAllocator class, which is used to 8 // allocate contiguous ranges of GL path handles. 9 10 #ifndef LIBANGLE_HANDLERANGEALLOCATOR_H_ 11 #define LIBANGLE_HANDLERANGEALLOCATOR_H_ 12 13 #include <map> 14 15 #include "angle_gl.h" 16 #include "common/angleutils.h" 17 18 namespace gl 19 { 20 21 // Allocates contiguous ranges of path object handles. 22 class HandleRangeAllocator final : angle::NonCopyable 23 { 24 public: 25 static const GLuint kInvalidHandle; 26 27 HandleRangeAllocator(); 28 ~HandleRangeAllocator(); 29 30 // Allocates a new path handle. 31 GLuint allocate(); 32 33 // Allocates a handle starting at or above the value of |wanted|. 34 // Note: may wrap if it starts near limit. 35 GLuint allocateAtOrAbove(GLuint wanted); 36 37 // Allocates |range| amount of contiguous paths. 38 // Returns the first id to |first_id| or |kInvalidHandle| if 39 // allocation failed. 40 GLuint allocateRange(GLuint range); 41 42 // Marks an id as used. Returns false if handle was already used. 43 bool markAsUsed(GLuint handle); 44 45 // Release handle. 46 void release(GLuint handle); 47 48 // Release a |range| amount of contiguous handles, starting from |first| 49 void releaseRange(GLuint first, GLuint range); 50 51 // Checks whether or not a resource ID is in use. 52 bool isUsed(GLuint handle) const; 53 54 private: 55 std::map<GLuint, GLuint> mUsed; 56 }; 57 58 } // namespace gl 59 60 #endif // LIBANGLE_HANDLERANGEALLOCATOR_H_ 61