blob: 9a213d511b3caa09cc6c09a44a2c3938ff8a0504 [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
Mike Reed4de2f1f2019-01-05 16:35:13 -050019 SkFont font(sk_tool_utils::create_portable_typeface(), 25);
Herb Derbya48ae6e2017-07-10 13:49:05 -040020
21 const double sigmas[] = {3.0, 8.0, 16.0, 24.0, 32.0};
22
Mike Reed4de2f1f2019-01-05 16:35:13 -050023 canvas->drawString("mask blur", 285, 50, font, paint);
24 canvas->drawString("image blur", 285 + 250, 50, font, paint);
Herb Derbya48ae6e2017-07-10 13:49:05 -040025
26
27 SkRect r = {35, 100, 135, 200};
28 for (auto sigma:sigmas) {
29
30 canvas->drawRect(r, paint);
31
32 char out[100];
33 sprintf(out, "Sigma: %g", sigma);
Mike Reed4de2f1f2019-01-05 16:35:13 -050034 canvas->drawString(out, r.left(), r.bottom() + 35, font, paint);
Herb Derbya48ae6e2017-07-10 13:49:05 -040035
36 r.offset(250, 0);
37
Mike Reed1be1f8d2018-03-14 13:01:17 -040038 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma));
Herb Derbya48ae6e2017-07-10 13:49:05 -040039 canvas->drawRect(r, paint);
40 paint.setMaskFilter(nullptr);
41
42 SkPaint imageBlurPaint;
43 r.offset(250, 0);
44 imageBlurPaint.setImageFilter(SkBlurImageFilter::Make(sigma, sigma, nullptr));
45 canvas->saveLayer(nullptr, &imageBlurPaint);
46
47 canvas->drawRect(r, paint);
48 canvas->restore();
49 r.offset(-500, 200);
50 }
51
52}
Mike Reed28266272018-01-17 23:04:04 -050053
54#include "Resources.h"
Chris Dalton50e24d72019-02-07 16:20:09 -070055DEF_SIMPLE_GM_CAN_FAIL(blur_image, canvas, errorMsg, 500, 500) {
Mike Reed28266272018-01-17 23:04:04 -050056 auto image = GetResourceAsImage("images/mandrill_128.png");
Hal Canarybaa2a282018-11-26 15:34:12 -050057 if (!image) {
Chris Dalton50e24d72019-02-07 16:20:09 -070058 *errorMsg = "Could not load mandrill_128.png. Did you forget to set the resourcePath?";
59 return skiagm::DrawResult::kFail;
Hal Canarybaa2a282018-11-26 15:34:12 -050060 }
Mike Reed28266272018-01-17 23:04:04 -050061
62 SkPaint paint;
Mike Reed1be1f8d2018-03-14 13:01:17 -040063 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 4));
Mike Reed28266272018-01-17 23:04:04 -050064
65 // both of these should draw with the blur, but (formerally) we had a bug where the unscaled
66 // version (taking the spriteblitter code path) ignore the maskfilter.
67
68 canvas->drawImage(image, 10, 10, &paint);
69 canvas->scale(1.01f, 1.01f);
70 canvas->drawImage(image, 10 + image->width() + 10.f, 10, &paint);
Chris Dalton50e24d72019-02-07 16:20:09 -070071 return skiagm::DrawResult::kOk;
Mike Reed28266272018-01-17 23:04:04 -050072}