Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Protected Types | Protected Member Functions | List of all members
SkArenaAlloc Class Reference

#include <SkArenaAlloc.h>

Inheritance diagram for SkArenaAlloc:
SkSTArenaAlloc< bytes > SkSTArenaAlloc< kSkBlitterContextSize > SkSTArenaAlloc< kBMStateSize > SkSTArenaAlloc< 512 > SkSTArenaAlloc< 65536 > SkSTArenaAlloc< 1024 > SkArenaAllocWithReset SkSTArenaAlloc< InlineStorageSize >

Classes

struct  Footer
 

Public Member Functions

 SkArenaAlloc (char *block, size_t blockSize, size_t firstHeapAllocation)
 
 SkArenaAlloc (size_t firstHeapAllocation)
 
 SkArenaAlloc (const SkArenaAlloc &)=delete
 
SkArenaAllocoperator= (const SkArenaAlloc &)=delete
 
 SkArenaAlloc (SkArenaAlloc &&)=delete
 
SkArenaAllocoperator= (SkArenaAlloc &&)=delete
 
 ~SkArenaAlloc ()
 
template<typename Ctor >
auto make (Ctor &&ctor) -> decltype(ctor(nullptr))
 
template<typename T , typename... Args>
Tmake (Args &&... args)
 
template<typename T >
Tmake ()
 
template<typename T >
TmakeArrayDefault (size_t count)
 
template<typename T >
TmakeArray (size_t count)
 
template<typename T , typename Initializer >
TmakeInitializedArray (size_t count, Initializer initializer)
 
void * makeBytesAlignedTo (size_t size, size_t align)
 

Protected Types

using FooterAction = char *(char *)
 

Protected Member Functions

char * cursor ()
 
char * end ()
 

Detailed Description

Definition at line 105 of file SkArenaAlloc.h.

Member Typedef Documentation

◆ FooterAction

using SkArenaAlloc::FooterAction = char* (char*)
protected

Definition at line 209 of file SkArenaAlloc.h.

Constructor & Destructor Documentation

◆ SkArenaAlloc() [1/4]

SkArenaAlloc::SkArenaAlloc ( char *  block,
size_t  blockSize,
size_t  firstHeapAllocation 
)

Definition at line 18 of file SkArenaAlloc.cpp.

19 : fDtorCursor {block}
20 , fCursor {block}
21 , fEnd {block + SkToU32(size)}
22 , fFibonacciProgression{SkToU32(size), SkToU32(firstHeapAllocation)}
23{
24 if (size < sizeof(Footer)) {
25 fEnd = fCursor = fDtorCursor = nullptr;
26 }
27
28 if (fCursor != nullptr) {
29 this->installFooter(end_chain, 0);
30 sk_asan_poison_memory_region(fCursor, fEnd - fCursor);
31 }
32}
static void sk_asan_poison_memory_region(void const volatile *addr, size_t size)
Definition: SkASAN.h:34
static char * end_chain(char *)
constexpr uint32_t SkToU32(S x)
Definition: SkTo.h:26
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

◆ SkArenaAlloc() [2/4]

SkArenaAlloc::SkArenaAlloc ( size_t  firstHeapAllocation)
inlineexplicit

Definition at line 109 of file SkArenaAlloc.h.

110 : SkArenaAlloc(nullptr, 0, firstHeapAllocation) {}
SkArenaAlloc(char *block, size_t blockSize, size_t firstHeapAllocation)

◆ SkArenaAlloc() [3/4]

SkArenaAlloc::SkArenaAlloc ( const SkArenaAlloc )
delete

◆ SkArenaAlloc() [4/4]

SkArenaAlloc::SkArenaAlloc ( SkArenaAlloc &&  )
delete

◆ ~SkArenaAlloc()

SkArenaAlloc::~SkArenaAlloc ( )

Definition at line 34 of file SkArenaAlloc.cpp.

34 {
35 RunDtorsOnBlock(fDtorCursor);
36}

Member Function Documentation

◆ cursor()

char * SkArenaAlloc::cursor ( )
inlineprotected

Definition at line 215 of file SkArenaAlloc.h.

215{ return fCursor; }

◆ end()

char * SkArenaAlloc::end ( )
inlineprotected

Definition at line 216 of file SkArenaAlloc.h.

216{ return fEnd; }

◆ make() [1/3]

template<typename T >
T * SkArenaAlloc::make ( )
inline

Definition at line 158 of file SkArenaAlloc.h.

158 {
160 // Just allocate some aligned bytes. This generates smaller code.
161 return (T*)this->makeBytesAlignedTo(sizeof(T), alignof(T));
162 } else {
163 // This isn't a POD type, so construct the object properly.
164 return this->make([&](void* objStart) {
165 return new(objStart) T();
166 });
167 }
168 }
void * makeBytesAlignedTo(size_t size, size_t align)
Definition: SkArenaAlloc.h:200
uint8_t value
#define T
Definition: precompiler.cc:65

◆ make() [2/3]

template<typename T , typename... Args>
T * SkArenaAlloc::make ( Args &&...  args)
inline

Definition at line 151 of file SkArenaAlloc.h.

151 {
152 return this->make([&](void* objStart) {
153 return new(objStart) T(std::forward<Args>(args)...);
154 });
155 }
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args

◆ make() [3/3]

template<typename Ctor >
auto SkArenaAlloc::make ( Ctor &&  ctor) -> decltype(ctor(nullptr))
inline

Definition at line 120 of file SkArenaAlloc.h.

120 {
121 using T = std::remove_pointer_t<decltype(ctor(nullptr))>;
122
123 uint32_t size = SkToU32(sizeof(T));
124 uint32_t alignment = SkToU32(alignof(T));
125 char* objStart;
127 objStart = this->allocObject(size, alignment);
128 fCursor = objStart + size;
130 } else {
131 objStart = this->allocObjectWithFooter(size + sizeof(Footer), alignment);
132 // Can never be UB because max value is alignof(T).
133 uint32_t padding = SkToU32(objStart - fCursor);
134
135 // Advance to end of object to install footer.
136 fCursor = objStart + size;
138 FooterAction* releaser = [](char* objEnd) {
139 char* objStart = objEnd - (sizeof(T) + sizeof(Footer));
140 ((T*)objStart)->~T();
141 return objStart;
142 };
143 this->installFooter(releaser, padding);
144 }
145
146 // This must be last to make objects with nested use of this allocator work.
147 return ctor(objStart);
148 }
static void sk_asan_unpoison_memory_region(void const volatile *addr, size_t size)
Definition: SkASAN.h:41
char *(char *) FooterAction
Definition: SkArenaAlloc.h:209

◆ makeArray()

template<typename T >
T * SkArenaAlloc::makeArray ( size_t  count)
inline

Definition at line 181 of file SkArenaAlloc.h.

181 {
182 T* array = this->allocUninitializedArray<T>(count);
183 for (size_t i = 0; i < count; i++) {
184 // Value initialization: if T is primitive then the value is zero-initialized.
185 new (&array[i]) T();
186 }
187 return array;
188 }
int count
Definition: FontMgrTest.cpp:50

◆ makeArrayDefault()

template<typename T >
T * SkArenaAlloc::makeArrayDefault ( size_t  count)
inline

Definition at line 171 of file SkArenaAlloc.h.

171 {
172 T* array = this->allocUninitializedArray<T>(count);
173 for (size_t i = 0; i < count; i++) {
174 // Default initialization: if T is primitive then the value is left uninitialized.
175 new (&array[i]) T;
176 }
177 return array;
178 }

◆ makeBytesAlignedTo()

void * SkArenaAlloc::makeBytesAlignedTo ( size_t  size,
size_t  align 
)
inline

Definition at line 200 of file SkArenaAlloc.h.

200 {
201 AssertRelease(SkTFitsIn<uint32_t>(size));
202 auto objStart = this->allocObject(SkToU32(size), SkToU32(align));
203 fCursor = objStart + size;
205 return objStart;
206 }

◆ makeInitializedArray()

template<typename T , typename Initializer >
T * SkArenaAlloc::makeInitializedArray ( size_t  count,
Initializer  initializer 
)
inline

Definition at line 191 of file SkArenaAlloc.h.

191 {
192 T* array = this->allocUninitializedArray<T>(count);
193 for (size_t i = 0; i < count; i++) {
194 new (&array[i]) T(initializer(i));
195 }
196 return array;
197 }
static struct Initializer initializer

◆ operator=() [1/2]

SkArenaAlloc & SkArenaAlloc::operator= ( const SkArenaAlloc )
delete

◆ operator=() [2/2]

SkArenaAlloc & SkArenaAlloc::operator= ( SkArenaAlloc &&  )
delete

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