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