Flutter Engine
The Flutter Engine
stringart.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"
11#include "include/core/SkPath.h"
14#include "include/core/SkSize.h"
17#include "tools/ToolUtils.h"
19
20// Reproduces https://code.google.com/p/chromium/issues/detail?id=279014
21
22constexpr int kWidth = 440;
23constexpr int kHeight = 440;
24constexpr SkScalar kAngle = 0.305f;
25constexpr int kMaxNumSteps = 140;
26
27// Renders a string art shape.
28// The particular shape rendered can be controlled by adjusting kAngle, from 0 to 1
29
30class StringArtGM : public skiagm::GM {
31public:
32 StringArtGM() : fNumSteps(kMaxNumSteps) {}
33
34protected:
35 SkString getName() const override { return SkString("stringart"); }
36
37 SkISize getISize() override { return SkISize::Make(kWidth, kHeight); }
38
39 void onDraw(SkCanvas* canvas) override {
43 SkScalar length = 5;
44 SkScalar step = angle;
45
47 path.moveTo(center);
48
49 for (int i = 0; i < fNumSteps && length < (SkScalarHalf(size) - 10.f); ++i) {
52 path.lineTo(rp);
54 step += angle;
55 }
56
58 paint.setAntiAlias(true);
60 paint.setColor(ToolUtils::color_to_565(0xFF007700));
61
62 canvas->drawPath(path, paint);
63 }
64
65 bool onAnimate(double nanos) override {
66 constexpr SkScalar kDesiredDurationSecs = 3.0f;
67
68 // Make the animation ping-pong back and forth but start in the fully drawn state
69 SkScalar fraction = 1.0f - TimeUtils::Scaled(1e-9 * nanos, 2.0f/kDesiredDurationSecs, 2.0f);
70 if (fraction <= 0.0f) {
71 fraction = -fraction;
72 }
73
74 SkASSERT(fraction >= 0.0f && fraction <= 1.0f);
75
76 fNumSteps = (int) (fraction * kMaxNumSteps);
77 return true;
78 }
79
80private:
81 int fNumSteps;
82
83 using INHERITED = GM;
84};
85
86DEF_GM( return new StringArtGM; )
static int step(int x, SkScalar min, SkScalar max)
Definition: BlurTest.cpp:215
#define SkASSERT(cond)
Definition: SkAssert.h:116
#define SkScalarSin(radians)
Definition: SkScalar.h:45
#define SkScalarHalf(a)
Definition: SkScalar.h:75
#define SkIntToScalar(x)
Definition: SkScalar.h:57
#define SkScalarCos(radians)
Definition: SkScalar.h:46
#define SK_ScalarPI
Definition: SkScalar.h:21
static SkScalar center(float pos0, float pos1)
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
Definition: SkPath.h:59
bool onAnimate(double nanos) override
Definition: stringart.cpp:65
SkISize getISize() override
Definition: stringart.cpp:37
SkString getName() const override
Definition: stringart.cpp:35
void onDraw(SkCanvas *canvas) override
Definition: stringart.cpp:39
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
static float min(float r, float g, float b)
Definition: hsl.cpp:48
size_t length
static float Scaled(float time, float speed, float period=0)
Definition: TimeUtils.h:27
SkColor color_to_565(SkColor color)
Definition: ToolUtils.cpp:139
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
constexpr SkScalar kAngle
Definition: stringart.cpp:24
constexpr int kWidth
Definition: stringart.cpp:22
constexpr int kMaxNumSteps
Definition: stringart.cpp:25
constexpr int kHeight
Definition: stringart.cpp:23
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkPoint Make(float x, float y)
Definition: SkPoint_impl.h:173