32#include <initializer_list>
48 { 1.0f, 0.0f, 0.0f, 1.0f },
49 { 0.0f, 1.0f, 0.0f, 1.0f },
50 { 0.0f, 0.0f, 1.0f, 1.0f },
51 { 1.0f, 1.0f, 1.0f, 1.0f },
52 { 0.0f, 0.0f, 0.0f, 1.0f }
65 { 1.0f, 0.0f, 0.0f, 1.0f },
66 { 0.0f, 1.0f, 0.0f, 1.0f },
67 { 0.0f, 1.0f, 0.0f, 1.0f },
68 { 0.0f, 0.0f, 1.0f, 1.0f }
71 { 2,
gColors, gColors4f,
nullptr },
74 { 5,
gColors, gColors4f,
nullptr },
108 data.fCount, tm, 0, &localMatrix);
127 data.fCount, 0, &localMatrix);
138 center0, (pts[1].fX - pts[0].fX) / 2,
152 center0, (pts[1].fX - pts[0].fX) / 2,
162 center0.
set(pts[0].fX + radius0, pts[0].fY + radius0);
163 center1.
set(pts[1].fX - radius1, pts[1].fY - radius1);
166 data.fCount, tm, 0, &localMatrix);
174 center0.
set(pts[0].fX + radius0, pts[0].fY + radius0);
175 center1.
set(pts[1].fX - radius1, pts[1].fY - radius1);
179 data.fCount, tm, 0, &localMatrix);
188 MakeLinear4f, MakeRadial4f, MakeSweep4f, Make2Radial4f, Make2Conical4f
208 paint.setAntiAlias(
true);
209 paint.setDither(fDither);
212 for (
size_t i = 0; i < std::size(
gGradData); i++) {
214 for (
size_t j = 0; j < std::size(
gGradMakers); j++) {
218 scale.setScale(0.5f, 0.5f);
219 scale.postTranslate(25.f, 25.f);
235 return SkString(fDither ?
"gradients" :
"gradients_nodither");
244class Gradients4fGM : public
skiagm::GM {
246 Gradients4fGM(bool dither) : fDither(dither) {}
249 void onOnceBeforeDraw()
override { this->setBGColor(0xFFDDDDDD); }
252 return SkString(fDither ?
"gradients4f" :
"gradients4f_nodither");
255 SkISize getISize()
override {
return {840, 815}; }
257 void onDraw(
SkCanvas* canvas)
override {
265 paint.setAntiAlias(
true);
266 paint.setDither(fDither);
269 for (
size_t i = 0; i < std::size(
gGradData); i++) {
271 for (
size_t j = 0; j < std::size(gGradMakers4f); j++) {
275 scale.setScale(0.5f, 0.5f);
276 scale.postTranslate(25.f, 25.f);
290DEF_GM(
return new Gradients4fGM(
true); )
291DEF_GM(
return new Gradients4fGM(
false); )
295class GradientsLocalPerspectiveGM : public
skiagm::GM {
297 GradientsLocalPerspectiveGM(bool dither) : fDither(dither) {
298 this->setBGColor(0xFFDDDDDD);
303 return SkString(fDither ?
"gradients_local_perspective" :
304 "gradients_local_perspective_nodither");
307 SkISize getISize()
override {
return {840, 815}; }
309 void onDraw(
SkCanvas* canvas)
override {
317 paint.setAntiAlias(
true);
318 paint.setDither(fDither);
321 for (
size_t i = 0; i < std::size(
gGradData); i++) {
323 for (
size_t j = 0; j < std::size(
gGradMakers); j++) {
341DEF_GM(
return new GradientsLocalPerspectiveGM(
true); )
342DEF_GM(
return new GradientsLocalPerspectiveGM(
false); )
346class GradientsViewPerspectiveGM : public
GradientsGM {
348 GradientsViewPerspectiveGM(bool dither) :
INHERITED(dither) { }
352 return SkString(fDither ?
"gradients_view_perspective" :
353 "gradients_view_perspective_nodither");
356 SkISize getISize()
override {
return {840, 500}; }
358 void onDraw(
SkCanvas* canvas)
override {
363 canvas->
concat(perspective);
364 this->INHERITED::onDraw(canvas);
370DEF_GM(
return new GradientsViewPerspectiveGM(
true); )
371DEF_GM(
return new GradientsViewPerspectiveGM(
false); )
389class GradientsDegenrate2PointGM : public
skiagm::GM {
391 GradientsDegenrate2PointGM(bool dither) : fDither(dither) {}
395 return SkString(fDither ?
"gradients_degenerate_2pt" :
"gradients_degenerate_2pt_nodither");
398 SkISize getISize()
override {
return {320, 320}; }
400 void onDraw(
SkCanvas* canvas)
override {
415 paint.setDither(fDither);
421DEF_GM(
return new GradientsDegenrate2PointGM(
true); )
422DEF_GM(
return new GradientsDegenrate2PointGM(
false); )
464 ClampedGradientsGM(
bool dither) : fDither(dither) {}
468 return SkString(fDither ?
"clamped_gradients" :
"clamped_gradients_nodither");
478 paint.setDither(fDither);
479 paint.setAntiAlias(
true);
493DEF_GM(
return new ClampedGradientsGM(
true); )
494DEF_GM(
return new ClampedGradientsGM(
false); )
499class RadialGradientGM : public
skiagm::GM {
502 SkISize getISize()
override {
return {1280, 1280}; }
504 void onDraw(
SkCanvas* canvas)
override {
505 const SkISize dim = this->getISize();
510 paint.setDither(
true);
514 const SkColor colors[] = { 0x7f7f7f7f, 0x7f7f7f7f, 0xb2000000 };
527DEF_GM(
return new RadialGradientGM; )
529class RadialGradient2GM : public
skiagm::GM {
531 RadialGradient2GM(bool dither) : fDither(dither) {}
535 return SkString(fDither ?
"radial_gradient2" :
"radial_gradient2_nodither");
538 SkISize getISize()
override {
return {800, 400}; }
541 void onDraw(
SkCanvas* canvas)
override {
542 SkPaint paint1, paint2, paint3;
548 { 0xFFFF0000, 0xFFFFFF00, 0xFF00FF00, 0xFF00FFFF, 0xFF0000FF, 0xFFFF00FF, 0xFFFF0000 };
549 const SkColor colors1[] = { 0xFFFFFFFF, 0x00000000 };
550 const SkColor colors2[] = { 0xFF000000, 0x00000000 };
552 const SkScalar cx = 200, cy = 200, radius = 150;
560 for (
size_t i = 0; i < std::size(
flags); i++) {
562 nullptr, std::size(sweep_colors),
565 nullptr, std::size(colors1),
569 nullptr, std::size(colors2),
589DEF_GM(
return new RadialGradient2GM(
true); )
590DEF_GM(
return new RadialGradient2GM(
false); )
593class RadialGradient3GM : public
skiagm::GM {
595 RadialGradient3GM(bool dither) : fDither(dither) { }
599 return SkString(fDither ?
"radial_gradient3" :
"radial_gradient3_nodither");
602 SkISize getISize()
override {
return {500, 500}; }
604 bool runAsBench()
const override {
return true; }
606 void onOnceBeforeDraw()
override {
614 void onDraw(
SkCanvas* canvas)
override {
616 paint.setShader(fShader);
617 paint.setDither(fDither);
627DEF_GM(
return new RadialGradient3GM(
true); )
628DEF_GM(
return new RadialGradient3GM(
false); )
630class RadialGradient4GM : public
skiagm::GM {
632 RadialGradient4GM(bool dither) : fDither(dither) { }
636 return SkString(fDither ?
"radial_gradient4" :
"radial_gradient4_nodither");
639 SkISize getISize()
override {
return {500, 500}; }
641 void onOnceBeforeDraw()
override {
646 const SkScalar pos[] = { 0, .4f, .4f, .8f, .8f, 1 };
651 void onDraw(
SkCanvas* canvas)
override {
653 paint.setAntiAlias(
true);
654 paint.setDither(fDither);
655 paint.setShader(fShader);
665DEF_GM(
return new RadialGradient4GM(
true); )
666DEF_GM(
return new RadialGradient4GM(
false); )
668class LinearGradientGM : public
skiagm::GM {
670 LinearGradientGM(bool dither) : fDither(dither) { }
674 return SkString(fDither ?
"linear_gradient" :
"linear_gradient_nodither");
681 SkISize getISize()
override {
return {500, 500}; }
683 void onOnceBeforeDraw()
override {
684 SkPoint pts[2] = { {0, 0}, {0, 0} };
687 const SkScalar unitPos[] = { 0, 50, 70, 500, 540 };
690 for (
int index = 0; index < (
int) std::size(fShader); ++index) {
691 pts[1].
fX = 500.f + index * kWidthBump;
692 for (
int inner = 0; inner < (
int) std::size(unitPos); ++inner) {
693 pos[inner] = unitPos[inner] / (kMinWidth + index * kWidthBump);
700 void onDraw(
SkCanvas* canvas)
override {
702 paint.setAntiAlias(
true);
703 paint.setDither(fDither);
704 for (
int index = 0; index < (
int) std::size(fShader); ++index) {
705 paint.setShader(fShader[index]);
717DEF_GM(
return new LinearGradientGM(
true); )
718DEF_GM(
return new LinearGradientGM(
false); )
720class LinearGradientTinyGM : public
skiagm::GM {
721 inline static constexpr uint32_t kFlags = 0;
723 SkString getName()
const override {
return SkString(
"linear_gradient_tiny"); }
725 SkISize getISize()
override {
return {600, 500}; }
727 void onDraw(
SkCanvas* canvas)
override {
752 for (
unsigned i = 0; i < std::size(configs); ++i) {
757 canvas->
translate(kRectSize * ((i % 4) * 1.5f + 0.25f),
758 kRectSize * ((i / 4) * 1.5f + 0.25f));
765DEF_GM(
return new LinearGradientTinyGM; )
793 run.fColors,
run.fPos,
run.fCount, mode);
808 const SkColor preColor = 0xFFFF0000;
809 const SkColor postColor = 0xFF0000FF;
810 const SkColor color0 = 0xFF000000;
811 const SkColor color1 = 0xFF00FF00;
812 const SkColor badColor = 0xFF3388BB;
815 { { color0, color1, badColor, badColor },
819 { { preColor, color0, color1, badColor },
823 { { color0, color1, postColor, badColor },
827 { { preColor, color0, color1, postColor },
831 { { color0, color0, color1, color1 },
832 { 0, 0.5f, 0.5f, 1 },
847 for (
auto factory : factories) {
850 for (
const auto&
run : runs) {
851 paint.setShader(factory(
run, mode));
860 const SkPoint pts[] = { {50, 50}, {450, 450}};
886 const SkPoint pts[] = {{50, 50}, {450, 450}};
916 p.setAntiAlias(
true);
917 p.setShader(shaderFunc());
920 p.setShader(
nullptr);
931 SkColor colors1[] = { 0xff000000, 0xff000000,
932 0xffffffff, 0xffffffff,
933 0xff000000, 0xff000000 };
934 SkColor colors2[] = { 0xff000000, 0xff000000,
935 0x00000000, 0x00000000,
936 0xff000000, 0xff000000 };
938 static_assert(std::size(colors1) == std::size(
pos),
"color/pos size mismatch");
939 static_assert(std::size(colors2) == std::size(
pos),
"color/pos size mismatch");
946 SkPoint pts1[] = { { 0, 0 }, { kTileSize, kTileSize }};
951 SkPoint pts2[] = { { 0, kTileSize }, { kTileSize, 0 }};
966 SkColor colors[] = { 0xff000000, 0xff000000,
967 0xffffffff, 0xffffffff,
968 0xff000000, 0xff000000,
969 0xffffffff, 0xffffffff };
970 SkScalar pos[] = { 0, .25f, .25f, .5f, .5f, .75f, .75f, 1 };
971 static_assert(std::size(colors) == std::size(
pos),
"color/pos size mismatch");
975 colors,
pos, std::size(colors), 0,
nullptr));
988 SkColor colors[] = {
a,
a,
b,
b,
a,
a,
b,
b,
a,
a,
b,
b,
a,
a,
b,
b};
989 SkScalar pos[] = { 0, .125f, .125f, .25f, .25f, .375f, .375f, .5f, .5f,
990 .625f, .625f, .75f, .75f, .875f, .875f, 1};
991 static_assert(std::size(colors) == std::size(
pos),
"color/pos size mismatch");
995 std::size(colors), 0,
nullptr);
999 std::size(colors), 0, &m);
1003 SkScalar radialPos[] = { 0, .02f, .02f, .04f, .04f, .08f, .08f, .16f, .16f, .31f, .31f,
1004 .62f, .62f, 1, 1, 1 };
1005 static_assert(std::size(colors) == std::size(radialPos),
1006 "color/pos size mismatch");
1011 std::size(radialPos),
1017 static constexpr SkScalar size = 160;
1019 static constexpr SkScalar pos[] = { 0, .25f, .50f };
1020 static_assert(std::size(colors) == std::size(
pos),
"size mismatch");
1026 static const struct {
1038 for (
auto mode : modes) {
1042 for (
auto angle : angles) {
1044 std::size(colors), mode,
1045 angle.start, angle.end, 0,
nullptr));
1056 static constexpr SkScalar size = 100;
1061 static constexpr SkScalar pos[] = { 0, .25f, .25f, .50f, .50f, .75, .75, 1 };
1062 static_assert(std::size(colors) == std::size(
pos),
"size mismatch");
1075 static const SkScalar softRight[] = { 0, .999f, 1 };
1076 static const SkScalar hardLeft[] = { 0, 0, 1 };
1077 static const SkScalar hardRight[] = { 0, 1, 1 };
1078 static const SkScalar hardCenter[] = { 0, .5f, .5f, 1 };
1080 static const struct {
1085 { colors2,
nullptr, 2 },
1086 { colors3,
nullptr, 3 },
1087 { colors3, softRight, 3 },
1088 { colors3, hardLeft, 3 },
1089 { colors3, hardRight, 3 },
1090 { colors4, hardCenter, 4 },
1099 static constexpr SkScalar size = 200;
1100 static const SkPoint pts[] = { { size / 3, size / 3 }, { size * 2 / 3, size * 2 / 3} };
1103 for (
const auto& cfg : configs) {
1106 for (
auto mode : modes) {
1125 static const Config kConfigs[] = {
1126 { CS::kSRGB,
"sRGB" },
1127 { CS::kSRGBLinear,
"Linear" },
1128 { CS::kLab,
"Lab" },
1129 { CS::kOKLab,
"OKLab" },
1130 { CS::kOKLabGamutMap,
"OKLabGamutMap" },
1131 { CS::kLCH,
"LCH" },
1132 { CS::kOKLCH,
"OKLCH" },
1133 { CS::kOKLCHGamutMap,
"OKLCHGamutMap" },
1134 { CS::kHSL,
"HSL" },
1135 { CS::kHWB,
"HWB" },
1138 SkPoint pts[] = {{0, 0}, {200, 0}};
1147 for (
const Config& config : kConfigs) {
1151 canvas->
drawRect({0, 0, 200, 20}, p);
1165 static const Config kConfigs[] = {
1166 { HM::kShorter,
"Shorter" },
1167 { HM::kLonger,
"Longer" },
1168 { HM::kIncreasing,
"Increasing" },
1169 { HM::kDecreasing,
"Decreasing" },
1172 SkPoint pts[] = {{0, 0}, {200, 0}};
1182 for (
const Config& config : kConfigs) {
1183 interpolation.
fHueMethod = config.fHueMethod;
1186 canvas->
drawRect({0, 0, 200, 20}, p);
1198 SkScalar middlePos[] = { 0.3f, 0.7f };
1201 canvas->
drawRect({0, 0, 200, 20}, p);
1209 SkScalar allPos[] = { 0.0f, 0.3f, 0.7f, 1.0f };
1212 canvas->
drawRect({0, 0, 200, 20}, p);
1222 SkPoint pts[] = {{20, 0}, {120, 0}};
1235 canvas->
drawRect({0, 0, 350, 20}, p);
1245 const SkPoint pts[] = { {50, 50}, {450, 465}};
1274 auto nextRow = [=]() {
1280 auto gradient = [&](std::initializer_list<SkColor4f> colors,
1281 std::initializer_list<float>
pos,
1282 bool inPremul =
false) {
1286 SkPoint pts[] = {{0, 0}, {200, 0}};
1287 Interpolation interpolation;
1288 interpolation.fColorSpace = colorSpace;
1289 interpolation.fInPremul =
static_cast<Interpolation::InPremul
>(inPremul);
1293 pos.size() == 0 ?
nullptr :
pos.begin(),
1341 {1.00f, 0.99f, 0.99f, 1.0f},
1342 {0.99f, 0.99f, 1.00f, 1.0f},
1344 {0.0f, 0.5f, 0.5f, 1.0f});
1349 {0.01f, 0.00f, 0.00f, 1.0f},
1350 {0.00f, 0.00f, 0.01f, 1.0f},
1352 {0.0f, 0.5f, 0.5f, 1.0f});
1357 {0.01f, 0.00f, 0.00f, 0.0f},
1358 {0.00f, 0.00f, 0.01f, 0.0f},
1360 {0.0f, 0.5f, 0.5f, 1.0f});
1366 auto blackWhiteGradient = [&](HueMethod hm) {
1369 SkPoint pts[] = {{0, 0}, {405, 0}};
1370 Interpolation interpolation;
1371 interpolation.fColorSpace = colorSpace;
1372 interpolation.fHueMethod = hm;
1388 blackWhiteGradient(HueMethod::kShorter);
1389 blackWhiteGradient(HueMethod::kIncreasing);
1390 blackWhiteGradient(HueMethod::kDecreasing);
1391 blackWhiteGradient(HueMethod::kLonger);
1394#define DEF_POWERLESS_HUE_GM(colorSpace) \
1395 DEF_SIMPLE_GM(gradients_powerless_hue_##colorSpace, canvas, 415, 330) { \
1396 draw_powerless_hue_gradients(canvas, \
1397 SkGradientShader::Interpolation::ColorSpace::k##colorSpace); \
static const int kStopCount
static const GradData gGradData[]
static sk_sp< SkShader > MakeSweep(const SkPoint pts[2], const GradData &data, SkTileMode tm, float scale)
Ignores scale.
sk_sp< SkShader >(* GradMaker)(const SkPoint pts[2], const GradData &data, SkTileMode tm, float scale)
static const SkColor gColors[]
@ kExclusion
rc = s + d - two(s*d), ra = kSrcOver
constexpr SkColor SK_ColorYELLOW
constexpr SkColor SK_ColorGRAY
constexpr SkColor SK_ColorBLUE
constexpr SkColor SK_ColorRED
constexpr SkColor SK_ColorBLACK
constexpr SkColor SK_ColorGREEN
constexpr SkColor SK_ColorWHITE
@ kUTF8
uses bytes to represent UTF-8 or ASCII
#define INHERITED(method,...)
#define SkScalarAve(a, b)
static SkScalar SkScalarInterp(SkScalar A, SkScalar B, SkScalar t)
static constexpr int kSkTileModeCount
static const SkScalar gPos2[]
static const SkScalar gPos1[]
static const SkScalar gPos0[]
static SkScalar center(float pos0, float pos1)
Type::kYUV Type::kRGBA() int(0.7 *637)
static sk_sp< SkShader > make_radial()
static sk_sp< SkShader > MakeRadial()
SkISize getISize() override
void onDraw(SkCanvas *canvas) override
SkString getName() const override
void drawRect(const SkRect &rect, const SkPaint &paint)
void drawSimpleText(const void *text, size_t byteLength, SkTextEncoding encoding, SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
void translate(SkScalar dx, SkScalar dy)
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
void drawPaint(const SkPaint &paint)
void concat(const SkMatrix &matrix)
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
static sk_sp< SkColorSpace > MakeSRGB()
static sk_sp< SkShader > MakeTwoPointConical(const SkPoint &start, SkScalar startRadius, const SkPoint &end, SkScalar endRadius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
static sk_sp< SkShader > MakeSweep(SkScalar cx, SkScalar cy, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, SkScalar startAngle, SkScalar endAngle, uint32_t flags, const SkMatrix *localMatrix)
static sk_sp< SkShader > MakeRadial(const SkPoint ¢er, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
@ kInterpolateColorsInPremul_Flag
SkMatrix & setSkewX(SkScalar v)
SkMatrix & setPerspY(SkScalar v)
static const SkMatrix & I()
void setStyle(Style style)
void setDither(bool dither)
@ kStroke_Style
set to stroke geometry
@ kFill_Style
set to fill geometry
void setShader(sk_sp< SkShader > shader)
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
SkCanvas * getRecordingCanvas()
sk_sp< SkPicture > finishRecordingAsPicture()
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, SkFilterMode mode, const SkMatrix *localMatrix, const SkRect *tileRect) const
virtual SkISize getISize()=0
virtual void onOnceBeforeDraw()
virtual SkString getName() const =0
virtual DrawResult onDraw(SkCanvas *, SkString *errorMsg)
static sk_sp< SkShader > MakeLinear()
FlutterSemanticsFlag flags
#define DEF_SIMPLE_GM_BG(NAME, CANVAS, W, H, BGCOLOR)
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
constexpr GradData gGradData[]
constexpr GradMaker gGradMakers[]
static void draw_powerless_hue_gradients(SkCanvas *canvas, SkGradientShader::Interpolation::ColorSpace colorSpace)
static void draw_many_stops(SkCanvas *canvas)
static void draw_many_hard_stops(SkCanvas *canvas)
static sk_sp< SkShader > make_linear(const GradRun &run, SkTileMode mode)
static sk_sp< SkShader > make_conical(const GradRun &run, SkTileMode mode)
#define DEF_POWERLESS_HUE_GM(colorSpace)
static sk_sp< SkShader > make_sweep(const GradRun &run, SkTileMode)
static void draw_circle_shader(SkCanvas *canvas, SkScalar cx, SkScalar cy, SkScalar r, sk_sp< SkShader >(*shaderFunc)())
static sk_sp< SkShader > Make2Conical(const SkPoint pts[2], const GradData &data, SkTileMode tm)
static sk_sp< SkShader > Make2Radial(const SkPoint pts[2], const GradData &data, SkTileMode tm)
constexpr SkColor4f kGreen
constexpr SkColor4f kWhite
constexpr SkColor4f kTransparent
constexpr SkColor4f kBlack
constexpr SkColor4f kGray
constexpr SkColor4f kBlue
constexpr SkColor4f kYellow
constexpr SkColor4f kDkGray
PODArray< SkColor > colors
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
constexpr SkColor gColorClamp[]
constexpr SkScalar gPosClamp[]
constexpr int32_t width() const
constexpr int32_t height() const
void iset(int32_t x, int32_t y)
static constexpr SkPoint Make(float x, float y)
void set(float x, float y)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
static constexpr SkRect MakeWH(float w, float h)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)