blob: 65e62b7e65f19ab753b2fafc389653a4ab51d66d [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 Reedebfce6d2016-12-12 10:02:12 -05009#include "SkClipOpPriv.h"
robertphillips4e567722015-12-10 13:29:14 -080010#include "SkColorFilter.h"
Mike Reed1be1f8d2018-03-14 13:01:17 -040011#include "SkMaskFilter.h"
robertphillips4e567722015-12-10 13:29:14 -080012#include "SkPaint.h"
13#include "SkRRect.h"
14
15namespace skiagm {
16
17// This GM reproduces the precision artifacts seen in crbug.com/560651.
18// It draws a largish blurred circle with its center clipped out.
19class BlurredClippedCircleGM : public GM {
20public:
21 BlurredClippedCircleGM() {
Mike Kleind46dce32018-08-16 10:17:03 -040022 this->setBGColor(0xFFCCCCCC);
robertphillips4e567722015-12-10 13:29:14 -080023 }
24
25protected:
26
27 SkString onShortName() override {
28 return SkString("blurredclippedcircle");
29 }
30
31 SkISize onISize() override {
32 return SkISize::Make(kWidth, kHeight);
33 }
34
35 void onDraw(SkCanvas* canvas) override {
36 SkPaint whitePaint;
37 whitePaint.setColor(SK_ColorWHITE);
reed374772b2016-10-05 17:33:02 -070038 whitePaint.setBlendMode(SkBlendMode::kSrc);
robertphillips4e567722015-12-10 13:29:14 -080039 whitePaint.setAntiAlias(true);
40
41 // This scale exercises precision limits in the circle blur effect (crbug.com/560651)
mtkleindbfd7ab2016-09-01 11:24:54 -070042 constexpr float kScale = 2.0f;
robertphillips4e567722015-12-10 13:29:14 -080043 canvas->scale(kScale, kScale);
44
45 canvas->save();
46 SkRect clipRect1 = SkRect::MakeLTRB(0, 0,
47 SkIntToScalar(kWidth), SkIntToScalar(kHeight));
48
reed73603f32016-09-20 08:42:38 -070049 canvas->clipRect(clipRect1);
robertphillips4e567722015-12-10 13:29:14 -080050
51 canvas->save();
52
reed73603f32016-09-20 08:42:38 -070053 canvas->clipRect(clipRect1);
robertphillips4e567722015-12-10 13:29:14 -080054 canvas->drawRect(clipRect1, whitePaint);
55
56 canvas->save();
57
58 SkRect clipRect2 = SkRect::MakeLTRB(8, 8, 288, 288);
59 SkRRect clipRRect = SkRRect::MakeOval(clipRect2);
Mike Reedc1f77742016-12-09 09:00:50 -050060 canvas->clipRRect(clipRRect, kDifference_SkClipOp, true);
robertphillips4e567722015-12-10 13:29:14 -080061
62 SkRect r = SkRect::MakeLTRB(4, 4, 292, 292);
63 SkRRect rr = SkRRect::MakeOval(r);
64
65 SkPaint paint;
66
Mike Reed1be1f8d2018-03-14 13:01:17 -040067 paint.setMaskFilter(SkMaskFilter::MakeBlur(
robertphillips4e567722015-12-10 13:29:14 -080068 kNormal_SkBlurStyle,
Mike Reed1be1f8d2018-03-14 13:01:17 -040069 1.366025f));
reedd053ce92016-03-22 10:17:23 -070070 paint.setColorFilter(SkColorFilter::MakeModeFilter(
robertphillips4e567722015-12-10 13:29:14 -080071 SK_ColorRED,
Mike Reed7d954ad2016-10-28 15:42:34 -040072 SkBlendMode::kSrcIn));
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}