Flutter Engine
The Flutter Engine
srcmode.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2012 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"
12#include "include/core/SkFont.h"
15#include "include/core/SkPath.h"
17#include "include/core/SkRect.h"
21#include "include/core/SkSize.h"
28#include "tools/ToolUtils.h"
30
31#define W SkIntToScalar(80)
32#define H SkIntToScalar(60)
33
34typedef void (*PaintProc)(SkPaint*);
35
37 paint->setShader(nullptr);
38}
39
42 const SkPoint pts[] = { { 0, 0 }, { W, H } };
43 paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, std::size(colors),
45}
46
47typedef void (*Proc)(SkCanvas*, const SkPaint&, const SkFont&);
48
49static void draw_hair(SkCanvas* canvas, const SkPaint& paint, const SkFont&) {
51 p.setStrokeWidth(0);
52 canvas->drawLine(0, 0, W, H, p);
53}
54
55static void draw_thick(SkCanvas* canvas, const SkPaint& paint, const SkFont&) {
57 p.setStrokeWidth(H/5);
58 canvas->drawLine(0, 0, W, H, p);
59}
60
61static void draw_rect(SkCanvas* canvas, const SkPaint& paint, const SkFont&) {
62 canvas->drawRect(SkRect::MakeWH(W, H), paint);
63}
64
65static void draw_oval(SkCanvas* canvas, const SkPaint& paint, const SkFont&) {
66 canvas->drawOval(SkRect::MakeWH(W, H), paint);
67}
68
69static void draw_text(SkCanvas* canvas, const SkPaint& paint, const SkFont& font) {
70 canvas->drawString("Hamburge", 0, H*2/3, font, paint);
71}
72
73class SrcModeGM : public skiagm::GM {
74 SkPath fPath;
75
76 void onOnceBeforeDraw() override { this->setBGColor(SK_ColorBLACK); }
77
78 SkString getName() const override { return SkString("srcmode"); }
79
80 SkISize getISize() override { return {640, 760}; }
81
82 void drawContent(SkCanvas* canvas) {
83 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
84
87 paint.setColor(0x80F60000);
88
89 const Proc procs[] = {
91 };
92
93 const SkBlendMode modes[] = {
95 };
96
97 const PaintProc paintProcs[] = {
99 };
100
101 for (int aa = 0; aa <= 1; ++aa) {
102 paint.setAntiAlias(SkToBool(aa));
104 canvas->save();
105 for (size_t i = 0; i < std::size(paintProcs); ++i) {
106 paintProcs[i](&paint);
107 for (size_t x = 0; x < std::size(modes); ++x) {
108 paint.setBlendMode(modes[x]);
109 canvas->save();
110 for (size_t y = 0; y < std::size(procs); ++y) {
111 procs[y](canvas, paint, font);
112 canvas->translate(0, H * 5 / 4);
113 }
114 canvas->restore();
115 canvas->translate(W * 5 / 4, 0);
116 }
117 }
118 canvas->restore();
119 canvas->translate(0, (H * 5 / 4) * std::size(procs));
120 }
121 }
122
123 static sk_sp<SkSurface> compat_surface(SkCanvas* canvas, const SkISize& size) {
126 if (nullptr == surface) {
127 // picture canvas will return null, so fall-back to raster
129 }
130 return surface;
131 }
132
133 void onDraw(SkCanvas* canvas) override {
134 auto surf(compat_surface(canvas, this->getISize()));
135 surf->getCanvas()->drawColor(SK_ColorWHITE);
136 this->drawContent(surf->getCanvas());
137 surf->draw(canvas, 0, 0);
138 }
139};
140
141///////////////////////////////////////////////////////////////////////////////
142
143DEF_GM(return new SrcModeGM;)
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SkBlendMode
Definition: SkBlendMode.h:38
@ kSrcOver
r = s + (1-sa)*d
@ kClear
r = 0
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
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 SkIntToScalar(x)
Definition: SkScalar.h:57
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void drawOval(const SkRect &oval, const SkPaint &paint)
Definition: SkCanvas.cpp:1698
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
sk_sp< SkSurface > makeSurface(const SkImageInfo &info, const SkSurfaceProps *props=nullptr)
Definition: SkCanvas.cpp:1195
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
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
@ kAntiAlias
may have transparent pixels on glyph edges
@ kAlias
no transparent pixels on glyph edges
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: SkPath.h:59
Definition: gm.h:110
void setBGColor(SkColor)
Definition: gm.cpp:159
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
#define DEF_GM(CODE)
Definition: gm.h:40
double y
double x
PODArray< SkColor > colors
Definition: SkRecords.h:276
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
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 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.
void(* PaintProc)(SkPaint *)
Definition: srcmode.cpp:34
#define W
Definition: srcmode.cpp:31
static void draw_hair(SkCanvas *canvas, const SkPaint &paint, const SkFont &)
Definition: srcmode.cpp:49
static void draw_rect(SkCanvas *canvas, const SkPaint &paint, const SkFont &)
Definition: srcmode.cpp:61
static void draw_text(SkCanvas *canvas, const SkPaint &paint, const SkFont &font)
Definition: srcmode.cpp:69
static void gradient_paintproc(SkPaint *paint)
Definition: srcmode.cpp:40
static void draw_thick(SkCanvas *canvas, const SkPaint &paint, const SkFont &)
Definition: srcmode.cpp:55
static void draw_oval(SkCanvas *canvas, const SkPaint &paint, const SkFont &)
Definition: srcmode.cpp:65
static void identity_paintproc(SkPaint *paint)
Definition: srcmode.cpp:36
void(* Proc)(SkCanvas *, const SkPaint &, const SkFont &)
Definition: srcmode.cpp:47
Definition: SkMD5.cpp:130
Definition: SkSize.h:16
static SkImageInfo MakeN32Premul(int width, int height)
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609