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"
39 #include "../private/SkMalloc.h"
49 #define SKIA_VERSION_MAJOR 1
50 #define SKIA_VERSION_MINOR 0
51 #define SKIA_VERSION_PATCH 0
62 #ifdef override_GLOBAL_NEW
65 inline void*
operator new(
size_t size) {
66 return sk_malloc_throw(size);
69 inline void operator delete(
void* p) {
76 #define SK_INIT_TO_AVOID_WARNING = 0
79 SK_API
void SkDebugf(
const char format[], ...);
82 #define SkREQUIRE_SEMICOLON_AFTER(code) do { code } while (false)
84 #define SkASSERT_RELEASE(cond) \
85 SkREQUIRE_SEMICOLON_AFTER(if (!(cond)) { SK_ABORT(#cond); } )
88 #define SkASSERT(cond) \
89 SkREQUIRE_SEMICOLON_AFTER(if (!(cond)) { SK_ABORT("assert(" #cond ")"); })
90 #define SkASSERTF(cond, fmt, ...) \
91 SkREQUIRE_SEMICOLON_AFTER(if (!(cond)) { \
92 SkDebugf(fmt"\n", __VA_ARGS__); \
93 SK_ABORT("assert(" #cond ")"); \
95 #define SkDEBUGFAIL(message) SK_ABORT(message)
96 #define SkDEBUGFAILF(fmt, ...) SkASSERTF(false, fmt, ##__VA_ARGS__)
97 #define SkDEBUGCODE(...) __VA_ARGS__
98 #define SkDECLAREPARAM(type, var) , type var
99 #define SkPARAM(var) , var
100 #define SkDEBUGF(args ) SkDebugf args
101 #define SkAssertResult(cond) SkASSERT(cond)
103 #define SkASSERT(cond)
104 #define SkASSERTF(cond, fmt, ...)
105 #define SkDEBUGFAIL(message)
106 #define SkDEBUGFAILF(fmt, ...)
107 #define SkDEBUGCODE(...)
108 #define SkDEBUGF(args)
109 #define SkDECLAREPARAM(type, var)
114 #define SkAssertResult(cond) if (cond) {} do {} while(false)
118 #define SkFAIL(message) SK_ABORT(message)
119 #define sk_throw() SK_ABORT("sk_throw")
121 #ifdef SK_IGNORE_TO_STRING
122 #define SK_TO_STRING_NONVIRT()
123 #define SK_TO_STRING_VIRT()
124 #define SK_TO_STRING_PUREVIRT()
125 #define SK_TO_STRING_OVERRIDE()
130 #define SK_TO_STRING_NONVIRT() void toString(SkString* str) const;
131 #define SK_TO_STRING_VIRT() virtual void toString(SkString* str) const;
132 #define SK_TO_STRING_PUREVIRT() virtual void toString(SkString* str) const = 0;
133 #define SK_TO_STRING_OVERRIDE() void toString(SkString* str) const override;
142 #define SK_MACRO_CONCAT(X, Y) SK_MACRO_CONCAT_IMPL_PRIV(X, Y)
143 #define SK_MACRO_CONCAT_IMPL_PRIV(X, Y) X ## Y
151 #define SK_MACRO_APPEND_LINE(name) SK_MACRO_CONCAT(name, __LINE__)
176 #define SK_REQUIRE_LOCAL_VAR(classname) \
177 static_assert(false, "missing name for " #classname)
210 #include "../private/SkTFitsIn.h"
211 template <
typename D,
typename S> D SkTo(S s) {
212 SkASSERT(SkTFitsIn<D>(s));
213 return static_cast<D
>(s);
215 #define SkToS8(x) SkTo<int8_t>(x)
216 #define SkToU8(x) SkTo<uint8_t>(x)
217 #define SkToS16(x) SkTo<int16_t>(x)
218 #define SkToU16(x) SkTo<uint16_t>(x)
219 #define SkToS32(x) SkTo<int32_t>(x)
220 #define SkToU32(x) SkTo<uint32_t>(x)
221 #define SkToInt(x) SkTo<int>(x)
222 #define SkToUInt(x) SkTo<unsigned>(x)
223 #define SkToSizeT(x) SkTo<size_t>(x)
227 #define SkToBool(cond) ((cond) != 0)
229 #define SK_MaxS16 32767
230 #define SK_MinS16 -32767
231 #define SK_MaxU16 0xFFFF
233 #define SK_MaxS32 0x7FFFFFFF
234 #define SK_MinS32 -SK_MaxS32
235 #define SK_MaxU32 0xFFFFFFFF
237 #define SK_NaN32 ((int) (1U << 31))
242 return (int16_t)x == x;
248 return (uint16_t)x == x;
251 static inline int32_t SkLeftShift(int32_t value, int32_t shift) {
252 return (int32_t) ((uint32_t) value << shift);
255 static inline int64_t SkLeftShift(int64_t value, int32_t shift) {
256 return (int64_t) ((uint64_t) value << shift);
263 #define SK_ARRAY_COUNT(array) (sizeof(SkArrayCountHelper(array)))
266 #if defined(__clang__) // This should work on GCC too, but GCC diagnostic pop didn't seem to work!
267 #define SK_BEGIN_REQUIRE_DENSE _Pragma("GCC diagnostic push") \
268 _Pragma("GCC diagnostic error \"-Wpadded\"")
269 #define SK_END_REQUIRE_DENSE _Pragma("GCC diagnostic pop")
271 #define SK_BEGIN_REQUIRE_DENSE
272 #define SK_END_REQUIRE_DENSE
275 #define SkAlign2(x) (((x) + 1) >> 1 << 1)
276 #define SkIsAlign2(x) (0 == ((x) & 1))
278 #define SkAlign4(x) (((x) + 3) >> 2 << 2)
279 #define SkIsAlign4(x) (0 == ((x) & 3))
281 #define SkAlign8(x) (((x) + 7) >> 3 << 3)
282 #define SkIsAlign8(x) (0 == ((x) & 7))
284 #define SkAlign16(x) (((x) + 15) >> 4 << 4)
285 #define SkIsAlign16(x) (0 == ((x) & 15))
287 #define SkAlignPtr(x) (sizeof(void*) == 8 ? SkAlign8(x) : SkAlign4(x))
288 #define SkIsAlignPtr(x) (sizeof(void*) == 8 ? SkIsAlign8(x) : SkIsAlign4(x))
290 typedef uint32_t SkFourByteTag;
291 #define SkSetFourByteTag(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
307 #define SK_MSec1 1000
310 #define SK_MSecMax 0x7FFFFFFF
313 #define SkMSec_LT(a, b) ((int32_t)(a) - (int32_t)(b) < 0)
316 #define SkMSec_LE(a, b) ((int32_t)(a) - (int32_t)(b) <= 0)
320 #define SK_InvalidGenID 0
323 #define SK_InvalidUniqueID 0
332 static inline constexpr
int Sk32ToBool(uint32_t n) {
333 return (n | (0-n)) >> 31;
338 template <
typename T>
static inline void SkTSwap(T& a, T& b) {
344 static inline int32_t SkAbs32(int32_t value) {
345 SkASSERT(value != SK_NaN32);
352 template <
typename T>
static inline T SkTAbs(T value) {
359 static inline int32_t SkMax32(int32_t a, int32_t b) {
365 static inline int32_t SkMin32(int32_t a, int32_t b) {
371 template <
typename T> constexpr
const T& SkTMin(
const T& a,
const T& b) {
372 return (a < b) ? a : b;
375 template <
typename T> constexpr
const T& SkTMax(
const T& a,
const T& b) {
376 return (b < a) ? a : b;
379 static inline int32_t SkSign32(int32_t a) {
380 return (a >> 31) | ((unsigned) -a >> 31);
383 static inline int32_t SkFastMin32(int32_t value, int32_t max) {
391 template <
typename T>
static constexpr
const T& SkTPin(
const T& value,
const T& min,
const T& max) {
392 return SkTMax(SkTMin(value, max), min);
401 enum class SkBudgeted : bool {
410 enum class SkBackingFit {
419 template <
typename T>
420 T SkTBitOr(T a, T b) {
427 template <
typename Dst> Dst SkTCast(
const void* ptr) {
443 class SK_API SkNoncopyable {
445 SkNoncopyable() =
default;
447 SkNoncopyable(SkNoncopyable&&) =
default;
448 SkNoncopyable& operator =(SkNoncopyable&&) =
default;
450 SkNoncopyable(
const SkNoncopyable&) =
delete;
451 SkNoncopyable& operator=(
const SkNoncopyable&) =
delete;
uint16_t SkGlyphID
16 bit unsigned integer to hold a glyph index
Definition: SkTypes.h:299
char(& SkArrayCountHelper(T(&array)[N]))[N]
Returns the number of entries in an array (not a pointer)
uint8_t SkBool8
Meant to be a small version of bool, for storage purposes.
Definition: SkTypes.h:208
unsigned U16CPU
Fast type for unsigned 16 bits.
Definition: SkTypes.h:203
uint32_t SkMSec
32 bit value to hold a millisecond duration Note that SK_MSecMax is about 25 days.
Definition: SkTypes.h:304
static bool SkIsS16(long x)
Returns true if the value can be represented with signed 16bits.
Definition: SkTypes.h:241
static bool SkIsU16(long x)
Returns true if the value can be represented with unsigned 16bits.
Definition: SkTypes.h:247
int S8CPU
Fast type for signed 8 bits.
Definition: SkTypes.h:185
int32_t SkUnichar
32 bit integer to hold a unicode value
Definition: SkTypes.h:295
SK_API void sk_abort_no_print(void)
Called internally if we hit an unrecoverable error.
unsigned U8CPU
Fast type for unsigned 8 bits.
Definition: SkTypes.h:191
Light weight class for managing strings.
Definition: SkString.h:121
int S16CPU
Fast type for signed 16 bits.
Definition: SkTypes.h:197