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" 4REG_FIDDLE(blur4444, 650, 480, false, 0) { 5void draw(SkCanvas* canvas) { 6 bool forceRaster = false; 7 bool dither = false; 8 bool postDither = false; 9 10 canvas->clear(SK_ColorTRANSPARENT); 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 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); 26 } else { 27 surf = SkSurface::MakeRaster(ii); 28 } 29 if (!surf) { 30 return; 31 } 32 33 auto c = surf->getCanvas(); 34 c->clear(SK_ColorTRANSPARENT); 35 36 SkPaint blrPaint; 37 blrPaint.setAntiAlias(true); 38 blrPaint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 12.047)); 39 blrPaint.setBlendMode(SkBlendMode::kSrc); 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 62