blob: 2d00ace0fc9621fa3e521325097981587511fe19 [file] [log] [blame]
Hal Canary6c8422c2020-01-10 15:22:09 -05001// 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(blur_alpha_img, 256, 256, false, 0) {
5sk_sp<SkImage> foo() {
6 int w = 240, h = 240;
7 SkScalar scale = 10.0f;
8 SkPath path;
9 static const int8_t pts[] = {2, 2, 1, 3, 0, 3, 2, 1, 3, 1, 4, 0, 4, 1,
10 5, 1, 4, 2, 4, 3, 2, 5, 2, 4, 3, 3, 2, 3};
11 path.moveTo(2 * scale, 3 * scale);
12 for (size_t i = 0; i < sizeof(pts) / sizeof(pts[0]); i += 2) {
13 path.lineTo(pts[i] * scale, pts[i + 1] * scale);
14 }
15 path.close();
Mike Reed1f607332020-05-21 12:11:27 -040016 SkMatrix matrix = SkMatrix::Scale(4 * scale, 4 * scale);
Hal Canary6c8422c2020-01-10 15:22:09 -050017 SkPaint paint;
18 paint.setPathEffect(SkPath2DPathEffect::Make(matrix, path));
19 paint.setAntiAlias(true);
20 SkRect bounds{-4 * scale, -4 * scale, (float)w, (float)h};
21 SkBitmap bm;
22 bm.allocPixels(SkImageInfo::MakeA8(w, h));
23 SkCanvas c(bm);
24 c.clear(0);
25 c.drawRect(bounds, paint);
26 return SkImage::MakeFromBitmap(bm);
27}
28
29void draw(SkCanvas* canvas) {
30 auto a8img = foo();
31 SkPaint paint;
32 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 2.0f, 0));
33 paint.setColor(0xFF008000);
34 canvas->drawImage(a8img, 8, 8, &paint);
35}
36} // END FIDDLE