Flutter Engine
The Flutter Engine
Classes | Macros | Functions
SkEndian.h File Reference
#include "include/private/base/SkAssert.h"
#include "include/private/base/SkFeatures.h"
#include <cstdint>

Go to the source code of this file.

Classes

struct  SkTEndianSwap16< N >
 
struct  SkTEndianSwap32< N >
 
struct  SkTEndianSwap64< N >
 

Macros

#define SkEndian_SwapBE16(n)   static_cast<uint16_t>(n)
 
#define SkEndian_SwapBE32(n)   static_cast<uint32_t>(n)
 
#define SkEndian_SwapBE64(n)   static_cast<uint64_t>(n)
 
#define SkEndian_SwapLE16(n)   SkEndianSwap16(n)
 
#define SkEndian_SwapLE32(n)   SkEndianSwap32(n)
 
#define SkEndian_SwapLE64(n)   SkEndianSwap64(n)
 
#define SkTEndian_SwapBE16(n)   (n)
 
#define SkTEndian_SwapBE32(n)   (n)
 
#define SkTEndian_SwapBE64(n)   (n)
 
#define SkTEndian_SwapLE16(n)   SkTEndianSwap16<n>::value
 
#define SkTEndian_SwapLE32(n)   SkTEndianSwap32<n>::value
 
#define SkTEndian_SwapLE64(n)   SkTEndianSwap64<n>::value
 
#define SkEndian_Byte0Shift   24
 
#define SkEndian_Byte1Shift   16
 
#define SkEndian_Byte2Shift   8
 
#define SkEndian_Byte3Shift   0
 
#define SK_UINT8_BITFIELD_BENDIAN
 
#define SK_UINT8_BITFIELD(f0, f1, f2, f3, f4, f5, f6, f7)
 

Functions

static uint16_t SkEndianSwap16 (uint16_t value)
 
static void SkEndianSwap16s (uint16_t array[], int count)
 
static constexpr uint32_t SkEndianSwap32 (uint32_t value)
 
static void SkEndianSwap32s (uint32_t array[], int count)
 
static uint64_t SkEndianSwap64 (uint64_t value)
 
static void SkEndianSwap64s (uint64_t array[], int count)
 

Detailed Description

Macros and helper functions for handling 16 and 32 bit values in big and little endian formats.

Definition in file SkEndian.h.

Macro Definition Documentation

◆ SK_UINT8_BITFIELD

#define SK_UINT8_BITFIELD (   f0,
  f1,
  f2,
  f3,
  f4,
  f5,
  f6,
  f7 
)
Value:
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;
uint8_t SK_OT_BYTE

Definition at line 188 of file SkEndian.h.

◆ SK_UINT8_BITFIELD_BENDIAN

#define SK_UINT8_BITFIELD_BENDIAN

Definition at line 173 of file SkEndian.h.

◆ SkEndian_Byte0Shift

#define SkEndian_Byte0Shift   24

Definition at line 158 of file SkEndian.h.

◆ SkEndian_Byte1Shift

#define SkEndian_Byte1Shift   16

Definition at line 159 of file SkEndian.h.

◆ SkEndian_Byte2Shift

#define SkEndian_Byte2Shift   8

Definition at line 160 of file SkEndian.h.

◆ SkEndian_Byte3Shift

#define SkEndian_Byte3Shift   0

Definition at line 161 of file SkEndian.h.

◆ SkEndian_SwapBE16

#define SkEndian_SwapBE16 (   n)    static_cast<uint16_t>(n)

Definition at line 135 of file SkEndian.h.

◆ SkEndian_SwapBE32

#define SkEndian_SwapBE32 (   n)    static_cast<uint32_t>(n)

Definition at line 136 of file SkEndian.h.

◆ SkEndian_SwapBE64

#define SkEndian_SwapBE64 (   n)    static_cast<uint64_t>(n)

Definition at line 137 of file SkEndian.h.

◆ SkEndian_SwapLE16

#define SkEndian_SwapLE16 (   n)    SkEndianSwap16(n)

Definition at line 138 of file SkEndian.h.

◆ SkEndian_SwapLE32

#define SkEndian_SwapLE32 (   n)    SkEndianSwap32(n)

Definition at line 139 of file SkEndian.h.

◆ SkEndian_SwapLE64

#define SkEndian_SwapLE64 (   n)    SkEndianSwap64(n)

Definition at line 140 of file SkEndian.h.

◆ SkTEndian_SwapBE16

#define SkTEndian_SwapBE16 (   n)    (n)

Definition at line 142 of file SkEndian.h.

◆ SkTEndian_SwapBE32

#define SkTEndian_SwapBE32 (   n)    (n)

Definition at line 143 of file SkEndian.h.

◆ SkTEndian_SwapBE64

#define SkTEndian_SwapBE64 (   n)    (n)

Definition at line 144 of file SkEndian.h.

◆ SkTEndian_SwapLE16

#define SkTEndian_SwapLE16 (   n)    SkTEndianSwap16<n>::value

Definition at line 145 of file SkEndian.h.

◆ SkTEndian_SwapLE32

#define SkTEndian_SwapLE32 (   n)    SkTEndianSwap32<n>::value

Definition at line 146 of file SkEndian.h.

◆ SkTEndian_SwapLE64

#define SkTEndian_SwapLE64 (   n)    SkTEndianSwap64<n>::value

Definition at line 147 of file SkEndian.h.

Function Documentation

◆ SkEndianSwap16()

static uint16_t SkEndianSwap16 ( uint16_t  value)
inlinestatic

Swap the two bytes in the low 16bits of the parameters. e.g. 0x1234 -> 0x3412

Definition at line 33 of file SkEndian.h.

33 {
34 return static_cast<uint16_t>((value >> 8) | ((value & 0xFF) << 8));
35}
uint8_t value

◆ SkEndianSwap16s()

static void SkEndianSwap16s ( uint16_t  array[],
int  count 
)
inlinestatic

Vector version of SkEndianSwap16(), which swaps the low two bytes of each value in the array.

Definition at line 44 of file SkEndian.h.

44 {
45 SkASSERT(count == 0 || array != nullptr);
46
47 while (--count >= 0) {
48 *array = SkEndianSwap16(*array);
49 array += 1;
50 }
51}
int count
Definition: FontMgrTest.cpp:50
#define SkASSERT(cond)
Definition: SkAssert.h:116
static uint16_t SkEndianSwap16(uint16_t value)
Definition: SkEndian.h:33

◆ SkEndianSwap32()

static constexpr uint32_t SkEndianSwap32 ( uint32_t  value)
staticconstexpr

Reverse all 4 bytes in a 32bit value. e.g. 0x12345678 -> 0x78563412

Definition at line 56 of file SkEndian.h.

56 {
57 return ((value & 0xFF) << 24) |
58 ((value & 0xFF00) << 8) |
59 ((value & 0xFF0000) >> 8) |
60 (value >> 24);
61}

◆ SkEndianSwap32s()

static void SkEndianSwap32s ( uint32_t  array[],
int  count 
)
inlinestatic

Vector version of SkEndianSwap32(), which swaps the bytes of each value in the array.

Definition at line 73 of file SkEndian.h.

73 {
74 SkASSERT(count == 0 || array != nullptr);
75
76 while (--count >= 0) {
77 *array = SkEndianSwap32(*array);
78 array += 1;
79 }
80}
static constexpr uint32_t SkEndianSwap32(uint32_t value)
Definition: SkEndian.h:56

◆ SkEndianSwap64()

static uint64_t SkEndianSwap64 ( uint64_t  value)
inlinestatic

Reverse all 8 bytes in a 64bit value. e.g. 0x1122334455667788 -> 0x8877665544332211

Definition at line 85 of file SkEndian.h.

85 {
86 return (((value & 0x00000000000000FFULL) << (8*7)) |
87 ((value & 0x000000000000FF00ULL) << (8*5)) |
88 ((value & 0x0000000000FF0000ULL) << (8*3)) |
89 ((value & 0x00000000FF000000ULL) << (8*1)) |
90 ((value & 0x000000FF00000000ULL) >> (8*1)) |
91 ((value & 0x0000FF0000000000ULL) >> (8*3)) |
92 ((value & 0x00FF000000000000ULL) >> (8*5)) |
93 ((value) >> (8*7)));
94}

◆ SkEndianSwap64s()

static void SkEndianSwap64s ( uint64_t  array[],
int  count 
)
inlinestatic

Vector version of SkEndianSwap64(), which swaps the bytes of each value in the array.

Definition at line 109 of file SkEndian.h.

109 {
110 SkASSERT(count == 0 || array != nullptr);
111
112 while (--count >= 0) {
113 *array = SkEndianSwap64(*array);
114 array += 1;
115 }
116}
static uint64_t SkEndianSwap64(uint64_t value)
Definition: SkEndian.h:85