Flutter Engine
The Flutter Engine
blurredclippedcircle.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 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"
17#include "include/core/SkRect.h"
19#include "include/core/SkSize.h"
21
22namespace skiagm {
23
24// This GM reproduces the precision artifacts seen in crbug.com/560651.
25// It draws a largish blurred circle with its center clipped out.
26class BlurredClippedCircleGM : public GM {
27public:
29 this->setBGColor(0xFFCCCCCC);
30 }
31
32protected:
33 SkString getName() const override { return SkString("blurredclippedcircle"); }
34
35 SkISize getISize() override { return SkISize::Make(kWidth, kHeight); }
36
37 void onDraw(SkCanvas* canvas) override {
38 SkPaint whitePaint;
39 whitePaint.setColor(SK_ColorWHITE);
41 whitePaint.setAntiAlias(true);
42
43 // This scale exercises precision limits in the circle blur effect (crbug.com/560651)
44 constexpr float kScale = 2.0f;
45 canvas->scale(kScale, kScale);
46
47 canvas->save();
48 SkRect clipRect1 = SkRect::MakeLTRB(0, 0, kWidth, kHeight);
49 canvas->clipRect(clipRect1);
50
51 canvas->save();
52
53 canvas->clipRect(clipRect1);
54 canvas->drawRect(clipRect1, whitePaint);
55
56 canvas->save();
57
58 SkRect clipRect2 = SkRect::MakeLTRB(8, 8, 288, 288);
61
62 SkRect r = SkRect::MakeLTRB(4, 4, 292, 292);
64
66
67 paint.setMaskFilter(SkMaskFilter::MakeBlur(
69 1.366025f));
71 paint.setAntiAlias(true);
72
73 canvas->drawRRect(rr, paint);
74
75 canvas->restore();
76 canvas->restore();
77 canvas->restore();
78 }
79
80private:
81 inline static constexpr int kWidth = 1164;
82 inline static constexpr int kHeight = 802;
83
84 using INHERITED = GM;
85};
86
87//////////////////////////////////////////////////////////////////////////////
88
89DEF_GM(return new BlurredClippedCircleGM;)
90} // namespace skiagm
@ kSrcIn
r = s * da
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void restore()
Definition: SkCanvas.cpp:461
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
Definition: SkCanvas.cpp:1705
int save()
Definition: SkCanvas.cpp:447
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
void clipRRect(const SkRRect &rrect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1439
static sk_sp< SkColorFilter > Blend(const SkColor4f &c, sk_sp< SkColorSpace >, SkBlendMode mode)
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setBlendMode(SkBlendMode mode)
Definition: SkPaint.cpp:151
static SkRRect MakeOval(const SkRect &oval)
Definition: SkRRect.h:162
SkString getName() const override
void onDraw(SkCanvas *canvas) override
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
void setBGColor(SkColor)
Definition: gm.cpp:159
const Paint & paint
Definition: color_source.cc:38
clipRRect(r.rrect, r.opAA.op(), r.opAA.aa())) DRAW(ClipRect
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646