blob: 495d16a3c2482eb2503c7ca017302481ddaefd42 [file] [log] [blame]
robertphillips4e567722015-12-10 13:29:14 -08001/*
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
14namespace 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.
18class BlurredClippedCircleGM : public GM {
19public:
20 BlurredClippedCircleGM() {
21 this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC));
22 }
23
24protected:
25
26 SkString onShortName() override {
27 return SkString("blurredclippedcircle");
28 }
29
30 SkISize onISize() override {
31 return SkISize::Make(kWidth, kHeight);
32 }
33
34 void onDraw(SkCanvas* canvas) override {
35 SkPaint whitePaint;
36 whitePaint.setColor(SK_ColorWHITE);
reedcfb6bdf2016-03-29 11:32:50 -070037 whitePaint.setXfermode(SkXfermode::Make(SkXfermode::kSrc_Mode));
robertphillips4e567722015-12-10 13:29:14 -080038 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
reedefdfd512016-04-04 10:02:58 -070066 paint.setMaskFilter(SkBlurMaskFilter::Make(
robertphillips4e567722015-12-10 13:29:14 -080067 kNormal_SkBlurStyle,
68 1.366025f,
reedefdfd512016-04-04 10:02:58 -070069 SkBlurMaskFilter::kHighQuality_BlurFlag));
reedd053ce92016-03-22 10:17:23 -070070 paint.setColorFilter(SkColorFilter::MakeModeFilter(
robertphillips4e567722015-12-10 13:29:14 -080071 SK_ColorRED,
reedd053ce92016-03-22 10:17:23 -070072 SkXfermode::kSrcIn_Mode));
robertphillips4e567722015-12-10 13:29:14 -080073 paint.setAntiAlias(true);
74
75 canvas->drawRRect(rr, paint);
76
77 canvas->restore();
78 canvas->restore();
79 canvas->restore();
80 }
81
82private:
83 static const int kWidth = 1164;
84 static const int kHeight = 802;
85
86 typedef GM INHERITED;
87};
88
89//////////////////////////////////////////////////////////////////////////////
90
91DEF_GM(return new BlurredClippedCircleGM;)
92}