tor-browser

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

Etagere.h (2188B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #ifndef MOZILLA_GFX_ETAGERE_H
      6 #define MOZILLA_GFX_ETAGERE_H
      7 
      8 namespace Etagere {
      9 
     10 constexpr static const uint32_t FLAGS_VERTICAL_SHELVES = 1;
     11 
     12 /// A shelf-packing dynamic texture atlas allocator tracking each allocation
     13 /// individually and with support for coalescing empty shelves.
     14 struct AtlasAllocator;
     15 
     16 /// Options to tweak the behavior of the atlas allocator.
     17 struct AllocatorOptions {
     18  int32_t width_alignment;
     19  int32_t height_alignment;
     20  int32_t num_columns;
     21  uint32_t flags;
     22 };
     23 
     24 /// 1 means OK, 0 means error.
     25 using Status = uint32_t;
     26 
     27 struct Rectangle {
     28  int32_t min_x;
     29  int32_t min_y;
     30  int32_t max_x;
     31  int32_t max_y;
     32 };
     33 
     34 using AllocationId = uint32_t;
     35 
     36 constexpr static const uint32_t INVALID_ALLOCATION_ID = ~0U;
     37 
     38 struct Allocation {
     39  Rectangle rectangle;
     40  AllocationId id;
     41 };
     42 
     43 extern "C" {
     44 
     45 AtlasAllocator* etagere_atlas_allocator_new(int32_t width, int32_t height);
     46 
     47 AtlasAllocator* etagere_atlas_allocator_with_options(
     48    int32_t width, int32_t height, const AllocatorOptions* options);
     49 
     50 void etagere_atlas_allocator_delete(AtlasAllocator* allocator);
     51 
     52 Status etagere_atlas_allocator_allocate(AtlasAllocator* allocator,
     53                                        int32_t width, int32_t height,
     54                                        Allocation* allocation);
     55 
     56 void etagere_atlas_allocator_deallocate(AtlasAllocator* allocator,
     57                                        AllocationId id);
     58 
     59 void etagere_atlas_allocator_clear(AtlasAllocator* allocator);
     60 
     61 int32_t etagere_atlas_allocator_allocated_space(
     62    const AtlasAllocator* allocator);
     63 
     64 int32_t etagere_atlas_allocator_free_space(const AtlasAllocator* allocator);
     65 
     66 Rectangle etagere_atlas_allocator_get(const AtlasAllocator* allocator,
     67                                      AllocationId id);
     68 
     69 Status etagere_atlas_allocator_dump_svg(const AtlasAllocator* allocator,
     70                                        const char* file_name);
     71 
     72 }  // extern "C"
     73 
     74 }  // namespace Etagere
     75 
     76 #endif  // MOZILLA_GFX_ETAGERE_H