xref: /aosp_15_r20/external/skia/tests/FlattenableFactoryToName.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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/SkColor.h"
10 #include "include/core/SkFlattenable.h"
11 #include "include/core/SkImage.h"
12 #include "include/core/SkImageFilter.h"
13 #include "include/core/SkRefCnt.h"
14 #include "include/core/SkSamplingOptions.h"
15 #include "include/core/SkShader.h"
16 #include "include/effects/SkImageFilters.h"
17 #include "tests/Test.h"
18 
test_flattenable(skiatest::Reporter * r,const SkFlattenable * f,const char * desc)19 static void test_flattenable(skiatest::Reporter* r,
20                              const SkFlattenable* f,
21                              const char* desc) {
22     if (f) {
23         SkFlattenable::Factory factory = f->getFactory();
24         REPORTER_ASSERT(r, factory);
25         if (factory) {
26             if (!SkFlattenable::FactoryToName(factory)) {
27                 ERRORF(r, "SkFlattenable::FactoryToName() fails with %s.", desc);
28             }
29         }
30     }
31 }
32 
DEF_TEST(FlattenableFactoryToName,r)33 DEF_TEST(FlattenableFactoryToName, r) {
34     sk_sp<SkImageFilter> filter(SkImageFilters::Blur(0.2f, 0.7f, nullptr));
35     test_flattenable(r, filter.get(), "SkImageFilters::Blur()");
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