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/gm.h" 9 #include "include/core/SkBlendMode.h" 10 #include "include/core/SkBlurTypes.h" 11 #include "include/core/SkCanvas.h" 12 #include "include/core/SkColor.h" 13 #include "include/core/SkColorFilter.h" 14 #include "include/core/SkMaskFilter.h" 15 #include "include/core/SkPaint.h" 16 #include "include/core/SkRRect.h" 17 #include "include/core/SkRect.h" 18 #include "include/core/SkScalar.h" 19 #include "include/core/SkSize.h" 20 #include "include/core/SkString.h" 21 #include "src/core/SkClipOpPriv.h" 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: BlurredClippedCircleGM()29 BlurredClippedCircleGM() { 30 this->setBGColor(0xFFCCCCCC); 31 } 32 33 protected: 34 onShortName()35 SkString onShortName() override { 36 return SkString("blurredclippedcircle"); 37 } 38 onISize()39 SkISize onISize() override { 40 return SkISize::Make(kWidth, kHeight); 41 } 42 onDraw(SkCanvas * canvas)43 void onDraw(SkCanvas* canvas) override { 44 SkPaint whitePaint; 45 whitePaint.setColor(SK_ColorWHITE); 46 whitePaint.setBlendMode(SkBlendMode::kSrc); 47 whitePaint.setAntiAlias(true); 48 49 // This scale exercises precision limits in the circle blur effect (crbug.com/560651) 50 constexpr float kScale = 2.0f; 51 canvas->scale(kScale, kScale); 52 53 canvas->save(); 54 SkRect clipRect1 = SkRect::MakeLTRB(0, 0, 55 SkIntToScalar(kWidth), SkIntToScalar(kHeight)); 56 57 canvas->clipRect(clipRect1); 58 59 canvas->save(); 60 61 canvas->clipRect(clipRect1); 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); 68 canvas->clipRRect(clipRRect, kDifference_SkClipOp, true); 69 70 SkRect r = SkRect::MakeLTRB(4, 4, 292, 292); 71 SkRRect rr = SkRRect::MakeOval(r); 72 73 SkPaint paint; 74 75 paint.setMaskFilter(SkMaskFilter::MakeBlur( 76 kNormal_SkBlurStyle, 77 1.366025f)); 78 paint.setColorFilter(SkColorFilters::Blend(SK_ColorRED, 79 SkBlendMode::kSrcIn)); 80 paint.setAntiAlias(true); 81 82 canvas->drawRRect(rr, paint); 83 84 canvas->restore(); 85 canvas->restore(); 86 canvas->restore(); 87 } 88 89 private: 90 static constexpr int kWidth = 1164; 91 static constexpr int kHeight = 802; 92 93 using INHERITED = GM; 94 }; 95 96 ////////////////////////////////////////////////////////////////////////////// 97 98 DEF_GM(return new BlurredClippedCircleGM;) 99 } // namespace skiagm 100