Flutter Engine
The Flutter Engine
gradients_degenerate.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2018 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "gm/gm.h"
11#include "include/core/SkFont.h"
14#include "include/core/SkRect.h"
18#include "include/core/SkSize.h"
23#include "tools/ToolUtils.h"
25
26// NOTE: The positions define hardstops for the red and green borders. For the repeating degenerate
27// gradients, that means the red and green are never visible, so the average color used should only
28// be based off of the white, blue, black blend.
31static const SkScalar POS[] = { 0.0, 0.0, 0.5, 1.0, 1.0 };
32static const int COLOR_CT = std::size(COLORS);
33
38static const char* TILE_NAMES[] = { "decal", "repeat", "mirror", "clamp" };
39static const int TILE_MODE_CT = std::size(TILE_MODES);
40
41static constexpr int TILE_SIZE = 100;
42static constexpr int TILE_GAP = 10;
43
45
47
48static void draw_tile_header(SkCanvas* canvas) {
49 canvas->save();
50
52 for (int i = 0; i < TILE_MODE_CT; ++i) {
53 canvas->drawString(TILE_NAMES[i], 0, 0, font, SkPaint());
54 canvas->translate(TILE_SIZE + TILE_GAP, 0);
55 }
56
57 canvas->restore();
58
59 // Now adjust to start at rows below the header
60 canvas->translate(0, 2 * TILE_GAP);
61}
62
63static void draw_row(SkCanvas* canvas, const char* desc, GradientFactory factory) {
64 canvas->save();
65
67 text.setAntiAlias(true);
68
70
71 canvas->translate(0, TILE_GAP);
72 canvas->drawString(desc, 0, 0, font, text);
73 canvas->translate(0, TILE_GAP);
74
76 paint.setColor(SK_ColorBLACK);
78 paint.setStrokeWidth(2.0f);
79
80 for (int i = 0; i < TILE_MODE_CT; ++i) {
81 paint.setShader(factory(TILE_MODES[i]));
83 canvas->translate(TILE_SIZE + TILE_GAP, 0);
84 }
85
86 canvas->restore();
87
88 // Now adjust to start the next row below this one (1 gap for text and 2 gap for margin)
89 canvas->translate(0, 3 * TILE_GAP + TILE_SIZE);
90}
91
93 // Same position
94 SkPoint pts[2] = {CENTER, CENTER};
96}
97
99 // Radius = 0
101}
102
104 // Start and end angles at 45
105 static constexpr SkScalar SWEEP_ANG = 45.0;
107 SWEEP_ANG, SWEEP_ANG, 0, nullptr);
108}
109
111 // Start and end angles at 0
113 0.0, 0.0, 0, nullptr);
114}
115
117 // Start and end radius = TILE_SIZE, same position
120}
121
123 // Start and end radius = 0, same position
125 COLOR_CT, mode);
126}
127
129public:
131
132 }
133
134protected:
135 SkString getName() const override { return SkString("degenerate_gradients"); }
136
137 SkISize getISize() override { return SkISize::Make(800, 800); }
138
139 void onDraw(SkCanvas* canvas) override {
140 canvas->translate(3 * TILE_GAP, 3 * TILE_GAP);
141 draw_tile_header(canvas);
142
143 draw_row(canvas, "linear: empty, blue, blue, green", make_linear);
144 draw_row(canvas, "radial: empty, blue, blue, green", make_radial);
145 draw_row(canvas, "sweep-0: empty, blue, blue, green", make_sweep_zero_ang);
146 draw_row(canvas, "sweep-45: empty, blue, blue, red 45 degree sector then green",
147 make_sweep);
148 draw_row(canvas, "2pt-conic-0: empty, blue, blue, green", make_2pt_conic_zero_rad);
149 draw_row(canvas, "2pt-conic-1: empty, blue, blue, full red circle on green",
151 }
152
153private:
154 using INHERITED = skiagm::GM;
155};
156
157DEF_GM(return new DegenerateGradientGM;)
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
SkTileMode
Definition: SkTileMode.h:13
SkISize getISize() override
void onDraw(SkCanvas *canvas) override
SkString getName() const override
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
int save()
Definition: SkCanvas.cpp:447
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
Definition: SkFont.h:35
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 &center, 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)
@ kStrokeAndFill_Style
sets to stroke and fill geometry
Definition: SkPaint.h:195
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
#define DEF_GM(CODE)
Definition: gm.h:40
static const int COLOR_CT
static void draw_tile_header(SkCanvas *canvas)
static void draw_row(SkCanvas *canvas, const char *desc, GradientFactory factory)
static const SkColor COLORS[]
static sk_sp< SkShader > make_linear(SkTileMode mode)
sk_sp< SkShader >(* GradientFactory)(SkTileMode tm)
static const char * TILE_NAMES[]
static const SkScalar POS[]
static constexpr int TILE_SIZE
static const SkTileMode TILE_MODES[]
static sk_sp< SkShader > make_2pt_conic(SkTileMode mode)
static sk_sp< SkShader > make_radial(SkTileMode mode)
static sk_sp< SkShader > make_sweep(SkTileMode mode)
static const SkPoint CENTER
static constexpr int TILE_GAP
static sk_sp< SkShader > make_2pt_conic_zero_rad(SkTileMode mode)
static const int TILE_MODE_CT
static sk_sp< SkShader > make_sweep_zero_ang(SkTileMode mode)
std::u16string text
sk_sp< SkTypeface > DefaultPortableTypeface()
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
font
Font Metadata and Metrics.
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
float fX
x-axis value
Definition: SkPoint_impl.h:164
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173
float fY
y-axis value
Definition: SkPoint_impl.h:165
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609