blob: 23bacdcceb409bf5e5593b1209490705ac761abc [file] [log] [blame]
Herb Derby010d39d2017-12-20 14:36:53 -05001/*
2 * Copyright 2017 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 "SkBlurImageFilter.h"
10
11// For all sigma, the black box should be centered in the red outline. For small sigma,
12// the rectangle is not blurred, but still must be centered properly.
13
14DEF_SIMPLE_GM(check_small_sigma_offset, canvas, 200, 1200) {
15
16 for (auto sigma : {0.0, 0.1, 0.2, 0.3, 0.4, 0.6, 0.8, 1.0, 1.2}) {
17 // border calculation from SkBlurImageFilter
18 int border = SkScalarCeilToInt(sigma * 3);
19
20 SkRect r = SkRect::MakeXYWH(50, 50, 100, 50);
21 SkRect b = r.makeOutset(border + 1, border + 1);
22 b.inset(0.5f, 0.5f);
23 SkPaint p;
24 p.setColor(SK_ColorRED);
25 p.setStyle(SkPaint::Style::kStroke_Style);
26
27 canvas->drawRect(b, p);
28
29 p.reset();
30 p.setColor(SK_ColorBLACK);
31 p.setImageFilter(SkBlurImageFilter::Make(sigma, sigma, nullptr));
32 canvas->drawRect(r, p);
33
34 canvas->translate(0, 100);
35 }
36}