blob: f62cb1270e3b7f098cd2a2d3444916afd0205b6c [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"
robertphillips4e567722015-12-10 13:29:14 -080010#include "SkBlurMaskFilter.h"
Mike Reedebfce6d2016-12-12 10:02:12 -050011#include "SkClipOpPriv.h"
robertphillips4e567722015-12-10 13:29:14 -080012#include "SkColorFilter.h"
13#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
reedefdfd512016-04-04 10:02:58 -070068 paint.setMaskFilter(SkBlurMaskFilter::Make(
robertphillips4e567722015-12-10 13:29:14 -080069 kNormal_SkBlurStyle,
70 1.366025f,
reedefdfd512016-04-04 10:02:58 -070071 SkBlurMaskFilter::kHighQuality_BlurFlag));
reedd053ce92016-03-22 10:17:23 -070072 paint.setColorFilter(SkColorFilter::MakeModeFilter(
robertphillips4e567722015-12-10 13:29:14 -080073 SK_ColorRED,
Mike Reed7d954ad2016-10-28 15:42:34 -040074 SkBlendMode::kSrcIn));
robertphillips4e567722015-12-10 13:29:14 -080075 paint.setAntiAlias(true);
76
77 canvas->drawRRect(rr, paint);
78
79 canvas->restore();
80 canvas->restore();
81 canvas->restore();
82 }
83
84private:
mtkleindbfd7ab2016-09-01 11:24:54 -070085 static constexpr int kWidth = 1164;
86 static constexpr int kHeight = 802;
robertphillips4e567722015-12-10 13:29:14 -080087
88 typedef GM INHERITED;
89};
90
91//////////////////////////////////////////////////////////////////////////////
92
93DEF_GM(return new BlurredClippedCircleGM;)
94}