blob: ee83df2a5d6325622bc803330737466feb409b16 [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(shader_alphaimage, 256, 256, false, 0) {
5sk_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}
10sk_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
17void 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, &p);
23 canvas->drawRect({0, 128, 128, 256}, p);
24}
25} // END FIDDLE