reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 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 "SkCanvas.h" |
| 9 | #include "SkDrawFilter.h" |
| 10 | #include "SkSurface.h" |
| 11 | #include "Test.h" |
| 12 | |
benjaminwagner | 1c2729c | 2016-01-22 09:45:14 -0800 | [diff] [blame^] | 13 | #ifdef SK_SUPPORT_LEGACY_DRAWFILTER |
| 14 | |
reed | ffab15f | 2015-04-11 19:29:31 -0700 | [diff] [blame] | 15 | namespace { |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 16 | class TestFilter : public SkDrawFilter { |
| 17 | public: |
| 18 | bool filter(SkPaint* p, Type) override { |
| 19 | return true; |
| 20 | } |
| 21 | }; |
reed | ffab15f | 2015-04-11 19:29:31 -0700 | [diff] [blame] | 22 | } |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 23 | |
| 24 | /** |
| 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 |
| 27 | * it was before the save. |
| 28 | */ |
| 29 | static void test_saverestore(skiatest::Reporter* reporter) { |
| 30 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10)); |
| 31 | SkCanvas* canvas = surface->getCanvas(); |
| 32 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 33 | SkAutoTUnref<TestFilter> df(new TestFilter); |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 34 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 35 | REPORTER_ASSERT(reporter, nullptr == canvas->getDrawFilter()); |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 36 | |
| 37 | canvas->save(); |
| 38 | canvas->setDrawFilter(df); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 39 | REPORTER_ASSERT(reporter, nullptr != canvas->getDrawFilter()); |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 40 | canvas->restore(); |
| 41 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 42 | REPORTER_ASSERT(reporter, nullptr == canvas->getDrawFilter()); |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | DEF_TEST(DrawFilter, reporter) { |
| 46 | test_saverestore(reporter); |
| 47 | } |
benjaminwagner | 1c2729c | 2016-01-22 09:45:14 -0800 | [diff] [blame^] | 48 | |
| 49 | #endif |