blob: 13ae5c6bd073753049a9b5b10115a71deefc4c73 [file] [log] [blame]
reed51985e32015-04-11 08:04:56 -07001/*
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
reedffab15f2015-04-11 19:29:31 -070013namespace {
reed51985e32015-04-11 08:04:56 -070014class TestFilter : public SkDrawFilter {
15public:
16 bool filter(SkPaint* p, Type) override {
17 return true;
18 }
19};
reedffab15f2015-04-11 19:29:31 -070020}
reed51985e32015-04-11 08:04:56 -070021
22/**
23 * canvas.setDrawFilter is defined to be local to the save/restore block, such that if you
24 * do the following: save / modify-drawfilter / restore, the current drawfilter should be what
25 * it was before the save.
26 */
27static void test_saverestore(skiatest::Reporter* reporter) {
28 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(10, 10));
29 SkCanvas* canvas = surface->getCanvas();
30
31
32 SkAutoTUnref<TestFilter> df(SkNEW(TestFilter));
33
34 REPORTER_ASSERT(reporter, NULL == canvas->getDrawFilter());
35
36 canvas->save();
37 canvas->setDrawFilter(df);
38 REPORTER_ASSERT(reporter, NULL != canvas->getDrawFilter());
39 canvas->restore();
40
41 REPORTER_ASSERT(reporter, NULL == canvas->getDrawFilter());
42}
43
44DEF_TEST(DrawFilter, reporter) {
45 test_saverestore(reporter);
46}