robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 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.h" |
Mike Reed | ebfce6d | 2016-12-12 10:02:12 -0500 | [diff] [blame] | 9 | #include "SkClipOpPriv.h" |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 10 | #include "SkColorFilter.h" |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 11 | #include "SkMaskFilter.h" |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 12 | #include "SkPaint.h" |
| 13 | #include "SkRRect.h" |
| 14 | |
| 15 | namespace skiagm { |
| 16 | |
| 17 | // This GM reproduces the precision artifacts seen in crbug.com/560651. |
| 18 | // It draws a largish blurred circle with its center clipped out. |
| 19 | class BlurredClippedCircleGM : public GM { |
| 20 | public: |
| 21 | BlurredClippedCircleGM() { |
Mike Klein | d46dce3 | 2018-08-16 10:17:03 -0400 | [diff] [blame] | 22 | this->setBGColor(0xFFCCCCCC); |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 23 | } |
| 24 | |
| 25 | protected: |
| 26 | |
| 27 | SkString onShortName() override { |
| 28 | return SkString("blurredclippedcircle"); |
| 29 | } |
| 30 | |
| 31 | SkISize onISize() override { |
| 32 | return SkISize::Make(kWidth, kHeight); |
| 33 | } |
| 34 | |
| 35 | void onDraw(SkCanvas* canvas) override { |
| 36 | SkPaint whitePaint; |
| 37 | whitePaint.setColor(SK_ColorWHITE); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 38 | whitePaint.setBlendMode(SkBlendMode::kSrc); |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 39 | whitePaint.setAntiAlias(true); |
| 40 | |
| 41 | // This scale exercises precision limits in the circle blur effect (crbug.com/560651) |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 42 | constexpr float kScale = 2.0f; |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 43 | canvas->scale(kScale, kScale); |
| 44 | |
| 45 | canvas->save(); |
| 46 | SkRect clipRect1 = SkRect::MakeLTRB(0, 0, |
| 47 | SkIntToScalar(kWidth), SkIntToScalar(kHeight)); |
| 48 | |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 49 | canvas->clipRect(clipRect1); |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 50 | |
| 51 | canvas->save(); |
| 52 | |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 53 | canvas->clipRect(clipRect1); |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 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); |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 60 | canvas->clipRRect(clipRRect, kDifference_SkClipOp, true); |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 61 | |
| 62 | SkRect r = SkRect::MakeLTRB(4, 4, 292, 292); |
| 63 | SkRRect rr = SkRRect::MakeOval(r); |
| 64 | |
| 65 | SkPaint paint; |
| 66 | |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 67 | paint.setMaskFilter(SkMaskFilter::MakeBlur( |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 68 | kNormal_SkBlurStyle, |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 69 | 1.366025f)); |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 70 | paint.setColorFilter(SkColorFilter::MakeModeFilter( |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 71 | SK_ColorRED, |
Mike Reed | 7d954ad | 2016-10-28 15:42:34 -0400 | [diff] [blame] | 72 | SkBlendMode::kSrcIn)); |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 73 | paint.setAntiAlias(true); |
| 74 | |
| 75 | canvas->drawRRect(rr, paint); |
| 76 | |
| 77 | canvas->restore(); |
| 78 | canvas->restore(); |
| 79 | canvas->restore(); |
| 80 | } |
| 81 | |
| 82 | private: |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 83 | static constexpr int kWidth = 1164; |
| 84 | static constexpr int kHeight = 802; |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 85 | |
| 86 | typedef GM INHERITED; |
| 87 | }; |
| 88 | |
| 89 | ////////////////////////////////////////////////////////////////////////////// |
| 90 | |
| 91 | DEF_GM(return new BlurredClippedCircleGM;) |
| 92 | } |