Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 };
39 const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, };
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,
51 colors, pos, std::size(colors), tm,
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
85 SkRRect rrect;
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
SkColor4f color
@ 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
static sk_sp< SkShader > MakeRadial()
bool runAsBench() const override
SkString getName() const override
void onDraw(SkCanvas *canvas) override
SkISize getISize() override
static SkScalar SK_SPI ConvertRadiusToSigma(SkScalar radius)
void translate(SkScalar dx, SkScalar dy)
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
void scale(SkScalar sx, SkScalar sy)
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)
SkMatrix & postTranslate(SkScalar dx, SkScalar dy)
Definition SkMatrix.cpp:281
SkMatrix & setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition SkMatrix.cpp:296
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
const Paint & paint
float SkScalar
Definition extension.cpp:12
#define DEF_GM(CODE)
Definition gm.h:40
#define DEF_SIMPLE_GM(NAME, CANVAS, W, H)
Definition gm.h:50
const Scalar scale
void set(float x, float y)
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