8 #ifndef SkTypes_DEFINED
9 #define SkTypes_DEFINED
22 #if defined(__GNUC__) && __GNUC__ == 4 \
23 && ((defined(__arm__) && (defined(__ARM_NEON__) || defined(__ARM_NEON))) || defined(__aarch64__)) \
24 && defined(_LIBCPP_VERSION)
25 typedef float float32_t;
29 #include "SkPreConfig.h"
30 #include "SkUserConfig.h"
31 #include "SkPostConfig.h"
65 #define SKIA_VERSION_MAJOR 1
66 #define SKIA_VERSION_MINOR 0
67 #define SKIA_VERSION_PATCH 0
102 SK_API
extern void sk_free(
void*);
106 SK_API
extern void*
sk_calloc(
size_t size);
113 static inline void sk_bzero(
void* buffer,
size_t size) {
116 memset(buffer, 0, size);
122 #ifdef override_GLOBAL_NEW
125 inline void*
operator new(
size_t size) {
129 inline void operator delete(
void* p) {
136 #define SK_INIT_TO_AVOID_WARNING = 0
139 SK_API
void SkDebugf(
const char format[], ...);
142 #define SkREQUIRE_SEMICOLON_AFTER(code) do { code } while (false)
144 #define SkASSERT_RELEASE(cond) \
145 SkREQUIRE_SEMICOLON_AFTER(if (!(cond)) { SK_ABORT(#cond); } )
148 #define SkASSERT(cond) \
149 SkREQUIRE_SEMICOLON_AFTER(if (!(cond)) { SK_ABORT("assert(" #cond ")"); })
150 #define SkASSERTF(cond, fmt, ...) \
151 SkREQUIRE_SEMICOLON_AFTER(if (!(cond)) { \
152 SkDebugf(fmt"\n", __VA_ARGS__); \
153 SK_ABORT("assert(" #cond ")"); \
155 #define SkDEBUGFAIL(message) SK_ABORT(message)
156 #define SkDEBUGFAILF(fmt, ...) SkASSERTF(false, fmt, ##__VA_ARGS__)
157 #define SkDEBUGCODE(...) __VA_ARGS__
158 #define SkDECLAREPARAM(type, var) , type var
159 #define SkPARAM(var) , var
160 #define SkDEBUGF(args ) SkDebugf args
161 #define SkAssertResult(cond) SkASSERT(cond)
163 #define SkASSERT(cond)
164 #define SkASSERTF(cond, fmt, ...)
165 #define SkDEBUGFAIL(message)
166 #define SkDEBUGFAILF(fmt, ...)
167 #define SkDEBUGCODE(...)
168 #define SkDEBUGF(args)
169 #define SkDECLAREPARAM(type, var)
174 #define SkAssertResult(cond) if (cond) {} do {} while(false)
178 #define SkFAIL(message) SK_ABORT(message)
179 #define sk_throw() SK_ABORT("sk_throw")
181 #ifdef SK_IGNORE_TO_STRING
182 #define SK_TO_STRING_NONVIRT()
183 #define SK_TO_STRING_VIRT()
184 #define SK_TO_STRING_PUREVIRT()
185 #define SK_TO_STRING_OVERRIDE()
190 #define SK_TO_STRING_NONVIRT() void toString(SkString* str) const;
191 #define SK_TO_STRING_VIRT() virtual void toString(SkString* str) const;
192 #define SK_TO_STRING_PUREVIRT() virtual void toString(SkString* str) const = 0;
193 #define SK_TO_STRING_OVERRIDE() void toString(SkString* str) const override;
202 #define SK_MACRO_CONCAT(X, Y) SK_MACRO_CONCAT_IMPL_PRIV(X, Y)
203 #define SK_MACRO_CONCAT_IMPL_PRIV(X, Y) X ## Y
211 #define SK_MACRO_APPEND_LINE(name) SK_MACRO_CONCAT(name, __LINE__)
236 #define SK_REQUIRE_LOCAL_VAR(classname) \
237 static_assert(false, "missing name for " #classname)
270 #include "../private/SkTFitsIn.h"
271 template <
typename D,
typename S> D SkTo(S s) {
272 SkASSERT(SkTFitsIn<D>(s));
273 return static_cast<D
>(s);
275 #define SkToS8(x) SkTo<int8_t>(x)
276 #define SkToU8(x) SkTo<uint8_t>(x)
277 #define SkToS16(x) SkTo<int16_t>(x)
278 #define SkToU16(x) SkTo<uint16_t>(x)
279 #define SkToS32(x) SkTo<int32_t>(x)
280 #define SkToU32(x) SkTo<uint32_t>(x)
281 #define SkToInt(x) SkTo<int>(x)
282 #define SkToUInt(x) SkTo<unsigned>(x)
283 #define SkToSizeT(x) SkTo<size_t>(x)
287 #define SkToBool(cond) ((cond) != 0)
289 #define SK_MaxS16 32767
290 #define SK_MinS16 -32767
291 #define SK_MaxU16 0xFFFF
293 #define SK_MaxS32 0x7FFFFFFF
294 #define SK_MinS32 -SK_MaxS32
295 #define SK_MaxU32 0xFFFFFFFF
297 #define SK_NaN32 ((int) (1U << 31))
302 return (int16_t)x == x;
308 return (uint16_t)x == x;
311 static inline int32_t SkLeftShift(int32_t value, int32_t shift) {
312 return (int32_t) ((uint32_t) value << shift);
315 static inline int64_t SkLeftShift(int64_t value, int32_t shift) {
316 return (int64_t) ((uint64_t) value << shift);
323 #define SK_ARRAY_COUNT(array) (sizeof(SkArrayCountHelper(array)))
326 #if defined(__clang__) // This should work on GCC too, but GCC diagnostic pop didn't seem to work!
327 #define SK_BEGIN_REQUIRE_DENSE _Pragma("GCC diagnostic push") \
328 _Pragma("GCC diagnostic error \"-Wpadded\"")
329 #define SK_END_REQUIRE_DENSE _Pragma("GCC diagnostic pop")
331 #define SK_BEGIN_REQUIRE_DENSE
332 #define SK_END_REQUIRE_DENSE
335 #define SkAlign2(x) (((x) + 1) >> 1 << 1)
336 #define SkIsAlign2(x) (0 == ((x) & 1))
338 #define SkAlign4(x) (((x) + 3) >> 2 << 2)
339 #define SkIsAlign4(x) (0 == ((x) & 3))
341 #define SkAlign8(x) (((x) + 7) >> 3 << 3)
342 #define SkIsAlign8(x) (0 == ((x) & 7))
344 #define SkAlign16(x) (((x) + 15) >> 4 << 4)
345 #define SkIsAlign16(x) (0 == ((x) & 15))
347 #define SkAlignPtr(x) (sizeof(void*) == 8 ? SkAlign8(x) : SkAlign4(x))
348 #define SkIsAlignPtr(x) (sizeof(void*) == 8 ? SkIsAlign8(x) : SkIsAlign4(x))
350 typedef uint32_t SkFourByteTag;
351 #define SkSetFourByteTag(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
367 #define SK_MSec1 1000
370 #define SK_MSecMax 0x7FFFFFFF
373 #define SkMSec_LT(a, b) ((int32_t)(a) - (int32_t)(b) < 0)
376 #define SkMSec_LE(a, b) ((int32_t)(a) - (int32_t)(b) <= 0)
380 #define SK_InvalidGenID 0
383 #define SK_InvalidUniqueID 0
392 static inline constexpr
int Sk32ToBool(uint32_t n) {
393 return (n | (0-n)) >> 31;
398 template <
typename T>
inline void SkTSwap(T& a, T& b) {
404 static inline int32_t SkAbs32(int32_t value) {
405 SkASSERT(value != SK_NaN32);
412 template <
typename T>
inline T SkTAbs(T value) {
419 static inline int32_t SkMax32(int32_t a, int32_t b) {
425 static inline int32_t SkMin32(int32_t a, int32_t b) {
431 template <
typename T> constexpr
const T& SkTMin(
const T& a,
const T& b) {
432 return (a < b) ? a : b;
435 template <
typename T> constexpr
const T& SkTMax(
const T& a,
const T& b) {
436 return (b < a) ? a : b;
439 static inline int32_t SkSign32(int32_t a) {
440 return (a >> 31) | ((unsigned) -a >> 31);
443 static inline int32_t SkFastMin32(int32_t value, int32_t max) {
451 template <
typename T>
static constexpr
const T& SkTPin(
const T& value,
const T& min,
const T& max) {
452 return SkTMax(SkTMin(value, max), min);
461 enum class SkBudgeted : bool {
470 enum class SkBackingFit {
479 template <
typename T>
480 T SkTBitOr(T a, T b) {
487 template <
typename Dst> Dst SkTCast(
const void* ptr) {
503 class SK_API SkNoncopyable {
508 SkNoncopyable(
const SkNoncopyable&);
509 SkNoncopyable& operator=(
const SkNoncopyable&);
512 class SkAutoFree : SkNoncopyable {
514 SkAutoFree() : fPtr(NULL) {}
515 explicit SkAutoFree(
void* ptr) : fPtr(ptr) {}
516 ~SkAutoFree() {
sk_free(fPtr); }
520 void*
get()
const {
return fPtr; }
526 void* set(
void* ptr) {
536 void* release() {
return this->set(NULL); }
549 SkAutoFree(
const SkAutoFree&);
550 SkAutoFree& operator=(
const SkAutoFree&);
552 #define SkAutoFree(...) SK_REQUIRE_LOCAL_VAR(SkAutoFree)
559 class SkAutoMalloc : SkNoncopyable {
561 explicit SkAutoMalloc(
size_t size = 0) {
593 void* reset(
size_t size = 0, OnShrink shrink = kAlloc_OnShrink,
bool* didChangeAlloc = NULL) {
594 if (size == fSize || (kReuse_OnShrink == shrink && size < fSize)) {
595 if (didChangeAlloc) {
596 *didChangeAlloc =
false;
604 if (didChangeAlloc) {
605 *didChangeAlloc =
true;
614 void*
get() {
return fPtr; }
615 const void*
get()
const {
return fPtr; }
632 #define SkAutoMalloc(...) SK_REQUIRE_LOCAL_VAR(SkAutoMalloc)
640 template <
size_t kSizeRequested>
class SkAutoSMalloc : SkNoncopyable {
655 explicit SkAutoSMalloc(
size_t size) {
666 if (fPtr != (
void*)fStorage) {
676 void*
get()
const {
return fPtr; }
683 void* reset(
size_t size,
684 SkAutoMalloc::OnShrink shrink = SkAutoMalloc::kAlloc_OnShrink,
685 bool* didChangeAlloc = NULL) {
686 size = (size < kSize) ? kSize : size;
687 bool alloc = size != fSize && (SkAutoMalloc::kAlloc_OnShrink == shrink || size > fSize);
688 if (didChangeAlloc) {
689 *didChangeAlloc = alloc;
692 if (fPtr != (
void*)fStorage) {
697 SkASSERT(fPtr != fStorage);
705 SkASSERT(fSize >= size && fSize >= kSize);
706 SkASSERT((fPtr == fStorage) || fSize > kSize);
712 static const size_t kSizeAlign4 = SkAlign4(kSizeRequested);
716 static const size_t kMaxBytes = 4 * 1024;
717 static const size_t kSize = kSizeRequested > kMaxBytes ? kMaxBytes : kSizeAlign4;
719 static const size_t kSize = kSizeAlign4;
724 uint32_t fStorage[kSize >> 2];
SK_API void * sk_malloc_throw(size_t size)
Same as sk_malloc(), but hard coded to pass SK_MALLOC_THROW as the flag.
uint16_t SkGlyphID
16 bit unsigned integer to hold a glyph index
Definition: SkTypes.h:359
SK_API void sk_out_of_memory(void)
Called internally if we run out of memory.
char(& SkArrayCountHelper(T(&array)[N]))[N]
Returns the number of entries in an array (not a pointer)
SK_API void * sk_calloc_throw(size_t size)
Same as sk_calloc, but throws an exception instead of returning NULL on failure.
SK_API void * sk_malloc_flags(size_t size, unsigned flags)
Return a block of memory (at least 4-byte aligned) of at least the specified size.
uint8_t SkBool8
Meant to be a small version of bool, for storage purposes.
Definition: SkTypes.h:268
unsigned U16CPU
Fast type for unsigned 16 bits.
Definition: SkTypes.h:263
instructs sk_malloc to call sk_throw if the memory cannot be allocated.
Definition: SkTypes.h:85
SK_API void sk_free(void *)
Free memory returned by sk_malloc().
uint32_t SkMSec
32 bit value to hold a millisecond duration Note that SK_MSecMax is about 25 days.
Definition: SkTypes.h:364
hint to sk_malloc that the requested memory will be freed in the scope of the stack frame ...
Definition: SkTypes.h:84
static bool SkIsS16(long x)
Returns true if the value can be represented with signed 16bits.
Definition: SkTypes.h:301
static bool SkIsU16(long x)
Returns true if the value can be represented with unsigned 16bits.
Definition: SkTypes.h:307
int S8CPU
Fast type for signed 8 bits.
Definition: SkTypes.h:245
int32_t SkUnichar
32 bit integer to hold a unicode value
Definition: SkTypes.h:355
SK_API void sk_abort_no_print(void)
Called internally if we hit an unrecoverable error.
static void * sk_careful_memcpy(void *dst, const void *src, size_t len)
sk_careful_memcpy() is just like memcpy(), but guards against undefined behavior. ...
Definition: SkTypes.h:51
SK_API void * sk_realloc_throw(void *buffer, size_t size)
Same as standard realloc(), but this one never returns null on failure.
SK_API void * sk_calloc(size_t size)
Much like calloc: returns a pointer to at least size zero bytes, or NULL on failure.
unsigned U8CPU
Fast type for unsigned 8 bits.
Definition: SkTypes.h:251
Light weight class for managing strings.
Definition: SkString.h:121
int S16CPU
Fast type for signed 16 bits.
Definition: SkTypes.h:257