Flutter Engine
The Flutter Engine
emptyshader.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 Google LLC
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"
9
14
15namespace skiagm {
16
17namespace {
18
19sk_sp<SkShader> empty(SkRect r) { return sk_make_sp<SkEmptyShader>(); }
20
21sk_sp<SkShader> degen_sweep(SkRect r) {
22 // A too small angle between start and end falls back to an empty shader
23 const float startAngle = 0.0f;
24 const float endAngle = nextafter(startAngle, 360.0f);
26
28 colors,
29 /* pos= */ nullptr,
32 startAngle, endAngle,
33 /* flags= */ 0,
34 /* localMatrix= */ nullptr);
35}
36
37sk_sp<SkShader> degen_linear(SkRect r) {
38 // Having the two positions be the same causes a fallback to an empty shader
39 const SkPoint pts[2] = { r.center(), r.center() };
41
43 colors,
44 /* pos= */ nullptr,
47}
48
49sk_sp<SkShader> degen_radial(SkRect r) {
51
52 // Having a radius of 0.0 causes a fallback to an empty shader
54 /* radius= */ 0.0f,
55 colors,
56 /* pos= */ nullptr,
59}
60
61sk_sp<SkShader> degen_conical(SkRect r) {
63
64 // Having the start and end radii be the same causes a fallback to an empty shader
65 return SkGradientShader::MakeTwoPointConical(r.center(), /* startRadius= */ 0.0f,
66 r.center(), /* endRadius= */ 0.0f,
67 colors,
68 /* pos= */ nullptr,
71}
72
73} // anonymous namespace
74
75class EmptyShaderGM : public GM {
76public:
78 this->setBGColor(0xFFCCCCCC);
79 }
80
81protected:
82 SkString getName() const override { return SkString("emptyshader"); }
83
84 SkISize getISize() override { return SkISize::Make(128, 88); }
85
86 void onDraw(SkCanvas* canvas) override {
89
90 int left = kPad, top = kPad;
91 for (auto f : { empty, degen_sweep, degen_linear, degen_radial, degen_conical }) {
92 SkRect r = SkRect::MakeXYWH(left, top, kSize, kSize);
93
94 SkPaint p;
95 p.setColor(SK_ColorBLUE);
96 p.setShader(f(r));
97
98 canvas->drawRect(r, p);
99 canvas->drawRect(r, stroke);
100
101 left += kSize + kPad;
102 if (left >= this->getISize().width()) {
103 left = kPad;
104 top += kSize + kPad;
105 }
106 }
107 }
108
109private:
110 static constexpr int kPad = 8;
111 static constexpr int kSize = 32;
112};
113
114//////////////////////////////////////////////////////////////////////////////
115
116DEF_GM(return new EmptyShaderGM;)
117
118} // namespace skiagm
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_ColorGREEN
Definition: SkColor.h:131
constexpr int kPad
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
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)
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void onDraw(SkCanvas *canvas) override
Definition: emptyshader.cpp:86
SkString getName() const override
Definition: emptyshader.cpp:82
SkISize getISize() override
Definition: emptyshader.cpp:84
Definition: gm.h:110
SkScalar width()
Definition: gm.h:159
void setBGColor(SkColor)
Definition: gm.cpp:159
EMSCRIPTEN_KEEPALIVE void empty()
SkScalar startAngle
Definition: SkRecords.h:250
PODArray< SkColor > colors
Definition: SkRecords.h:276
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
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
constexpr float centerX() const
Definition: SkRect.h:776
constexpr float centerY() const
Definition: SkRect.h:785
constexpr SkPoint center() const
Definition: SkRect.h:792