Add STSubRunAllocator, an inline SubRunAllocator

Bug: oss-fuzz:48695
Bug: oss-fuzz:48690
Change-Id: I9fb634df54f8e1e7dee84036e2be2512d7a395d8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/556030
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
Herb Derby 2022-07-06 15:58:50 -04:00 committed by SkCQ
parent f0f4277443
commit 45600771c2
2 changed files with 16 additions and 16 deletions

View File

@ -286,6 +286,20 @@ private:
BagOfBytes fAlloc;
};
// 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 {
public:
explicit STSubRunAllocator(size_t firstHeapAllocation = InlineStorageSize)
: SubRunAllocator{this->data(), SkToInt(this->size()), SkToInt(firstHeapAllocation)} {}
};
} // namespace sktext::gpu
#endif // sktext_gpu_SubRunAllocator_DEFINED

View File

@ -206,20 +206,6 @@ DEF_TEST(BagOfBytesBasic, r) {
}
}
// 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 inlineSize>
class GrSTSubRunAllocator : private BagOfBytes::Storage<inlineSize>, public SubRunAllocator {
public:
explicit GrSTSubRunAllocator(int firstHeapAllocation =
BagOfBytes::PlatformMinimumSizeWithOverhead(inlineSize, 1))
: SubRunAllocator{this->data(), SkTo<int>(this->size()), firstHeapAllocation} {}
};
DEF_TEST(SubRunAllocator, r) {
static int created = 0;
static int destroyed = 0;
@ -273,7 +259,7 @@ DEF_TEST(SubRunAllocator, r) {
// Exercise on stack arena
{
GrSTSubRunAllocator<64> arena;
sktext::gpu::STSubRunAllocator<64, 16> arena;
exercise(&arena);
}
@ -314,7 +300,7 @@ DEF_TEST(SubRunAllocator, r) {
~I() {}
int i;
};
GrSTSubRunAllocator<64> arena;
sktext::gpu::STSubRunAllocator<64, 16> arena;
auto a = arena.makeUniqueArray<I>(8, [](size_t i) { return i; });
for (size_t i = 0; i < 8; i++) {
REPORTER_ASSERT(r, a[i].i == (int)i);