Flutter Engine
The Flutter Engine
gradient_dirty_laundry.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2013 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"
13#include "include/core/SkRect.h"
17#include "include/core/SkSize.h"
22
23using namespace skiagm;
24
25struct GradData {
26 int fCount;
27 const SkColor* fColors;
28 const SkScalar* fPos;
29};
30
31constexpr SkColor gColors[] = {
40};
41
42//constexpr SkScalar gPos[] = { SK_Scalar1*999/2000, SK_Scalar1*1001/2000 };
43
44constexpr GradData gGradData[] = {
45 { 40, gColors, nullptr },
46 // { 2, gColors, gPos },
47 // { 2, gCol2, nullptr },
48};
49
50static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, SkTileMode tm) {
51 return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCount, tm);
52}
53
54static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, SkTileMode tm) {
55 const SkPoint pt{ SkScalarAve(pts[0].fX, pts[1].fX), SkScalarAve(pts[0].fY, pts[1].fY) };
56 return SkGradientShader::MakeRadial(pt, pt.fX, data.fColors, data.fPos, data.fCount, tm);
57}
58
60 const SkPoint pt{ SkScalarAve(pts[0].fX, pts[1].fX), SkScalarAve(pts[0].fY, pts[1].fY) };
61 return SkGradientShader::MakeSweep(pt.fX, pt.fY, data.fColors, data.fPos, data.fCount);
62}
63
64
65typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData&, SkTileMode);
66
67constexpr GradMaker gGradMakers[] = {
69};
70
71///////////////////////////////////////////////////////////////////////////////
72
73class GradientsGM : public GM {
74public:
76 this->setBGColor(0xFFDDDDDD);
77 }
78
79protected:
80 SkString getName() const override { return SkString("gradient_dirty_laundry"); }
81 SkISize getISize() override { return SkISize::Make(640, 615); }
82
83 void onDraw(SkCanvas* canvas) override {
84 SkPoint pts[2] = { { 0, 0 },
85 { SkIntToScalar(100), SkIntToScalar(100) }
86 };
88 SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) };
90 paint.setAntiAlias(true);
91
92 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
93 for (size_t i = 0; i < std::size(gGradData); i++) {
94 canvas->save();
95 for (size_t j = 0; j < std::size(gGradMakers); j++) {
96 paint.setShader(gGradMakers[j](pts, gGradData[i], tm));
97 canvas->drawRect(r, paint);
98 canvas->translate(0, SkIntToScalar(120));
99 }
100 canvas->restore();
101 canvas->translate(SkIntToScalar(120), 0);
102 }
103 }
104
105private:
106 using INHERITED = GM;
107};
108
109///////////////////////////////////////////////////////////////////////////////
110
111DEF_GM( return new GradientsGM; )
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
#define SkScalarAve(a, b)
Definition: SkScalar.h:74
#define SkIntToScalar(x)
Definition: SkScalar.h:57
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
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)
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
void setBGColor(SkColor)
Definition: gm.cpp:159
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
#define DEF_GM(CODE)
Definition: gm.h:40
sk_sp< SkShader >(* GradMaker)(const SkPoint pts[2], const GradData &, SkTileMode)
constexpr SkColor gColors[]
constexpr GradData gGradData[]
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const GradData &data, SkTileMode tm)
static sk_sp< SkShader > MakeRadial(const SkPoint pts[2], const GradData &data, SkTileMode tm)
constexpr GradMaker gGradMakers[]
static sk_sp< SkShader > MakeSweep(const SkPoint pts[2], const GradData &data, SkTileMode)
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
const SkColor * fColors
const SkScalar * fPos
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63