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