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 "sk_tool_utils.h" 10 #include "SkBlurMaskFilter.h" 11 #include "SkClipOpPriv.h" 12 #include "SkColorFilter.h" 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: BlurredClippedCircleGM()22 BlurredClippedCircleGM() { 23 this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC)); 24 } 25 26 protected: 27 onShortName()28 SkString onShortName() override { 29 return SkString("blurredclippedcircle"); 30 } 31 onISize()32 SkISize onISize() override { 33 return SkISize::Make(kWidth, kHeight); 34 } 35 onDraw(SkCanvas * canvas)36 void onDraw(SkCanvas* canvas) override { 37 SkPaint whitePaint; 38 whitePaint.setColor(SK_ColorWHITE); 39 whitePaint.setBlendMode(SkBlendMode::kSrc); 40 whitePaint.setAntiAlias(true); 41 42 // This scale exercises precision limits in the circle blur effect (crbug.com/560651) 43 constexpr float kScale = 2.0f; 44 canvas->scale(kScale, kScale); 45 46 canvas->save(); 47 SkRect clipRect1 = SkRect::MakeLTRB(0, 0, 48 SkIntToScalar(kWidth), SkIntToScalar(kHeight)); 49 50 canvas->clipRect(clipRect1); 51 52 canvas->save(); 53 54 canvas->clipRect(clipRect1); 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); 61 canvas->clipRRect(clipRRect, kDifference_SkClipOp, true); 62 63 SkRect r = SkRect::MakeLTRB(4, 4, 292, 292); 64 SkRRect rr = SkRRect::MakeOval(r); 65 66 SkPaint paint; 67 68 paint.setMaskFilter(SkBlurMaskFilter::Make( 69 kNormal_SkBlurStyle, 70 1.366025f, 71 SkBlurMaskFilter::kHighQuality_BlurFlag)); 72 paint.setColorFilter(SkColorFilter::MakeModeFilter( 73 SK_ColorRED, 74 SkBlendMode::kSrcIn)); 75 paint.setAntiAlias(true); 76 77 canvas->drawRRect(rr, paint); 78 79 canvas->restore(); 80 canvas->restore(); 81 canvas->restore(); 82 } 83 84 private: 85 static constexpr int kWidth = 1164; 86 static constexpr int kHeight = 802; 87 88 typedef GM INHERITED; 89 }; 90 91 ////////////////////////////////////////////////////////////////////////////// 92 93 DEF_GM(return new BlurredClippedCircleGM;) 94 } 95