Flutter Engine
The Flutter Engine
shallowgradient.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"
16#include "include/core/SkSize.h"
21
22typedef sk_sp<SkShader> (*MakeShaderProc)(const SkColor[], int count, const SkSize&);
23
25 SkPoint pts[] = { { 0, 0 }, { size.width(), size.height() } };
27}
28
30 SkPoint center = { size.width()/2, size.height()/2 };
31 return SkGradientShader::MakeRadial(center, size.width()/2, colors, nullptr, count,
33}
34
36 SkPoint center = { size.width()/2, size.height()/2 };
37 return SkGradientShader::MakeTwoPointConical(center, size.width()/64, center, size.width()/2,
39}
40
42 return SkGradientShader::MakeSweep(size.width()/2, size.height()/2, colors, nullptr, count);
43}
44
46public:
47 ShallowGradientGM(MakeShaderProc proc, const char name[], bool dither)
48 : fProc(proc), fName(name), fDither(dither) {}
49
50private:
51 MakeShaderProc fProc;
52 const char* fName;
53 bool fDither;
54
55 SkString getName() const override {
56 return SkStringPrintf("shallow_gradient_%s%s", fName, fDither ? "" : "_nodither");
57 }
58
59 SkISize getISize() override { return {800, 800}; }
60
61 void onDraw(SkCanvas* canvas) override {
62 const SkColor colors[] = { 0xFF555555, 0xFF444444 };
63 const int colorCount = std::size(colors);
64
65 SkRect r = { 0, 0, this->width(), this->height() };
67
69 paint.setShader(fProc(colors, colorCount, size));
70 paint.setDither(fDither);
71 canvas->drawRect(r, paint);
72 }
73};
74
75///////////////////////////////////////////////////////////////////////////////
76
77#define M(PROC, DITHER) DEF_GM( return new ShallowGradientGM(shader_ ## PROC, #PROC, DITHER); )
78M(linear, true)
79M(radial, true)
80M(conical, true)
81M(sweep, true)
82
84M(radial, false)
85M(conical, false)
86M(sweep, false)
87#undef M
int count
Definition: FontMgrTest.cpp:50
IsFiniteProc fProc
Definition: MathBench.cpp:219
uint32_t SkColor
Definition: SkColor.h:37
SK_API SkString SkStringPrintf(const char *format,...) SK_PRINTF_LIKE(1
Creates a new string and writes into it using a printf()-style format.
static SkScalar center(float pos0, float pos1)
ShallowGradientGM(MakeShaderProc proc, const char name[], bool dither)
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)
Definition: gm.h:110
SkScalar width()
Definition: gm.h:159
SkScalar height()
Definition: gm.h:162
const Paint & paint
Definition: color_source.cc:38
PODArray< SkColor > colors
Definition: SkRecords.h:276
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
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
static sk_sp< SkShader > shader_linear(const SkColor colors[], int count, const SkSize &size)
static sk_sp< SkShader > shader_conical(const SkColor colors[], int count, const SkSize &size)
#define M(PROC, DITHER)
static sk_sp< SkShader > shader_radial(const SkColor colors[], int count, const SkSize &size)
static sk_sp< SkShader > shader_sweep(const SkColor colors[], int count, const SkSize &size)
sk_sp< SkShader >(* MakeShaderProc)(const SkColor[], int count, const SkSize &)
Definition: SkSize.h:16
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762
Definition: SkSize.h:52
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:56
static sk_sp< SkShader > linear(sk_sp< SkShader > shader)