Flutter Engine
The Flutter Engine
scaledstrokes.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 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/SkRect.h"
14#include "include/core/SkSize.h"
16
18public:
20
21protected:
22 SkString getName() const override { return SkString("scaledstrokes"); }
23
24 SkISize getISize() override { return SkISize::Make(640, 320); }
25
26 static void draw_path(SkScalar size, SkCanvas* canvas, SkPaint paint) {
27 SkScalar c = 0.551915024494f * size;
29 path.moveTo(0.0f, size);
30 path.cubicTo(c, size, size, c, size, 0.0f);
31 path.cubicTo(size, -c, c, -size, 0.0f, -size);
32 path.cubicTo(-c, -size, -size, -c, -size, 0.0f);
33 path.cubicTo(-size, c, -c, size, 0.0f, size);
34 canvas->drawPath(path.detach(), paint);
35 }
36
37 void onDraw(SkCanvas* canvas) override {
40 paint.setStyle(SkPaint::Style::kStroke_Style);
41 canvas->translate(5.0f, 5.0f);
42 const SkScalar size = 60.0f;
43 for (int i = 0; i < 2; i++) {
44 paint.setAntiAlias(i == 1);
45 for (int j = 0; j < 4; j++) {
46 SkScalar scale = 4.0f - j;
47 paint.setStrokeWidth(4.0f / scale);
48 canvas->save();
49 canvas->translate(size / 2.0f, size / 2.0f);
50 canvas->scale(scale, scale);
51 draw_path(size / 2.0f / scale, canvas, paint);
52 canvas->restore();
53
54 canvas->save();
55 canvas->translate(size / 2.0f, 80.0f + size / 2.0f);
56 canvas->scale(scale, scale);
57 canvas->drawCircle(0.0f, 0.0f, size / 2.0f / scale, paint);
58 canvas->restore();
59
60 canvas->save();
61 canvas->translate(0.0f, 160.0f);
62 canvas->scale(scale, scale);
63 canvas->drawRect(SkRect::MakeXYWH(0.0f, 0.0f, size / scale, size / scale), paint);
64 canvas->restore();
65
66 canvas->save();
67 canvas->translate(0.0f, 240.0f);
68 canvas->scale(scale, scale);
69 canvas->drawLine(0.0f, 0.0f, size / scale, size / scale, paint);
70 canvas->restore();
71
72 canvas->translate(80.0f, 0.0f);
73 }
74 }
75
76 }
77
78private:
79 using INHERITED = GM;
80};
81
82DEF_GM( return new ScaledStrokesGM; )
SkString getName() const override
SkISize getISize() override
static void draw_path(SkScalar size, SkCanvas *canvas, SkPaint paint)
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
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
int save()
Definition: SkCanvas.cpp:447
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
Definition: SkPath.h:59
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
#define DEF_GM(CODE)
Definition: gm.h:40
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
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 Scalar scale
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659