2015-12-18 15:14:24 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 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 "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkRegion.h"
|
|
|
|
#include "include/effects/SkAlphaThresholdFilter.h"
|
|
|
|
#include "tests/Test.h"
|
2015-12-18 15:14:24 +00:00
|
|
|
|
|
|
|
static void test_flattenable(skiatest::Reporter* r,
|
|
|
|
const SkFlattenable* f,
|
|
|
|
const char* desc) {
|
|
|
|
if (f) {
|
|
|
|
SkFlattenable::Factory factory = f->getFactory();
|
|
|
|
REPORTER_ASSERT(r, factory);
|
|
|
|
if (factory) {
|
|
|
|
if (!SkFlattenable::FactoryToName(factory)) {
|
|
|
|
ERRORF(r, "SkFlattenable::FactoryToName() fails with %s.", desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(FlattenableFactoryToName, r) {
|
|
|
|
SkIRect rects[2];
|
|
|
|
rects[0] = SkIRect::MakeXYWH(0, 150, 500, 200);
|
|
|
|
rects[1] = SkIRect::MakeXYWH(150, 0, 200, 500);
|
|
|
|
SkRegion region;
|
|
|
|
region.setRects(rects, 2);
|
2016-04-01 17:34:43 +00:00
|
|
|
sk_sp<SkImageFilter> filter(SkAlphaThresholdFilter::Make(region, 0.2f, 0.7f, nullptr));
|
|
|
|
test_flattenable(r, filter.get(), "SkAlphaThresholdFilter()");
|
2015-12-18 15:14:24 +00:00
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocN32Pixels(8, 8);
|
|
|
|
bm.eraseColor(SK_ColorCYAN);
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm));
|
2017-04-28 15:12:19 +00:00
|
|
|
test_flattenable(r, image->makeShader().get(), "SkImage::newShader()");
|
2015-12-18 15:14:24 +00:00
|
|
|
}
|