Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
sktext::gpu::SubRunAllocator Class Reference

#include <SubRunAllocator.h>

Inheritance diagram for sktext::gpu::SubRunAllocator:
sktext::gpu::STSubRunAllocator< InlineStorageSize, InlineStorageAlignment >

Classes

struct  ArrayDestroyer
 
struct  Destroyer
 

Public Member Functions

 SubRunAllocator (char *block, int blockSize, int firstHeapAllocation)
 
 SubRunAllocator (int firstHeapAllocation=0)
 
 SubRunAllocator (const SubRunAllocator &)=delete
 
SubRunAllocatoroperator= (const SubRunAllocator &)=delete
 
 SubRunAllocator (SubRunAllocator &&)=default
 
SubRunAllocatoroperator= (SubRunAllocator &&)=default
 
template<typename T , typename... Args>
TmakePOD (Args &&... args)
 
template<typename T , typename... Args>
std::unique_ptr< T, DestroyermakeUnique (Args &&... args)
 
template<typename T >
TmakePODArray (int n)
 
template<typename T >
SkSpan< TmakePODSpan (SkSpan< const T > s)
 
template<typename T , typename Src , typename Map >
SkSpan< TmakePODArray (const Src &src, Map map)
 
template<typename T >
std::unique_ptr< T[], ArrayDestroyermakeUniqueArray (int n)
 
template<typename T , typename I >
std::unique_ptr< T[], ArrayDestroyermakeUniqueArray (int n, I initializer)
 
template<typename T , typename U , typename Map >
std::unique_ptr< T[], ArrayDestroyermakeUniqueArray (SkSpan< const U > src, Map map)
 
void * alignedBytes (int size, int alignment)
 

Static Public Member Functions

template<typename T >
static std::tuple< SubRunInitializer< T >, int, SubRunAllocatorAllocateClassMemoryAndArena (int allocSizeHint)
 

Static Public Attributes

template<class T >
static constexpr bool HasNoDestructor = std::is_trivially_destructible<T>::value
 

Detailed Description

Definition at line 208 of file SubRunAllocator.h.

Constructor & Destructor Documentation

◆ SubRunAllocator() [1/4]

sktext::gpu::SubRunAllocator::SubRunAllocator ( char *  block,
int  blockSize,
int  firstHeapAllocation 
)

Definition at line 83 of file SubRunAllocator.cpp.

84 : fAlloc{bytes, SkTo<size_t>(size), SkTo<size_t>(firstHeapAllocation)} {
85 SkASSERT_RELEASE(SkTFitsIn<size_t>(size));
86 SkASSERT_RELEASE(SkTFitsIn<size_t>(firstHeapAllocation));
87}
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ SubRunAllocator() [2/4]

sktext::gpu::SubRunAllocator::SubRunAllocator ( int  firstHeapAllocation = 0)
explicit

Definition at line 89 of file SubRunAllocator.cpp.

90 : SubRunAllocator(nullptr, 0, firstHeapAllocation) { }
SubRunAllocator(char *block, int blockSize, int firstHeapAllocation)

◆ SubRunAllocator() [3/4]

sktext::gpu::SubRunAllocator::SubRunAllocator ( const SubRunAllocator )
delete

◆ SubRunAllocator() [4/4]

sktext::gpu::SubRunAllocator::SubRunAllocator ( SubRunAllocator &&  )
default

Member Function Documentation

◆ alignedBytes()

void * sktext::gpu::SubRunAllocator::alignedBytes ( int  size,
int  alignment 
)

Definition at line 92 of file SubRunAllocator.cpp.

92 {
93 return fAlloc.alignedBytes(unsafeSize, unsafeAlignment);
94}
void * alignedBytes(int unsafeSize, int unsafeAlignment)

◆ AllocateClassMemoryAndArena()

template<typename T >
static std::tuple< SubRunInitializer< T >, int, SubRunAllocator > sktext::gpu::SubRunAllocator::AllocateClassMemoryAndArena ( int  allocSizeHint)
inlinestatic

Definition at line 235 of file SubRunAllocator.h.

235 {
236 SkASSERT_RELEASE(allocSizeHint >= 0);
237 // Round the size after the object the optimal amount.
238 int extraSize = BagOfBytes::PlatformMinimumSizeWithOverhead(allocSizeHint, alignof(T));
239
240 // Don't overflow or die.
241 SkASSERT_RELEASE(INT_MAX - SkTo<int>(sizeof(T)) > extraSize);
242 int totalMemorySize = sizeof(T) + extraSize;
243
244 void* memory = ::operator new (totalMemorySize);
245 SubRunAllocator alloc{SkTAddOffset<char>(memory, sizeof(T)), extraSize, extraSize/2};
246 return {memory, totalMemorySize, std::move(alloc)};
247 }
static constexpr int PlatformMinimumSizeWithOverhead(int requestedSize, int assumedAlignment)
#define T
Definition: precompiler.cc:65

◆ makePOD()

template<typename T , typename... Args>
T * sktext::gpu::SubRunAllocator::makePOD ( Args &&...  args)
inline

Definition at line 249 of file SubRunAllocator.h.

249 {
250 static_assert(HasNoDestructor<T>, "This is not POD. Use makeUnique.");
251 char* bytes = fAlloc.template allocateBytesFor<T>();
252 return new (bytes) T(std::forward<Args>(args)...);
253 }
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args

◆ makePODArray() [1/2]

template<typename T , typename Src , typename Map >
SkSpan< T > sktext::gpu::SubRunAllocator::makePODArray ( const Src &  src,
Map  map 
)
inline

Definition at line 280 of file SubRunAllocator.h.

280 {
281 static_assert(HasNoDestructor<T>, "This is not POD. Use makeUniqueArray.");
282 int size = SkTo<int>(src.size());
283 T* result = this->template makePODArray<T>(size);
284 for (int i = 0; i < size; i++) {
285 new (&result[i]) T(map(src[i]));
286 }
287 return {result, src.size()};
288 }
GAsyncResult * result
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
Definition: SkVx.h:680

◆ makePODArray() [2/2]

template<typename T >
T * sktext::gpu::SubRunAllocator::makePODArray ( int  n)
inline

Definition at line 262 of file SubRunAllocator.h.

262 {
263 static_assert(HasNoDestructor<T>, "This is not POD. Use makeUniqueArray.");
264 return reinterpret_cast<T*>(fAlloc.template allocateBytesFor<T>(n));
265 }

◆ makePODSpan()

template<typename T >
SkSpan< T > sktext::gpu::SubRunAllocator::makePODSpan ( SkSpan< const T s)
inline

Definition at line 268 of file SubRunAllocator.h.

268 {
269 static_assert(HasNoDestructor<T>, "This is not POD. Use makeUniqueArray.");
270 if (s.empty()) {
271 return SkSpan<T>{};
272 }
273
274 T* result = this->makePODArray<T>(SkTo<int>(s.size()));
275 memcpy(result, s.data(), s.size_bytes());
276 return {result, s.size()};
277 }
struct MyStruct s

◆ makeUnique()

template<typename T , typename... Args>
std::unique_ptr< T, Destroyer > sktext::gpu::SubRunAllocator::makeUnique ( Args &&...  args)
inline

Definition at line 256 of file SubRunAllocator.h.

256 {
257 static_assert(!HasNoDestructor<T>, "This is POD. Use makePOD.");
258 char* bytes = fAlloc.template allocateBytesFor<T>();
259 return std::unique_ptr<T, Destroyer>{new (bytes) T(std::forward<Args>(args)...)};
260 }

◆ makeUniqueArray() [1/3]

template<typename T >
std::unique_ptr< T[], ArrayDestroyer > sktext::gpu::SubRunAllocator::makeUniqueArray ( int  n)
inline

Definition at line 291 of file SubRunAllocator.h.

291 {
292 static_assert(!HasNoDestructor<T>, "This is POD. Use makePODArray.");
293 T* array = reinterpret_cast<T*>(fAlloc.template allocateBytesFor<T>(n));
294 for (int i = 0; i < n; i++) {
295 new (&array[i]) T{};
296 }
297 return std::unique_ptr<T[], ArrayDestroyer>{array, ArrayDestroyer{n}};
298 }

◆ makeUniqueArray() [2/3]

template<typename T , typename I >
std::unique_ptr< T[], ArrayDestroyer > sktext::gpu::SubRunAllocator::makeUniqueArray ( int  n,
I  initializer 
)
inline

Definition at line 301 of file SubRunAllocator.h.

301 {
302 static_assert(!HasNoDestructor<T>, "This is POD. Use makePODArray.");
303 T* array = reinterpret_cast<T*>(fAlloc.template allocateBytesFor<T>(n));
304 for (int i = 0; i < n; i++) {
305 new (&array[i]) T(initializer(i));
306 }
307 return std::unique_ptr<T[], ArrayDestroyer>{array, ArrayDestroyer{n}};
308 }
static struct Initializer initializer

◆ makeUniqueArray() [3/3]

template<typename T , typename U , typename Map >
std::unique_ptr< T[], ArrayDestroyer > sktext::gpu::SubRunAllocator::makeUniqueArray ( SkSpan< const U >  src,
Map  map 
)
inline

Definition at line 311 of file SubRunAllocator.h.

311 {
312 static_assert(!HasNoDestructor<T>, "This is POD. Use makePODArray.");
313 int count = SkCount(src);
314 T* array = reinterpret_cast<T*>(fAlloc.template allocateBytesFor<T>(src.size()));
315 for (int i = 0; i < count; ++i) {
316 new (&array[i]) T(map(src[i]));
317 }
318 return std::unique_ptr<T[], ArrayDestroyer>{array, ArrayDestroyer{count}};
319 }
int count
Definition: FontMgrTest.cpp:50
constexpr int SkCount(const Container &c)
Definition: SkTLogic.h:54

◆ operator=() [1/2]

SubRunAllocator & sktext::gpu::SubRunAllocator::operator= ( const SubRunAllocator )
delete

◆ operator=() [2/2]

SubRunAllocator & sktext::gpu::SubRunAllocator::operator= ( SubRunAllocator &&  )
default

Member Data Documentation

◆ HasNoDestructor

template<class T >
constexpr bool sktext::gpu::SubRunAllocator::HasNoDestructor = std::is_trivially_destructible<T>::value
inlinestaticconstexpr

Definition at line 224 of file SubRunAllocator.h.


The documentation for this class was generated from the following files: