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 13 #ifdef SK_SUPPORT_LEGACY_DRAWFILTER 14 15 namespace { 16 class TestFilter : public SkDrawFilter { 17 public: 18 bool filter(SkPaint* p, Type) override { 19 return true; 20 } 21 }; 22 } 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 33 SkAutoTUnref<TestFilter> df(new TestFilter); 34 35 REPORTER_ASSERT(reporter, nullptr == canvas->getDrawFilter()); 36 37 canvas->save(); 38 canvas->setDrawFilter(df); 39 REPORTER_ASSERT(reporter, nullptr != canvas->getDrawFilter()); 40 canvas->restore(); 41 42 REPORTER_ASSERT(reporter, nullptr == canvas->getDrawFilter()); 43 } 44 45 DEF_TEST(DrawFilter, reporter) { 46 test_saverestore(reporter); 47 } 48 49 #endif 50