Flutter Engine
The Flutter Engine
blurroundrect.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"
19#include "include/core/SkRect.h"
23#include "include/core/SkSize.h"
28#include "src/core/SkBlurMask.h"
29
30/*
31 * Spits out an arbitrary gradient to test blur with shader on paint
32 */
34 SkPoint pts[2] = {
35 { 0, 0 },
36 { SkIntToScalar(100), SkIntToScalar(100) }
37 };
40 const SkScalar pos[] = { SK_Scalar1/4, SK_Scalar1*3/4 };
42 scale.setScale(0.5f, 0.5f);
43 scale.postTranslate(5.f, 5.f);
44 SkPoint center0, center1;
45 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
46 SkScalarAve(pts[0].fY, pts[1].fY));
47 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
48 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
49 return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
50 center0, (pts[1].fX - pts[0].fX) / 2,
52 0, &scale);
53}
54
55// Simpler blurred RR test cases where all the radii are the same.
57 SkString getName() const override { return SkString("simpleblurroundrect"); }
58
59 SkISize getISize() override { return {1000, 500}; }
60
61 bool runAsBench() const override { return true; }
62
63 void onDraw(SkCanvas* canvas) override {
64 canvas->scale(1.5f, 1.5f);
65 canvas->translate(50,50);
66
67 const float blurRadii[] = { 1,5,10,20 };
68 const int cornerRadii[] = { 1,5,10,20 };
70 for (size_t i = 0; i < std::size(blurRadii); ++i) {
71 SkAutoCanvasRestore autoRestore(canvas, true);
72 canvas->translate(0, (r.height() + SkIntToScalar(50)) * i);
73 for (size_t j = 0; j < std::size(cornerRadii); ++j) {
74 for (int k = 0; k <= 1; k++) {
76 paint.setColor(SK_ColorBLACK);
79
80 bool useRadial = SkToBool(k);
81 if (useRadial) {
82 paint.setShader(MakeRadial());
83 }
84
86 rrect.setRectXY(r, SkIntToScalar(cornerRadii[j]),
87 SkIntToScalar(cornerRadii[j]));
88 canvas->drawRRect(rrect, paint);
89 canvas->translate(r.width() + SkIntToScalar(50), 0);
90 }
91 }
92 }
93 }
94};
95
96// Create one with dimensions/rounded corners based on the skp
97//
98// TODO(scroggo): Disabled in an attempt to rememdy
99// https://code.google.com/p/skia/issues/detail?id=1801 ('Win7 Test bots all failing GenerateGMs:
100// ran wrong number of tests')
101//DEF_GM(return new BlurRoundRectGM(600, 5514, 6);)
102
103DEF_GM(return new SimpleBlurRoundRectGM();)
104
105// From crbug.com/1138810
106DEF_SIMPLE_GM(blur_large_rrects, canvas, 300, 300) {
109
110 auto rect = SkRect::MakeLTRB(5.f, -20000.f, 240.f, 25.f);
111 SkRRect rrect = SkRRect::MakeRectXY(rect, 40.f, 40.f);
112 for (int i = 0; i < 4; ++i) {
113 SkColor4f color{(i & 1) ? 1.f : 0.f,
114 (i & 2) ? 1.f : 0.f,
115 (i < 2) ? 1.f : 0.f,
116 1.f};
117 paint.setColor(color);
118 canvas->drawRRect(rrect, paint);
119 canvas->rotate(90.f, 150.f, 150.f);
120 }
121}
SkPoint pos
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkScalarAve(a, b)
Definition: SkScalar.h:74
#define SkIntToScalar(x)
Definition: SkScalar.h:57
static SkScalar SkScalarInterp(SkScalar A, SkScalar B, SkScalar t)
Definition: SkScalar.h:131
SkTileMode
Definition: SkTileMode.h:13
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
DEF_SIMPLE_GM(blur_large_rrects, canvas, 300, 300)
static sk_sp< SkShader > MakeRadial()
static SkScalar SK_SPI ConvertRadiusToSigma(SkScalar radius)
Definition: SkBlurMask.cpp:39
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
Definition: SkCanvas.cpp:1705
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
static sk_sp< SkShader > MakeTwoPointConical(const SkPoint &start, SkScalar startRadius, const SkPoint &end, SkScalar endRadius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
static SkRRect MakeRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition: SkRRect.h:180
void setRectXY(const SkRect &rect, SkScalar xRad, SkScalar yRad)
Definition: SkRRect.cpp:52
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
DlColor color
float SkScalar
Definition: extension.cpp:12
#define DEF_GM(CODE)
Definition: gm.h:40
SkRRect rrect
Definition: SkRecords.h:232
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
PODArray< SkColor > colors
Definition: SkRecords.h:276
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
void set(float x, float y)
Definition: SkPoint_impl.h:200
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646