Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
bigblurs.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"
16#include "include/core/SkRect.h"
18#include "include/core/SkSize.h"
21#include "src/core/SkBlurMask.h"
22
23namespace skiagm {
24
25// This GM exercises the blurred rect nine-patching special cases when the
26// blurred rect is very large and/or very far from the origin.
27// It creates a large blurred rect/rectori then renders the 4 corners and the
28// middle.
29class BigBlursGM : public GM {
30public:
32 this->setBGColor(0xFFDDDDDD);
33 }
34
35protected:
36 SkString getName() const override { return SkString("bigblurs"); }
37
38 SkISize getISize() override { return SkISize::Make(kWidth, kHeight); }
39
40 void onDraw(SkCanvas* canvas) override {
41 constexpr int kBig = 65536;
43
44 const SkRect bigRect = SkRect::MakeWH(SkIntToScalar(kBig), SkIntToScalar(kBig));
45 SkRect insetRect = bigRect;
46 insetRect.inset(20, 20);
47
48 SkPath rectori = SkPathBuilder().addRect(bigRect)
50 .detach();
51
52 // The blur extends 3*kSigma out from the big rect.
53 // Offset the close-up windows so we get the entire blur
54 const SkScalar kLeftTopPad = 3*kSigma; // use on left & up of big rect
55 const SkScalar kRightBotPad = kCloseUpSize-3*kSigma; // use on right and bot sides
56
57 // UL hand corners of the rendered closeups
58 const SkPoint origins[] = {
59 { -kLeftTopPad, -kLeftTopPad }, // UL
60 { kBig-kRightBotPad, -kLeftTopPad }, // UR
61 { kBig-kRightBotPad, kBig-kRightBotPad }, // LR
62 { -kLeftTopPad, kBig-kRightBotPad }, // LL
63 { kBig/2-kCloseUpSize/2, kBig/2-kCloseUpSize/2 }, // center
64 };
65
66 SkPaint outlinePaint;
67 outlinePaint.setColor(SK_ColorRED);
68 outlinePaint.setStyle(SkPaint::kStroke_Style);
69
70 SkPaint blurPaint;
71 blurPaint.setAntiAlias(true);
72 blurPaint.setColor(SK_ColorBLACK);
73
74 int desiredX = 0, desiredY = 0;
75
76 for (int i = 0; i < 2; ++i) {
77 for (int j = 0; j <= kLastEnum_SkBlurStyle; ++j) {
79
80 for (int k = 0; k < (int)std::size(origins); ++k) {
81 canvas->save();
82
83 SkRect clipRect = SkRect::MakeXYWH(SkIntToScalar(desiredX),
84 SkIntToScalar(desiredY),
85 SkIntToScalar(kCloseUpSize),
86 SkIntToScalar(kCloseUpSize));
87
88 canvas->clipRect(clipRect);
89
90 canvas->translate(desiredX-origins[k].fX,
91 desiredY-origins[k].fY);
92
93 if (0 == i) {
94 canvas->drawRect(bigRect, blurPaint);
95 } else {
96 canvas->drawPath(rectori, blurPaint);
97 }
98 canvas->restore();
99 canvas->drawRect(clipRect, outlinePaint);
100
101 desiredX += kCloseUpSize;
102 }
103
104 desiredX = 0;
105 desiredY += kCloseUpSize;
106 }
107 }
108 }
109
110private:
111 inline static constexpr int kCloseUpSize = 64;
112 inline static constexpr int kWidth = 5 * kCloseUpSize;
113 inline static constexpr int kHeight = 2 * (kLastEnum_SkBlurStyle + 1) * kCloseUpSize;
114
115 using INHERITED = GM;
116};
117
118DEF_GM(return new BigBlursGM;)
119} // namespace skiagm
SkBlurStyle
Definition SkBlurTypes.h:11
@ kLastEnum_SkBlurStyle
Definition SkBlurTypes.h:17
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
#define SkIntToScalar(x)
Definition SkScalar.h:57
Type::kYUV Type::kRGBA() int(0.7 *637)
static SkScalar SK_SPI ConvertRadiusToSigma(SkScalar radius)
void drawRect(const SkRect &rect, const SkPaint &paint)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
int save()
Definition SkCanvas.cpp:451
void drawPath(const SkPath &path, const SkPaint &paint)
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
void setStyle(Style style)
Definition SkPaint.cpp:105
void setColor(SkColor color)
Definition SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
void setMaskFilter(sk_sp< SkMaskFilter > maskFilter)
SkPathBuilder & addRect(const SkRect &, SkPathDirection, unsigned startIndex)
void onDraw(SkCanvas *canvas) override
Definition bigblurs.cpp:40
SkISize getISize() override
Definition bigblurs.cpp:38
SkString getName() const override
Definition bigblurs.cpp:36
void setBGColor(SkColor)
Definition gm.cpp:159
float SkScalar
Definition extension.cpp:12
#define DEF_GM(CODE)
Definition gm.h:40
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
void inset(float dx, float dy)
Definition SkRect.h:1060
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609