blob: a0359c367a2cb8a49496023e4240bf31fe67f4a5 [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);
reed374772b2016-10-05 17:33:02 -070037 whitePaint.setBlendMode(SkBlendMode::kSrc);
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)
mtkleindbfd7ab2016-09-01 11:24:54 -070041 constexpr float kScale = 2.0f;
robertphillips4e567722015-12-10 13:29:14 -080042 canvas->scale(kScale, kScale);
43
44 canvas->save();
45 SkRect clipRect1 = SkRect::MakeLTRB(0, 0,
46 SkIntToScalar(kWidth), SkIntToScalar(kHeight));
47
reed73603f32016-09-20 08:42:38 -070048 canvas->clipRect(clipRect1);
robertphillips4e567722015-12-10 13:29:14 -080049
50 canvas->save();
51
reed73603f32016-09-20 08:42:38 -070052 canvas->clipRect(clipRect1);
robertphillips4e567722015-12-10 13:29:14 -080053 canvas->drawRect(clipRect1, whitePaint);
54
55 canvas->save();
56
57 SkRect clipRect2 = SkRect::MakeLTRB(8, 8, 288, 288);
58 SkRRect clipRRect = SkRRect::MakeOval(clipRect2);
reed73603f32016-09-20 08:42:38 -070059 canvas->clipRRect(clipRRect, SkCanvas::kDifference_Op, true);
robertphillips4e567722015-12-10 13:29:14 -080060
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:
mtkleindbfd7ab2016-09-01 11:24:54 -070083 static constexpr int kWidth = 1164;
84 static constexpr int kHeight = 802;
robertphillips4e567722015-12-10 13:29:14 -080085
86 typedef GM INHERITED;
87};
88
89//////////////////////////////////////////////////////////////////////////////
90
91DEF_GM(return new BlurredClippedCircleGM;)
92}