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" |
| 9 | #include "SkBlurMaskFilter.h" |
| 10 | #include "SkColorFilter.h" |
| 11 | #include "SkPaint.h" |
| 12 | #include "SkRRect.h" |
| 13 | |
| 14 | namespace skiagm { |
| 15 | |
| 16 | // This GM reproduces the precision artifacts seen in crbug.com/560651. |
| 17 | // It draws a largish blurred circle with its center clipped out. |
| 18 | class BlurredClippedCircleGM : public GM { |
| 19 | public: |
| 20 | BlurredClippedCircleGM() { |
| 21 | this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC)); |
| 22 | } |
| 23 | |
| 24 | protected: |
| 25 | |
| 26 | SkString onShortName() override { |
| 27 | return SkString("blurredclippedcircle"); |
| 28 | } |
| 29 | |
| 30 | SkISize onISize() override { |
| 31 | return SkISize::Make(kWidth, kHeight); |
| 32 | } |
| 33 | |
| 34 | void onDraw(SkCanvas* canvas) override { |
| 35 | SkPaint whitePaint; |
| 36 | whitePaint.setColor(SK_ColorWHITE); |
reed | 374772b | 2016-10-05 17:33:02 -0700 | [diff] [blame] | 37 | whitePaint.setBlendMode(SkBlendMode::kSrc); |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 38 | whitePaint.setAntiAlias(true); |
| 39 | |
| 40 | // This scale exercises precision limits in the circle blur effect (crbug.com/560651) |
mtklein | dbfd7ab | 2016-09-01 11:24:54 -0700 | [diff] [blame] | 41 | constexpr float kScale = 2.0f; |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 42 | canvas->scale(kScale, kScale); |
| 43 | |
| 44 | canvas->save(); |
| 45 | SkRect clipRect1 = SkRect::MakeLTRB(0, 0, |
| 46 | SkIntToScalar(kWidth), SkIntToScalar(kHeight)); |
| 47 | |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 48 | canvas->clipRect(clipRect1); |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 49 | |
| 50 | canvas->save(); |
| 51 | |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 52 | canvas->clipRect(clipRect1); |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 53 | canvas->drawRect(clipRect1, whitePaint); |
| 54 | |
| 55 | canvas->save(); |
| 56 | |
| 57 | SkRect clipRect2 = SkRect::MakeLTRB(8, 8, 288, 288); |
| 58 | SkRRect clipRRect = SkRRect::MakeOval(clipRect2); |
reed | 73603f3 | 2016-09-20 08:42:38 -0700 | [diff] [blame] | 59 | canvas->clipRRect(clipRRect, SkCanvas::kDifference_Op, true); |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 60 | |
| 61 | SkRect r = SkRect::MakeLTRB(4, 4, 292, 292); |
| 62 | SkRRect rr = SkRRect::MakeOval(r); |
| 63 | |
| 64 | SkPaint paint; |
| 65 | |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 66 | paint.setMaskFilter(SkBlurMaskFilter::Make( |
robertphillips | 4e56772 | 2015-12-10 13:29:14 -0800 | [diff] [blame] | 67 | kNormal_SkBlurStyle, |
| 68 | 1.366025f, |
reed | efdfd51 | 2016-04-04 10:02:58 -0700 | [diff] [blame] | 69 | SkBlurMaskFilter::kHighQuality_BlurFlag)); |
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, |
reed | d053ce9 | 2016-03-22 10:17:23 -0700 | [diff] [blame] | 72 | SkXfermode::kSrcIn_Mode)); |
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 | } |