• 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.h"
9 #include "SkClipOpPriv.h"
10 #include "SkColorFilter.h"
11 #include "SkMaskFilter.h"
12 #include "SkPaint.h"
13 #include "SkRRect.h"
14 
15 namespace skiagm {
16 
17 // This GM reproduces the precision artifacts seen in crbug.com/560651.
18 // It draws a largish blurred circle with its center clipped out.
19 class BlurredClippedCircleGM : public GM {
20 public:
BlurredClippedCircleGM()21     BlurredClippedCircleGM() {
22         this->setBGColor(0xFFCCCCCC);
23     }
24 
25 protected:
26 
onShortName()27     SkString onShortName() override {
28         return SkString("blurredclippedcircle");
29     }
30 
onISize()31     SkISize onISize() override {
32         return SkISize::Make(kWidth, kHeight);
33     }
34 
onDraw(SkCanvas * canvas)35     void onDraw(SkCanvas* canvas) override {
36         SkPaint whitePaint;
37         whitePaint.setColor(SK_ColorWHITE);
38         whitePaint.setBlendMode(SkBlendMode::kSrc);
39         whitePaint.setAntiAlias(true);
40 
41         // This scale exercises precision limits in the circle blur effect (crbug.com/560651)
42         constexpr float kScale = 2.0f;
43         canvas->scale(kScale, kScale);
44 
45         canvas->save();
46             SkRect clipRect1 = SkRect::MakeLTRB(0, 0,
47                                                 SkIntToScalar(kWidth), SkIntToScalar(kHeight));
48 
49             canvas->clipRect(clipRect1);
50 
51             canvas->save();
52 
53                 canvas->clipRect(clipRect1);
54                 canvas->drawRect(clipRect1, whitePaint);
55 
56                 canvas->save();
57 
58                     SkRect clipRect2 = SkRect::MakeLTRB(8, 8, 288, 288);
59                     SkRRect clipRRect = SkRRect::MakeOval(clipRect2);
60                     canvas->clipRRect(clipRRect, kDifference_SkClipOp, true);
61 
62                     SkRect r = SkRect::MakeLTRB(4, 4, 292, 292);
63                     SkRRect rr = SkRRect::MakeOval(r);
64 
65                     SkPaint paint;
66 
67                     paint.setMaskFilter(SkMaskFilter::MakeBlur(
68                                             kNormal_SkBlurStyle,
69                                             1.366025f));
70                     paint.setColorFilter(SkColorFilter::MakeModeFilter(
71                                              SK_ColorRED,
72                                              SkBlendMode::kSrcIn));
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 constexpr int kWidth = 1164;
84     static constexpr int kHeight = 802;
85 
86     typedef GM INHERITED;
87 };
88 
89 //////////////////////////////////////////////////////////////////////////////
90 
91 DEF_GM(return new BlurredClippedCircleGM;)
92 }
93