Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
alphagradients.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"
15#include "include/core/SkSize.h"
20
22public:
24
25protected:
26 SkString getName() const override { return SkString("alphagradients"); }
27
28 SkISize getISize() override { return SkISize::Make(640, 480); }
29
30 static void draw_grad(SkCanvas* canvas, const SkRect& r,
31 SkColor c0, SkColor c1, bool doPreMul) {
32 SkColor colors[] = { c0, c1 };
33 SkPoint pts[] = { { r.fLeft, r.fTop }, { r.fRight, r.fBottom } };
36 paint.setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, 2,
37 SkTileMode::kClamp, flags, nullptr));
38 canvas->drawRect(r, paint);
39
40 paint.setShader(nullptr);
42 canvas->drawRect(r, paint);
43 }
44
45 void onDraw(SkCanvas* canvas) override {
46 constexpr struct {
47 SkColor fColor0;
48 SkColor fColor1;
49 } gRec[] = {
50 { 0xFFFFFFFF, 0x00000000 },
51 { 0xFFFFFFFF, 0x00FF0000 },
52 { 0xFFFFFFFF, 0x00FFFF00 },
53 { 0xFFFFFFFF, 0x00FFFFFF },
54 { 0xFFFF0000, 0x00000000 },
55 { 0xFFFF0000, 0x00FF0000 },
56 { 0xFFFF0000, 0x00FFFF00 },
57 { 0xFFFF0000, 0x00FFFFFF },
58 { 0xFF0000FF, 0x00000000 },
59 { 0xFF0000FF, 0x00FF0000 },
60 { 0xFF0000FF, 0x00FFFF00 },
61 { 0xFF0000FF, 0x00FFFFFF },
62 };
63
64 SkRect r = SkRect::MakeWH(300, 30);
65
66 canvas->translate(10, 10);
67
68 for (int doPreMul = 0; doPreMul <= 1; ++doPreMul) {
69 canvas->save();
70 for (size_t i = 0; i < std::size(gRec); ++i) {
71 draw_grad(canvas, r, gRec[i].fColor0, gRec[i].fColor1, SkToBool(doPreMul));
72 canvas->translate(0, r.height() + 8);
73 }
74 canvas->restore();
75 canvas->translate(r.width() + 10, 0);
76 }
77 }
78
79private:
80 using INHERITED = skiagm::GM;
81};
82
83DEF_GM(return new AlphaGradientsGM;)
static const struct @223 gRec[]
uint32_t SkColor
Definition: SkColor.h:37
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
SkISize getISize() override
static void draw_grad(SkCanvas *canvas, const SkRect &r, SkColor c0, SkColor c1, bool doPreMul)
SkString getName() const override
void onDraw(SkCanvas *canvas) 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 > 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
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
FlutterSemanticsFlag flags
#define DEF_GM(CODE)
Definition: gm.h:40
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
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15