• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "SkRegion.h"
11 #include "Test.h"
12 
test_flattenable(skiatest::Reporter * r,const SkFlattenable * f,const char * desc)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 
DEF_TEST(FlattenableFactoryToName,r)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);
33     sk_sp<SkImageFilter> filter(SkAlphaThresholdFilter::Make(region, 0.2f, 0.7f, nullptr));
34     test_flattenable(r, filter.get(), "SkAlphaThresholdFilter()");
35 
36     SkBitmap bm;
37     bm.allocN32Pixels(8, 8);
38     bm.eraseColor(SK_ColorCYAN);
39     sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm));
40     test_flattenable(r, image->makeShader().get(), "SkImage::newShader()");
41 }
42