| 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 "gm/gm.h" |
| 9 |
#include "include/core/SkBlendMode.h" |
| 10 |
#include "include/core/SkBlurTypes.h" |
| 11 |
#include "include/core/SkCanvas.h" |
| 12 |
#include "include/core/SkColor.h" |
| 13 |
#include "include/core/SkColorFilter.h" |
| 14 |
#include "include/core/SkMaskFilter.h" |
| 15 |
#include "include/core/SkPaint.h" |
| 16 |
#include "include/core/SkRRect.h" |
| 17 |
#include "include/core/SkRect.h" |
| 18 |
#include "include/core/SkScalar.h" |
| 19 |
#include "include/core/SkSize.h" |
| 20 |
#include "include/core/SkString.h" |
| 21 |
|
| 22 |
namespace skiagm { |
| 23 |
|
| 24 |
// This GM reproduces the precision artifacts seen in crbug.com/560651. |
| 25 |
// It draws a largish blurred circle with its center clipped out. |
| 26 |
class BlurredClippedCircleGM : public GM { |
| 27 |
public: |
| 28 |
BlurredClippedCircleGM() { |
| 29 |
this->setBGColor(0xFFCCCCCC); |
| 30 |
} |
| 31 |
|
| 32 |
protected: |
| 33 |
SkString getName() const override { return SkString("blurredclippedcircle"); } |
| 34 |
|
| 35 |
SkISize getISize() override { return SkISize::Make(kWidth, kHeight); } |
| 36 |
|
| 37 |
void onDraw(SkCanvas* canvas) override { |
| 38 |
SkPaint whitePaint; |
| 39 |
whitePaint.setColor(SK_ColorWHITE); |
| 40 |
whitePaint.setBlendMode(SkBlendMode::kSrc); |
| 41 |
whitePaint.setAntiAlias(true); |
| 42 |
|
| 43 |
// This scale exercises precision limits in the circle blur effect (crbug.com/560651) |
| 44 |
constexpr float kScale = 2.0f; |
| 45 |
canvas->scale(kScale, kScale); |
| 46 |
|
| 47 |
canvas->save(); |
| 48 |
SkRect clipRect1 = SkRect::MakeLTRB(0, 0, kWidth, kHeight); |
| 49 |
canvas->clipRect(clipRect1); |
| 50 |
|
| 51 |
canvas->save(); |
| 52 |
|
| 53 |
canvas->clipRect(clipRect1); |
| 54 |
canvas->drawRect(clipRect1, whitePaint); |
| 55 |
|
| 56 |
canvas->save(); |
| 57 |
|
| 58 |
SkRect clipRect2 = SkRect::MakeLTRB(8, 8, 288, 288); |
| 59 |
SkRRect clipRRect = SkRRect::MakeOval(clipRect2); |
| 60 |
canvas->clipRRect(clipRRect, SkClipOp::kDifference, true); |
| 61 |
|
| 62 |
SkRect r = SkRect::MakeLTRB(4, 4, 292, 292); |
| 63 |
SkRRect rr = SkRRect::MakeOval(r); |
| 64 |
|
| 65 |
SkPaint paint; |
| 66 |
|
| 67 |
paint.setMaskFilter(SkMaskFilter::MakeBlur( |
| 68 |
kNormal_SkBlurStyle, |
| 69 |
1.366025f)); |
| 70 |
paint.setColorFilter(SkColorFilters::Blend(SK_ColorRED, SkBlendMode::kSrcIn)); |
| 71 |
paint.setAntiAlias(true); |
| 72 |
|
| 73 |
canvas->drawRRect(rr, paint); |
| 74 |
|
| 75 |
canvas->restore(); |
| 76 |
canvas->restore(); |
| 77 |
canvas->restore(); |
| 78 |
} |
| 79 |
|
| 80 |
private: |
| 81 |
inline static constexpr int kWidth = 1164; |
| 82 |
inline static constexpr int kHeight = 802; |
| 83 |
|
| 84 |
using INHERITED = GM; |
| 85 |
}; |
| 86 |
|
| 87 |
////////////////////////////////////////////////////////////////////////////// |
| 88 |
|
| 89 |
DEF_GM(return new BlurredClippedCircleGM;) |
| 90 |
} // namespace skiagm |