blob: 7fe412e8b2f8bf017b6111074c4b1fa19225be88 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "gm/gm.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -04009#include "include/core/SkBlendMode.h"
10#include "include/core/SkBlurTypes.h"
11#include "include/core/SkCanvas.h"
12#include "include/core/SkColor.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050013#include "include/core/SkColorFilter.h"
14#include "include/core/SkMaskFilter.h"
15#include "include/core/SkPaint.h"
16#include "include/core/SkRRect.h"
Ben Wagner6a34f3a2019-05-01 10:59:30 -040017#include "include/core/SkRect.h"
18#include "include/core/SkScalar.h"
19#include "include/core/SkSize.h"
20#include "include/core/SkString.h"
robertphillips4e567722015-12-10 13:29:14 -080021
22namespace skiagm {
23
24// This GM reproduces the precision artifacts seen in crbug.com/560651.
25// It draws a largish blurred circle with its center clipped out.
26class BlurredClippedCircleGM : public GM {
27public:
28 BlurredClippedCircleGM() {
Mike Kleind46dce32018-08-16 10:17:03 -040029 this->setBGColor(0xFFCCCCCC);
robertphillips4e567722015-12-10 13:29:14 -080030 }
31
32protected:
Leandro Lovisolo24fa2112023-08-15 19:05:17 +000033 SkString getName() const override { return SkString("blurredclippedcircle"); }
robertphillips4e567722015-12-10 13:29:14 -080034
Leandro Lovisolo8f023882023-08-15 21:13:52 +000035 SkISize getISize() override { return SkISize::Make(kWidth, kHeight); }
robertphillips4e567722015-12-10 13:29:14 -080036
37 void onDraw(SkCanvas* canvas) override {
38 SkPaint whitePaint;
39 whitePaint.setColor(SK_ColorWHITE);
reed374772b2016-10-05 17:33:02 -070040 whitePaint.setBlendMode(SkBlendMode::kSrc);
robertphillips4e567722015-12-10 13:29:14 -080041 whitePaint.setAntiAlias(true);
42
43 // This scale exercises precision limits in the circle blur effect (crbug.com/560651)
mtkleindbfd7ab2016-09-01 11:24:54 -070044 constexpr float kScale = 2.0f;
robertphillips4e567722015-12-10 13:29:14 -080045 canvas->scale(kScale, kScale);
46
47 canvas->save();
Michael Ludwig2f6e2f82021-08-03 13:08:50 -040048 SkRect clipRect1 = SkRect::MakeLTRB(0, 0, kWidth, kHeight);
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);
Michael Ludwig2f6e2f82021-08-03 13:08:50 -040060 canvas->clipRRect(clipRRect, SkClipOp::kDifference, 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));
Michael Ludwig2f6e2f82021-08-03 13:08:50 -040070 paint.setColorFilter(SkColorFilters::Blend(SK_ColorRED, SkBlendMode::kSrcIn));
robertphillips4e567722015-12-10 13:29:14 -080071 paint.setAntiAlias(true);
72
73 canvas->drawRRect(rr, paint);
74
75 canvas->restore();
76 canvas->restore();
77 canvas->restore();
78 }
79
80private:
Brian Salomon9fa47cc2021-10-08 18:48:26 -040081 inline static constexpr int kWidth = 1164;
82 inline static constexpr int kHeight = 802;
robertphillips4e567722015-12-10 13:29:14 -080083
John Stiles7571f9e2020-09-02 22:42:33 -040084 using INHERITED = GM;
robertphillips4e567722015-12-10 13:29:14 -080085};
86
87//////////////////////////////////////////////////////////////////////////////
88
89DEF_GM(return new BlurredClippedCircleGM;)
John Stilesa6841be2020-08-06 14:11:56 -040090} // namespace skiagm