tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

HandleAllocator.h (1503B)


      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 
     43    // Represents an inclusive range [begin, end]
     44    struct HandleRange
     45    {
     46        HandleRange(GLuint beginIn, GLuint endIn) : begin(beginIn), end(endIn) {}
     47 
     48        GLuint begin;
     49        GLuint end;
     50    };
     51 
     52    struct HandleRangeComparator;
     53 
     54    // The freelist consists of never-allocated handles, stored
     55    // as ranges, and handles that were previously allocated and
     56    // released, stored in a heap.
     57    std::vector<HandleRange> mUnallocatedList;
     58    std::vector<GLuint> mReleasedList;
     59 
     60    bool mLoggingEnabled;
     61 };
     62 
     63 }  // namespace gl
     64 
     65 #endif  // LIBANGLE_HANDLEALLOCATOR_H_