blob: 35ec98493fdc52d64440a0b10b6487da80da15e5 [file] [log] [blame]
scroggo56fbbfe2015-12-18 07:14:24 -08001/*
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"
robertphillipsf7142e72016-04-18 07:20:05 -070010#include "SkRegion.h"
scroggo56fbbfe2015-12-18 07:14:24 -080011#include "Test.h"
12
13static 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
27DEF_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);
robertphillipsf6242042016-04-01 10:34:43 -070033 sk_sp<SkImageFilter> filter(SkAlphaThresholdFilter::Make(region, 0.2f, 0.7f, nullptr));
34 test_flattenable(r, filter.get(), "SkAlphaThresholdFilter()");
scroggo56fbbfe2015-12-18 07:14:24 -080035
36 SkBitmap bm;
37 bm.allocN32Pixels(8, 8);
38 bm.eraseColor(SK_ColorCYAN);
reed9ce9d672016-03-17 10:51:11 -070039 sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm));
reed5671c5b2016-03-09 14:47:34 -080040 auto shader = image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode);
41 test_flattenable(r, shader.get(), "SkImage::newShader()");
scroggo56fbbfe2015-12-18 07:14:24 -080042}