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.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(blur4444, 650, 480, false, 0) {
5 void draw(SkCanvas* canvas) {
6 bool forceRaster = false;
8 bool postDither = false;
10 canvas->clear(SK_ColorTRANSPARENT);
12 grayPaint.setColor(SK_ColorGRAY);
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());
22 sk_sp<SkSurface> surf;
23 auto ii = SkImageInfo::Make(650, 480, kARGB_4444_SkColorType, kPremul_SkAlphaType);
24 if (canvas->recordingContext() && !forceRaster) {
25 surf = SkSurface::MakeRenderTarget(canvas->recordingContext(), SkBudgeted::kNo, ii);
27 surf = SkSurface::MakeRaster(ii);
33 auto c = surf->getCanvas();
34 c->clear(SK_ColorTRANSPARENT);
37 blrPaint.setAntiAlias(true);
38 blrPaint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 12.047));
39 blrPaint.setBlendMode(SkBlendMode::kSrc);
40 blrPaint.setDither(dither);
42 blrPaint.setColor(SK_ColorWHITE);
43 c->drawRect(SkRect{0, 20, 640, 104}, blrPaint);
45 blrPaint.setColor(SkColorSetARGB(255, 247, 247, 247));
46 c->drawRect(SkRect{0, 0, 640, 84}.makeOffset(0, 300), blrPaint);
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);
52 grdPaint.setShader(grd);
53 grdPaint.setDither(dither);
55 c->drawRect(SkRect{0, 0, 640, 100}.makeOffset(0, 150), grdPaint);
58 postPaint.setDither(postDither);
59 surf->draw(canvas, 0, 0, SkSamplingOptions(), &postPaint);