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 "SkBlurImageFilter.h" 9 #include "SkMaskFilter.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 SkFont font(sk_tool_utils::create_portable_typeface(), 25); 20 21 const double sigmas[] = {3.0, 8.0, 16.0, 24.0, 32.0}; 22 23 canvas->drawString("mask blur", 285, 50, font, paint); 24 canvas->drawString("image blur", 285 + 250, 50, font, paint); 25 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); 34 canvas->drawString(out, r.left(), r.bottom() + 35, font, paint); 35 36 r.offset(250, 0); 37 38 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, sigma)); 39 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 } 53 54 #include "Resources.h" 55 DEF_SIMPLE_GM_CAN_FAIL(blur_image, canvas, errorMsg, 500, 500) { 56 auto image = GetResourceAsImage("images/mandrill_128.png"); 57 if (!image) { 58 *errorMsg = "Could not load mandrill_128.png. Did you forget to set the resourcePath?"; 59 return skiagm::DrawResult::kFail; 60 } 61 62 SkPaint paint; 63 paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, 4)); 64 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); 71 return skiagm::DrawResult::kOk; 72 } 73