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