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 | |
| 8 | #include "SkAlphaThresholdFilter.h" |
| 9 | #include "SkImage.h" |
robertphillips | f7142e7 | 2016-04-18 07:20:05 -0700 | [diff] [blame] | 10 | #include "SkRegion.h" |
scroggo | 56fbbfe | 2015-12-18 07:14:24 -0800 | [diff] [blame] | 11 | #include "Test.h" |
| 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); |
robertphillips | f624204 | 2016-04-01 10:34:43 -0700 | [diff] [blame] | 33 | sk_sp<SkImageFilter> filter(SkAlphaThresholdFilter::Make(region, 0.2f, 0.7f, nullptr)); |
| 34 | test_flattenable(r, filter.get(), "SkAlphaThresholdFilter()"); |
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)); |
reed | 5671c5b | 2016-03-09 14:47:34 -0800 | [diff] [blame] | 40 | auto shader = image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); |
| 41 | test_flattenable(r, shader.get(), "SkImage::newShader()"); |
scroggo | 56fbbfe | 2015-12-18 07:14:24 -0800 | [diff] [blame] | 42 | } |