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.
|
|
|
|
*/
|
|
|
|
|
2020-12-23 15:11:33 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImage.h"
|
|
|
|
#include "include/core/SkRegion.h"
|
2019-08-05 14:41:10 +00:00
|
|
|
#include "include/effects/SkImageFilters.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#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);
|
2019-08-05 14:41:10 +00:00
|
|
|
sk_sp<SkImageFilter> filter(SkImageFilters::AlphaThreshold(region, 0.2f, 0.7f, nullptr));
|
|
|
|
test_flattenable(r, filter.get(), "SkImageFilters::AlphaThreshold()");
|
2015-12-18 15:14:24 +00:00
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocN32Pixels(8, 8);
|
|
|
|
bm.eraseColor(SK_ColorCYAN);
|
2020-12-23 16:50:36 +00:00
|
|
|
sk_sp<SkImage> image(bm.asImage());
|
2020-12-08 18:16:56 +00:00
|
|
|
test_flattenable(r, image->makeShader(SkSamplingOptions()).get(), "SkImage::newShader()");
|
2015-12-18 15:14:24 +00:00
|
|
|
}
|