Flutter Engine
The Flutter Engine
Functions
crbug_1174354.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkImageFilters.h"

Go to the source code of this file.

Functions

static void draw_bg_blur (SkCanvas *canvas, SkIRect rect, float sigma)
 
 DEF_SIMPLE_GM (crbug_1174354, canvas, 70, 250)
 

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( crbug_1174354  ,
canvas  ,
70  ,
250   
)

Definition at line 47 of file crbug_1174354.cpp.

47 {
48 // The initial fix for crbug.com/1156805 had an issue where the border added to the downsampled
49 // texture that was used as input to the blur could actually bring in transparency when there
50 // wasn't any within the original src bounds. It was populated the border using a filtering draw
51 // from the full res source that could read from outside the pixels surrounding the original src
52 // bounds.
53 draw_bg_blur(canvas, SkIRect::MakeXYWH(10, 10, 50, 50), 5);
54 draw_bg_blur(canvas, SkIRect::MakeXYWH(10, 70, 50, 50), 15);
55 draw_bg_blur(canvas, SkIRect::MakeXYWH(10, 130, 50, 50), 30);
56 draw_bg_blur(canvas, SkIRect::MakeXYWH(10, 190, 50, 50), 70);
57}
static void draw_bg_blur(SkCanvas *canvas, SkIRect rect, float sigma)
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104

◆ draw_bg_blur()

static void draw_bg_blur ( SkCanvas canvas,
SkIRect  rect,
float  sigma 
)
static

Definition at line 15 of file crbug_1174354.cpp.

15 {
16 // First create an intermediate layer that has an opaque area that we blur with transparency
17 // all around it. We want to make sure the transparency doesn't affect the blur of the opaque
18 // content.
19 auto outsetRect = SkRect::Make(rect).makeOutset(10, 10);
20 canvas->saveLayer(outsetRect, nullptr);
22 float cx = (rect.left() + rect.right() )/2.f;
23 float cy = (rect.top() + rect.bottom())/2.f;
25 cy,
26 colors,
27 nullptr,
28 3,
30 0,
31 45,
32 0,
33 nullptr);
35 paint.setShader(std::move(g));
37 // Now do the bg-blur into another save-layer that should only read the opaque region.
39 auto blur = SkImageFilters::Blur(sigma, sigma, SkTileMode::kClamp, nullptr, rect);
40 rec.fBounds = &outsetRect;
41 rec.fBackdrop = blur.get();
42 canvas->saveLayer(rec);
43 canvas->restore();
44 canvas->restore();
45}
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition: SkCanvas.cpp:496
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
static sk_sp< SkShader > MakeSweep(SkScalar cx, SkScalar cy, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, SkScalar startAngle, SkScalar endAngle, uint32_t flags, const SkMatrix *localMatrix)
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
const Paint & paint
Definition: color_source.cc:38
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
PODArray< SkColor > colors
Definition: SkRecords.h:276
const SkRect * fBounds
Definition: SkCanvas.h:740
const SkImageFilter * fBackdrop
Definition: SkCanvas.h:753
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
SkRect makeOutset(float dx, float dy) const
Definition: SkRect.h:1002