Flutter Engine
The Flutter Engine
blur4444.cpp
Go to the documentation of this file.
1// Copyright 2020 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4REG_FIDDLE(blur4444, 650, 480, false, 0) {
5void draw(SkCanvas* canvas) {
6 bool forceRaster = false;
7 bool dither = false;
8 bool postDither = false;
9
11 SkPaint grayPaint;
12 grayPaint.setColor(SK_ColorGRAY);
13 SkPaint ltGrayPaint;
14 ltGrayPaint.setColor(SK_ColorLTGRAY);
15 canvas->drawRect({350, 0, 400, 480}, ltGrayPaint);
16 canvas->drawRect({400, 0, 500, 480}, grayPaint);
17 canvas->drawRect({500, 0, 640, 480}, SkPaint());
18 canvas->drawRect({0, 200, 320, 215}, ltGrayPaint);
19 canvas->drawRect({0, 215, 320, 230}, grayPaint);
20 canvas->drawRect({0, 230, 320, 250}, SkPaint());
21
24 if (canvas->recordingContext() && !forceRaster) {
26 } else {
27 surf = SkSurfaces::Raster(ii);
28 }
29 if (!surf) {
30 return;
31 }
32
33 auto c = surf->getCanvas();
35
36 SkPaint blrPaint;
37 blrPaint.setAntiAlias(true);
40 blrPaint.setDither(dither);
41
42 blrPaint.setColor(SK_ColorWHITE);
43 c->drawRect(SkRect{0, 20, 640, 104}, blrPaint);
44
45 blrPaint.setColor(SkColorSetARGB(255, 247, 247, 247));
46 c->drawRect(SkRect{0, 0, 640, 84}.makeOffset(0, 300), blrPaint);
47
48 static constexpr SkColor colors[]{SkColorSetARGB(255, 247, 247, 247), 0};
49 static constexpr SkPoint pts[]{{0.5, 0}, {256.5, 0}};
50 auto grd = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp);
51 SkPaint grdPaint;
52 grdPaint.setShader(grd);
53 grdPaint.setDither(dither);
54
55 c->drawRect(SkRect{0, 0, 640, 100}.makeOffset(0, 150), grdPaint);
56
57 SkPaint postPaint;
58 postPaint.setDither(postDither);
59 surf->draw(canvas, 0, 0, SkSamplingOptions(), &postPaint);
60}
61} // END FIDDLE
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
Definition: SkColorType.h:23
constexpr SkColor SK_ColorLTGRAY
Definition: SkColor.h:118
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
REG_FIDDLE(blur4444, 650, 480, false, 0)
Definition: blur4444.cpp:4
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
void clear(SkColor color)
Definition: SkCanvas.h:1199
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], 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)
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
void setDither(bool dither)
Definition: SkPaint.h:182
void setMaskFilter(sk_sp< SkMaskFilter > maskFilter)
void setShader(sk_sp< SkShader > shader)
void setBlendMode(SkBlendMode mode)
Definition: SkPaint.cpp:151
SkCanvas * getCanvas()
Definition: SkSurface.cpp:82
void draw(SkCanvas *canvas, SkScalar x, SkScalar y, const SkSamplingOptions &sampling, const SkPaint *paint)
Definition: SkSurface.cpp:116
PODArray< SkColor > colors
Definition: SkRecords.h:276
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
SkSamplingOptions(SkFilterMode::kLinear))
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
constexpr SkRect makeOffset(float dx, float dy) const
Definition: SkRect.h:965