2017-12-20 19:36:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColor.h"
|
|
|
|
#include "include/core/SkImageFilter.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/effects/SkBlurImageFilter.h"
|
2017-12-20 19:36:53 +00:00
|
|
|
|
2019-05-01 14:59:30 +00:00
|
|
|
#include <initializer_list>
|
|
|
|
|
2017-12-20 19:36:53 +00:00
|
|
|
// For all sigma, the black box should be centered in the red outline. For small sigma,
|
|
|
|
// the rectangle is not blurred, but still must be centered properly.
|
|
|
|
|
|
|
|
DEF_SIMPLE_GM(check_small_sigma_offset, canvas, 200, 1200) {
|
|
|
|
|
|
|
|
for (auto sigma : {0.0, 0.1, 0.2, 0.3, 0.4, 0.6, 0.8, 1.0, 1.2}) {
|
|
|
|
// border calculation from SkBlurImageFilter
|
|
|
|
int border = SkScalarCeilToInt(sigma * 3);
|
|
|
|
|
|
|
|
SkRect r = SkRect::MakeXYWH(50, 50, 100, 50);
|
|
|
|
SkRect b = r.makeOutset(border + 1, border + 1);
|
|
|
|
b.inset(0.5f, 0.5f);
|
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorRED);
|
|
|
|
p.setStyle(SkPaint::Style::kStroke_Style);
|
|
|
|
|
|
|
|
canvas->drawRect(b, p);
|
|
|
|
|
|
|
|
p.reset();
|
|
|
|
p.setColor(SK_ColorBLACK);
|
|
|
|
p.setImageFilter(SkBlurImageFilter::Make(sigma, sigma, nullptr));
|
|
|
|
canvas->drawRect(r, p);
|
|
|
|
|
|
|
|
canvas->translate(0, 100);
|
|
|
|
}
|
|
|
|
}
|