robertphillips@google.com | 17ad2bd | 2013-07-30 12:15:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 "gm.h" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 9 | #include "SkBlurMask.h" |
robertphillips@google.com | 17ad2bd | 2013-07-30 12:15:19 +0000 | [diff] [blame] | 10 | #include "SkBlurMaskFilter.h" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 11 | #include "SkCanvas.h" |
robertphillips@google.com | 17ad2bd | 2013-07-30 12:15:19 +0000 | [diff] [blame] | 12 | |
| 13 | // This GM tests out the quick reject bounds of the blur mask filter. It draws |
| 14 | // four blurred rects around a central clip. The blurred rect geometry outset |
| 15 | // by the blur radius does not overlap the clip rect so, if the blur clipping |
| 16 | // just uses the radius, they will be clipped out (and the result will differ |
| 17 | // from the result if quick reject were disabled. If the blur clipping uses |
| 18 | // the correct 3 sigma bound then the images with and without quick rejecting |
| 19 | // will be the same. |
| 20 | class BlurQuickRejectGM : public skiagm::GM { |
| 21 | public: |
| 22 | BlurQuickRejectGM() {} |
| 23 | |
| 24 | protected: |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 25 | SkString onShortName() override { |
robertphillips@google.com | 17ad2bd | 2013-07-30 12:15:19 +0000 | [diff] [blame] | 26 | return SkString("blurquickreject"); |
| 27 | } |
| 28 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 29 | SkISize onISize() override { |
robertphillips@google.com | 17ad2bd | 2013-07-30 12:15:19 +0000 | [diff] [blame] | 30 | return SkISize::Make(kWidth, kHeight); |
| 31 | } |
| 32 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 33 | void onDraw(SkCanvas* canvas) override { |
robertphillips@google.com | 17ad2bd | 2013-07-30 12:15:19 +0000 | [diff] [blame] | 34 | static const SkScalar kBlurRadius = SkIntToScalar(20); |
| 35 | static const SkScalar kBoxSize = SkIntToScalar(100); |
| 36 | |
| 37 | SkRect clipRect = SkRect::MakeXYWH(0, 0, kBoxSize, kBoxSize); |
| 38 | SkRect blurRects[] = { |
| 39 | { -kBoxSize - (kBlurRadius+1), 0, -(kBlurRadius+1), kBoxSize }, |
| 40 | { 0, -kBoxSize - (kBlurRadius+1), kBoxSize, -(kBlurRadius+1) }, |
| 41 | { kBoxSize+kBlurRadius+1, 0, 2*kBoxSize+kBlurRadius+1, kBoxSize }, |
| 42 | { 0, kBoxSize+kBlurRadius+1, kBoxSize, 2*kBoxSize+kBlurRadius+1 } |
| 43 | }; |
| 44 | SkColor colors[] = { |
| 45 | SK_ColorRED, |
| 46 | SK_ColorGREEN, |
| 47 | SK_ColorBLUE, |
| 48 | SK_ColorYELLOW, |
| 49 | }; |
| 50 | SkASSERT(SK_ARRAY_COUNT(colors) == SK_ARRAY_COUNT(blurRects)); |
| 51 | |
| 52 | SkPaint hairlinePaint; |
| 53 | hairlinePaint.setStyle(SkPaint::kStroke_Style); |
| 54 | hairlinePaint.setColor(SK_ColorWHITE); |
| 55 | hairlinePaint.setStrokeWidth(0); |
| 56 | |
| 57 | SkPaint blurPaint; |
reed | 93a1215 | 2015-03-16 10:08:34 -0700 | [diff] [blame] | 58 | blurPaint.setFilterQuality(kLow_SkFilterQuality); |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 59 | blurPaint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, |
| 60 | SkBlurMask::ConvertRadiusToSigma(kBlurRadius))); |
robertphillips@google.com | 17ad2bd | 2013-07-30 12:15:19 +0000 | [diff] [blame] | 61 | |
| 62 | canvas->clear(SK_ColorBLACK); |
| 63 | canvas->save(); |
| 64 | canvas->translate(kBoxSize, kBoxSize); |
| 65 | canvas->drawRect(clipRect, hairlinePaint); |
| 66 | canvas->clipRect(clipRect); |
robertphillips@google.com | 073a32e | 2013-07-30 12:29:20 +0000 | [diff] [blame] | 67 | for (size_t i = 0; i < SK_ARRAY_COUNT(blurRects); ++i) { |
robertphillips@google.com | 17ad2bd | 2013-07-30 12:15:19 +0000 | [diff] [blame] | 68 | blurPaint.setColor(colors[i]); |
| 69 | canvas->drawRect(blurRects[i], blurPaint); |
| 70 | canvas->drawRect(blurRects[i], hairlinePaint); |
| 71 | } |
| 72 | canvas->restore(); |
| 73 | } |
| 74 | |
| 75 | private: |
| 76 | static const int kWidth = 300; |
| 77 | static const int kHeight = 300; |
| 78 | |
| 79 | typedef GM INHERITED; |
| 80 | }; |
| 81 | |
| 82 | DEF_GM( return new BlurQuickRejectGM(); ) |