Flutter Engine
The Flutter Engine
AnimBlurSlide.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
12#include "src/base/SkRandom.h"
13#include "tools/viewer/Slide.h"
14
15#include <iterator>
16
17SkScalar get_anim_sin(double secs, SkScalar amplitude, SkScalar periodInSec, SkScalar phaseInSec) {
18 if (!periodInSec) {
19 return 0;
20 }
21 double t = secs + phaseInSec;
22 t *= (2 * SK_ScalarPI) / periodInSec;
23 amplitude = SK_ScalarHalf * amplitude;
24 return amplitude * SkDoubleToScalar(sin(t)) + amplitude;
25}
26
27class AnimBlurSlide : public Slide {
28 SkScalar fBlurSigma = 0;
29 SkScalar fCircleRadius = 100;
30
31public:
32 AnimBlurSlide() { fName ="AnimBlur"; }
33
34 void draw(SkCanvas* canvas) override {
35 static const SkBlurStyle gStyles[] = {
40 };
41 SkRandom random;
42
43 for (size_t i = 0; i < std::size(gStyles); ++i) {
46 fBlurSigma));
47 paint.setColor(random.nextU() | 0xff000000);
48 canvas->drawCircle(200 * SK_Scalar1 + 400 * (i % 2) * SK_Scalar1,
49 200 * SK_Scalar1 + i / 2 * 400 * SK_Scalar1,
50 fCircleRadius, paint);
51 }
52 }
53
54 bool animate(double nanos) override {
55 fBlurSigma = get_anim_sin(1e-9 * nanos, 100, 4, 5);
56 fCircleRadius = 3 + get_anim_sin(1e-9 * nanos, 150, 25, 3);
57 return true;
58 }
59};
60
61DEF_SLIDE( return new AnimBlurSlide(); )
SkScalar get_anim_sin(double secs, SkScalar amplitude, SkScalar periodInSec, SkScalar phaseInSec)
SkBlurStyle
Definition: SkBlurTypes.h:11
@ kOuter_SkBlurStyle
nothing inside, fuzzy outside
Definition: SkBlurTypes.h:14
@ kSolid_SkBlurStyle
solid inside, fuzzy outside
Definition: SkBlurTypes.h:13
@ kInner_SkBlurStyle
fuzzy inside, nothing outside
Definition: SkBlurTypes.h:15
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
#define SK_Scalar1
Definition: SkScalar.h:18
#define SK_ScalarHalf
Definition: SkScalar.h:19
#define SkDoubleToScalar(x)
Definition: SkScalar.h:64
#define SK_ScalarPI
Definition: SkScalar.h:21
#define DEF_SLIDE(code)
Definition: Slide.h:25
void draw(SkCanvas *canvas) override
bool animate(double nanos) override
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
uint32_t nextU()
Definition: SkRandom.h:42
Definition: Slide.h:29
SkString fName
Definition: Slide.h:54
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
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
static constexpr SkFontStyle gStyles[]
Definition: typeface.cpp:89