| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright 2015 Google Inc. | 2  * Copyright 2015 Google Inc. | 
| 3  * | 3  * | 
| 4  * Use of this source code is governed by a BSD-style license that can be | 4  * Use of this source code is governed by a BSD-style license that can be | 
| 5  * found in the LICENSE file. | 5  * found in the LICENSE file. | 
| 6  */ | 6  */ | 
| 7 | 7 | 
| 8 #include "gm.h" | 8 #include "gm.h" | 
| 9 #include "SkBlurMask.h" | 9 #include "SkBlurMask.h" | 
| 10 #include "SkBlurMaskFilter.h" | 10 #include "SkBlurMaskFilter.h" | 
| 11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" | 
| 12 #include "SkDrawFilter.h" | 12 #include "SkDrawFilter.h" | 
| 13 #include "SkPaint.h" | 13 #include "SkPaint.h" | 
| 14 | 14 | 
| 15 /** | 15 /** | 
| 16  * Initial test coverage for SkDrawFilter. | 16  * Initial test coverage for SkDrawFilter. | 
| 17  * Draws two rectangles; if draw filters are broken, they will match. | 17  * Draws two rectangles; if draw filters are broken, they will match. | 
| 18  * If draw filters are working correctly, the first will be blue and blurred, | 18  * If draw filters are working correctly, the first will be blue and blurred, | 
| 19  * the second red and sharp. | 19  * the second red and sharp. | 
| 20  */ | 20  */ | 
| 21 | 21 | 
| 22 namespace { | 22 namespace { | 
| 23 class TestFilter : public SkDrawFilter { | 23 class TestFilter : public SkDrawFilter { | 
| 24 public: | 24 public: | 
| 25     bool filter(SkPaint* p, Type) override { | 25     bool filter(SkPaint* p, Type) override { | 
| 26         p->setColor(SK_ColorRED); | 26         p->setColor(SK_ColorRED); | 
| 27         p->setMaskFilter(NULL); | 27         p->setMaskFilter(nullptr); | 
| 28         return true; | 28         return true; | 
| 29     } | 29     } | 
| 30 }; | 30 }; | 
| 31 } | 31 } | 
| 32 | 32 | 
| 33 class DrawFilterGM : public skiagm::GM { | 33 class DrawFilterGM : public skiagm::GM { | 
| 34     SkAutoTUnref<SkMaskFilter> fBlur; | 34     SkAutoTUnref<SkMaskFilter> fBlur; | 
| 35 | 35 | 
| 36 protected: | 36 protected: | 
| 37     SkISize onISize() override { | 37     SkISize onISize() override { | 
| 38         return SkISize::Make(320, 240); | 38         return SkISize::Make(320, 240); | 
| 39     } | 39     } | 
| 40 | 40 | 
| 41     SkString onShortName() override { | 41     SkString onShortName() override { | 
| 42         return SkString("drawfilter"); | 42         return SkString("drawfilter"); | 
| 43     } | 43     } | 
| 44 | 44 | 
| 45     void onOnceBeforeDraw() override { | 45     void onOnceBeforeDraw() override { | 
| 46         fBlur.reset(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, | 46         fBlur.reset(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, | 
| 47                     SkBlurMask::ConvertRadiusToSigma(10.0f), | 47                     SkBlurMask::ConvertRadiusToSigma(10.0f), | 
| 48                     kLow_SkBlurQuality)); | 48                     kLow_SkBlurQuality)); | 
| 49     } | 49     } | 
| 50 | 50 | 
| 51     void onDraw(SkCanvas* canvas) override { | 51     void onDraw(SkCanvas* canvas) override { | 
| 52         SkPaint p; | 52         SkPaint p; | 
| 53         p.setColor(SK_ColorBLUE); | 53         p.setColor(SK_ColorBLUE); | 
| 54         p.setMaskFilter(fBlur.get()); | 54         p.setMaskFilter(fBlur.get()); | 
| 55         SkRect r = { 20, 20, 100, 100 }; | 55         SkRect r = { 20, 20, 100, 100 }; | 
| 56         canvas->setDrawFilter(NULL); | 56         canvas->setDrawFilter(nullptr); | 
| 57         canvas->drawRect(r, p); | 57         canvas->drawRect(r, p); | 
| 58         TestFilter redNoBlur; | 58         TestFilter redNoBlur; | 
| 59         canvas->setDrawFilter(&redNoBlur); | 59         canvas->setDrawFilter(&redNoBlur); | 
| 60         canvas->translate(120.0f, 40.0f); | 60         canvas->translate(120.0f, 40.0f); | 
| 61         canvas->drawRect(r, p); | 61         canvas->drawRect(r, p); | 
| 62 | 62 | 
| 63         // Must unset if the DrawFilter is from the stack to avoid refcount erro
    rs! | 63         // Must unset if the DrawFilter is from the stack to avoid refcount erro
    rs! | 
| 64         canvas->setDrawFilter(NULL); | 64         canvas->setDrawFilter(nullptr); | 
| 65     } | 65     } | 
| 66 | 66 | 
| 67 private: | 67 private: | 
| 68     typedef GM INHERITED; | 68     typedef GM INHERITED; | 
| 69 }; | 69 }; | 
| 70 | 70 | 
| 71 static skiagm::GM* MyFactory(void*) { return new DrawFilterGM; } | 71 static skiagm::GM* MyFactory(void*) { return new DrawFilterGM; } | 
| 72 static skiagm::GMRegistry reg(MyFactory); | 72 static skiagm::GMRegistry reg(MyFactory); | 
| 73 | 73 | 
| OLD | NEW | 
|---|