Flutter Engine
The Flutter Engine
GrColor.h
Go to the documentation of this file.
1
2/*
3 * Copyright 2010 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9
10
11#ifndef GrColor_DEFINED
12#define GrColor_DEFINED
13
16#include "include/gpu/GrTypes.h"
18#include "src/base/SkHalf.h"
20
21/**
22 * GrColor is 4 bytes for R, G, B, A, in a specific order defined below. Whether the color is
23 * premultiplied or not depends on the context in which it is being used.
24 */
25typedef uint32_t GrColor;
26
27// shift amount to assign a component to a GrColor int
28// These shift values are chosen for compatibility with GL attrib arrays
29// ES doesn't allow BGRA vertex attrib order so if they were not in this order
30// we'd have to swizzle in shaders.
31#ifdef SK_CPU_BENDIAN
32 #define GrColor_SHIFT_R 24
33 #define GrColor_SHIFT_G 16
34 #define GrColor_SHIFT_B 8
35 #define GrColor_SHIFT_A 0
36#else
37 #define GrColor_SHIFT_R 0
38 #define GrColor_SHIFT_G 8
39 #define GrColor_SHIFT_B 16
40 #define GrColor_SHIFT_A 24
41#endif
42
43/**
44 * Pack 4 components (RGBA) into a GrColor int
45 */
46static inline GrColor GrColorPackRGBA(unsigned r, unsigned g, unsigned b, unsigned a) {
47 SkASSERT((uint8_t)r == r);
48 SkASSERT((uint8_t)g == g);
49 SkASSERT((uint8_t)b == b);
50 SkASSERT((uint8_t)a == a);
51 return (r << GrColor_SHIFT_R) |
52 (g << GrColor_SHIFT_G) |
53 (b << GrColor_SHIFT_B) |
54 (a << GrColor_SHIFT_A);
55}
56
57// extract a component (byte) from a GrColor int
58
59#define GrColorUnpackR(color) (((color) >> GrColor_SHIFT_R) & 0xFF)
60#define GrColorUnpackG(color) (((color) >> GrColor_SHIFT_G) & 0xFF)
61#define GrColorUnpackB(color) (((color) >> GrColor_SHIFT_B) & 0xFF)
62#define GrColorUnpackA(color) (((color) >> GrColor_SHIFT_A) & 0xFF)
63
64/**
65 * Since premultiplied means that alpha >= color, we construct a color with
66 * each component==255 and alpha == 0 to be "illegal"
67 */
68#define GrColor_ILLEGAL (~(0xFF << GrColor_SHIFT_A))
69
70/** Normalizes and coverts an uint8_t to a float. [0, 255] -> [0.0, 1.0] */
71static inline float GrNormalizeByteToFloat(uint8_t value) {
72 static const float ONE_OVER_255 = 1.f / 255.f;
73 return value * ONE_OVER_255;
74}
75
76/** Used to pick vertex attribute types. */
77static inline bool SkPMColor4fFitsInBytes(const SkPMColor4f& color) {
78 // Might want to instead check that the components are [0...a] instead of [0...1]?
79 return color.fitsInBytes();
80}
81
82static inline uint64_t SkPMColor4f_toFP16(const SkPMColor4f& color) {
83 uint64_t halfColor;
84 to_half(skvx::float4::Load(color.vec())).store(&halfColor);
85 return halfColor;
86}
87
88#endif
#define GrColor_SHIFT_G
Definition: GrColor.h:38
static GrColor GrColorPackRGBA(unsigned r, unsigned g, unsigned b, unsigned a)
Definition: GrColor.h:46
static uint64_t SkPMColor4f_toFP16(const SkPMColor4f &color)
Definition: GrColor.h:82
#define GrColor_SHIFT_B
Definition: GrColor.h:39
static bool SkPMColor4fFitsInBytes(const SkPMColor4f &color)
Definition: GrColor.h:77
#define GrColor_SHIFT_A
Definition: GrColor.h:40
#define GrColor_SHIFT_R
Definition: GrColor.h:37
uint32_t GrColor
Definition: GrColor.h:25
static float GrNormalizeByteToFloat(uint8_t value)
Definition: GrColor.h:71
#define SkASSERT(cond)
Definition: SkAssert.h:116
DlColor color
static bool b
struct MyStruct a[10]
uint8_t value
SIN Vec< N, uint16_t > to_half(const Vec< N, float > &x)
Definition: SkVx.h:750
static SKVX_ALWAYS_INLINE Vec Load(const void *ptr)
Definition: SkVx.h:109