reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2006 The Android Open Source Project |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 3 | * |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef SkTypes_DEFINED |
| 9 | #define SkTypes_DEFINED |
| 10 | |
bungeman | f20488b | 2015-07-29 11:49:40 -0700 | [diff] [blame] | 11 | // IWYU pragma: begin_exports |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 12 | #include "SkPreConfig.h" |
| 13 | #include "SkUserConfig.h" |
| 14 | #include "SkPostConfig.h" |
bungeman | f20488b | 2015-07-29 11:49:40 -0700 | [diff] [blame] | 15 | #include <stddef.h> |
bungeman@google.com | fab44db | 2013-10-11 18:50:45 +0000 | [diff] [blame] | 16 | #include <stdint.h> |
bungeman | f20488b | 2015-07-29 11:49:40 -0700 | [diff] [blame] | 17 | // IWYU pragma: end_exports |
| 18 | |
bungeman | f20488b | 2015-07-29 11:49:40 -0700 | [diff] [blame] | 19 | #include <string.h> |
Mike Klein | 22ce794 | 2018-06-12 11:05:16 -0400 | [diff] [blame] | 20 | #include <utility> |
Mike Reed | ea5e676 | 2017-03-02 20:22:35 +0000 | [diff] [blame] | 21 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 22 | /** \file SkTypes.h |
| 23 | */ |
| 24 | |
reed@android.com | 9aa8b32 | 2010-04-13 13:22:54 +0000 | [diff] [blame] | 25 | /** See SkGraphics::GetVersion() to retrieve these at runtime |
| 26 | */ |
| 27 | #define SKIA_VERSION_MAJOR 1 |
| 28 | #define SKIA_VERSION_MINOR 0 |
| 29 | #define SKIA_VERSION_PATCH 0 |
| 30 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 31 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 32 | /** Called internally if we hit an unrecoverable error. |
| 33 | The platform implementation must not return, but should either throw |
| 34 | an exception or otherwise exit. |
| 35 | */ |
djsollen | f2b340f | 2016-01-29 08:51:04 -0800 | [diff] [blame] | 36 | SK_API extern void sk_abort_no_print(void); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 37 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 38 | #ifndef SkDebugf |
george | c4ade57 | 2014-08-01 12:02:07 -0700 | [diff] [blame] | 39 | SK_API void SkDebugf(const char format[], ...); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 40 | #endif |
| 41 | |
Mike Klein | 37bbfe3 | 2017-09-28 09:47:45 -0400 | [diff] [blame] | 42 | // SkASSERT, SkASSERTF and SkASSERT_RELEASE can be used as stand alone assertion expressions, e.g. |
| 43 | // uint32_t foo(int x) { |
| 44 | // SkASSERT(x > 4); |
| 45 | // return x - 4; |
| 46 | // } |
| 47 | // and are also written to be compatible with constexpr functions: |
| 48 | // constexpr uint32_t foo(int x) { |
| 49 | // return SkASSERT(x > 4), |
| 50 | // x - 4; |
| 51 | // } |
caryclark | d656200 | 2016-07-27 12:02:07 -0700 | [diff] [blame] | 52 | #define SkASSERT_RELEASE(cond) \ |
Mike Klein | 37bbfe3 | 2017-09-28 09:47:45 -0400 | [diff] [blame] | 53 | static_cast<void>( (cond) ? (void)0 : []{ SK_ABORT("assert(" #cond ")"); }() ) |
djsollen | f2b340f | 2016-01-29 08:51:04 -0800 | [diff] [blame] | 54 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 55 | #ifdef SK_DEBUG |
Mike Klein | 37bbfe3 | 2017-09-28 09:47:45 -0400 | [diff] [blame] | 56 | #define SkASSERT(cond) SkASSERT_RELEASE(cond) |
| 57 | #define SkASSERTF(cond, fmt, ...) static_cast<void>( (cond) ? (void)0 : [&]{ \ |
| 58 | SkDebugf(fmt"\n", __VA_ARGS__); \ |
| 59 | SK_ABORT("assert(" #cond ")"); \ |
| 60 | }() ) |
bungeman | 1f790aa | 2016-07-20 09:49:10 -0700 | [diff] [blame] | 61 | #define SkDEBUGFAIL(message) SK_ABORT(message) |
herb | 966e3d3 | 2015-09-18 07:00:48 -0700 | [diff] [blame] | 62 | #define SkDEBUGFAILF(fmt, ...) SkASSERTF(false, fmt, ##__VA_ARGS__) |
csmartdalton | ceeaa78 | 2016-08-10 10:07:57 -0700 | [diff] [blame] | 63 | #define SkDEBUGCODE(...) __VA_ARGS__ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 64 | #define SkDEBUGF(args ) SkDebugf args |
| 65 | #define SkAssertResult(cond) SkASSERT(cond) |
| 66 | #else |
Mike Klein | 37bbfe3 | 2017-09-28 09:47:45 -0400 | [diff] [blame] | 67 | #define SkASSERT(cond) static_cast<void>(0) |
| 68 | #define SkASSERTF(cond, fmt, ...) static_cast<void>(0) |
tomhudson@google.com | 0c00f21 | 2011-12-28 14:59:50 +0000 | [diff] [blame] | 69 | #define SkDEBUGFAIL(message) |
hstern | e6f8ff0 | 2016-08-15 15:26:31 -0700 | [diff] [blame] | 70 | #define SkDEBUGFAILF(fmt, ...) |
csmartdalton | ceeaa78 | 2016-08-10 10:07:57 -0700 | [diff] [blame] | 71 | #define SkDEBUGCODE(...) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 72 | #define SkDEBUGF(args) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 73 | |
bsalomon | 9daa4b9 | 2016-05-09 09:14:36 -0700 | [diff] [blame] | 74 | // unlike SkASSERT, this guy executes its condition in the non-debug build. |
bsalomon | 1b4c01c | 2016-05-09 12:35:17 -0700 | [diff] [blame] | 75 | // The if is present so that this can be used with functions marked SK_WARN_UNUSED_RESULT. |
| 76 | #define SkAssertResult(cond) if (cond) {} do {} while(false) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 77 | #endif |
| 78 | |
Hal Canary | bc718c1 | 2018-06-12 14:16:11 -0400 | [diff] [blame] | 79 | //////////////////////////////////////////////////////////////////////////////// |
| 80 | |
reed@google.com | 37a3133 | 2011-01-25 14:55:42 +0000 | [diff] [blame] | 81 | /** |
reed@google.com | 37a3133 | 2011-01-25 14:55:42 +0000 | [diff] [blame] | 82 | * Fast type for unsigned 8 bits. Use for parameter passing and local |
| 83 | * variables, not for storage |
| 84 | */ |
| 85 | typedef unsigned U8CPU; |
| 86 | |
| 87 | /** |
| 88 | * Fast type for signed 16 bits. Use for parameter passing and local variables, |
| 89 | * not for storage |
| 90 | */ |
| 91 | typedef int S16CPU; |
| 92 | |
| 93 | /** |
| 94 | * Fast type for unsigned 16 bits. Use for parameter passing and local |
| 95 | * variables, not for storage |
| 96 | */ |
| 97 | typedef unsigned U16CPU; |
| 98 | |
Hal Canary | fdcfb8b | 2018-06-13 09:42:32 -0400 | [diff] [blame] | 99 | #include "../private/SkTFitsIn.h" |
| 100 | template <typename D, typename S> constexpr D SkTo(S s) { |
| 101 | return SkASSERT(SkTFitsIn<D>(s)), |
| 102 | static_cast<D>(s); |
| 103 | } |
| 104 | #define SkToS8(x) SkTo<int8_t>(x) |
| 105 | #define SkToU8(x) SkTo<uint8_t>(x) |
| 106 | #define SkToS16(x) SkTo<int16_t>(x) |
| 107 | #define SkToU16(x) SkTo<uint16_t>(x) |
| 108 | #define SkToS32(x) SkTo<int32_t>(x) |
| 109 | #define SkToU32(x) SkTo<uint32_t>(x) |
| 110 | #define SkToInt(x) SkTo<int>(x) |
| 111 | #define SkToUInt(x) SkTo<unsigned>(x) |
| 112 | #define SkToSizeT(x) SkTo<size_t>(x) |
| 113 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 114 | /** Returns 0 or 1 based on the condition |
| 115 | */ |
Ben Wagner | 5b07178 | 2017-08-28 15:06:57 -0400 | [diff] [blame] | 116 | #define SkToBool(cond) ((cond) != 0) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 117 | |
Hal Canary | e1bc7de | 2018-06-13 15:01:39 -0400 | [diff] [blame^] | 118 | #define SK_MaxS16 INT16_MAX |
| 119 | #define SK_MinS16 -SK_MaxS16 |
| 120 | #define SK_MaxS32 INT32_MAX |
caryclark@google.com | 594dd3c | 2012-09-24 19:33:57 +0000 | [diff] [blame] | 121 | #define SK_MinS32 -SK_MaxS32 |
Hal Canary | e1bc7de | 2018-06-13 15:01:39 -0400 | [diff] [blame^] | 122 | #define SK_NaN32 INT32_MIN |
| 123 | static constexpr int64_t SK_MaxS64 = INT64_MAX; |
Mike Reed | 3d5a6b5 | 2018-01-31 15:55:47 -0500 | [diff] [blame] | 124 | static constexpr int64_t SK_MinS64 = -SK_MaxS64; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 125 | |
Hal Canary | bb9ee9b | 2018-06-12 16:47:47 -0400 | [diff] [blame] | 126 | static inline constexpr int32_t SkLeftShift(int32_t value, int32_t shift) { |
caryclark | 3127c99 | 2015-12-09 12:02:30 -0800 | [diff] [blame] | 127 | return (int32_t) ((uint32_t) value << shift); |
| 128 | } |
| 129 | |
Hal Canary | bb9ee9b | 2018-06-12 16:47:47 -0400 | [diff] [blame] | 130 | static inline constexpr int64_t SkLeftShift(int64_t value, int32_t shift) { |
caryclark | 3127c99 | 2015-12-09 12:02:30 -0800 | [diff] [blame] | 131 | return (int64_t) ((uint64_t) value << shift); |
| 132 | } |
| 133 | |
reed@android.com | d457775 | 2009-11-21 02:48:11 +0000 | [diff] [blame] | 134 | ////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 135 | |
mtklein | fc00a7c | 2015-05-07 10:58:44 -0700 | [diff] [blame] | 136 | /** Returns the number of entries in an array (not a pointer) */ |
| 137 | template <typename T, size_t N> char (&SkArrayCountHelper(T (&array)[N]))[N]; |
caryclark | 95b96d6 | 2015-08-19 10:12:59 -0700 | [diff] [blame] | 138 | #define SK_ARRAY_COUNT(array) (sizeof(SkArrayCountHelper(array))) |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 139 | |
Hal Canary | bc718c1 | 2018-06-12 14:16:11 -0400 | [diff] [blame] | 140 | //////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 141 | |
Hal Canary | bb9ee9b | 2018-06-12 16:47:47 -0400 | [diff] [blame] | 142 | template <typename T> static constexpr T SkAlign2(T x) { return (x + 1) >> 1 << 1; } |
| 143 | template <typename T> static constexpr T SkAlign4(T x) { return (x + 3) >> 2 << 2; } |
| 144 | template <typename T> static constexpr T SkAlign8(T x) { return (x + 7) >> 3 << 3; } |
reed@google.com | c6faa5a | 2012-06-27 15:07:11 +0000 | [diff] [blame] | 145 | |
Hal Canary | bb9ee9b | 2018-06-12 16:47:47 -0400 | [diff] [blame] | 146 | template <typename T> static constexpr bool SkIsAlign2(T x) { return 0 == (x & 1); } |
| 147 | template <typename T> static constexpr bool SkIsAlign4(T x) { return 0 == (x & 3); } |
| 148 | template <typename T> static constexpr bool SkIsAlign8(T x) { return 0 == (x & 7); } |
tomhudson@google.com | 01224d5 | 2011-11-28 18:22:01 +0000 | [diff] [blame] | 149 | |
Hal Canary | bb9ee9b | 2018-06-12 16:47:47 -0400 | [diff] [blame] | 150 | template <typename T> static constexpr T SkAlignPtr(T x) { |
Hal Canary | bc718c1 | 2018-06-12 14:16:11 -0400 | [diff] [blame] | 151 | return sizeof(void*) == 8 ? SkAlign8(x) : SkAlign4(x); |
| 152 | } |
Hal Canary | bb9ee9b | 2018-06-12 16:47:47 -0400 | [diff] [blame] | 153 | template <typename T> static constexpr bool SkIsAlignPtr(T x) { |
Hal Canary | bc718c1 | 2018-06-12 14:16:11 -0400 | [diff] [blame] | 154 | return sizeof(void*) == 8 ? SkIsAlign8(x) : SkIsAlign4(x); |
| 155 | } |
mtklein | 0209e95 | 2014-08-28 14:10:05 -0700 | [diff] [blame] | 156 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 157 | typedef uint32_t SkFourByteTag; |
Hal Canary | bb9ee9b | 2018-06-12 16:47:47 -0400 | [diff] [blame] | 158 | static inline constexpr SkFourByteTag SkSetFourByteTag(char a, char b, char c, char d) { |
Hal Canary | bc718c1 | 2018-06-12 14:16:11 -0400 | [diff] [blame] | 159 | return (((uint8_t)a << 24) | ((uint8_t)b << 16) | ((uint8_t)c << 8) | (uint8_t)d); |
| 160 | } |
| 161 | |
| 162 | //////////////////////////////////////////////////////////////////////////////// |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 163 | |
| 164 | /** 32 bit integer to hold a unicode value |
| 165 | */ |
| 166 | typedef int32_t SkUnichar; |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 167 | |
halcanary | d0e95a5 | 2016-07-25 07:18:12 -0700 | [diff] [blame] | 168 | /** 16 bit unsigned integer to hold a glyph index |
| 169 | */ |
| 170 | typedef uint16_t SkGlyphID; |
| 171 | |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 172 | /** 32 bit value to hold a millisecond duration |
| 173 | * Note that SK_MSecMax is about 25 days. |
| 174 | */ |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 175 | typedef uint32_t SkMSec; |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 176 | /** maximum representable milliseconds; 24d 20h 31m 23.647s. |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 177 | */ |
| 178 | #define SK_MSecMax 0x7FFFFFFF |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 179 | |
commit-bot@chromium.org | 2b4e370 | 2014-04-07 18:26:22 +0000 | [diff] [blame] | 180 | /** The generation IDs in Skia reserve 0 has an invalid marker. |
| 181 | */ |
| 182 | #define SK_InvalidGenID 0 |
bsalomon | 1c63bf6 | 2014-07-22 13:09:46 -0700 | [diff] [blame] | 183 | /** The unique IDs in Skia reserve 0 has an invalid marker. |
| 184 | */ |
| 185 | #define SK_InvalidUniqueID 0 |
commit-bot@chromium.org | 2b4e370 | 2014-04-07 18:26:22 +0000 | [diff] [blame] | 186 | |
bsalomon@google.com | ff43661 | 2013-02-27 19:07:32 +0000 | [diff] [blame] | 187 | /** Generic swap function. Classes with efficient swaps should specialize this function to take |
| 188 | their fast path. This function is used by SkTSort. */ |
Mike Klein | bde64e4 | 2016-11-14 08:39:39 -0500 | [diff] [blame] | 189 | template <typename T> static inline void SkTSwap(T& a, T& b) { |
bungeman | 6f4293a | 2016-10-26 12:11:28 -0700 | [diff] [blame] | 190 | T c(std::move(a)); |
| 191 | a = std::move(b); |
| 192 | b = std::move(c); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 193 | } |
| 194 | |
reed@android.com | d457775 | 2009-11-21 02:48:11 +0000 | [diff] [blame] | 195 | static inline int32_t SkAbs32(int32_t value) { |
mtklein | 09a22e9 | 2014-11-21 11:38:53 -0800 | [diff] [blame] | 196 | SkASSERT(value != SK_NaN32); // The most negative int32_t can't be negated. |
commit-bot@chromium.org | 38bad32 | 2013-07-30 13:16:29 +0000 | [diff] [blame] | 197 | if (value < 0) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 198 | value = -value; |
commit-bot@chromium.org | 38bad32 | 2013-07-30 13:16:29 +0000 | [diff] [blame] | 199 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 200 | return value; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 201 | } |
| 202 | |
Mike Klein | bde64e4 | 2016-11-14 08:39:39 -0500 | [diff] [blame] | 203 | template <typename T> static inline T SkTAbs(T value) { |
reed@google.com | 2b57dc6 | 2013-01-08 13:23:32 +0000 | [diff] [blame] | 204 | if (value < 0) { |
| 205 | value = -value; |
| 206 | } |
| 207 | return value; |
| 208 | } |
| 209 | |
reed@android.com | d457775 | 2009-11-21 02:48:11 +0000 | [diff] [blame] | 210 | static inline int32_t SkMax32(int32_t a, int32_t b) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 211 | if (a < b) |
| 212 | a = b; |
| 213 | return a; |
| 214 | } |
| 215 | |
reed@android.com | d457775 | 2009-11-21 02:48:11 +0000 | [diff] [blame] | 216 | static inline int32_t SkMin32(int32_t a, int32_t b) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 217 | if (a > b) |
| 218 | a = b; |
| 219 | return a; |
| 220 | } |
| 221 | |
halcanary | a0af771 | 2016-05-23 09:11:58 -0700 | [diff] [blame] | 222 | template <typename T> constexpr const T& SkTMin(const T& a, const T& b) { |
caryclark@google.com | 3b97af5 | 2013-04-23 11:56:44 +0000 | [diff] [blame] | 223 | return (a < b) ? a : b; |
| 224 | } |
| 225 | |
halcanary | a0af771 | 2016-05-23 09:11:58 -0700 | [diff] [blame] | 226 | template <typename T> constexpr const T& SkTMax(const T& a, const T& b) { |
caryclark@google.com | 3b97af5 | 2013-04-23 11:56:44 +0000 | [diff] [blame] | 227 | return (b < a) ? a : b; |
| 228 | } |
| 229 | |
Chris Dalton | 42c2115 | 2018-06-13 15:28:19 -0600 | [diff] [blame] | 230 | template <typename T> constexpr const T& SkTClamp(const T& x, const T& lo, const T& hi) { |
| 231 | return (x < lo) ? lo : SkTMin(x, hi); |
| 232 | } |
| 233 | |
reed@android.com | d457775 | 2009-11-21 02:48:11 +0000 | [diff] [blame] | 234 | static inline int32_t SkFastMin32(int32_t value, int32_t max) { |
commit-bot@chromium.org | 38bad32 | 2013-07-30 13:16:29 +0000 | [diff] [blame] | 235 | if (value > max) { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 236 | value = max; |
commit-bot@chromium.org | 38bad32 | 2013-07-30 13:16:29 +0000 | [diff] [blame] | 237 | } |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 238 | return value; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 239 | } |
| 240 | |
bungeman | 62ce030 | 2015-08-28 09:09:32 -0700 | [diff] [blame] | 241 | /** Returns value pinned between min and max, inclusively. */ |
halcanary | a0af771 | 2016-05-23 09:11:58 -0700 | [diff] [blame] | 242 | template <typename T> static constexpr const T& SkTPin(const T& value, const T& min, const T& max) { |
bungeman | 62ce030 | 2015-08-28 09:09:32 -0700 | [diff] [blame] | 243 | return SkTMax(SkTMin(value, max), min); |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 244 | } |
| 245 | |
bsalomon | 5ec26ae | 2016-02-25 08:33:02 -0800 | [diff] [blame] | 246 | |
| 247 | /////////////////////////////////////////////////////////////////////////////// |
| 248 | |
| 249 | /** |
| 250 | * Indicates whether an allocation should count against a cache budget. |
| 251 | */ |
| 252 | enum class SkBudgeted : bool { |
| 253 | kNo = false, |
| 254 | kYes = true |
| 255 | }; |
| 256 | |
robertphillips | 76948d4 | 2016-05-04 12:47:41 -0700 | [diff] [blame] | 257 | /** |
| 258 | * Indicates whether a backing store needs to be an exact match or can be larger |
| 259 | * than is strictly necessary |
| 260 | */ |
| 261 | enum class SkBackingFit { |
| 262 | kApprox, |
| 263 | kExact |
| 264 | }; |
| 265 | |
reed@google.com | 1fcd51e | 2011-01-05 15:50:27 +0000 | [diff] [blame] | 266 | /////////////////////////////////////////////////////////////////////////////// |
| 267 | |
| 268 | /** |
| 269 | * Use to cast a pointer to a different type, and maintaining strict-aliasing |
| 270 | */ |
| 271 | template <typename Dst> Dst SkTCast(const void* ptr) { |
| 272 | union { |
| 273 | const void* src; |
| 274 | Dst dst; |
| 275 | } data; |
| 276 | data.src = ptr; |
| 277 | return data.dst; |
| 278 | } |
| 279 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 280 | ////////////////////////////////////////////////////////////////////////////// |
| 281 | |
| 282 | /** \class SkNoncopyable |
| 283 | |
fmalita | 055f6b5 | 2015-04-09 08:49:32 -0700 | [diff] [blame] | 284 | SkNoncopyable is the base class for objects that do not want to |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 285 | be copied. It hides its copy-constructor and its assignment-operator. |
| 286 | */ |
ctguil@chromium.org | 7ffb1b2 | 2011-03-15 21:27:08 +0000 | [diff] [blame] | 287 | class SK_API SkNoncopyable { |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 288 | public: |
Chris Blume | 2b6be20 | 2017-04-25 17:33:13 -0700 | [diff] [blame] | 289 | SkNoncopyable() = default; |
reed@google.com | 1fcd51e | 2011-01-05 15:50:27 +0000 | [diff] [blame] | 290 | |
Chris Blume | 2b6be20 | 2017-04-25 17:33:13 -0700 | [diff] [blame] | 291 | SkNoncopyable(SkNoncopyable&&) = default; |
| 292 | SkNoncopyable& operator =(SkNoncopyable&&) = default; |
| 293 | |
| 294 | SkNoncopyable(const SkNoncopyable&) = delete; |
| 295 | SkNoncopyable& operator=(const SkNoncopyable&) = delete; |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 296 | }; |
| 297 | |
reed@android.com | 8a1c16f | 2008-12-17 15:59:43 +0000 | [diff] [blame] | 298 | #endif |