Flutter Engine
The Flutter Engine
Functions
color4f.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkShader.h"
#include "include/core/SkSurface.h"
#include "include/effects/SkColorMatrix.h"

Go to the source code of this file.

Functions

static sk_sp< SkShadermake_opaque_color ()
 
static sk_sp< SkShadermake_alpha_color ()
 
static sk_sp< SkColorFiltermake_cf_null ()
 
static sk_sp< SkColorFiltermake_cf0 ()
 
static sk_sp< SkColorFiltermake_cf1 ()
 
static sk_sp< SkColorFiltermake_cf2 ()
 
static void draw_into_canvas (SkCanvas *canvas)
 
 DEF_SIMPLE_GM (color4f, canvas, 1024, 260)
 
 DEF_SIMPLE_GM (color4shader, canvas, 360, 480)
 
 DEF_SIMPLE_GM (color4blendcf, canvas, 360, 480)
 

Function Documentation

◆ DEF_SIMPLE_GM() [1/3]

DEF_SIMPLE_GM ( color4blendcf  ,
canvas  ,
360  ,
480   
)

Definition at line 131 of file color4f.cpp.

131 {
132 canvas->translate(10, 10);
133
134 auto srgb = SkColorSpace::MakeSRGB();
135 auto spin = srgb->makeColorSpin(); // RGB -> GBR
136
137 const SkColor4f colors[] {
138 { 1, 0, 0, 1 },
139 { 0, 1, 0, 1 },
140 { 0, 0, 1, 1 },
141 { 0.5, 0.5, 0.5, 1 },
142 };
143
145 paint.setColor(SK_ColorWHITE);
146 SkRect r = SkRect::MakeWH(100, 100);
147
148 for (const auto& c4 : colors) {
149 sk_sp<SkColorFilter> filters[] {
150 // Use kModulate and a paint color of white so the final drawn color is color-space
151 // managed 'c4'.
155 };
156
157 canvas->save();
158 for (const auto& f : filters) {
159 paint.setColorFilter(f);
160 canvas->drawRect(r, paint);
161 canvas->translate(r.width() * 6 / 5, 0);
162 }
163 canvas->restore();
164 canvas->translate(0, r.height() * 6 / 5);
165 }
166}
@ kModulate
r = s*d
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static sk_sp< SkColorFilter > Blend(const SkColor4f &c, sk_sp< SkColorSpace >, SkBlendMode mode)
static sk_sp< SkColorSpace > MakeSRGB()
const Paint & paint
Definition: color_source.cc:38
PODArray< SkColor > colors
Definition: SkRecords.h:276
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
static sk_sp< SkColorFilter > spin(sk_sp< SkColorFilter > cf)

◆ DEF_SIMPLE_GM() [2/3]

DEF_SIMPLE_GM ( color4f  ,
canvas  ,
1024  ,
260   
)

Definition at line 72 of file color4f.cpp.

72 {
73 canvas->translate(10, 10);
74
75 SkPaint bg;
76 // need the target to be opaque, so we can draw it to the screen
77 // even if it holds sRGB values.
78 bg.setColor(0xFFFFFFFF);
79
80 sk_sp<SkColorSpace> colorSpaces[]{
81 nullptr,
83 };
84 for (const sk_sp<SkColorSpace>& colorSpace : colorSpaces) {
85 const SkImageInfo info = SkImageInfo::Make(1024, 100, kN32_SkColorType, kPremul_SkAlphaType,
86 colorSpace);
88 surface->getCanvas()->drawPaint(bg);
89 draw_into_canvas(surface->getCanvas());
90 surface->draw(canvas, 0, 0);
91 canvas->translate(0, 120);
92 }
93}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
void setColor(SkColor color)
Definition: SkPaint.cpp:119
static void draw_into_canvas(SkCanvas *canvas)
Definition: color4f.cpp:56
VkSurfaceKHR surface
Definition: main.cc:49
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ DEF_SIMPLE_GM() [3/3]

DEF_SIMPLE_GM ( color4shader  ,
canvas  ,
360  ,
480   
)

Definition at line 97 of file color4f.cpp.

97 {
98 canvas->translate(10, 10);
99
100 auto srgb = SkColorSpace::MakeSRGB();
101 auto spin = srgb->makeColorSpin(); // RGB -> GBR
102
103 const SkColor4f colors[] {
104 { 1, 0, 0, 1 },
105 { 0, 1, 0, 1 },
106 { 0, 0, 1, 1 },
107 { 0.5, 0.5, 0.5, 1 },
108 };
109
111 SkRect r = SkRect::MakeWH(100, 100);
112
113 for (const auto& c4 : colors) {
114 sk_sp<SkShader> shaders[] {
115 SkShaders::Color(c4, nullptr),
116 SkShaders::Color(c4, srgb),
118 };
119
120 canvas->save();
121 for (const auto& s : shaders) {
122 paint.setShader(s);
123 canvas->drawRect(r, paint);
124 canvas->translate(r.width() * 6 / 5, 0);
125 }
126 canvas->restore();
127 canvas->translate(0, r.height() * 6 / 5);
128 }
129}
struct MyStruct s
SK_API sk_sp< SkShader > Color(SkColor)

◆ draw_into_canvas()

static void draw_into_canvas ( SkCanvas canvas)
static

Definition at line 56 of file color4f.cpp.

56 {
57 const SkRect r = SkRect::MakeWH(50, 100);
60
62 for (auto shProc : shaders) {
63 paint.setShader(shProc());
64 for (auto cfProc : filters) {
65 paint.setColorFilter(cfProc());
66 canvas->drawRect(r, paint);
67 canvas->translate(60, 0);
68 }
69 }
70}
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
static sk_sp< SkShader > make_opaque_color()
Definition: color4f.cpp:22
static sk_sp< SkShader > make_alpha_color()
Definition: color4f.cpp:26
static sk_sp< SkColorFilter > make_cf_null()
Definition: color4f.cpp:30
static sk_sp< SkColorFilter > make_cf0()
Definition: color4f.cpp:34
static sk_sp< SkColorFilter > make_cf1()
Definition: color4f.cpp:40
static sk_sp< SkColorFilter > make_cf2()
Definition: color4f.cpp:52

◆ make_alpha_color()

static sk_sp< SkShader > make_alpha_color ( )
static

Definition at line 26 of file color4f.cpp.

26 {
27 return SkShaders::Color(0x80FF0000);
28}

◆ make_cf0()

static sk_sp< SkColorFilter > make_cf0 ( )
static

Definition at line 34 of file color4f.cpp.

34 {
36 cm.setSaturation(0.75f);
37 return SkColorFilters::Matrix(cm);
38}
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
void setSaturation(float sat)

◆ make_cf1()

static sk_sp< SkColorFilter > make_cf1 ( )
static

Definition at line 40 of file color4f.cpp.

40 {
42 cm.setSaturation(0.75f);
43 auto a = SkColorFilters::Matrix(cm);
44 // CreateComposedFilter will try to concat these two matrices, resulting in a single
45 // filter (which is good for speed). For this test, we want to force a real compose of
46 // these two, so our inner filter has a scale-up, which disables the optimization of
47 // combining the two matrices.
48 cm.setScale(1.1f, 0.9f, 1);
49 return a->makeComposed(SkColorFilters::Matrix(cm));
50}
void setScale(float rScale, float gScale, float bScale, float aScale=1.0f)
struct MyStruct a[10]

◆ make_cf2()

static sk_sp< SkColorFilter > make_cf2 ( )
static

Definition at line 52 of file color4f.cpp.

52 {
54}
@ kSrcATop
r = s*da + d*(1-sa)

◆ make_cf_null()

static sk_sp< SkColorFilter > make_cf_null ( )
static

Definition at line 30 of file color4f.cpp.

30 {
31 return nullptr;
32}

◆ make_opaque_color()

static sk_sp< SkShader > make_opaque_color ( )
static

Definition at line 22 of file color4f.cpp.

22 {
23 return SkShaders::Color(0xFFFF0000);
24}