Update rive-cpp to 2.0 version
[platform/core/uifw/rive-tizen.git] / submodule / skia / docs / examples / alpha_bitmap_color_filter_mask_filter.cpp
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(alpha_bitmap_color_filter_mask_filter, 256, 256, false, 0) {
5 static SkBitmap make_alpha_image(int w, int h) {
6     SkBitmap bm;
7     bm.allocPixels(SkImageInfo::MakeA8(w, h));
8     bm.eraseARGB(10, 0, 0, 0);
9     for (int y = 0; y < bm.height(); ++y) {
10         for (int x = y; x < bm.width(); ++x) {
11             *bm.getAddr8(x, y) = 0xFF;
12         }
13     }
14     bm.setImmutable();
15     return bm;
16 }
17
18 static sk_sp<SkColorFilter> make_color_filter() {
19     SkScalar colorMatrix[20] = {
20         1, 0, 0,   0,   0,
21         0, 1, 0,   0,   0,
22         0, 0, 0.5, 0.5, 0,
23         0, 0, 0.5, 0.5, 0}; // mix G and A.
24     return SkColorFilters::Matrix(colorMatrix);
25 }
26
27 void draw(SkCanvas* canvas) {
28     auto image = make_alpha_image(96, 96).asImage();
29     SkSamplingOptions sampling;
30     SkPaint paint;
31
32     paint.setColorFilter(make_color_filter());
33     paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 10.0f, false));
34     canvas->drawImage(image.get(), 16, 16, sampling, &paint);
35
36     paint.setColorFilter(nullptr);
37     paint.setShader(SkShaders::Color(SK_ColorCYAN));
38     canvas->drawImage(image.get(), 144, 16, sampling, &paint);
39
40     paint.setColorFilter(make_color_filter());
41     canvas->drawImage(image.get(), 16, 144, sampling, &paint);
42
43     paint.setMaskFilter(nullptr);
44     canvas->drawImage(image.get(), 144, 144, sampling, &paint);
45 }
46 }  // END FIDDLE