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 | |
| 8 | #include "SkBlurMaskFilter.h" |
| 9 | #include "SkBlurImageFilter.h" |
| 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 | |
| 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 | } |