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 "include/core/SkBitmap.h"
9 #include "include/core/SkImage.h"
10 #include "include/core/SkRegion.h"
11 #include "include/effects/SkImageFilters.h"
12 #include "tests/Test.h"
13 
test_flattenable(skiatest::Reporter * r,const SkFlattenable * f,const char * desc)14 static void test_flattenable(skiatest::Reporter* r,
15                              const SkFlattenable* f,
16                              const char* desc) {
17     if (f) {
18         SkFlattenable::Factory factory = f->getFactory();
19         REPORTER_ASSERT(r, factory);
20         if (factory) {
21             if (!SkFlattenable::FactoryToName(factory)) {
22                 ERRORF(r, "SkFlattenable::FactoryToName() fails with %s.", desc);
23             }
24         }
25     }
26 }
27 
DEF_TEST(FlattenableFactoryToName,r)28 DEF_TEST(FlattenableFactoryToName, r) {
29     SkIRect rects[2];
30     rects[0] = SkIRect::MakeXYWH(0, 150, 500, 200);
31     rects[1] = SkIRect::MakeXYWH(150, 0, 200, 500);
32     SkRegion region;
33     region.setRects(rects, 2);
34     sk_sp<SkImageFilter> filter(SkImageFilters::AlphaThreshold(region, 0.2f, 0.7f, nullptr));
35     test_flattenable(r, filter.get(), "SkImageFilters::AlphaThreshold()");
36 
37     SkBitmap bm;
38     bm.allocN32Pixels(8, 8);
39     bm.eraseColor(SK_ColorCYAN);
40     sk_sp<SkImage> image(bm.asImage());
41     test_flattenable(r, image->makeShader(SkSamplingOptions()).get(), "SkImage::newShader()");
42 }
43