Hal Canary | 6c8422c | 2020-01-10 15:22:09 -0500 | [diff] [blame] | 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; |
| 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); |
Robert Phillips | d1ce4cb | 2020-07-10 16:20:53 -0400 | [diff] [blame] | 24 | if (canvas->recordingContext() && !forceRaster) { |
| 25 | surf = SkSurface::MakeRenderTarget(canvas->recordingContext(), SkBudgeted::kNo, ii); |
Hal Canary | 6c8422c | 2020-01-10 15:22:09 -0500 | [diff] [blame] | 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.setFilterQuality(kLow_SkFilterQuality); |
| 40 | blrPaint.setBlendMode(SkBlendMode::kSrc); |
| 41 | blrPaint.setDither(dither); |
| 42 | |
| 43 | blrPaint.setColor(SK_ColorWHITE); |
| 44 | c->drawRect(SkRect{0, 20, 640, 104}, blrPaint); |
| 45 | |
| 46 | blrPaint.setColor(SkColorSetARGB(255, 247, 247, 247)); |
| 47 | c->drawRect(SkRect{0, 0, 640, 84}.makeOffset(0, 300), blrPaint); |
| 48 | |
| 49 | static constexpr SkColor colors[]{SkColorSetARGB(255, 247, 247, 247), 0}; |
| 50 | static constexpr SkPoint pts[]{{0.5, 0}, {256.5, 0}}; |
| 51 | auto grd = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp); |
| 52 | SkPaint grdPaint; |
| 53 | grdPaint.setShader(grd); |
| 54 | grdPaint.setDither(dither); |
| 55 | |
| 56 | c->drawRect(SkRect{0, 0, 640, 100}.makeOffset(0, 150), grdPaint); |
| 57 | |
| 58 | SkPaint postPaint; |
| 59 | postPaint.setDither(postDither); |
| 60 | surf->draw(canvas, 0, 0, &postPaint); |
| 61 | } |
| 62 | } // END FIDDLE |