• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
22 namespace skiagm {
23 
24 // This GM reproduces the precision artifacts seen in crbug.com/560651.
25 // It draws a largish blurred circle with its center clipped out.
26 class BlurredClippedCircleGM : public GM {
27 public:
BlurredClippedCircleGM()28     BlurredClippedCircleGM() {
29         this->setBGColor(0xFFCCCCCC);
30     }
31 
32 protected:
33 
onShortName()34     SkString onShortName() override {
35         return SkString("blurredclippedcircle");
36     }
37 
onISize()38     SkISize onISize() override {
39         return SkISize::Make(kWidth, kHeight);
40     }
41 
onDraw(SkCanvas * canvas)42     void onDraw(SkCanvas* canvas) override {
43         SkPaint whitePaint;
44         whitePaint.setColor(SK_ColorWHITE);
45         whitePaint.setBlendMode(SkBlendMode::kSrc);
46         whitePaint.setAntiAlias(true);
47 
48         // This scale exercises precision limits in the circle blur effect (crbug.com/560651)
49         constexpr float kScale = 2.0f;
50         canvas->scale(kScale, kScale);
51 
52         canvas->save();
53             SkRect clipRect1 = SkRect::MakeLTRB(0, 0, kWidth, kHeight);
54             canvas->clipRect(clipRect1);
55 
56             canvas->save();
57 
58                 canvas->clipRect(clipRect1);
59                 canvas->drawRect(clipRect1, whitePaint);
60 
61                 canvas->save();
62 
63                     SkRect clipRect2 = SkRect::MakeLTRB(8, 8, 288, 288);
64                     SkRRect clipRRect = SkRRect::MakeOval(clipRect2);
65                     canvas->clipRRect(clipRRect, SkClipOp::kDifference, true);
66 
67                     SkRect r = SkRect::MakeLTRB(4, 4, 292, 292);
68                     SkRRect rr = SkRRect::MakeOval(r);
69 
70                     SkPaint paint;
71 
72                     paint.setMaskFilter(SkMaskFilter::MakeBlur(
73                                             kNormal_SkBlurStyle,
74                                             1.366025f));
75                     paint.setColorFilter(SkColorFilters::Blend(SK_ColorRED, SkBlendMode::kSrcIn));
76                     paint.setAntiAlias(true);
77 
78                     canvas->drawRRect(rr, paint);
79 
80                 canvas->restore();
81             canvas->restore();
82         canvas->restore();
83     }
84 
85 private:
86     inline static constexpr int kWidth = 1164;
87     inline static constexpr int kHeight = 802;
88 
89     using INHERITED = GM;
90 };
91 
92 //////////////////////////////////////////////////////////////////////////////
93 
94 DEF_GM(return new BlurredClippedCircleGM;)
95 }  // namespace skiagm
96