Skia
2DGraphicsLibrary
|
#include <ciso646>
#include "SkPreConfig.h"
#include "SkUserConfig.h"
#include "SkPostConfig.h"
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "../private/SkTFitsIn.h"
Go to the source code of this file.
Macros | |
#define | SKIA_VERSION_MAJOR 1 |
See SkGraphics::GetVersion() to retrieve these at runtime. | |
#define | SKIA_VERSION_MINOR 0 |
#define | SKIA_VERSION_PATCH 0 |
#define | SK_INIT_TO_AVOID_WARNING = 0 |
#define | SkREQUIRE_SEMICOLON_AFTER(code) do { code } while (false) |
#define | SkASSERT_RELEASE(cond) SkREQUIRE_SEMICOLON_AFTER(if (!(cond)) { SK_ABORT(#cond); } ) |
#define | SkASSERT(cond) SkREQUIRE_SEMICOLON_AFTER(if (!(cond)) { SK_ABORT("assert(" #cond ")"); }) |
#define | SkASSERTF(cond, fmt,...) |
#define | SkDEBUGFAIL(message) SK_ABORT(message) |
#define | SkDEBUGFAILF(fmt,...) SkASSERTF(false, fmt, ##__VA_ARGS__) |
#define | SkDEBUGCODE(...) __VA_ARGS__ |
#define | SkDECLAREPARAM(type, var) , type var |
#define | SkPARAM(var) , var |
#define | SkDEBUGF(args) SkDebugf args |
#define | SkAssertResult(cond) SkASSERT(cond) |
#define | SkFAIL(message) SK_ABORT(message) |
#define | sk_throw() SK_ABORT("sk_throw") |
#define | SK_TO_STRING_NONVIRT() void toString(SkString* str) const; |
#define | SK_TO_STRING_VIRT() virtual void toString(SkString* str) const; |
#define | SK_TO_STRING_PUREVIRT() virtual void toString(SkString* str) const = 0; |
#define | SK_TO_STRING_OVERRIDE() void toString(SkString* str) const override; |
#define | SK_MACRO_CONCAT(X, Y) SK_MACRO_CONCAT_IMPL_PRIV(X, Y) |
#define | SK_MACRO_CONCAT_IMPL_PRIV(X, Y) X ## Y |
#define | SK_MACRO_APPEND_LINE(name) SK_MACRO_CONCAT(name, __LINE__) |
#define | SK_REQUIRE_LOCAL_VAR(classname) static_assert(false, "missing name for " #classname) |
For some classes, it's almost always an error to instantiate one without a name, e.g. More... | |
#define | SkToS8(x) SkTo<int8_t>(x) |
#define | SkToU8(x) SkTo<uint8_t>(x) |
#define | SkToS16(x) SkTo<int16_t>(x) |
#define | SkToU16(x) SkTo<uint16_t>(x) |
#define | SkToS32(x) SkTo<int32_t>(x) |
#define | SkToU32(x) SkTo<uint32_t>(x) |
#define | SkToInt(x) SkTo<int>(x) |
#define | SkToUInt(x) SkTo<unsigned>(x) |
#define | SkToSizeT(x) SkTo<size_t>(x) |
#define | SkToBool(cond) ((cond) != 0) |
Returns 0 or 1 based on the condition. | |
#define | SK_MaxS16 32767 |
#define | SK_MinS16 -32767 |
#define | SK_MaxU16 0xFFFF |
#define | SK_MinU16 0 |
#define | SK_MaxS32 0x7FFFFFFF |
#define | SK_MinS32 -SK_MaxS32 |
#define | SK_MaxU32 0xFFFFFFFF |
#define | SK_MinU32 0 |
#define | SK_NaN32 ((int) (1U << 31)) |
#define | SK_ARRAY_COUNT(array) (sizeof(SkArrayCountHelper(array))) |
#define | SK_BEGIN_REQUIRE_DENSE |
#define | SK_END_REQUIRE_DENSE |
#define | SkAlign2(x) (((x) + 1) >> 1 << 1) |
#define | SkIsAlign2(x) (0 == ((x) & 1)) |
#define | SkAlign4(x) (((x) + 3) >> 2 << 2) |
#define | SkIsAlign4(x) (0 == ((x) & 3)) |
#define | SkAlign8(x) (((x) + 7) >> 3 << 3) |
#define | SkIsAlign8(x) (0 == ((x) & 7)) |
#define | SkAlign16(x) (((x) + 15) >> 4 << 4) |
#define | SkIsAlign16(x) (0 == ((x) & 15)) |
#define | SkAlignPtr(x) (sizeof(void*) == 8 ? SkAlign8(x) : SkAlign4(x)) |
#define | SkIsAlignPtr(x) (sizeof(void*) == 8 ? SkIsAlign8(x) : SkIsAlign4(x)) |
#define | SkSetFourByteTag(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d)) |
#define | SK_MSec1 1000 |
1 second measured in milliseconds | |
#define | SK_MSecMax 0x7FFFFFFF |
maximum representable milliseconds; 24d 20h 31m 23.647s. | |
#define | SkMSec_LT(a, b) ((int32_t)(a) - (int32_t)(b) < 0) |
Returns a < b for milliseconds, correctly handling wrap-around from 0xFFFFFFFF to 0. | |
#define | SkMSec_LE(a, b) ((int32_t)(a) - (int32_t)(b) <= 0) |
Returns a <= b for milliseconds, correctly handling wrap-around from 0xFFFFFFFF to 0. | |
#define | SK_InvalidGenID 0 |
The generation IDs in Skia reserve 0 has an invalid marker. | |
#define | SK_InvalidUniqueID 0 |
The unique IDs in Skia reserve 0 has an invalid marker. | |
Typedefs | |
typedef int | S8CPU |
Fast type for signed 8 bits. More... | |
typedef unsigned | U8CPU |
Fast type for unsigned 8 bits. More... | |
typedef int | S16CPU |
Fast type for signed 16 bits. More... | |
typedef unsigned | U16CPU |
Fast type for unsigned 16 bits. More... | |
typedef uint8_t | SkBool8 |
Meant to be a small version of bool, for storage purposes. More... | |
typedef uint32_t | SkFourByteTag |
typedef int32_t | SkUnichar |
32 bit integer to hold a unicode value | |
typedef uint16_t | SkGlyphID |
16 bit unsigned integer to hold a glyph index | |
typedef uint32_t | SkMSec |
32 bit value to hold a millisecond duration Note that SK_MSecMax is about 25 days. | |
Enumerations | |
enum | { SK_MALLOC_TEMP = 0x01, SK_MALLOC_THROW = 0x02 } |
Functions | |
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. More... | |
SK_API void | sk_out_of_memory (void) |
Called internally if we run out of memory. More... | |
SK_API void | sk_abort_no_print (void) |
Called internally if we hit an unrecoverable error. More... | |
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. More... | |
SK_API void * | sk_malloc_throw (size_t size) |
Same as sk_malloc(), but hard coded to pass SK_MALLOC_THROW as the flag. | |
SK_API void * | sk_realloc_throw (void *buffer, size_t size) |
Same as standard realloc(), but this one never returns null on failure. More... | |
SK_API void | sk_free (void *) |
Free memory returned by sk_malloc(). More... | |
SK_API void * | sk_calloc (size_t size) |
Much like calloc: returns a pointer to at least size zero bytes, or NULL on failure. | |
SK_API void * | sk_calloc_throw (size_t size) |
Same as sk_calloc, but throws an exception instead of returning NULL on failure. | |
static void | sk_bzero (void *buffer, size_t size) |
SK_API void | SkDebugf (const char format[],...) |
template<typename D , typename S > | |
D | SkTo (S s) |
static bool | SkIsS16 (long x) |
Returns true if the value can be represented with signed 16bits. | |
static bool | SkIsU16 (long x) |
Returns true if the value can be represented with unsigned 16bits. | |
static int32_t | SkLeftShift (int32_t value, int32_t shift) |
static int64_t | SkLeftShift (int64_t value, int32_t shift) |
template<typename T , size_t N> | |
char(& | SkArrayCountHelper (T(&array)[N]))[N] |
Returns the number of entries in an array (not a pointer) | |
#define SK_REQUIRE_LOCAL_VAR | ( | classname | ) | static_assert(false, "missing name for " #classname) |
For some classes, it's almost always an error to instantiate one without a name, e.g.
{ SkAutoMutexAcquire(&mutex); <some code>=""> } In this case, the writer meant to hold mutex while the rest of the code in the block runs, but instead the mutex is acquired and then immediately released. The correct usage is { SkAutoMutexAcquire lock(&mutex); <some code>=""> }
To prevent callers from instantiating your class without a name, use SK_REQUIRE_LOCAL_VAR like this: class classname { <your class>=""> }; #define classname(...) SK_REQUIRE_LOCAL_VAR(classname)
This won't work with templates, and you must inline the class' constructors and destructors. Take a look at SkAutoFree and SkAutoMalloc in this file for examples.
#define SkASSERTF | ( | cond, | |
fmt, | |||
... | |||
) |
typedef int S16CPU |
Fast type for signed 16 bits.
Use for parameter passing and local variables, not for storage
typedef int S8CPU |
Fast type for signed 8 bits.
Use for parameter passing and local variables, not for storage.
typedef uint8_t SkBool8 |
Meant to be a small version of bool, for storage purposes.
Will be 0 or 1
typedef unsigned U16CPU |
Fast type for unsigned 16 bits.
Use for parameter passing and local variables, not for storage
typedef unsigned U8CPU |
Fast type for unsigned 8 bits.
Use for parameter passing and local variables, not for storage
anonymous enum |
SK_API void sk_abort_no_print | ( | void | ) |
Called internally if we hit an unrecoverable error.
The platform implementation must not return, but should either throw an exception or otherwise exit.
|
inlinestatic |
sk_careful_memcpy() is just like memcpy(), but guards against undefined behavior.
It is undefined behavior to call memcpy() with null dst or src, even if len is 0. If an optimizer is "smart" enough, it can exploit this to do unexpected things. memcpy(dst, src, 0); if (src) { printf("%x\n", *src); } In this code the compiler can assume src is not null and omit the if (src) {...} check, unconditionally running the printf, crashing the program if src really is null. Of the compilers we pay attention to only GCC performs this optimization in practice.
SK_API void sk_free | ( | void * | ) |
Free memory returned by sk_malloc().
It is safe to pass null.
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.
If the requested memory cannot be returned, either return null (if SK_MALLOC_TEMP bit is clear) or throw an exception (if SK_MALLOC_TEMP bit is set). To free the memory, call sk_free().
SK_API void sk_out_of_memory | ( | void | ) |
Called internally if we run out of memory.
The platform implementation must not return, but should either throw an exception or otherwise exit.
SK_API void* sk_realloc_throw | ( | void * | buffer, |
size_t | size | ||
) |
Same as standard realloc(), but this one never returns null on failure.
It will throw an exception if it fails.