blob: 58f3d9308a7862ef77a7ef19801d0fa5c58b384b [file] [log] [blame]
scroggo56fbbfe2015-12-18 07:14:24 -08001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkImage.h"
9#include "include/core/SkRegion.h"
Michael Ludwig55edb502019-08-05 10:41:10 -040010#include "include/effects/SkImageFilters.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "tests/Test.h"
scroggo56fbbfe2015-12-18 07:14:24 -080012
13static void test_flattenable(skiatest::Reporter* r,
14 const SkFlattenable* f,
15 const char* desc) {
16 if (f) {
17 SkFlattenable::Factory factory = f->getFactory();
18 REPORTER_ASSERT(r, factory);
19 if (factory) {
20 if (!SkFlattenable::FactoryToName(factory)) {
21 ERRORF(r, "SkFlattenable::FactoryToName() fails with %s.", desc);
22 }
23 }
24 }
25}
26
27DEF_TEST(FlattenableFactoryToName, r) {
28 SkIRect rects[2];
29 rects[0] = SkIRect::MakeXYWH(0, 150, 500, 200);
30 rects[1] = SkIRect::MakeXYWH(150, 0, 200, 500);
31 SkRegion region;
32 region.setRects(rects, 2);
Michael Ludwig55edb502019-08-05 10:41:10 -040033 sk_sp<SkImageFilter> filter(SkImageFilters::AlphaThreshold(region, 0.2f, 0.7f, nullptr));
34 test_flattenable(r, filter.get(), "SkImageFilters::AlphaThreshold()");
scroggo56fbbfe2015-12-18 07:14:24 -080035
36 SkBitmap bm;
37 bm.allocN32Pixels(8, 8);
38 bm.eraseColor(SK_ColorCYAN);
reed9ce9d672016-03-17 10:51:11 -070039 sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm));
Mike Reed0acd7952017-04-28 11:12:19 -040040 test_flattenable(r, image->makeShader().get(), "SkImage::newShader()");
scroggo56fbbfe2015-12-18 07:14:24 -080041}