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
8#include "SkBlurMaskFilter.h"
9#include "SkBlurImageFilter.h"
10#include "gm.h"
11#include "sk_tool_utils.h"
12
13
14DEF_SIMPLE_GM(blurimagevmask, canvas, 700, 1200) {
15    SkPaint paint;
16    paint.setAntiAlias(true);
17    paint.setColor(SK_ColorBLACK);
18
19    SkPaint textPaint;
20    textPaint.setAntiAlias(true);
21    sk_tool_utils::set_portable_typeface(&textPaint);
22    textPaint.setTextSize(SkIntToScalar(25));
23
24    const double sigmas[] = {3.0, 8.0, 16.0, 24.0, 32.0};
25
26    canvas->drawString("mask blur",  285, 50, textPaint);
27    canvas->drawString("image blur", 285 + 250, 50, textPaint);
28
29
30    SkRect r = {35, 100, 135, 200};
31    for (auto sigma:sigmas) {
32
33        canvas->drawRect(r, paint);
34
35        char out[100];
36        sprintf(out, "Sigma: %g", sigma);
37        canvas->drawString(out, r.left(), r.bottom() + 35, textPaint);
38
39        r.offset(250, 0);
40
41        paint.setMaskFilter(
42            SkBlurMaskFilter::Make(kNormal_SkBlurStyle, sigma,
43                                   SkBlurMaskFilter::kHighQuality_BlurFlag));
44        canvas->drawRect(r, paint);
45        paint.setMaskFilter(nullptr);
46
47        SkPaint imageBlurPaint;
48        r.offset(250, 0);
49        imageBlurPaint.setImageFilter(SkBlurImageFilter::Make(sigma, sigma, nullptr));
50        canvas->saveLayer(nullptr, &imageBlurPaint);
51
52        canvas->drawRect(r, paint);
53        canvas->restore();
54        r.offset(-500, 200);
55    }
56
57}
58
59#include "Resources.h"
60DEF_SIMPLE_GM(blur_image, canvas, 500, 500) {
61    auto image = GetResourceAsImage("images/mandrill_128.png");
62
63    SkPaint paint;
64    paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 4));
65
66    // both of these should draw with the blur, but (formerally) we had a bug where the unscaled
67    // version (taking the spriteblitter code path) ignore the maskfilter.
68
69    canvas->drawImage(image, 10, 10, &paint);
70    canvas->scale(1.01f, 1.01f);
71    canvas->drawImage(image, 10 + image->width() + 10.f, 10, &paint);
72}
73