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(shader_alphaimage, 256, 256, false, 0) {
alpha_image()5 sk_sp<SkImage> alpha_image() {
6 auto s = SkSurface::MakeRaster(SkImageInfo::MakeA8(128, 128));
7 s->getCanvas()->clear(SkColorSetARGB(0xF0, 0x00, 0x00, 0x00));
8 return s->makeImageSnapshot();
9 }
linear_gradient()10 sk_sp<SkShader> linear_gradient() {
11 SkPoint gpts[2] = {{0, 0}, {256, 256}};
12 SkColor gc[6] = {SK_ColorCYAN, SK_ColorBLUE, SK_ColorMAGENTA,
13 SK_ColorRED, SK_ColorYELLOW, SK_ColorGREEN};
14 return SkGradientShader::MakeLinear(gpts, gc, nullptr, 6, SkTileMode::kClamp);
15 }
16
draw(SkCanvas * canvas)17 void draw(SkCanvas* canvas) {
18 canvas->clear(SK_ColorLTGRAY);
19 SkPaint p;
20 p.setShader(linear_gradient());
21 auto i = alpha_image();
22 canvas->drawImage(i.get(), 128, 0, SkSamplingOptions(), &p);
23 canvas->drawRect({0, 128, 128, 256}, p);
24 }
25 } // END FIDDLE
26