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" |
| 10 | #include "Test.h" |
| 11 | |
| 12 | static void test_flattenable(skiatest::Reporter* r, |
| 13 | const SkFlattenable* f, |
| 14 | const char* desc) { |
| 15 | if (f) { |
| 16 | SkFlattenable::Factory factory = f->getFactory(); |
| 17 | REPORTER_ASSERT(r, factory); |
| 18 | if (factory) { |
| 19 | if (!SkFlattenable::FactoryToName(factory)) { |
| 20 | ERRORF(r, "SkFlattenable::FactoryToName() fails with %s.", desc); |
| 21 | } |
| 22 | } |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | DEF_TEST(FlattenableFactoryToName, r) { |
| 27 | SkIRect rects[2]; |
| 28 | rects[0] = SkIRect::MakeXYWH(0, 150, 500, 200); |
| 29 | rects[1] = SkIRect::MakeXYWH(150, 0, 200, 500); |
| 30 | SkRegion region; |
| 31 | region.setRects(rects, 2); |
| 32 | SkAutoTUnref<SkImageFilter> filter( SkAlphaThresholdFilter::Create(region, 0.2f, 0.7f)); |
| 33 | test_flattenable(r, filter, "SkAlphaThresholdFilter()"); |
| 34 | |
| 35 | SkBitmap bm; |
| 36 | bm.allocN32Pixels(8, 8); |
| 37 | bm.eraseColor(SK_ColorCYAN); |
reed | 9ce9d67 | 2016-03-17 10:51:11 -0700 | [diff] [blame] | 38 | sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm)); |
reed | 5671c5b | 2016-03-09 14:47:34 -0800 | [diff] [blame] | 39 | auto shader = image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); |
| 40 | test_flattenable(r, shader.get(), "SkImage::newShader()"); |
scroggo | 56fbbfe | 2015-12-18 07:14:24 -0800 | [diff] [blame] | 41 | } |