Flutter Engine
The Flutter Engine
blurcircles.cpp
Go to the documentation of this file.
1/*
2* Copyright 2014 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"
16#include "include/core/SkSize.h"
19#include "src/core/SkBlurMask.h"
20
21class BlurCirclesGM : public skiagm::GM {
22public:
24
25protected:
26 bool runAsBench() const override { return true; }
27
28 SkString getName() const override { return SkString("blurcircles"); }
29
30 SkISize getISize() override { return SkISize::Make(950, 950); }
31
32 void onOnceBeforeDraw() override {
33 const float blurRadii[kNumBlurs] = {1.f, 5.f, 10.f, 20.f};
34
35 for (int i = 0; i < kNumBlurs; ++i) {
36 fBlurFilters[i] = SkMaskFilter::MakeBlur(
39 }
40 }
41
42 void onDraw(SkCanvas* canvas) override {
43 canvas->scale(1.5f, 1.5f);
44 canvas->translate(50,50);
45
46 const float circleRadii[] = {5.f, 10.f, 25.f, 50.f};
47
48 for (size_t i = 0; i < kNumBlurs; ++i) {
49 SkAutoCanvasRestore autoRestore(canvas, true);
50 canvas->translate(0, 150.f*i);
51 for (size_t j = 0; j < std::size(circleRadii); ++j) {
53 paint.setColor(SK_ColorBLACK);
54 paint.setMaskFilter(fBlurFilters[i]);
55
56 static constexpr SkPoint kCenter = {50.f, 50.f};
57 // Throw a rotation in the mix to make sure GPU fast path handles it correctly.
58 canvas->save();
59 canvas->rotate(j*22.f, kCenter.fX, kCenter.fY);
60 canvas->drawCircle(kCenter, circleRadii[j], paint);
61 canvas->restore();
62 canvas->translate(150.f, 0.f);
63 }
64 }
65 }
66private:
67 inline static constexpr int kNumBlurs = 4;
68
69 sk_sp<SkMaskFilter> fBlurFilters[kNumBlurs];
70
71 using INHERITED = skiagm::GM;
72};
73
74DEF_GM(return new BlurCirclesGM();)
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
void onOnceBeforeDraw() override
Definition: blurcircles.cpp:32
bool runAsBench() const override
Definition: blurcircles.cpp:26
SkISize getISize() override
Definition: blurcircles.cpp:30
void onDraw(SkCanvas *canvas) override
Definition: blurcircles.cpp:42
SkString getName() const override
Definition: blurcircles.cpp:28
static SkScalar SK_SPI ConvertRadiusToSigma(SkScalar radius)
Definition: SkBlurMask.cpp:39
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void rotate(SkScalar degrees)
Definition: SkCanvas.cpp:1300
int save()
Definition: SkCanvas.cpp:447
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
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
#define DEF_GM(CODE)
Definition: gm.h:40
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
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20