Flutter Engine
The Flutter Engine
Functions
blurimagevmask.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBlurTypes.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFont.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkMaskFilter.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkString.h"
#include "include/core/SkTypeface.h"
#include "include/effects/SkImageFilters.h"
#include "tools/DecodeUtils.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include <stdio.h>

Go to the source code of this file.

Functions

 DEF_SIMPLE_GM (blurimagevmask, canvas, 700, 1200)
 
 DEF_SIMPLE_GM_CAN_FAIL (blur_image, canvas, errorMsg, 500, 500)
 

Function Documentation

◆ DEF_SIMPLE_GM()

DEF_SIMPLE_GM ( blurimagevmask  ,
canvas  ,
700  ,
1200   
)

Definition at line 29 of file blurimagevmask.cpp.

29 {
31 paint.setAntiAlias(true);
32 paint.setColor(SK_ColorBLACK);
33
35
36 const double sigmas[] = {3.0, 8.0, 16.0, 24.0, 32.0};
37
38 canvas->drawString("mask blur", 285, 50, font, paint);
39 canvas->drawString("image blur", 285 + 250, 50, font, paint);
40
41
42 SkRect r = {35, 100, 135, 200};
43 for (auto sigma:sigmas) {
44
45 canvas->drawRect(r, paint);
46
47 char out[100];
48 sprintf(out, "Sigma: %g", sigma);
49 canvas->drawString(out, r.left(), r.bottom() + 35, font, paint);
50
51 r.offset(250, 0);
52
54 canvas->drawRect(r, paint);
55 paint.setMaskFilter(nullptr);
56
57 SkPaint imageBlurPaint;
58 r.offset(250, 0);
59 imageBlurPaint.setImageFilter(SkImageFilters::Blur(sigma, sigma, nullptr));
60 canvas->saveLayer(nullptr, &imageBlurPaint);
61
62 canvas->drawRect(r, paint);
63 canvas->restore();
64 r.offset(-500, 200);
65 }
66
67}
@ kNormal_SkBlurStyle
fuzzy inside and outside
Definition: SkBlurTypes.h:12
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
Definition: SkFont.h:35
static sk_sp< SkImageFilter > Blur(SkScalar sigmaX, SkScalar sigmaY, SkTileMode tileMode, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkMaskFilter > MakeBlur(SkBlurStyle style, SkScalar sigma, bool respectCTM=true)
void setImageFilter(sk_sp< SkImageFilter > imageFilter)
const Paint & paint
Definition: color_source.cc:38
sk_sp< SkTypeface > DefaultPortableTypeface()
font
Font Metadata and Metrics.
constexpr float left() const
Definition: SkRect.h:734
void offset(float dx, float dy)
Definition: SkRect.h:1016
constexpr float bottom() const
Definition: SkRect.h:755

◆ DEF_SIMPLE_GM_CAN_FAIL()

DEF_SIMPLE_GM_CAN_FAIL ( blur_image  ,
canvas  ,
errorMsg  ,
500  ,
500   
)

Definition at line 69 of file blurimagevmask.cpp.

69 {
70 auto image = ToolUtils::GetResourceAsImage("images/mandrill_128.png");
71 if (!image) {
72 *errorMsg = "Could not load mandrill_128.png. Did you forget to set the resourcePath?";
74 }
75
78
79 // both of these should draw with the blur, but (formerally) we had a bug where the unscaled
80 // version (taking the spriteblitter code path) ignore the maskfilter.
81
82 canvas->drawImage(image, 10, 10, SkSamplingOptions(), &paint);
83 canvas->scale(1.01f, 1.01f);
84 canvas->drawImage(image, 10 + image->width() + 10.f, 10, SkSamplingOptions(), &paint);
86}
int width() const
Definition: SkImage.h:285
sk_sp< const SkImage > image
Definition: SkRecords.h:269
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
SkSamplingOptions(SkFilterMode::kLinear))