| 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); |
| 24 |
if (canvas->recordingContext() && !forceRaster) { |
| 25 |
surf = SkSurfaces::RenderTarget(canvas->recordingContext(), skgpu::Budgeted::kNo, ii); |
| 26 |
} else { |
| 27 |
surf = SkSurfaces::Raster(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 const SkColor4f colors[]{ |
| 49 |
SkColor4f::FromColor(SkColorSetARGB(255, 247, 247, 247)), {0,0,0,0}}; |
| 50 |
static constexpr SkPoint pts[]{{0.5, 0}, {256.5, 0}}; |
| 51 |
auto grd = SkShaders::LinearGradient(pts, {{colors, {}, 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, SkSamplingOptions(), &postPaint); |
| 61 |
} |
| 62 |
} // END FIDDLE |