2012-06-29 17:28:50 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkBlendMode.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkColor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColorPriv.h"
|
|
|
|
#include "include/core/SkImage.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkImageInfo.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkShader.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkSize.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkString.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkTileMode.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/effects/SkGradientShader.h"
|
|
|
|
#include "include/private/SkTDArray.h"
|
2019-07-09 17:22:50 +00:00
|
|
|
#include "src/core/SkTLazy.h"
|
2012-06-29 17:28:50 +00:00
|
|
|
|
2019-05-01 21:28:53 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2016-10-28 19:42:34 +00:00
|
|
|
static sk_sp<SkShader> make_shader(SkBlendMode mode) {
|
2014-05-05 18:23:54 +00:00
|
|
|
SkPoint pts[2];
|
|
|
|
SkColor colors[2];
|
2014-05-06 03:06:53 +00:00
|
|
|
|
2014-05-05 18:23:54 +00:00
|
|
|
pts[0].set(0, 0);
|
|
|
|
pts[1].set(SkIntToScalar(100), 0);
|
|
|
|
colors[0] = SK_ColorRED;
|
|
|
|
colors[1] = SK_ColorBLUE;
|
2019-04-03 14:27:45 +00:00
|
|
|
auto shaderA = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp);
|
2014-05-06 03:06:53 +00:00
|
|
|
|
2014-05-05 18:23:54 +00:00
|
|
|
pts[0].set(0, 0);
|
|
|
|
pts[1].set(0, SkIntToScalar(100));
|
|
|
|
colors[0] = SK_ColorBLACK;
|
|
|
|
colors[1] = SkColorSetARGB(0x80, 0, 0, 0);
|
2019-04-03 14:27:45 +00:00
|
|
|
auto shaderB = SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp);
|
2014-05-06 03:06:53 +00:00
|
|
|
|
2019-04-09 17:55:36 +00:00
|
|
|
return SkShaders::Blend(mode, std::move(shaderA), std::move(shaderB));
|
2014-05-05 18:23:54 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 16:19:08 +00:00
|
|
|
class ComposeShaderGM : public skiagm::GM {
|
2020-11-05 15:05:19 +00:00
|
|
|
protected:
|
|
|
|
void onOnceBeforeDraw() override {
|
2016-10-28 19:42:34 +00:00
|
|
|
fShader = make_shader(SkBlendMode::kDstIn);
|
2012-06-29 17:28:50 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2012-06-29 17:28:50 +00:00
|
|
|
return SkString("composeshader");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-05-05 16:19:08 +00:00
|
|
|
return SkISize::Make(120, 120);
|
2012-06-29 17:28:50 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2012-06-29 17:28:50 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorGREEN);
|
2017-02-22 18:21:42 +00:00
|
|
|
canvas->drawRect(SkRect::MakeWH(100, 100), paint);
|
2012-06-29 17:28:50 +00:00
|
|
|
paint.setShader(fShader);
|
2017-02-22 18:21:42 +00:00
|
|
|
canvas->drawRect(SkRect::MakeWH(100, 100), paint);
|
2012-06-29 17:28:50 +00:00
|
|
|
}
|
|
|
|
|
2014-05-05 16:19:08 +00:00
|
|
|
protected:
|
2016-03-09 17:50:50 +00:00
|
|
|
sk_sp<SkShader> fShader;
|
2014-05-05 16:19:08 +00:00
|
|
|
|
|
|
|
private:
|
2012-06-29 17:28:50 +00:00
|
|
|
typedef GM INHERITED ;
|
|
|
|
};
|
2018-02-02 19:36:05 +00:00
|
|
|
DEF_GM( return new ComposeShaderGM; )
|
2012-06-29 17:28:50 +00:00
|
|
|
|
2014-05-05 18:23:54 +00:00
|
|
|
class ComposeShaderAlphaGM : public skiagm::GM {
|
2014-05-05 16:19:08 +00:00
|
|
|
public:
|
|
|
|
ComposeShaderAlphaGM() {}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2014-05-05 16:19:08 +00:00
|
|
|
return SkString("composeshader_alpha");
|
|
|
|
}
|
2014-05-06 03:06:53 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2015-09-03 15:32:22 +00:00
|
|
|
return SkISize::Make(750, 220);
|
2014-05-05 16:19:08 +00:00
|
|
|
}
|
2014-05-05 19:37:22 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2016-03-09 17:50:50 +00:00
|
|
|
sk_sp<SkShader> shaders[] = {
|
2016-10-28 19:42:34 +00:00
|
|
|
make_shader(SkBlendMode::kDstIn),
|
|
|
|
make_shader(SkBlendMode::kSrcOver),
|
2016-03-09 17:50:50 +00:00
|
|
|
};
|
2014-05-05 18:23:54 +00:00
|
|
|
|
2014-05-05 16:19:08 +00:00
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorGREEN);
|
2014-05-06 03:06:53 +00:00
|
|
|
|
2014-05-05 16:19:08 +00:00
|
|
|
const SkRect r = SkRect::MakeXYWH(5, 5, 100, 100);
|
2014-05-06 03:06:53 +00:00
|
|
|
|
2014-05-05 18:23:54 +00:00
|
|
|
for (size_t y = 0; y < SK_ARRAY_COUNT(shaders); ++y) {
|
|
|
|
canvas->save();
|
|
|
|
for (int alpha = 0xFF; alpha > 0; alpha -= 0x28) {
|
2019-02-15 21:13:57 +00:00
|
|
|
paint.setAlphaf(1.0f);
|
2015-08-27 14:41:13 +00:00
|
|
|
paint.setShader(nullptr);
|
2014-05-05 18:23:54 +00:00
|
|
|
canvas->drawRect(r, paint);
|
2014-05-06 03:06:53 +00:00
|
|
|
|
2014-05-05 18:23:54 +00:00
|
|
|
paint.setAlpha(alpha);
|
2016-03-09 17:50:50 +00:00
|
|
|
paint.setShader(shaders[y]);
|
2014-05-05 18:23:54 +00:00
|
|
|
canvas->drawRect(r, paint);
|
2014-05-06 03:06:53 +00:00
|
|
|
|
2014-05-05 18:23:54 +00:00
|
|
|
canvas->translate(r.width() + 5, 0);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, r.height() + 5);
|
2014-05-05 16:19:08 +00:00
|
|
|
}
|
|
|
|
}
|
2015-09-03 15:32:22 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED ;
|
|
|
|
};
|
2018-02-02 19:36:05 +00:00
|
|
|
DEF_GM( return new ComposeShaderAlphaGM; )
|
2015-09-03 15:32:22 +00:00
|
|
|
|
|
|
|
// creates a square bitmap with red background and a green circle in the center
|
|
|
|
static void draw_color_bm(SkBitmap* bm, int length) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorGREEN);
|
|
|
|
|
|
|
|
bm->allocN32Pixels(length, length);
|
|
|
|
bm->eraseColor(SK_ColorRED);
|
|
|
|
|
|
|
|
SkCanvas canvas(*bm);
|
|
|
|
canvas.drawCircle(SkIntToScalar(length/2), SkIntToScalar(length/2), SkIntToScalar(length/2),
|
|
|
|
paint);
|
|
|
|
}
|
|
|
|
|
|
|
|
// creates a square alpha8 bitmap with transparent background and an opaque circle in the center
|
|
|
|
static void draw_alpha8_bm(SkBitmap* bm, int length) {
|
|
|
|
SkPaint circlePaint;
|
|
|
|
circlePaint.setColor(SK_ColorBLACK);
|
|
|
|
|
|
|
|
bm->allocPixels(SkImageInfo::MakeA8(length, length));
|
|
|
|
bm->eraseColor(SK_ColorTRANSPARENT);
|
|
|
|
|
|
|
|
SkCanvas canvas(*bm);
|
|
|
|
canvas.drawCircle(SkIntToScalar(length/2), SkIntToScalar(length/2), SkIntToScalar(length/4),
|
|
|
|
circlePaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
// creates a linear gradient shader
|
2016-03-09 17:50:50 +00:00
|
|
|
static sk_sp<SkShader> make_linear_gradient_shader(int length) {
|
2015-09-03 15:32:22 +00:00
|
|
|
SkPoint pts[2];
|
|
|
|
SkColor colors[2];
|
|
|
|
pts[0].set(0, 0);
|
|
|
|
pts[1].set(SkIntToScalar(length), 0);
|
|
|
|
colors[0] = SK_ColorBLUE;
|
|
|
|
colors[1] = SkColorSetARGB(0, 0, 0, 0xFF);
|
2019-04-03 14:27:45 +00:00
|
|
|
return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp);
|
2015-09-03 15:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class ComposeShaderBitmapGM : public skiagm::GM {
|
|
|
|
public:
|
2019-07-09 17:22:50 +00:00
|
|
|
ComposeShaderBitmapGM(bool use_lm) : fUseLocalMatrix(use_lm) {}
|
2016-01-04 22:17:47 +00:00
|
|
|
|
2016-01-08 21:48:43 +00:00
|
|
|
protected:
|
2016-01-04 22:17:47 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2015-09-03 15:32:22 +00:00
|
|
|
draw_color_bm(&fColorBitmap, squareLength);
|
|
|
|
draw_alpha8_bm(&fAlpha8Bitmap, squareLength);
|
|
|
|
SkMatrix s;
|
|
|
|
s.reset();
|
2019-04-08 17:20:23 +00:00
|
|
|
fColorBitmapShader = fColorBitmap.makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat, &s);
|
|
|
|
fAlpha8BitmapShader = fAlpha8Bitmap.makeShader(SkTileMode::kRepeat,
|
|
|
|
SkTileMode::kRepeat, &s);
|
2015-09-03 15:32:22 +00:00
|
|
|
fLinearGradientShader = make_linear_gradient_shader(squareLength);
|
|
|
|
}
|
2016-01-04 22:17:47 +00:00
|
|
|
|
2015-09-03 15:32:22 +00:00
|
|
|
SkString onShortName() override {
|
2019-07-09 17:22:50 +00:00
|
|
|
return SkStringPrintf("composeshader_bitmap%s", fUseLocalMatrix ? "_lm" : "");
|
2015-09-03 15:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkISize onISize() override {
|
|
|
|
return SkISize::Make(7 * (squareLength + 5), 2 * (squareLength + 5));
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2016-10-28 19:42:34 +00:00
|
|
|
SkBlendMode mode = SkBlendMode::kDstOver;
|
2015-09-03 15:32:22 +00:00
|
|
|
|
2020-05-21 16:11:27 +00:00
|
|
|
SkMatrix lm = SkMatrix::Translate(0, squareLength * 0.5f);
|
2019-07-09 17:22:50 +00:00
|
|
|
|
2016-03-09 17:50:50 +00:00
|
|
|
sk_sp<SkShader> shaders[] = {
|
|
|
|
// gradient should appear over color bitmap
|
2020-03-25 17:13:20 +00:00
|
|
|
SkShaders::Blend(mode, fLinearGradientShader, fColorBitmapShader),
|
2016-03-09 17:50:50 +00:00
|
|
|
// gradient should appear over alpha8 bitmap colorized by the paint color
|
2020-03-25 17:13:20 +00:00
|
|
|
SkShaders::Blend(mode, fLinearGradientShader, fAlpha8BitmapShader),
|
2016-03-09 17:50:50 +00:00
|
|
|
};
|
2020-03-25 17:13:20 +00:00
|
|
|
if (fUseLocalMatrix) {
|
|
|
|
for (unsigned i = 0; i < SK_ARRAY_COUNT(shaders); ++i) {
|
|
|
|
shaders[i] = shaders[i]->makeWithLocalMatrix(lm);
|
|
|
|
}
|
|
|
|
}
|
2015-09-03 15:32:22 +00:00
|
|
|
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorYELLOW);
|
|
|
|
|
2020-03-25 17:13:20 +00:00
|
|
|
const SkRect r = SkRect::MakeIWH(squareLength, squareLength);
|
2015-09-03 15:32:22 +00:00
|
|
|
|
|
|
|
for (size_t y = 0; y < SK_ARRAY_COUNT(shaders); ++y) {
|
|
|
|
canvas->save();
|
|
|
|
for (int alpha = 0xFF; alpha > 0; alpha -= 0x28) {
|
|
|
|
paint.setAlpha(alpha);
|
2016-03-09 17:50:50 +00:00
|
|
|
paint.setShader(shaders[y]);
|
2015-09-03 15:32:22 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
|
|
|
|
canvas->translate(r.width() + 5, 0);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, r.height() + 5);
|
|
|
|
}
|
|
|
|
}
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2015-09-03 15:32:22 +00:00
|
|
|
private:
|
2016-02-15 16:27:14 +00:00
|
|
|
/** This determines the length and width of the bitmaps used in the ComposeShaders. Values
|
2015-09-03 15:32:22 +00:00
|
|
|
* above 20 may cause an SkASSERT to fail in SkSmallAllocator. However, larger values will
|
|
|
|
* work in a release build. You can change this parameter and then compile a release build
|
|
|
|
* to have this GM draw larger bitmaps for easier visual inspection.
|
|
|
|
*/
|
2016-09-01 18:24:54 +00:00
|
|
|
static constexpr int squareLength = 20;
|
2015-09-03 15:32:22 +00:00
|
|
|
|
2019-07-09 17:22:50 +00:00
|
|
|
const bool fUseLocalMatrix;
|
|
|
|
|
2015-09-03 15:32:22 +00:00
|
|
|
SkBitmap fColorBitmap;
|
|
|
|
SkBitmap fAlpha8Bitmap;
|
2016-03-09 17:50:50 +00:00
|
|
|
sk_sp<SkShader> fColorBitmapShader;
|
|
|
|
sk_sp<SkShader> fAlpha8BitmapShader;
|
|
|
|
sk_sp<SkShader> fLinearGradientShader;
|
2015-09-03 15:32:22 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = GM;
|
2014-05-05 16:19:08 +00:00
|
|
|
};
|
2019-07-09 17:22:50 +00:00
|
|
|
DEF_GM( return new ComposeShaderBitmapGM(false); )
|
|
|
|
DEF_GM( return new ComposeShaderBitmapGM(true); )
|
2014-05-05 16:19:08 +00:00
|
|
|
|
2016-08-15 19:03:33 +00:00
|
|
|
DEF_SIMPLE_GM(composeshader_bitmap2, canvas, 200, 200) {
|
|
|
|
int width = 255;
|
|
|
|
int height = 255;
|
|
|
|
SkTDArray<uint8_t> dst8Storage;
|
|
|
|
dst8Storage.setCount(width * height);
|
|
|
|
SkTDArray<uint32_t> dst32Storage;
|
|
|
|
dst32Storage.setCount(width * height * sizeof(int32_t));
|
|
|
|
for (int y = 0; y < height; ++y) {
|
|
|
|
for (int x = 0; x < width; ++x) {
|
|
|
|
dst8Storage[y * width + x] = (y + x) / 2;
|
|
|
|
dst32Storage[y * width + x] = SkPackARGB32(0xFF, x, y, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
paint.setColor(SK_ColorBLUE);
|
|
|
|
SkRect r = {0, 0, SkIntToScalar(width), SkIntToScalar(height)};
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
SkBitmap skBitmap, skMask;
|
|
|
|
SkImageInfo imageInfo = SkImageInfo::Make(width, height,
|
|
|
|
SkColorType::kN32_SkColorType, kPremul_SkAlphaType);
|
|
|
|
skBitmap.installPixels(imageInfo, dst32Storage.begin(), width * sizeof(int32_t),
|
2017-07-18 14:53:11 +00:00
|
|
|
nullptr, nullptr);
|
2016-08-15 19:03:33 +00:00
|
|
|
imageInfo = SkImageInfo::Make(width, height,
|
|
|
|
SkColorType::kAlpha_8_SkColorType, kPremul_SkAlphaType);
|
2017-07-18 14:53:11 +00:00
|
|
|
skMask.installPixels(imageInfo, dst8Storage.begin(), width, nullptr, nullptr);
|
2016-08-15 19:03:33 +00:00
|
|
|
sk_sp<SkImage> skSrc = SkImage::MakeFromBitmap(skBitmap);
|
|
|
|
sk_sp<SkImage> skMaskImage = SkImage::MakeFromBitmap(skMask);
|
|
|
|
paint.setShader(
|
2019-04-09 17:55:36 +00:00
|
|
|
SkShaders::Blend(SkBlendMode::kSrcIn, skMaskImage->makeShader(), skSrc->makeShader()));
|
2016-08-15 19:03:33 +00:00
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
|
|
|
|
2018-02-02 19:36:05 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2012-06-29 17:28:50 +00:00
|
|
|
|
2018-02-02 19:36:05 +00:00
|
|
|
static sk_sp<SkShader> make_src_shader(SkScalar size) {
|
|
|
|
const SkPoint pts[] = { { 0, 0 }, { 0, size } };
|
|
|
|
const SkColor colors[] = { 0xFF0000FF, 0x000000FF };
|
2019-04-03 14:27:45 +00:00
|
|
|
return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp);
|
2018-02-02 19:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static sk_sp<SkShader> make_dst_shader(SkScalar size) {
|
|
|
|
const SkPoint pts[] = { { 0, 0 }, { size, 0 } };
|
|
|
|
const SkColor colors[] = { SK_ColorRED, 0x00FF0000 };
|
2019-04-03 14:27:45 +00:00
|
|
|
return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkTileMode::kClamp);
|
2018-02-02 19:36:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const SkScalar gCellSize = 100;
|
|
|
|
|
|
|
|
static void draw_cell(SkCanvas* canvas, sk_sp<SkShader> src, sk_sp<SkShader> dst,
|
|
|
|
SkBlendMode mode, SkAlpha alpha) {
|
|
|
|
const SkRect r = SkRect::MakeWH(gCellSize, gCellSize);
|
|
|
|
SkPaint p;
|
|
|
|
p.setAlpha(alpha);
|
|
|
|
|
|
|
|
SkAutoCanvasRestore acr(canvas, false);
|
|
|
|
canvas->saveLayer(&r, &p);
|
|
|
|
p.setAlpha(0xFF);
|
|
|
|
|
|
|
|
p.setShader(dst);
|
|
|
|
p.setBlendMode(SkBlendMode::kSrc);
|
|
|
|
canvas->drawRect(r, p);
|
|
|
|
|
|
|
|
p.setShader(src);
|
|
|
|
p.setBlendMode(mode);
|
|
|
|
canvas->drawRect(r, p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_composed(SkCanvas* canvas, sk_sp<SkShader> src, sk_sp<SkShader> dst,
|
|
|
|
SkBlendMode mode, SkAlpha alpha) {
|
|
|
|
SkPaint p;
|
|
|
|
p.setAlpha(alpha);
|
2019-04-09 17:55:36 +00:00
|
|
|
p.setShader(SkShaders::Blend(mode, dst, src));
|
2018-02-02 19:36:05 +00:00
|
|
|
canvas->drawRect(SkRect::MakeWH(gCellSize, gCellSize), p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_pair(SkCanvas* canvas, sk_sp<SkShader> src, sk_sp<SkShader> dst,
|
|
|
|
SkBlendMode mode) {
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
|
|
|
|
const SkScalar gap = 4;
|
|
|
|
SkRect r = SkRect::MakeWH(2 * gCellSize + gap, 2 * gCellSize + gap);
|
2018-02-02 21:15:49 +00:00
|
|
|
r.outset(gap + 1.5f, gap + 1.5f);
|
2018-02-02 19:36:05 +00:00
|
|
|
SkPaint p;
|
|
|
|
p.setStyle(SkPaint::kStroke_Style);
|
|
|
|
canvas->drawRect(r, p); // border
|
|
|
|
|
|
|
|
SkAlpha alpha = 0xFF;
|
|
|
|
for (int y = 0; y < 2; ++y) {
|
|
|
|
draw_cell(canvas, src, dst, mode, alpha);
|
|
|
|
canvas->save();
|
|
|
|
canvas->translate(gCellSize + gap, 0);
|
|
|
|
draw_composed(canvas, src, dst, mode, alpha);
|
|
|
|
canvas->restore();
|
|
|
|
|
|
|
|
canvas->translate(0, gCellSize + gap);
|
|
|
|
alpha = 0x80;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_SIMPLE_GM(composeshader_grid, canvas, 882, 882) {
|
|
|
|
auto src = make_src_shader(gCellSize);
|
|
|
|
auto dst = make_dst_shader(gCellSize);
|
|
|
|
|
2018-02-02 21:15:49 +00:00
|
|
|
const SkScalar margin = 15;
|
2018-02-02 19:36:05 +00:00
|
|
|
const SkScalar dx = 2*gCellSize + margin;
|
|
|
|
const SkScalar dy = 2*gCellSize + margin;
|
|
|
|
|
|
|
|
canvas->translate(margin, margin);
|
|
|
|
canvas->save();
|
|
|
|
for (int m = 0; m < 16; ++m) {
|
|
|
|
SkBlendMode mode = static_cast<SkBlendMode>(m);
|
|
|
|
draw_pair(canvas, src, dst, mode);
|
|
|
|
if ((m % 4) == 3) {
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(0, dy);
|
|
|
|
canvas->save();
|
|
|
|
} else {
|
|
|
|
canvas->translate(dx, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
}
|