Herb Derby | a48ae6e | 2017-07-10 13:49:05 -0400 | [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 | |
Herb Derby | a48ae6e | 2017-07-10 13:49:05 -0400 | [diff] [blame] | 8 | #include "SkBlurImageFilter.h" |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 9 | #include "SkMaskFilter.h" |
Herb Derby | a48ae6e | 2017-07-10 13:49:05 -0400 | [diff] [blame] | 10 | #include "gm.h" |
| 11 | #include "sk_tool_utils.h" |
| 12 | |
| 13 | |
| 14 | DEF_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 Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 41 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma)); |
Herb Derby | a48ae6e | 2017-07-10 13:49:05 -0400 | [diff] [blame] | 42 | 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 Reed | 2826627 | 2018-01-17 23:04:04 -0500 | [diff] [blame] | 56 | |
| 57 | #include "Resources.h" |
| 58 | DEF_SIMPLE_GM(blur_image, canvas, 500, 500) { |
| 59 | auto image = GetResourceAsImage("images/mandrill_128.png"); |
| 60 | |
| 61 | SkPaint paint; |
Mike Reed | 1be1f8d | 2018-03-14 13:01:17 -0400 | [diff] [blame] | 62 | paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 4)); |
Mike Reed | 2826627 | 2018-01-17 23:04:04 -0500 | [diff] [blame] | 63 | |
| 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 | } |