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 | cfb6bdf | 2016-03-29 11:32:50 -0700 | [diff] [blame] | 37 | whitePaint.setXfermode(SkXfermode::Make(SkXfermode::kSrc_Mode)); |
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) |
| 41 | static const float kScale = 2.0f; |
| 42 | canvas->scale(kScale, kScale); |
| 43 | |
| 44 | canvas->save(); |
| 45 | SkRect clipRect1 = SkRect::MakeLTRB(0, 0, |
| 46 | SkIntToScalar(kWidth), SkIntToScalar(kHeight)); |
| 47 | |
| 48 | canvas->clipRect(clipRect1, SkRegion::kIntersect_Op, false); |
| 49 | |
| 50 | canvas->save(); |
| 51 | |
| 52 | canvas->clipRect(clipRect1, SkRegion::kIntersect_Op, false); |
| 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); |
| 59 | canvas->clipRRect(clipRRect, SkRegion::kDifference_Op, true); |
| 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: |
| 83 | static const int kWidth = 1164; |
| 84 | static const int kHeight = 802; |
| 85 | |
| 86 | typedef GM INHERITED; |
| 87 | }; |
| 88 | |
| 89 | ////////////////////////////////////////////////////////////////////////////// |
| 90 | |
| 91 | DEF_GM(return new BlurredClippedCircleGM;) |
| 92 | } |