OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkDrawFilter.h" | 9 #include "SkDrawFilter.h" |
10 #include "SkSurface.h" | 10 #include "SkSurface.h" |
11 #include "Test.h" | 11 #include "Test.h" |
12 | 12 |
13 #ifdef SK_SUPPORT_LEGACY_DRAWFILTER | 13 #ifdef SK_SUPPORT_LEGACY_DRAWFILTER |
14 | 14 |
15 namespace { | 15 namespace { |
16 class TestFilter : public SkDrawFilter { | 16 class TestFilter : public SkDrawFilter { |
17 public: | 17 public: |
18 bool filter(SkPaint* p, Type) override { | 18 bool filter(SkPaint* p, Type) override { |
19 return true; | 19 return true; |
20 } | 20 } |
21 }; | 21 }; |
22 } | 22 } |
23 | 23 |
24 /** | 24 /** |
25 * canvas.setDrawFilter is defined to be local to the save/restore block, such
that if you | 25 * canvas.setDrawFilter is defined to be local to the save/restore block, such
that if you |
26 * do the following: save / modify-drawfilter / restore, the current drawfilter
should be what | 26 * do the following: save / modify-drawfilter / restore, the current drawfilter
should be what |
27 * it was before the save. | 27 * it was before the save. |
28 */ | 28 */ |
29 static void test_saverestore(skiatest::Reporter* reporter) { | 29 static void test_saverestore(skiatest::Reporter* reporter) { |
30 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10)); | 30 auto surface(SkSurface::MakeRasterN32Premul(10, 10)); |
31 SkCanvas* canvas = surface->getCanvas(); | 31 SkCanvas* canvas = surface->getCanvas(); |
32 | 32 |
33 SkAutoTUnref<TestFilter> df(new TestFilter); | 33 SkAutoTUnref<TestFilter> df(new TestFilter); |
34 | 34 |
35 REPORTER_ASSERT(reporter, nullptr == canvas->getDrawFilter()); | 35 REPORTER_ASSERT(reporter, nullptr == canvas->getDrawFilter()); |
36 | 36 |
37 canvas->save(); | 37 canvas->save(); |
38 canvas->setDrawFilter(df); | 38 canvas->setDrawFilter(df); |
39 REPORTER_ASSERT(reporter, nullptr != canvas->getDrawFilter()); | 39 REPORTER_ASSERT(reporter, nullptr != canvas->getDrawFilter()); |
40 canvas->restore(); | 40 canvas->restore(); |
41 | 41 |
42 REPORTER_ASSERT(reporter, nullptr == canvas->getDrawFilter()); | 42 REPORTER_ASSERT(reporter, nullptr == canvas->getDrawFilter()); |
43 } | 43 } |
44 | 44 |
45 DEF_TEST(DrawFilter, reporter) { | 45 DEF_TEST(DrawFilter, reporter) { |
46 test_saverestore(reporter); | 46 test_saverestore(reporter); |
47 } | 47 } |
48 | 48 |
49 #endif | 49 #endif |
OLD | NEW |