blob: 533555d01504639f88efd952f9ae33af90ebecf6 [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"
Mike Klein33d20552017-03-22 13:47:51 -04009#include "sk_tool_utils.h"
Mike Reedebfce6d2016-12-12 10:02:12 -050010#include "SkClipOpPriv.h"
robertphillips4e567722015-12-10 13:29:14 -080011#include "SkColorFilter.h"
Mike Reed1be1f8d2018-03-14 13:01:17 -040012#include "SkMaskFilter.h"
robertphillips4e567722015-12-10 13:29:14 -080013#include "SkPaint.h"
14#include "SkRRect.h"
15
16namespace skiagm {
17
18// This GM reproduces the precision artifacts seen in crbug.com/560651.
19// It draws a largish blurred circle with its center clipped out.
20class BlurredClippedCircleGM : public GM {
21public:
22 BlurredClippedCircleGM() {
23 this->setBGColor(sk_tool_utils::color_to_565(0xFFCCCCCC));
24 }
25
26protected:
27
28 SkString onShortName() override {
29 return SkString("blurredclippedcircle");
30 }
31
32 SkISize onISize() override {
33 return SkISize::Make(kWidth, kHeight);
34 }
35
36 void onDraw(SkCanvas* canvas) override {
37 SkPaint whitePaint;
38 whitePaint.setColor(SK_ColorWHITE);
reed374772b2016-10-05 17:33:02 -070039 whitePaint.setBlendMode(SkBlendMode::kSrc);
robertphillips4e567722015-12-10 13:29:14 -080040 whitePaint.setAntiAlias(true);
41
42 // This scale exercises precision limits in the circle blur effect (crbug.com/560651)
mtkleindbfd7ab2016-09-01 11:24:54 -070043 constexpr float kScale = 2.0f;
robertphillips4e567722015-12-10 13:29:14 -080044 canvas->scale(kScale, kScale);
45
46 canvas->save();
47 SkRect clipRect1 = SkRect::MakeLTRB(0, 0,
48 SkIntToScalar(kWidth), SkIntToScalar(kHeight));
49
reed73603f32016-09-20 08:42:38 -070050 canvas->clipRect(clipRect1);
robertphillips4e567722015-12-10 13:29:14 -080051
52 canvas->save();
53
reed73603f32016-09-20 08:42:38 -070054 canvas->clipRect(clipRect1);
robertphillips4e567722015-12-10 13:29:14 -080055 canvas->drawRect(clipRect1, whitePaint);
56
57 canvas->save();
58
59 SkRect clipRect2 = SkRect::MakeLTRB(8, 8, 288, 288);
60 SkRRect clipRRect = SkRRect::MakeOval(clipRect2);
Mike Reedc1f77742016-12-09 09:00:50 -050061 canvas->clipRRect(clipRRect, kDifference_SkClipOp, true);
robertphillips4e567722015-12-10 13:29:14 -080062
63 SkRect r = SkRect::MakeLTRB(4, 4, 292, 292);
64 SkRRect rr = SkRRect::MakeOval(r);
65
66 SkPaint paint;
67
Mike Reed1be1f8d2018-03-14 13:01:17 -040068 paint.setMaskFilter(SkMaskFilter::MakeBlur(
robertphillips4e567722015-12-10 13:29:14 -080069 kNormal_SkBlurStyle,
Mike Reed1be1f8d2018-03-14 13:01:17 -040070 1.366025f));
reedd053ce92016-03-22 10:17:23 -070071 paint.setColorFilter(SkColorFilter::MakeModeFilter(
robertphillips4e567722015-12-10 13:29:14 -080072 SK_ColorRED,
Mike Reed7d954ad2016-10-28 15:42:34 -040073 SkBlendMode::kSrcIn));
robertphillips4e567722015-12-10 13:29:14 -080074 paint.setAntiAlias(true);
75
76 canvas->drawRRect(rr, paint);
77
78 canvas->restore();
79 canvas->restore();
80 canvas->restore();
81 }
82
83private:
mtkleindbfd7ab2016-09-01 11:24:54 -070084 static constexpr int kWidth = 1164;
85 static constexpr int kHeight = 802;
robertphillips4e567722015-12-10 13:29:14 -080086
87 typedef GM INHERITED;
88};
89
90//////////////////////////////////////////////////////////////////////////////
91
92DEF_GM(return new BlurredClippedCircleGM;)
93}