Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
skgpu::Swizzle Class Reference

#include <Swizzle.h>

Public Types

using sk_is_trivially_relocatable = std::true_type
 

Public Member Functions

constexpr Swizzle ()
 
constexpr Swizzle (const char c[4])
 
constexpr Swizzle (const Swizzle &)=default
 
constexpr Swizzleoperator= (const Swizzle &that)=default
 
constexpr bool operator== (const Swizzle &that) const
 
constexpr bool operator!= (const Swizzle &that) const
 
constexpr uint16_t asKey () const
 
SkString asString () const
 
constexpr char operator[] (int i) const
 
constexpr Swizzle selectChannelInR (int i) const
 
constexpr std::array< float, 4 > applyTo (std::array< float, 4 > color) const
 
template<SkAlphaType AlphaType>
constexpr SkRGBA4f< AlphaType > applyTo (SkRGBA4f< AlphaType > color) const
 
void apply (SkRasterPipeline *) const
 

Static Public Member Functions

static constexpr Swizzle Concat (const Swizzle &a, const Swizzle &b)
 
static constexpr Swizzle RGBA ()
 
static constexpr Swizzle BGRA ()
 
static constexpr Swizzle RRRA ()
 
static constexpr Swizzle RGB1 ()
 

Friends

class SwizzleCtorAccessor
 

Detailed Description

Represents a rgba swizzle. It can be converted either into a string or a eight bit int.

Definition at line 27 of file Swizzle.h.

Member Typedef Documentation

◆ sk_is_trivially_relocatable

Definition at line 71 of file Swizzle.h.

Constructor & Destructor Documentation

◆ Swizzle() [1/3]

constexpr skgpu::Swizzle::Swizzle ( )
inlineconstexpr

Definition at line 31 of file Swizzle.h.

31: Swizzle(0x3210) {}
constexpr Swizzle()
Definition: Swizzle.h:31

◆ Swizzle() [2/3]

constexpr skgpu::Swizzle::Swizzle ( const char  c[4])
explicitconstexpr

Definition at line 92 of file Swizzle.h.

93 : fKey(static_cast<uint16_t>((CToI(c[0]) << 0) | (CToI(c[1]) << 4) | (CToI(c[2]) << 8) |
94 (CToI(c[3]) << 12))) {}

◆ Swizzle() [3/3]

constexpr skgpu::Swizzle::Swizzle ( const Swizzle )
constexprdefault

Member Function Documentation

◆ apply()

void skgpu::Swizzle::apply ( SkRasterPipeline pipeline) const

Definition at line 17 of file Swizzle.cpp.

17 {
18 SkASSERT(pipeline);
19 switch (fKey) {
20 case Swizzle("rgba").asKey():
21 return;
22 case Swizzle("bgra").asKey():
23 pipeline->append(SkRasterPipelineOp::swap_rb);
24 return;
25 case Swizzle("aaa1").asKey():
26 pipeline->append(SkRasterPipelineOp::alpha_to_gray);
27 return;
28 case Swizzle("rgb1").asKey():
29 pipeline->append(SkRasterPipelineOp::force_opaque);
30 return;
31 case Swizzle("a001").asKey():
32 pipeline->append(SkRasterPipelineOp::alpha_to_red);
33 return;
34 default: {
35 static_assert(sizeof(uintptr_t) >= 4 * sizeof(char));
36 // Rather than allocate the 4 control bytes on the heap somewhere, just jam them right
37 // into a uintptr_t context.
38 uintptr_t ctx = {};
39 memcpy(&ctx, this->asString().c_str(), 4 * sizeof(char));
40 pipeline->append(SkRasterPipelineOp::swizzle, ctx);
41 return;
42 }
43 }
44}
#define SkASSERT(cond)
Definition: SkAssert.h:116
void append(SkRasterPipelineOp, void *=nullptr)
SkString asString() const
Definition: Swizzle.cpp:46

◆ applyTo() [1/2]

template<SkAlphaType AlphaType>
constexpr SkRGBA4f< AlphaType > skgpu::Swizzle::applyTo ( SkRGBA4f< AlphaType >  color) const
inlineconstexpr

Convenience version for SkRGBA colors.

Definition at line 59 of file Swizzle.h.

59 {
60 std::array<float, 4> result = this->applyTo(color.array());
61 return {result[0], result[1], result[2], result[3]};
62 }
constexpr std::array< float, 4 > applyTo(std::array< float, 4 > color) const
Definition: Swizzle.h:101
GAsyncResult * result
std::array< float, 4 > array() const
Definition: SkColor.h:317

◆ applyTo() [2/2]

constexpr std::array< float, 4 > skgpu::Swizzle::applyTo ( std::array< float, 4 >  color) const
constexpr

Applies this swizzle to the input color and returns the swizzled color.

Definition at line 101 of file Swizzle.h.

101 {
102 uint32_t key = fKey;
103 // Index of the input color that should be mapped to output r.
104 size_t idx = (key & 15);
105 float outR = ComponentIndexToFloat(color, idx);
106 key >>= 4;
107 idx = (key & 15);
108 float outG = ComponentIndexToFloat(color, idx);
109 key >>= 4;
110 idx = (key & 15);
111 float outB = ComponentIndexToFloat(color, idx);
112 key >>= 4;
113 idx = (key & 15);
114 float outA = ComponentIndexToFloat(color, idx);
115 return { outR, outG, outB, outA };
116}
DlColor color

◆ asKey()

constexpr uint16_t skgpu::Swizzle::asKey ( ) const
inlineconstexpr

Compact representation of the swizzle suitable for a key.

Definition at line 43 of file Swizzle.h.

43{ return fKey; }

◆ asString()

SkString skgpu::Swizzle::asString ( ) const

4 char null terminated string consisting only of chars 'r', 'g', 'b', 'a', '0', and '1'.

Definition at line 46 of file Swizzle.cpp.

46 {
47 char swiz[5];
48 uint16_t key = fKey;
49 for (int i = 0; i < 4; ++i) {
50 swiz[i] = IToC(key & 0xfU);
51 key >>= 4;
52 }
53 swiz[4] = '\0';
54 return SkString(swiz);
55}

◆ BGRA()

static constexpr Swizzle skgpu::Swizzle::BGRA ( )
inlinestaticconstexpr

Definition at line 67 of file Swizzle.h.

67{ return Swizzle("bgra"); }

◆ Concat()

constexpr Swizzle skgpu::Swizzle::Concat ( const Swizzle a,
const Swizzle b 
)
staticconstexpr

Definition at line 156 of file Swizzle.h.

156 {
157 uint16_t key = 0;
158 for (unsigned i = 0; i < 4; ++i) {
159 int idx = (b.fKey >> (4U * i)) & 0xfU;
160 if (idx != CToI('0') && idx != CToI('1')) {
161 SkASSERT(idx >= 0 && idx < 4);
162 // Get the index value stored in a at location idx.
163 idx = ((a.fKey >> (4 * idx)) & 0xfU);
164 }
165 key |= (idx << (4U * i));
166 }
167 return Swizzle(key);
168}
static bool b
struct MyStruct a[10]

◆ operator!=()

constexpr bool skgpu::Swizzle::operator!= ( const Swizzle that) const
inlineconstexpr

Definition at line 40 of file Swizzle.h.

40{ return !(*this == that); }

◆ operator=()

constexpr Swizzle & skgpu::Swizzle::operator= ( const Swizzle that)
constexprdefault

◆ operator==()

constexpr bool skgpu::Swizzle::operator== ( const Swizzle that) const
inlineconstexpr

Definition at line 39 of file Swizzle.h.

39{ return fKey == that.fKey; }

◆ operator[]()

constexpr char skgpu::Swizzle::operator[] ( int  i) const
inlineconstexpr

Definition at line 48 of file Swizzle.h.

48{ return IToC(this->channelIndex(i)); }

◆ RGB1()

static constexpr Swizzle skgpu::Swizzle::RGB1 ( )
inlinestaticconstexpr

Definition at line 69 of file Swizzle.h.

69{ return Swizzle("rgb1"); }

◆ RGBA()

static constexpr Swizzle skgpu::Swizzle::RGBA ( )
inlinestaticconstexpr

Definition at line 66 of file Swizzle.h.

66{ return Swizzle("rgba"); }

◆ RRRA()

static constexpr Swizzle skgpu::Swizzle::RRRA ( )
inlinestaticconstexpr

Definition at line 68 of file Swizzle.h.

68{ return Swizzle("rrra"); }

◆ selectChannelInR()

constexpr Swizzle skgpu::Swizzle::selectChannelInR ( int  i) const
constexpr

Definition at line 96 of file Swizzle.h.

96 {
97 return Swizzle(static_cast<uint16_t>((this->channelIndex(i) << 0) | (CToI('0') << 4) |
98 (CToI('0') << 8) | (CToI('0') << 12)));
99}

Friends And Related Function Documentation

◆ SwizzleCtorAccessor

friend class SwizzleCtorAccessor
friend

Definition at line 74 of file Swizzle.h.


The documentation for this class was generated from the following files: