Herb Derby | 010d39d | 2017-12-20 14:36:53 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
| 10 | #include "include/core/SkColor.h" |
| 11 | #include "include/core/SkImageFilter.h" |
| 12 | #include "include/core/SkPaint.h" |
| 13 | #include "include/core/SkRect.h" |
| 14 | #include "include/core/SkScalar.h" |
Michael Ludwig | 898bbfa | 2019-08-02 15:21:23 -0400 | [diff] [blame] | 15 | #include "include/effects/SkImageFilters.h" |
Herb Derby | 010d39d | 2017-12-20 14:36:53 -0500 | [diff] [blame] | 16 | |
Ben Wagner | 6a34f3a | 2019-05-01 10:59:30 -0400 | [diff] [blame] | 17 | #include <initializer_list> |
| 18 | |
Herb Derby | 010d39d | 2017-12-20 14:36:53 -0500 | [diff] [blame] | 19 | // For all sigma, the black box should be centered in the red outline. For small sigma, |
| 20 | // the rectangle is not blurred, but still must be centered properly. |
| 21 | |
| 22 | DEF_SIMPLE_GM(check_small_sigma_offset, canvas, 200, 1200) { |
| 23 | |
| 24 | for (auto sigma : {0.0, 0.1, 0.2, 0.3, 0.4, 0.6, 0.8, 1.0, 1.2}) { |
| 25 | // border calculation from SkBlurImageFilter |
| 26 | int border = SkScalarCeilToInt(sigma * 3); |
| 27 | |
| 28 | SkRect r = SkRect::MakeXYWH(50, 50, 100, 50); |
| 29 | SkRect b = r.makeOutset(border + 1, border + 1); |
| 30 | b.inset(0.5f, 0.5f); |
| 31 | SkPaint p; |
| 32 | p.setColor(SK_ColorRED); |
| 33 | p.setStyle(SkPaint::Style::kStroke_Style); |
| 34 | |
| 35 | canvas->drawRect(b, p); |
| 36 | |
| 37 | p.reset(); |
| 38 | p.setColor(SK_ColorBLACK); |
Michael Ludwig | 898bbfa | 2019-08-02 15:21:23 -0400 | [diff] [blame] | 39 | p.setImageFilter(SkImageFilters::Blur(sigma, sigma, nullptr)); |
Herb Derby | 010d39d | 2017-12-20 14:36:53 -0500 | [diff] [blame] | 40 | canvas->drawRect(r, p); |
| 41 | |
| 42 | canvas->translate(0, 100); |
| 43 | } |
| 44 | } |