diff options
author | 2012-02-02 19:15:21 +0000 | |
---|---|---|
committer | 2012-02-02 19:15:21 +0000 | |
commit | f8d1aee2526a384a570b082b17f3a19fe72bd15e (patch) | |
tree | 5aa930c1953e83453e1d560332302a1be1bac23d /include | |
parent | afd87fe108629afbfbf065144274e76a2865794f (diff) |
Open type table definitions.
http://codereview.appspot.com/5577064/
git-svn-id: http://skia.googlecode.com/svn/trunk@3131 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include')
-rw-r--r-- | include/config/SkUserConfig.h | 9 | ||||
-rw-r--r-- | include/core/SkEndian.h | 56 |
2 files changed, 64 insertions, 1 deletions
diff --git a/include/config/SkUserConfig.h b/include/config/SkUserConfig.h index f0fa8417bc..75e929203c 100644 --- a/include/config/SkUserConfig.h +++ b/include/config/SkUserConfig.h @@ -86,6 +86,15 @@ //#define SK_CPU_BENDIAN //#define SK_CPU_LENDIAN +/* Most compilers use the same bit endianness for bit flags in a byte as the + system byte endianness, and this is the default. If for some reason this + needs to be overridden, specify which of the mutually exclusive flags to + use. For example, some atom processors in certain configurations have big + endian byte order but little endian bit orders. +*/ +//#define SK_UINT8_BITFIELD_BENDIAN +//#define SK_UINT8_BITFIELD_LENDIAN + /* Some compilers don't support long long for 64bit integers. If yours does not, define this to the appropriate type. diff --git a/include/core/SkEndian.h b/include/core/SkEndian.h index 3eb67dabfe..910cf1eeab 100644 --- a/include/core/SkEndian.h +++ b/include/core/SkEndian.h @@ -31,8 +31,11 @@ */ static inline uint16_t SkEndianSwap16(U16CPU value) { SkASSERT(value == (uint16_t)value); - return (uint16_t)((value >> 8) | (value << 8)); + return static_cast<uint16_t>((value >> 8) | (value << 8)); } +template<uint16_t N> struct SkTEndianSwap16 { + static const uint16_t value = static_cast<uint16_t>((N >> 8) | ((N & 0xFF) << 8)); +}; /** Vector version of SkEndianSwap16(), which swaps the low two bytes of each value in the array. @@ -55,6 +58,12 @@ static inline uint32_t SkEndianSwap32(uint32_t value) { ((value & 0xFF0000) >> 8) | (value >> 24); } +template<uint32_t N> struct SkTEndianSwap32 { + static const uint32_t value = ((N & 0xFF) << 24) | + ((N & 0xFF00) << 8) | + ((N & 0xFF0000) >> 8) | + (N >> 24); +}; /** Vector version of SkEndianSwap16(), which swaps the bytes of each value in the array. @@ -73,11 +82,21 @@ static inline void SkEndianSwap32s(uint32_t array[], int count) { #define SkEndian_SwapBE32(n) SkEndianSwap32(n) #define SkEndian_SwapLE16(n) (n) #define SkEndian_SwapLE32(n) (n) + + #define SkTEndian_SwapBE16(n) SkTEndianSwap16<n>::value + #define SkTEndian_SwapBE32(n) SkTEndianSwap32<n>::value + #define SkTEndian_SwapLE16(n) (n) + #define SkTEndian_SwapLE32(n) (n) #else // SK_CPU_BENDIAN #define SkEndian_SwapBE16(n) (n) #define SkEndian_SwapBE32(n) (n) #define SkEndian_SwapLE16(n) SkEndianSwap16(n) #define SkEndian_SwapLE32(n) SkEndianSwap32(n) + + #define SkTEndian_SwapBE16(n) (n) + #define SkTEndian_SwapBE32(n) (n) + #define SkTEndian_SwapLE16(n) SkTEndianSwap16<n>::value + #define SkTEndian_SwapLE32(n) SkTEndianSwap32<n>::value #endif // When a bytestream is embedded in a 32-bit word, how far we need to @@ -94,5 +113,40 @@ static inline void SkEndianSwap32s(uint32_t array[], int count) { #define SkEndian_Byte3Shift 0 #endif + +#if defined(SK_UINT8_BITFIELD_LENDIAN) && defined(SK_UINT8_BITFIELD_BENDIAN) + #error "can't have both bitfield LENDIAN and BENDIAN defined" +#endif + +#if !defined(SK_UINT8_BITFIELD_LENDIAN) && !defined(SK_UINT8_BITFIELD_BENDIAN) + #ifdef SK_CPU_LENDIAN + #define SK_UINT8_BITFIELD_LENDIAN + #else + #define SK_UINT8_BITFIELD_BENDIAN + #endif +#endif + +#ifdef SK_UINT8_BITFIELD_LENDIAN + #define SK_UINT8_BITFIELD(f0, f1, f2, f3, f4, f5, f6, f7) \ + SK_OT_BYTE f0 : 1; \ + SK_OT_BYTE f1 : 1; \ + SK_OT_BYTE f2 : 1; \ + SK_OT_BYTE f3 : 1; \ + SK_OT_BYTE f4 : 1; \ + SK_OT_BYTE f5 : 1; \ + SK_OT_BYTE f6 : 1; \ + SK_OT_BYTE f7 : 1; +#else + #define SK_UINT8_BITFIELD(f0, f1, f2, f3, f4, f5, f6, f7) \ + SK_OT_BYTE f7 : 1; \ + SK_OT_BYTE f6 : 1; \ + SK_OT_BYTE f5 : 1; \ + SK_OT_BYTE f4 : 1; \ + SK_OT_BYTE f3 : 1; \ + SK_OT_BYTE f2 : 1; \ + SK_OT_BYTE f1 : 1; \ + SK_OT_BYTE f0 : 1; +#endif + #endif |