Home | History | Annotate | Download | only in tests
      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 namespace {
     14 class TestFilter : public SkDrawFilter {
     15 public:
     16     bool filter(SkPaint* p, Type) override {
     17         return true;
     18     }
     19 };
     20 }
     21 
     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  */
     27 static 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 
     44 DEF_TEST(DrawFilter, reporter) {
     45     test_saverestore(reporter);
     46 }
     47