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" |
Ben Wagner | d90cd3b | 2018-05-22 10:48:08 -0400 | [diff] [blame] | 10 | #include "SkRefCnt.h" |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 11 | #include "SkSurface.h" |
| 12 | #include "Test.h" |
Ben Wagner | d90cd3b | 2018-05-22 10:48:08 -0400 | [diff] [blame] | 13 | class SkPaint; |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 14 | |
benjaminwagner | 1c2729c | 2016-01-22 09:45:14 -0800 | [diff] [blame] | 15 | #ifdef SK_SUPPORT_LEGACY_DRAWFILTER |
| 16 | |
reed | ffab15f | 2015-04-11 19:29:31 -0700 | [diff] [blame] | 17 | namespace { |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 18 | class TestFilter : public SkDrawFilter { |
| 19 | public: |
| 20 | bool filter(SkPaint* p, Type) override { |
| 21 | return true; |
| 22 | } |
| 23 | }; |
reed | ffab15f | 2015-04-11 19:29:31 -0700 | [diff] [blame] | 24 | } |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * canvas.setDrawFilter is defined to be local to the save/restore block, such that if you |
| 28 | * do the following: save / modify-drawfilter / restore, the current drawfilter should be what |
| 29 | * it was before the save. |
| 30 | */ |
| 31 | static void test_saverestore(skiatest::Reporter* reporter) { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 32 | auto surface(SkSurface::MakeRasterN32Premul(10, 10)); |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 33 | SkCanvas* canvas = surface->getCanvas(); |
| 34 | |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 35 | sk_sp<TestFilter> df(new TestFilter); |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 36 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 37 | REPORTER_ASSERT(reporter, nullptr == canvas->getDrawFilter()); |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 38 | |
| 39 | canvas->save(); |
Hal Canary | 342b7ac | 2016-11-04 11:49:42 -0400 | [diff] [blame] | 40 | canvas->setDrawFilter(df.get()); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 41 | REPORTER_ASSERT(reporter, nullptr != canvas->getDrawFilter()); |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 42 | canvas->restore(); |
| 43 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 44 | REPORTER_ASSERT(reporter, nullptr == canvas->getDrawFilter()); |
reed | 51985e3 | 2015-04-11 08:04:56 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | DEF_TEST(DrawFilter, reporter) { |
| 48 | test_saverestore(reporter); |
| 49 | } |
benjaminwagner | 1c2729c | 2016-01-22 09:45:14 -0800 | [diff] [blame] | 50 | |
| 51 | #endif |