Flutter Engine
The Flutter Engine
picture_shader.cpp
Go to the documentation of this file.
1// Copyright 2020 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4REG_FIDDLE(picture_shader, 256, 256, false, 5) {
5static void draw_centered(
6 const char* s, const SkFont& font, SkColor color, SkPoint xy, SkCanvas* c) {
8 xy -= SkPoint{b->bounds().centerX(), b->bounds().centerY()};
10 p.setColor(color);
11 c->drawTextBlob(b.get(), xy.x(), xy.y(), p);
12}
13
14SkPoint from_polar_deg(float r, float d) {
15 float a = d * 0.017453292519943295;
16 return {r * cosf(a), r * sinf(a)};
17}
18
19void draw_wheel(SkCanvas* c) {
20 const SkScalar scale = 512;
21 SkAutoCanvasRestore autoCanvasRestore(c, true);
22 c->translate(0.5f * scale, 0.5f * scale);
23 SkPaint p;
24 p.setAntiAlias(true);
25 p.setColor(SK_ColorWHITE);
26 c->drawCircle(0.0f, 0.0f, scale * 0.475f, p);
27
30 SkMatrix rot;
31 rot.setRotate(90.0f);
32 p.setShader(SkGradientShader::MakeSweep(0, 0, sweep_colors, nullptr,
33 std::size(sweep_colors), 0, &rot));
34 p.setStrokeWidth(0.05f * scale);
35 p.setStyle(SkPaint::kStroke_Style);
36 c->drawCircle(0.0f, 0.0f, 0.475f * scale, p);
37
38 SkFont f(nullptr, 0.28125f * scale);
39 draw_centered("K", f, SK_ColorBLACK, {0.0f, 0.0f}, c);
40 draw_centered("R", f, SK_ColorRED, from_polar_deg(0.3f * scale, 90), c);
41 draw_centered("G", f, SK_ColorGREEN, from_polar_deg(0.3f * scale, 210), c);
42 draw_centered("B", f, SK_ColorBLUE, from_polar_deg(0.3f * scale, 330), c);
43 draw_centered("C", f, SK_ColorCYAN, from_polar_deg(0.3f * scale, 270), c);
44 draw_centered("M", f, SK_ColorMAGENTA, from_polar_deg(0.3f * scale, 30), c);
45 draw_centered("Y", f, SK_ColorYELLOW, from_polar_deg(0.3f * scale, 150), c);
46}
47
48void draw(SkCanvas* canvas) {
49 canvas->clear(SK_ColorWHITE);
51 matrix.setScale(0.25f, 0.25f);
52 matrix.preRotate(30.0f);
55 draw_wheel(rec.beginRecording(512, 512));
58 canvas->drawPaint(paint);
59}
60} // END FIDDLE
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
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
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawPaint(const SkPaint &paint)
Definition: SkCanvas.cpp:1668
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawTextBlob(const SkTextBlob *blob, SkScalar x, SkScalar y, const SkPaint &paint)
Definition: SkCanvas.cpp:2484
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
Definition: SkFont.h:35
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)
SkMatrix & setRotate(SkScalar degrees, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:452
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, SkFilterMode mode, const SkMatrix *localMatrix, const SkRect *tileRect) const
static sk_sp< SkTextBlob > MakeFromString(const char *string, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
Definition: SkTextBlob.h:115
const Paint & paint
Definition: color_source.cc:38
DlColor color
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
float SkScalar
Definition: extension.cpp:12
static bool b
struct MyStruct s
struct MyStruct a[10]
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
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.
REG_FIDDLE(picture_shader, 256, 256, false, 5)
const Scalar scale
constexpr float y() const
Definition: SkPoint_impl.h:187
constexpr float x() const
Definition: SkPoint_impl.h:181