blob: 22e49c5f00e507ba25640ee97cb80665c8f48272 [file] [log] [blame]
Herb Derbya48ae6e2017-07-10 13:49:05 -04001/*
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
Herb Derbya48ae6e2017-07-10 13:49:05 -04008#include "SkBlurImageFilter.h"
Mike Reed1be1f8d2018-03-14 13:01:17 -04009#include "SkMaskFilter.h"
Herb Derbya48ae6e2017-07-10 13:49:05 -040010#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
Mike Reed1be1f8d2018-03-14 13:01:17 -040041 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma));
Herb Derbya48ae6e2017-07-10 13:49:05 -040042 canvas->drawRect(r, paint);
43 paint.setMaskFilter(nullptr);
44
45 SkPaint imageBlurPaint;
46 r.offset(250, 0);
47 imageBlurPaint.setImageFilter(SkBlurImageFilter::Make(sigma, sigma, nullptr));
48 canvas->saveLayer(nullptr, &imageBlurPaint);
49
50 canvas->drawRect(r, paint);
51 canvas->restore();
52 r.offset(-500, 200);
53 }
54
55}
Mike Reed28266272018-01-17 23:04:04 -050056
57#include "Resources.h"
58DEF_SIMPLE_GM(blur_image, canvas, 500, 500) {
59 auto image = GetResourceAsImage("images/mandrill_128.png");
60
61 SkPaint paint;
Mike Reed1be1f8d2018-03-14 13:01:17 -040062 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 4));
Mike Reed28266272018-01-17 23:04:04 -050063
64 // both of these should draw with the blur, but (formerally) we had a bug where the unscaled
65 // version (taking the spriteblitter code path) ignore the maskfilter.
66
67 canvas->drawImage(image, 10, 10, &paint);
68 canvas->scale(1.01f, 1.01f);
69 canvas->drawImage(image, 10 + image->width() + 10.f, 10, &paint);
70}