• 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 "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:
BlurredClippedCircleGM()20     BlurredClippedCircleGM() {
21         this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC));
22     }
23 
24 protected:
25 
onShortName()26     SkString onShortName() override {
27         return SkString("blurredclippedcircle");
28     }
29 
onISize()30     SkISize onISize() override {
31         return SkISize::Make(kWidth, kHeight);
32     }
33 
onDraw(SkCanvas * canvas)34     void onDraw(SkCanvas* canvas) override {
35         SkPaint whitePaint;
36         whitePaint.setColor(SK_ColorWHITE);
37         whitePaint.setXfermode(SkXfermode::Create(SkXfermode::kSrc_Mode))->unref();
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 
66                     paint.setMaskFilter(SkBlurMaskFilter::Create(
67                                             kNormal_SkBlurStyle,
68                                             1.366025f,
69                                             SkBlurMaskFilter::kHighQuality_BlurFlag))->unref();
70                     paint.setColorFilter(SkColorFilter::CreateModeFilter(
71                                              SK_ColorRED,
72                                              SkXfermode::kSrcIn_Mode))->unref();
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 }
93