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
15namespace {
16class TestFilter : public SkDrawFilter {
17public:
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 */
29static void test_saverestore(skiatest::Reporter* reporter) {
30    auto surface(SkSurface::MakeRasterN32Premul(10, 10));
31    SkCanvas* canvas = surface->getCanvas();
32
33    sk_sp<TestFilter> df(new TestFilter);
34
35    REPORTER_ASSERT(reporter, nullptr == canvas->getDrawFilter());
36
37    canvas->save();
38    canvas->setDrawFilter(df.get());
39    REPORTER_ASSERT(reporter, nullptr != canvas->getDrawFilter());
40    canvas->restore();
41
42    REPORTER_ASSERT(reporter, nullptr == canvas->getDrawFilter());
43}
44
45DEF_TEST(DrawFilter, reporter) {
46    test_saverestore(reporter);
47}
48
49#endif
50