scroggo | 56fbbfe | 2015-12-18 07:14:24 -0800 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkImage.h" |
| 9 | #include "include/core/SkRegion.h" |
Michael Ludwig | 55edb50 | 2019-08-05 10:41:10 -0400 | [diff] [blame] | 10 | #include "include/effects/SkImageFilters.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "tests/Test.h" |
scroggo | 56fbbfe | 2015-12-18 07:14:24 -0800 | [diff] [blame] | 12 | |
| 13 | static 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 | |
| 27 | DEF_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 Ludwig | 55edb50 | 2019-08-05 10:41:10 -0400 | [diff] [blame] | 33 | sk_sp<SkImageFilter> filter(SkImageFilters::AlphaThreshold(region, 0.2f, 0.7f, nullptr)); |
| 34 | test_flattenable(r, filter.get(), "SkImageFilters::AlphaThreshold()"); |
scroggo | 56fbbfe | 2015-12-18 07:14:24 -0800 | [diff] [blame] | 35 | |
| 36 | SkBitmap bm; |
| 37 | bm.allocN32Pixels(8, 8); |
| 38 | bm.eraseColor(SK_ColorCYAN); |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 39 | sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm)); |
Mike Reed | 0acd795 | 2017-04-28 11:12:19 -0400 | [diff] [blame] | 40 | test_flattenable(r, image->makeShader().get(), "SkImage::newShader()"); |
scroggo | 56fbbfe | 2015-12-18 07:14:24 -0800 | [diff] [blame] | 41 | } |