 |
Skia
2D Graphics Library
|
Go to the documentation of this file.
8 #ifndef SkTypes_DEFINED
9 #define SkTypes_DEFINED
18 #define SK_NOTHING_ARG1(arg1)
19 #define SK_NOTHING_ARG2(arg1, arg2)
20 #define SK_NOTHING_ARG3(arg1, arg2, arg3)
22 #if !defined(SK_BUILD_FOR_ANDROID) && !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_WIN) && \
23 !defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_MAC)
26 #include "TargetConditionals.h"
29 #if defined(_WIN32) || defined(__SYMBIAN32__)
30 #define SK_BUILD_FOR_WIN
31 #elif defined(ANDROID) || defined(__ANDROID__)
32 #define SK_BUILD_FOR_ANDROID
33 #elif defined(linux) || defined(__linux) || defined(__FreeBSD__) || \
34 defined(__OpenBSD__) || defined(__sun) || defined(__NetBSD__) || \
35 defined(__DragonFly__) || defined(__Fuchsia__) || \
36 defined(__GLIBC__) || defined(__GNU__) || defined(__unix__)
37 #define SK_BUILD_FOR_UNIX
38 #elif TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
39 #define SK_BUILD_FOR_IOS
41 #define SK_BUILD_FOR_MAC
46 #if defined(SK_BUILD_FOR_WIN) && !defined(__clang__)
47 #if !defined(SK_RESTRICT)
48 #define SK_RESTRICT __restrict
50 #if !defined(SK_WARN_UNUSED_RESULT)
51 #define SK_WARN_UNUSED_RESULT
55 #if !defined(SK_RESTRICT)
56 #define SK_RESTRICT __restrict__
59 #if !defined(SK_WARN_UNUSED_RESULT)
60 #define SK_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
63 #if !defined(SK_CPU_BENDIAN) && !defined(SK_CPU_LENDIAN)
64 #if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
65 #define SK_CPU_BENDIAN
66 #elif defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
67 #define SK_CPU_LENDIAN
68 #elif defined(__sparc) || defined(__sparc__) || \
69 defined(_POWER) || defined(__powerpc__) || \
70 defined(__ppc__) || defined(__hppa) || \
71 defined(__PPC__) || defined(__PPC64__) || \
72 defined(_MIPSEB) || defined(__ARMEB__) || \
73 defined(__s390__) || \
74 (defined(__sh__) && defined(__BIG_ENDIAN__)) || \
75 (defined(__ia64) && defined(__BIG_ENDIAN__))
76 #define SK_CPU_BENDIAN
78 #define SK_CPU_LENDIAN
82 #if defined(__i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)
92 #define SK_CPU_SSE_LEVEL_SSE1 10
93 #define SK_CPU_SSE_LEVEL_SSE2 20
94 #define SK_CPU_SSE_LEVEL_SSE3 30
95 #define SK_CPU_SSE_LEVEL_SSSE3 31
96 #define SK_CPU_SSE_LEVEL_SSE41 41
97 #define SK_CPU_SSE_LEVEL_SSE42 42
98 #define SK_CPU_SSE_LEVEL_AVX 51
99 #define SK_CPU_SSE_LEVEL_AVX2 52
100 #define SK_CPU_SSE_LEVEL_SKX 60
103 #ifndef SK_CPU_SSE_LEVEL
106 #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \
107 defined(__AVX512BW__) && defined(__AVX512VL__)
108 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX
109 #elif defined(__AVX2__)
110 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2
111 #elif defined(__AVX__)
112 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX
113 #elif defined(__SSE4_2__)
114 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE42
115 #elif defined(__SSE4_1__)
116 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE41
117 #elif defined(__SSSE3__)
118 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSSE3
119 #elif defined(__SSE3__)
120 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE3
121 #elif defined(__SSE2__)
122 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2
127 #ifndef SK_CPU_SSE_LEVEL
130 #if defined(__AVX512F__) && defined(__AVX512DQ__) && defined(__AVX512CD__) && \
131 defined(__AVX512BW__) && defined(__AVX512VL__)
132 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SKX
133 #elif defined(__AVX2__)
134 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX2
135 #elif defined(__AVX__)
136 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_AVX
137 #elif defined(_M_X64) || defined(_M_AMD64)
138 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2
139 #elif defined(_M_IX86_FP)
141 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE2
142 #elif _M_IX86_FP == 1
143 #define SK_CPU_SSE_LEVEL SK_CPU_SSE_LEVEL_SSE1
149 #if defined(__arm__) && (!defined(__APPLE__) || !TARGET_IPHONE_SIMULATOR)
151 #elif defined(__aarch64__)
156 #if !defined(SK_ARM_HAS_NEON) && defined(__ARM_NEON)
157 #define SK_ARM_HAS_NEON
160 #if defined(__ARM_FEATURE_CRC32)
161 #define SK_ARM_HAS_CRC32
166 #if !defined(SKIA_IMPLEMENTATION)
167 #define SKIA_IMPLEMENTATION 0
170 #if defined(SKIA_DLL)
171 #if defined(_MSC_VER)
172 #if SKIA_IMPLEMENTATION
173 #define SK_API __declspec(dllexport)
175 #define SK_API __declspec(dllimport)
178 #define SK_API __attribute__((visibility("default")))
187 #define SK_SPI SK_API
191 #if defined (SK_USER_CONFIG_HEADER)
192 #include SK_USER_CONFIG_HEADER
194 #include "include/config/SkUserConfig.h"
201 #if !defined(SK_DEBUG) && !defined(SK_RELEASE)
209 #if defined(SK_DEBUG) && defined(SK_RELEASE)
210 # error "cannot define both SK_DEBUG and SK_RELEASE"
211 #elif !defined(SK_DEBUG) && !defined(SK_RELEASE)
212 # error "must define either SK_DEBUG or SK_RELEASE"
215 #if defined(SK_CPU_LENDIAN) && defined(SK_CPU_BENDIAN)
216 # error "cannot define both SK_CPU_LENDIAN and SK_CPU_BENDIAN"
217 #elif !defined(SK_CPU_LENDIAN) && !defined(SK_CPU_BENDIAN)
218 # error "must define either SK_CPU_LENDIAN or SK_CPU_BENDIAN"
221 #if defined(SK_CPU_BENDIAN) && !defined(I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN)
222 #error "The Skia team is not endian-savvy enough to support big-endian CPUs."
223 #error "If you still want to use Skia,"
224 #error "please define I_ACKNOWLEDGE_SKIA_DOES_NOT_SUPPORT_BIG_ENDIAN."
227 #if !defined(SK_ATTRIBUTE)
228 # if defined(__clang__) || defined(__GNUC__)
229 # define SK_ATTRIBUTE(attr) __attribute__((attr))
231 # define SK_ATTRIBUTE(attr)
235 #if !defined(SK_SUPPORT_GPU)
236 # define SK_SUPPORT_GPU 1
247 #if !defined(SkUNREACHABLE)
248 # if defined(_MSC_VER) && !defined(__clang__)
250 # define FAST_FAIL_INVALID_ARG 5
253 [[noreturn]]
static inline void sk_fast_fail() { __fastfail(FAST_FAIL_INVALID_ARG); }
254 # define SkUNREACHABLE sk_fast_fail()
256 # define SkUNREACHABLE __builtin_trap()
260 #if defined(SK_BUILD_FOR_GOOGLE3)
261 void SkDebugfForDumpStackTrace(
const char* data,
void* unused);
262 void DumpStackTrace(
int skip_count,
void w(
const char*,
void*),
void* arg);
263 # define SK_DUMP_GOOGLE3_STACK() DumpStackTrace(0, SkDebugfForDumpStackTrace, nullptr)
265 # define SK_DUMP_GOOGLE3_STACK()
269 # ifdef SK_BUILD_FOR_WIN
271 # define SK_DUMP_LINE_FORMAT "%s(%d)"
273 # define SK_DUMP_LINE_FORMAT "%s:%d"
275 # define SK_ABORT(message, ...) \
277 SkDebugf(SK_DUMP_LINE_FORMAT ": fatal error: \"" message "\"\n", \
278 __FILE__, __LINE__, ##__VA_ARGS__); \
279 SK_DUMP_GOOGLE3_STACK(); \
280 sk_abort_no_print(); \
286 #if defined(SK_R32_SHIFT)
288 #elif defined(SK_BUILD_FOR_WIN)
289 #define SK_R32_SHIFT 16
291 #define SK_R32_SHIFT 0
294 #if defined(SK_B32_SHIFT)
297 #define SK_B32_SHIFT (16-SK_R32_SHIFT)
300 #define SK_G32_SHIFT 8
301 #define SK_A32_SHIFT 24
307 #ifdef SK_CPU_BENDIAN
308 # define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \
309 (SK_ ## C3 ## 32_SHIFT == 0 && \
310 SK_ ## C2 ## 32_SHIFT == 8 && \
311 SK_ ## C1 ## 32_SHIFT == 16 && \
312 SK_ ## C0 ## 32_SHIFT == 24)
314 # define SK_PMCOLOR_BYTE_ORDER(C0, C1, C2, C3) \
315 (SK_ ## C0 ## 32_SHIFT == 0 && \
316 SK_ ## C1 ## 32_SHIFT == 8 && \
317 SK_ ## C2 ## 32_SHIFT == 16 && \
318 SK_ ## C3 ## 32_SHIFT == 24)
321 #if defined SK_DEBUG && defined SK_BUILD_FOR_WIN
329 #if !defined(SK_UNUSED)
330 # if !defined(__clang__) && defined(_MSC_VER)
331 # define SK_UNUSED __pragma(warning(suppress:4189))
333 # define SK_UNUSED SK_ATTRIBUTE(unused)
343 #if !defined(SK_ALWAYS_INLINE)
344 # if defined(SK_BUILD_FOR_WIN)
345 # define SK_ALWAYS_INLINE __forceinline
347 # define SK_ALWAYS_INLINE SK_ATTRIBUTE(always_inline) inline
355 #if !defined(SK_NEVER_INLINE)
356 # if defined(SK_BUILD_FOR_WIN)
357 # define SK_NEVER_INLINE __declspec(noinline)
359 # define SK_NEVER_INLINE SK_ATTRIBUTE(noinline)
363 #if SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE1
364 #define SK_PREFETCH(ptr) _mm_prefetch(reinterpret_cast<const char*>(ptr), _MM_HINT_T0)
365 #elif defined(__GNUC__)
366 #define SK_PREFETCH(ptr) __builtin_prefetch(ptr)
368 #define SK_PREFETCH(ptr)
371 #ifndef SK_PRINTF_LIKE
372 # if defined(__clang__) || defined(__GNUC__)
373 # define SK_PRINTF_LIKE(A, B) __attribute__((format(printf, (A), (B))))
375 # define SK_PRINTF_LIKE(A, B)
379 #ifndef SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
380 #define SK_ALLOW_STATIC_GLOBAL_INITIALIZERS 0
383 #if !defined(SK_GAMMA_EXPONENT)
384 #define SK_GAMMA_EXPONENT (0.0f) // SRGB
387 #ifndef GR_TEST_UTILS
388 # define GR_TEST_UTILS 0
391 #if defined(SK_HISTOGRAM_ENUMERATION) || \
392 defined(SK_HISTOGRAM_BOOLEAN) || \
393 defined(SK_HISTOGRAM_EXACT_LINEAR) || \
394 defined(SK_HISTOGRAM_MEMORY_KB)
395 # define SK_HISTOGRAMS_ENABLED 1
397 # define SK_HISTOGRAMS_ENABLED 0
400 #ifndef SK_HISTOGRAM_BOOLEAN
401 # define SK_HISTOGRAM_BOOLEAN(name, sample)
404 #ifndef SK_HISTOGRAM_ENUMERATION
405 # define SK_HISTOGRAM_ENUMERATION(name, sample, enum_size)
408 #ifndef SK_HISTOGRAM_EXACT_LINEAR
409 # define SK_HISTOGRAM_EXACT_LINEAR(name, sample, value_max)
412 #ifndef SK_HISTOGRAM_MEMORY_KB
413 # define SK_HISTOGRAM_MEMORY_KB(name, sample)
416 #define SK_HISTOGRAM_PERCENTAGE(name, percent_as_int) \
417 SK_HISTOGRAM_EXACT_LINEAR(name, percent_as_int, 101)
419 #ifndef SK_DISABLE_LEGACY_SHADERCONTEXT
420 #define SK_ENABLE_LEGACY_SHADERCONTEXT
423 #ifdef SK_ENABLE_API_AVAILABLE
424 #define SK_API_AVAILABLE API_AVAILABLE
426 #define SK_API_AVAILABLE(...)
429 #if defined(SK_BUILD_FOR_LIBFUZZER) || defined(SK_BUILD_FOR_AFL_FUZZ)
430 #define SK_BUILD_FOR_FUZZER
442 #if defined(SK_BUILD_FOR_LIBFUZZER)
456 #define SkASSERT_RELEASE(cond) \
457 static_cast<void>( (cond) ? (void)0 : []{ SK_ABORT("assert(%s)", #cond); }() )
460 #define SkASSERT(cond) SkASSERT_RELEASE(cond)
461 #define SkASSERTF(cond, fmt, ...) static_cast<void>( (cond) ? (void)0 : [&]{ \
462 SkDebugf(fmt"\n", ##__VA_ARGS__); \
463 SK_ABORT("assert(%s)", #cond); \
465 #define SkDEBUGFAIL(message) SK_ABORT("%s", message)
466 #define SkDEBUGFAILF(fmt, ...) SK_ABORT(fmt, ##__VA_ARGS__)
467 #define SkDEBUGCODE(...) __VA_ARGS__
468 #define SkDEBUGF(...) SkDebugf(__VA_ARGS__)
469 #define SkAssertResult(cond) SkASSERT(cond)
471 #define SkASSERT(cond) static_cast<void>(0)
472 #define SkASSERTF(cond, fmt, ...) static_cast<void>(0)
473 #define SkDEBUGFAIL(message)
474 #define SkDEBUGFAILF(fmt, ...)
475 #define SkDEBUGCODE(...)
476 #define SkDEBUGF(...)
480 #define SkAssertResult(cond) if (cond) {} do {} while(false)
497 template <
typename T>
static constexpr
bool SkToBool(
const T& x) {
511 static inline constexpr int32_t
SkLeftShift(int32_t value, int32_t shift) {
512 return (int32_t) ((uint32_t) value << shift);
515 static inline constexpr int64_t
SkLeftShift(int64_t value, int32_t shift) {
516 return (int64_t) ((uint64_t) value << shift);
524 #define SK_ARRAY_COUNT(array) (sizeof(SkArrayCountHelper(array)))
528 template <
typename T>
static constexpr T
SkAlign2(T x) {
return (x + 1) >> 1 << 1; }
529 template <
typename T>
static constexpr T
SkAlign4(T x) {
return (x + 3) >> 2 << 2; }
530 template <
typename T>
static constexpr T
SkAlign8(T x) {
return (x + 7) >> 3 << 3; }
532 template <
typename T>
static constexpr
bool SkIsAlign2(T x) {
return 0 == (x & 1); }
533 template <
typename T>
static constexpr
bool SkIsAlign4(T x) {
return 0 == (x & 3); }
534 template <
typename T>
static constexpr
bool SkIsAlign8(T x) {
return 0 == (x & 7); }
545 return (((uint32_t)a << 24) | ((uint32_t)b << 16) | ((uint32_t)c << 8) | (uint32_t)d);
575 static inline int32_t
SkAbs32(int32_t value) {
583 template <
typename T>
static inline T
SkTAbs(T value) {
static constexpr bool SkIsAlign2(T x)
Definition: SkTypes.h:532
uint16_t SkGlyphID
16 bit unsigned integer to hold a glyph index
Definition: SkTypes.h:556
#define N
Definition: skcms.cc:2338
static constexpr uint32_t SK_InvalidGenID
The generation IDs in Skia reserve 0 has an invalid marker.
Definition: SkTypes.h:569
static constexpr int32_t SK_MaxS32
Definition: SkTypes.h:504
SkBackingFit
Indicates whether a backing store needs to be an exact match or can be larger than is strictly necess...
Definition: SkTypes.h:602
static constexpr SkMSec SK_MSecMax
Maximum representable milliseconds; 24d 20h 31m 23.647s.
Definition: SkTypes.h:565
static constexpr int32_t SkLeftShift(int32_t value, int32_t shift)
Definition: SkTypes.h:511
static constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d)
Definition: SkTypes.h:544
SK_API void SkDebugf(const char format[],...)
static constexpr bool SkIsAlign8(T x)
Definition: SkTypes.h:534
static constexpr T SkAlign4(T x)
Definition: SkTypes.h:529
static constexpr int64_t SK_MaxS64
Definition: SkTypes.h:508
char(& SkArrayCountHelper(T(&array)[N]))[N]
#define SK_R32_SHIFT
Definition: SkTypes.h:291
static constexpr T SkAlign2(T x)
Definition: SkTypes.h:528
static constexpr int16_t SK_MinS16
Definition: SkTypes.h:502
static constexpr bool SkIsAlignPtr(T x)
Definition: SkTypes.h:539
static constexpr uint32_t SK_InvalidUniqueID
The unique IDs in Skia reserve 0 has an invalid marker.
Definition: SkTypes.h:573
static constexpr bool SkToBool(const T &x)
Definition: SkTypes.h:497
uint32_t SkMSec
32 bit value to hold a millisecond duration Note that SK_MSecMax is about 25 days.
Definition: SkTypes.h:561
#define SK_API
Definition: SkTypes.h:181
#define SkASSERT(cond)
Definition: SkTypes.h:460
static int32_t SkAbs32(int32_t value)
Definition: SkTypes.h:575
SK_API void sk_abort_no_print(void)
Called internally if we hit an unrecoverable error.
unsigned U16CPU
Fast type for unsigned 16 bits.
Definition: SkTypes.h:493
#define SK_B32_SHIFT
Definition: SkTypes.h:297
static constexpr T SkAlign8(T x)
Definition: SkTypes.h:530
int32_t SkUnichar
32 bit integer to hold a unicode value
Definition: SkTypes.h:552
SkBudgeted
Indicates whether an allocation should count against a cache budget.
Definition: SkTypes.h:594
static T SkTAbs(T value)
Definition: SkTypes.h:583
static constexpr int64_t SK_MinS64
Definition: SkTypes.h:509
static constexpr bool SkIsAlign4(T x)
Definition: SkTypes.h:533
uint32_t SkFourByteTag
Definition: SkTypes.h:543
static constexpr int16_t SK_MaxS16
Definition: SkTypes.h:501
unsigned U8CPU
Fast type for unsigned 8 bits.
Definition: SkTypes.h:488
static constexpr T SkAlignPtr(T x)
Definition: SkTypes.h:536
static constexpr int32_t SK_NaN32
Definition: SkTypes.h:506
static constexpr int32_t SK_MinS32
Definition: SkTypes.h:505