2017-07-19 21:25:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
|
|
|
|
|
|
|
#include "SkColorFilter.h"
|
|
|
|
#include "SkImage.h"
|
2018-03-14 17:01:17 +00:00
|
|
|
#include "SkMaskFilter.h"
|
2017-07-19 21:25:38 +00:00
|
|
|
#include "SkShader.h"
|
|
|
|
|
|
|
|
static SkBitmap make_alpha_image(int w, int h) {
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(SkImageInfo::MakeA8(w, h));
|
|
|
|
bm.eraseARGB(10, 0, 0 , 0);
|
|
|
|
for (int y = 0; y < bm.height(); ++y) {
|
|
|
|
for (int x = y; x < bm.width(); ++x) {
|
|
|
|
*bm.getAddr8(x, y) = 0xFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bm.setImmutable();
|
|
|
|
return bm;
|
|
|
|
}
|
|
|
|
|
|
|
|
static sk_sp<SkColorFilter> make_color_filter() {
|
|
|
|
SkScalar colorMatrix[20] = {
|
|
|
|
1, 0, 0, 0, 0,
|
|
|
|
0, 1, 0, 0, 0,
|
|
|
|
0, 0, 0.5, 0.5, 0,
|
|
|
|
0, 0, 0.5, 0.5, 0}; // mix G and A.
|
2019-04-08 20:23:20 +00:00
|
|
|
return SkColorFilters::MatrixRowMajor255(colorMatrix);
|
2017-07-19 21:25:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEF_SIMPLE_GM(alpha_image, canvas, 256, 256) {
|
|
|
|
auto image = SkImage::MakeFromBitmap(make_alpha_image(96, 96));
|
|
|
|
SkPaint paint;
|
|
|
|
|
|
|
|
paint.setColorFilter(make_color_filter());
|
2018-03-14 17:01:17 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 10.0f));
|
2017-07-19 21:25:38 +00:00
|
|
|
canvas->drawImage(image.get(), 16, 16, &paint);
|
|
|
|
|
|
|
|
paint.setColorFilter(nullptr);
|
2019-04-09 17:55:36 +00:00
|
|
|
paint.setShader(SkShaders::Color(SK_ColorCYAN));
|
2017-07-19 21:25:38 +00:00
|
|
|
canvas->drawImage(image.get(), 144, 16, &paint);
|
|
|
|
|
|
|
|
paint.setColorFilter(make_color_filter());
|
|
|
|
canvas->drawImage(image.get(), 16, 144, &paint);
|
|
|
|
|
|
|
|
paint.setMaskFilter(nullptr);
|
|
|
|
canvas->drawImage(image.get(), 144, 144, &paint);
|
|
|
|
}
|