/* * Copyright 2021 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef sktext_gpu_SubRunAllocator_DEFINED #define sktext_gpu_SubRunAllocator_DEFINED #include "include/core/SkSpan.h" #include "include/private/base/SkAssert.h" #include "include/private/base/SkMath.h" #include "include/private/base/SkTLogic.h" #include "include/private/base/SkTemplates.h" #include "include/private/base/SkTo.h" #include "src/base/SkArenaAlloc.h" #include <algorithm> #include <array> #include <climits> #include <cstddef> #include <cstdint> #include <cstring> #include <limits> #include <memory> #include <new> #include <tuple> #include <utility> namespace sktext::gpu { // BagOfBytes parcels out bytes with a given size and alignment. class BagOfBytes { … }; template <typename T> class SubRunInitializer { … }; // GrSubRunAllocator provides fast allocation where the user takes care of calling the destructors // of the returned pointers, and GrSubRunAllocator takes care of deleting the storage. The // unique_ptrs returned, are to assist in assuring the object's destructor is called. // A note on zero length arrays: according to the standard a pointer must be returned, and it // can't be a nullptr. In such a case, SkArena allocates one byte, but does not initialize it. class SubRunAllocator { … }; // Helper for defining allocators with inline/reserved storage. // For argument declarations, stick to the base type (SubRunAllocator). // Note: Inheriting from the storage first means the storage will outlive the // SubRunAllocator, letting ~SubRunAllocator read it as it calls destructors. // (This is mostly only relevant for strict tools like MSAN.) template <size_t InlineStorageSize, size_t InlineStorageAlignment> class STSubRunAllocator : private std::array<char, BagOfBytes::PlatformMinimumSizeWithOverhead( InlineStorageSize, InlineStorageAlignment)>, public SubRunAllocator { … }; } // namespace sktext::gpu #endif // sktext_gpu_SubRunAllocator_DEFINED