Flutter Engine
The Flutter Engine
Typedefs | Functions
SkRPCtxUtils Namespace Reference

Typedefs

template<typename T >
using UnpackedType = typename std::conditional< sizeof(T)<=sizeof(void *), T, const T & >::type
 

Functions

template<typename T >
static void * Pack (const T &ctx, SkArenaAlloc *alloc)
 
template<typename T >
static UnpackedType< TUnpack (const T *ctx)
 

Typedef Documentation

◆ UnpackedType

template<typename T >
using SkRPCtxUtils::UnpackedType = typedef typename std::conditional<sizeof(T) <= sizeof(void*), T, const T&>::type

Definition at line 20 of file SkRasterPipelineContextUtils.h.

Function Documentation

◆ Pack()

template<typename T >
static void * SkRPCtxUtils::Pack ( const T ctx,
SkArenaAlloc alloc 
)
static

SkRPCtxUtils::Pack will check if the passed-in struct is small enough to fit directly in the context field. If so, it will return the data bit-casted into a void pointer. If not, it allocates a copy of the struct inside the alloc and then returns a pointer to the copy.

Definition at line 28 of file SkRasterPipelineContextUtils.h.

28 {
29 // If the context is small enough to fit in a pointer, bit-cast it; if not, alloc a copy.
30 if constexpr (sizeof(T) <= sizeof(void*)) {
31 return sk_bit_cast<void*>(ctx);
32 } else {
33 return alloc->make<T>(ctx);
34 }
35}
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
Definition: SkArenaAlloc.h:120
#define T
Definition: precompiler.cc:65

◆ Unpack()

template<typename T >
static UnpackedType< T > SkRPCtxUtils::Unpack ( const T ctx)
static

SkRPCtxUtils::Unpack performs the reverse operation: either un-bitcasting the object back to its original form, or returning the pointer as-is, depending on the size of the type.

Definition at line 42 of file SkRasterPipelineContextUtils.h.

42 {
43 // If the context struct fits in a pointer, reinterpret the bits; if it doesn't, return
44 // a reference. This can vary based on the architecture (32-bit pointers vs 64-bit) so we
45 // let the compiler decide which is right, rather than hard-coding it.
46 if constexpr (sizeof(T) <= sizeof(void*)) {
47 return sk_bit_cast<T>(ctx);
48 } else {
49 return *ctx;
50 }
51}