reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 1 | /* |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 2 | * Copyright 2012 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 | */ |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 7 | |
| 8 | #include "gm.h" |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 9 | #include "SkBlurMask.h" |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 10 | #include "SkBlurMaskFilter.h" |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 11 | #include "SkCanvas.h" |
| 12 | #include "SkPath.h" |
| 13 | |
| 14 | #define STROKE_WIDTH SkIntToScalar(10) |
| 15 | |
| 16 | typedef void (*Proc)(SkCanvas*, const SkRect&, const SkPaint&); |
| 17 | |
| 18 | static void fill_rect(SkCanvas* canvas, const SkRect& r, const SkPaint& p) { |
| 19 | canvas->drawRect(r, p); |
| 20 | } |
| 21 | |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 22 | static void draw_donut(SkCanvas* canvas, const SkRect& r, const SkPaint& p) { |
| 23 | SkRect rect; |
| 24 | SkPath path; |
skia.committer@gmail.com | 3458716 | 2012-11-20 02:01:23 +0000 | [diff] [blame] | 25 | |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 26 | rect = r; |
| 27 | rect.outset(STROKE_WIDTH/2, STROKE_WIDTH/2); |
| 28 | path.addRect(rect); |
| 29 | rect = r; |
| 30 | rect.inset(STROKE_WIDTH/2, STROKE_WIDTH/2); |
skia.committer@gmail.com | 3458716 | 2012-11-20 02:01:23 +0000 | [diff] [blame] | 31 | |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 32 | path.addRect(rect); |
| 33 | path.setFillType(SkPath::kEvenOdd_FillType); |
skia.committer@gmail.com | 3458716 | 2012-11-20 02:01:23 +0000 | [diff] [blame] | 34 | |
reed@google.com | 808b70f | 2012-11-19 16:14:02 +0000 | [diff] [blame] | 35 | canvas->drawPath(path, p); |
| 36 | } |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 37 | |
reed@google.com | 808b70f | 2012-11-19 16:14:02 +0000 | [diff] [blame] | 38 | static void draw_donut_skewed(SkCanvas* canvas, const SkRect& r, const SkPaint& p) { |
| 39 | SkRect rect; |
| 40 | SkPath path; |
skia.committer@gmail.com | 3458716 | 2012-11-20 02:01:23 +0000 | [diff] [blame] | 41 | |
reed@google.com | 808b70f | 2012-11-19 16:14:02 +0000 | [diff] [blame] | 42 | rect = r; |
| 43 | rect.outset(STROKE_WIDTH/2, STROKE_WIDTH/2); |
| 44 | path.addRect(rect); |
| 45 | rect = r; |
| 46 | rect.inset(STROKE_WIDTH/2, STROKE_WIDTH/2); |
skia.committer@gmail.com | 3458716 | 2012-11-20 02:01:23 +0000 | [diff] [blame] | 47 | |
reed@google.com | 808b70f | 2012-11-19 16:14:02 +0000 | [diff] [blame] | 48 | rect.offset(7, -7); |
skia.committer@gmail.com | 3458716 | 2012-11-20 02:01:23 +0000 | [diff] [blame] | 49 | |
reed@google.com | 808b70f | 2012-11-19 16:14:02 +0000 | [diff] [blame] | 50 | path.addRect(rect); |
| 51 | path.setFillType(SkPath::kEvenOdd_FillType); |
skia.committer@gmail.com | 3458716 | 2012-11-20 02:01:23 +0000 | [diff] [blame] | 52 | |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 53 | canvas->drawPath(path, p); |
| 54 | } |
| 55 | |
reed@google.com | 53007a2 | 2012-11-26 14:39:50 +0000 | [diff] [blame] | 56 | #include "SkGradientShader.h" |
| 57 | |
| 58 | typedef void (*PaintProc)(SkPaint*, SkScalar width); |
| 59 | |
reed@google.com | 57850b9 | 2012-12-17 21:20:53 +0000 | [diff] [blame] | 60 | static const char* gBlurStyle2Name[] = { |
| 61 | "normal", |
| 62 | "solid", |
| 63 | "outer", |
| 64 | "inner" |
| 65 | }; |
| 66 | |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 67 | class BlurRectGM : public skiagm::GM { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 68 | SkAutoTUnref<SkMaskFilter> fMaskFilter; |
| 69 | SkString fName; |
| 70 | PaintProc fPProc; |
| 71 | SkAlpha fAlpha; |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 72 | public: |
reed@google.com | 57850b9 | 2012-12-17 21:20:53 +0000 | [diff] [blame] | 73 | BlurRectGM(const char name[], PaintProc pproc, U8CPU alpha, |
skia.committer@gmail.com | 7bd141d | 2013-08-28 07:01:18 +0000 | [diff] [blame] | 74 | SkBlurMaskFilter::BlurStyle bs) |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 75 | : fMaskFilter(SkBlurMaskFilter::Create(bs, |
| 76 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(STROKE_WIDTH/2)), |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 77 | SkBlurMaskFilter::kHighQuality_BlurFlag)) |
| 78 | , fName(name) |
| 79 | , fPProc(pproc) |
| 80 | , fAlpha(SkToU8(alpha)) { |
reed@google.com | 57850b9 | 2012-12-17 21:20:53 +0000 | [diff] [blame] | 81 | fName.appendf("_%s", gBlurStyle2Name[bs]); |
| 82 | } |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 83 | |
| 84 | protected: |
| 85 | virtual SkString onShortName() { |
reed@google.com | 53007a2 | 2012-11-26 14:39:50 +0000 | [diff] [blame] | 86 | return fName; |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | virtual SkISize onISize() { |
| 90 | return SkISize::Make(640, 480); |
| 91 | } |
| 92 | |
| 93 | virtual void onDraw(SkCanvas* canvas) { |
| 94 | canvas->translate(STROKE_WIDTH*3/2, STROKE_WIDTH*3/2); |
| 95 | |
reed@google.com | 53007a2 | 2012-11-26 14:39:50 +0000 | [diff] [blame] | 96 | SkRect r = { 0, 0, 250, 120 }; |
skia.committer@gmail.com | 8ccf590 | 2012-11-27 02:01:19 +0000 | [diff] [blame] | 97 | |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 98 | SkPaint paint; |
| 99 | paint.setMaskFilter(fMaskFilter); |
reed@google.com | 53007a2 | 2012-11-26 14:39:50 +0000 | [diff] [blame] | 100 | if (fPProc) { |
| 101 | fPProc(&paint, r.width()); |
| 102 | } |
| 103 | paint.setAlpha(fAlpha); |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 104 | |
| 105 | static const Proc procs[] = { |
reed@google.com | 808b70f | 2012-11-19 16:14:02 +0000 | [diff] [blame] | 106 | fill_rect, draw_donut, draw_donut_skewed |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 109 | this->drawProcs(canvas, r, paint, false, procs, SK_ARRAY_COUNT(procs)); |
| 110 | canvas->translate(r.width() * 4/3, 0); |
| 111 | this->drawProcs(canvas, r, paint, true, procs, SK_ARRAY_COUNT(procs)); |
| 112 | } |
| 113 | |
| 114 | virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; } |
| 115 | |
| 116 | private: |
| 117 | void drawProcs(SkCanvas* canvas, const SkRect& r, const SkPaint& paint, |
| 118 | bool doClip, const Proc procs[], size_t procsCount) { |
| 119 | SkAutoCanvasRestore acr(canvas, true); |
| 120 | for (size_t i = 0; i < procsCount; ++i) { |
| 121 | if (doClip) { |
| 122 | SkRect clipRect(r); |
| 123 | clipRect.inset(STROKE_WIDTH/2, STROKE_WIDTH/2); |
| 124 | canvas->save(); |
| 125 | canvas->clipRect(r); |
| 126 | } |
| 127 | procs[i](canvas, r, paint); |
| 128 | if (doClip) { |
| 129 | canvas->restore(); |
| 130 | } |
| 131 | canvas->translate(0, r.height() * 4/3); |
| 132 | } |
| 133 | } |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 134 | private: |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 135 | typedef GM INHERITED; |
| 136 | }; |
| 137 | |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 138 | class BlurRectCompareGM : public skiagm::GM { |
| 139 | SkString fName; |
| 140 | unsigned int fRectWidth, fRectHeight; |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 141 | SkScalar fRadius; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 142 | SkBlurMask::Style fStyle; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 143 | public: |
skia.committer@gmail.com | b3ec29d | 2013-09-07 07:01:16 +0000 | [diff] [blame] | 144 | BlurRectCompareGM(const char name[], unsigned int rectWidth, |
| 145 | unsigned int rectHeight, float radius, |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 146 | SkBlurMask::Style style) |
bsalomon@google.com | 33cdbde | 2013-01-11 20:54:44 +0000 | [diff] [blame] | 147 | : fName(name) |
| 148 | , fRectWidth(rectWidth) |
| 149 | , fRectHeight(rectHeight) |
| 150 | , fRadius(radius) |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 151 | , fStyle(style) { |
| 152 | } |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 153 | int width() const { |
| 154 | return fRectWidth; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 155 | } |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 156 | int height() const { |
| 157 | return fRectHeight; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 158 | } |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 159 | SkScalar radius() const { |
| 160 | return fRadius; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 161 | } |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 162 | SkBlurMask::Style style() const { |
| 163 | return fStyle; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 164 | } |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 165 | |
| 166 | protected: |
| 167 | virtual SkString onShortName() { |
| 168 | return fName; |
| 169 | } |
| 170 | |
| 171 | virtual SkISize onISize() { |
| 172 | return SkISize::Make(640, 480); |
| 173 | } |
skia.committer@gmail.com | 8ae714b | 2013-01-05 02:02:05 +0000 | [diff] [blame] | 174 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 175 | virtual bool makeMask(SkMask *m, const SkRect&) = 0; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 176 | |
| 177 | virtual void onDraw(SkCanvas* canvas) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 178 | SkRect r; |
| 179 | r.setWH(SkIntToScalar(fRectWidth), SkIntToScalar(fRectHeight)); |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 180 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 181 | SkISize canvas_size = canvas->getDeviceSize(); |
jvanverth@google.com | d98df1a | 2013-02-20 19:02:34 +0000 | [diff] [blame] | 182 | int center_x = (canvas_size.fWidth - (int)(r.width()))/2; |
| 183 | int center_y = (canvas_size.fHeight - (int)(r.height()))/2; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 184 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 185 | SkMask mask; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 186 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 187 | if (!this->makeMask(&mask, r)) { |
| 188 | SkPaint paint; |
jvanverth@google.com | d98df1a | 2013-02-20 19:02:34 +0000 | [diff] [blame] | 189 | r.offset( SkIntToScalar(center_x), SkIntToScalar(center_y) ); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 190 | canvas->drawRect(r,paint); |
| 191 | return; |
| 192 | } |
| 193 | SkAutoMaskFreeImage amfi(mask.fImage); |
| 194 | |
| 195 | SkBitmap bm; |
| 196 | bm.setConfig(SkBitmap::kA8_Config, mask.fBounds.width(), mask.fBounds.height()); |
| 197 | bm.setPixels(mask.fImage); |
| 198 | |
| 199 | center_x = (canvas_size.fWidth - mask.fBounds.width())/2; |
| 200 | center_y = (canvas_size.fHeight - mask.fBounds.height())/2; |
| 201 | |
jvanverth@google.com | d98df1a | 2013-02-20 19:02:34 +0000 | [diff] [blame] | 202 | canvas->drawBitmap(bm, SkIntToScalar(center_x), SkIntToScalar(center_y), NULL); |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; } |
| 206 | |
| 207 | private: |
| 208 | typedef GM INHERITED; |
| 209 | }; |
| 210 | |
| 211 | class BlurRectFastGM: public BlurRectCompareGM { |
| 212 | public: |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 213 | BlurRectFastGM(const char name[], unsigned int rectWidth, |
| 214 | unsigned int rectHeight, float blurRadius, |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 215 | SkBlurMask::Style style) : |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 216 | INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 217 | } |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 218 | |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 219 | protected: |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 220 | virtual bool makeMask(SkMask *m, const SkRect& r) SK_OVERRIDE { |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 221 | return SkBlurMask::BlurRect(SkBlurMask::ConvertRadiusToSigma(this->radius()), |
| 222 | m, r, this->style()); |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 223 | } |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 224 | private: |
| 225 | typedef BlurRectCompareGM INHERITED; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 226 | }; |
| 227 | |
| 228 | class BlurRectSlowGM: public BlurRectCompareGM { |
| 229 | public: |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 230 | BlurRectSlowGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, |
| 231 | float blurRadius, SkBlurMask::Style style) |
| 232 | : INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 233 | } |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 234 | |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 235 | protected: |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 236 | virtual bool makeMask(SkMask *m, const SkRect& r) SK_OVERRIDE { |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 237 | SkMask src; |
| 238 | r.roundOut(&src.fBounds); |
| 239 | src.fBounds.offset(-src.fBounds.fLeft, -src.fBounds.fTop); // move to origin |
| 240 | src.fFormat = SkMask::kA8_Format; |
| 241 | src.fRowBytes = src.fBounds.width(); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 242 | src.fImage = SkMask::AllocImage(src.computeTotalImageSize()); |
bsalomon@google.com | 33cdbde | 2013-01-11 20:54:44 +0000 | [diff] [blame] | 243 | SkAutoMaskFreeImage amfi(src.fImage); |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 244 | |
bsalomon@google.com | 33cdbde | 2013-01-11 20:54:44 +0000 | [diff] [blame] | 245 | memset(src.fImage, 0xff, src.computeTotalImageSize()); |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 246 | |
skia.committer@gmail.com | b3ec29d | 2013-09-07 07:01:16 +0000 | [diff] [blame] | 247 | return SkBlurMask::BoxBlur(m, src, |
| 248 | SkBlurMask::ConvertRadiusToSigma(this->radius()), |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 249 | this->style(), this->getQuality()); |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 250 | } |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 251 | |
| 252 | virtual SkBlurMask::Quality getQuality() { |
| 253 | return SkBlurMask::kHigh_Quality; |
| 254 | } |
| 255 | private: |
| 256 | typedef BlurRectCompareGM INHERITED; |
| 257 | }; |
| 258 | |
| 259 | class BlurRectSlowLowGM: public BlurRectSlowGM { |
| 260 | public: |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 261 | BlurRectSlowLowGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 262 | float blurRadius, SkBlurMask::Style style) |
| 263 | : INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 264 | } |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 265 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 266 | protected: |
| 267 | virtual SkBlurMask::Quality getQuality() SK_OVERRIDE { |
| 268 | return SkBlurMask::kLow_Quality; |
| 269 | } |
| 270 | private: |
| 271 | typedef BlurRectSlowGM INHERITED; |
| 272 | }; |
| 273 | |
| 274 | class BlurRectGroundTruthGM: public BlurRectCompareGM { |
| 275 | public: |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 276 | BlurRectGroundTruthGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 277 | float blurRadius, SkBlurMask::Style style) |
| 278 | : INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 279 | } |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 280 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 281 | protected: |
| 282 | virtual bool makeMask(SkMask *m, const SkRect& r) SK_OVERRIDE { |
| 283 | SkMask src; |
| 284 | r.roundOut(&src.fBounds); |
| 285 | src.fBounds.offset(-src.fBounds.fLeft, -src.fBounds.fTop); // move to origin |
| 286 | src.fFormat = SkMask::kA8_Format; |
| 287 | src.fRowBytes = src.fBounds.width(); |
| 288 | src.fImage = SkMask::AllocImage(src.computeTotalImageSize()); |
| 289 | SkAutoMaskFreeImage amfi(src.fImage); |
| 290 | |
| 291 | memset(src.fImage, 0xff, src.computeTotalImageSize()); |
| 292 | |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 293 | return SkBlurMask::BlurGroundTruth(SkBlurMask::ConvertRadiusToSigma(this->radius()), |
| 294 | m, src, this->style()); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | virtual SkBlurMask::Quality getQuality() { |
| 298 | return SkBlurMask::kHigh_Quality; |
| 299 | } |
| 300 | private: |
| 301 | typedef BlurRectCompareGM INHERITED; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 305 | ////////////////////////////////////////////////////////////////////////////// |
| 306 | |
reed@google.com | 57850b9 | 2012-12-17 21:20:53 +0000 | [diff] [blame] | 307 | DEF_GM(return new BlurRectGM("blurrect", NULL, 0xFF, SkBlurMaskFilter::kNormal_BlurStyle);) |
| 308 | DEF_GM(return new BlurRectGM("blurrect", NULL, 0xFF, SkBlurMaskFilter::kSolid_BlurStyle);) |
| 309 | DEF_GM(return new BlurRectGM("blurrect", NULL, 0xFF, SkBlurMaskFilter::kOuter_BlurStyle);) |
| 310 | DEF_GM(return new BlurRectGM("blurrect", NULL, 0xFF, SkBlurMaskFilter::kInner_BlurStyle);) |
| 311 | |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 312 | static const SkScalar kBig = SkFloatToScalar(20); |
| 313 | static const SkScalar kSmall = SkFloatToScalar(2); |
| 314 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 315 | // regular size rects, blurs should be small enough not to completely overlap. |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 316 | |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 317 | DEF_GM(return new BlurRectFastGM( "blurrect_25_100_2_normal_fast", 25, 100, kSmall, SkBlurMask::kNormal_Style);) |
| 318 | DEF_GM(return new BlurRectFastGM("blurrect_25_100_20_normal_fast", 25, 100, kBig, SkBlurMask::kNormal_Style);) |
| 319 | DEF_GM(return new BlurRectSlowGM( "blurrect_25_100_2_normal_slow", 25, 100, kSmall, SkBlurMask::kNormal_Style);) |
| 320 | DEF_GM(return new BlurRectSlowGM("blurrect_25_100_20_normal_slow", 25, 100, kBig, SkBlurMask::kNormal_Style);) |
| 321 | DEF_GM(return new BlurRectFastGM( "blurrect_25_100_2_inner_fast", 25, 100, kSmall, SkBlurMask::kInner_Style);) |
| 322 | DEF_GM(return new BlurRectFastGM("blurrect_25_100_20_inner_fast", 25, 100, kBig, SkBlurMask::kInner_Style);) |
| 323 | DEF_GM(return new BlurRectSlowGM( "blurrect_25_100_2_inner_slow", 25, 100, kSmall, SkBlurMask::kInner_Style);) |
| 324 | DEF_GM(return new BlurRectSlowGM("blurrect_25_100_20_inner_slow", 25, 100, kBig, SkBlurMask::kInner_Style);) |
| 325 | DEF_GM(return new BlurRectFastGM( "blurrect_25_100_2_outer_fast", 25, 100, kSmall, SkBlurMask::kOuter_Style);) |
| 326 | DEF_GM(return new BlurRectFastGM("blurrect_25_100_20_outer_fast", 25, 100, kBig, SkBlurMask::kOuter_Style);) |
| 327 | DEF_GM(return new BlurRectSlowGM( "blurrect_25_100_2_outer_slow", 25, 100, kSmall, SkBlurMask::kOuter_Style);) |
| 328 | DEF_GM(return new BlurRectSlowGM("blurrect_25_100_20_outer_slow", 25, 100, kBig, SkBlurMask::kOuter_Style);) |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 329 | |
| 330 | // skinny tall rects, blurs overlap in X but not y |
| 331 | |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 332 | DEF_GM(return new BlurRectFastGM( "blurrect_5_100_2_normal_fast", 5, 100, kSmall, SkBlurMask::kNormal_Style);) |
| 333 | DEF_GM(return new BlurRectFastGM("blurrect_5_100_20_normal_fast", 5, 100, kBig, SkBlurMask::kNormal_Style);) |
| 334 | DEF_GM(return new BlurRectSlowGM( "blurrect_5_100_2_normal_slow", 5, 100, kSmall, SkBlurMask::kNormal_Style);) |
| 335 | DEF_GM(return new BlurRectSlowGM("blurrect_5_100_20_normal_slow", 5, 100, kBig, SkBlurMask::kNormal_Style);) |
| 336 | DEF_GM(return new BlurRectFastGM( "blurrect_5_100_2_inner_fast", 5, 100, kSmall, SkBlurMask::kInner_Style);) |
| 337 | DEF_GM(return new BlurRectFastGM("blurrect_5_100_20_inner_fast", 5, 100, kBig, SkBlurMask::kInner_Style);) |
| 338 | DEF_GM(return new BlurRectSlowGM( "blurrect_5_100_2_inner_slow", 5, 100, kSmall, SkBlurMask::kInner_Style);) |
| 339 | DEF_GM(return new BlurRectSlowGM("blurrect_5_100_20_inner_slow", 5, 100, kBig, SkBlurMask::kInner_Style);) |
| 340 | DEF_GM(return new BlurRectFastGM( "blurrect_5_100_2_outer_fast", 5, 100, kSmall, SkBlurMask::kOuter_Style);) |
| 341 | DEF_GM(return new BlurRectFastGM("blurrect_5_100_20_outer_fast", 5, 100, kBig, SkBlurMask::kOuter_Style);) |
| 342 | DEF_GM(return new BlurRectSlowGM( "blurrect_5_100_2_outer_slow", 5, 100, kSmall, SkBlurMask::kOuter_Style);) |
| 343 | DEF_GM(return new BlurRectSlowGM("blurrect_5_100_20_outer_slow", 5, 100, kBig, SkBlurMask::kOuter_Style);) |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 344 | |
| 345 | // tiny rects, blurs overlap in X and Y |
| 346 | |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 347 | DEF_GM(return new BlurRectFastGM( "blurrect_5_5_2_normal_fast", 5, 5, kSmall, SkBlurMask::kNormal_Style);) |
| 348 | DEF_GM(return new BlurRectFastGM("blurrect_5_5_20_normal_fast", 5, 5, kBig, SkBlurMask::kNormal_Style);) |
| 349 | DEF_GM(return new BlurRectSlowGM( "blurrect_5_5_2_normal_slow", 5, 5, kSmall, SkBlurMask::kNormal_Style);) |
| 350 | DEF_GM(return new BlurRectSlowGM("blurrect_5_5_20_normal_slow", 5, 5, kBig, SkBlurMask::kNormal_Style);) |
| 351 | DEF_GM(return new BlurRectFastGM( "blurrect_5_5_2_inner_fast", 5, 5, kSmall, SkBlurMask::kInner_Style);) |
| 352 | DEF_GM(return new BlurRectFastGM("blurrect_5_5_20_inner_fast", 5, 5, kBig, SkBlurMask::kInner_Style);) |
| 353 | DEF_GM(return new BlurRectSlowGM( "blurrect_5_5_2_inner_slow", 5, 5, kSmall, SkBlurMask::kInner_Style);) |
| 354 | DEF_GM(return new BlurRectSlowGM("blurrect_5_5_20_inner_slow", 5, 5, kBig, SkBlurMask::kInner_Style);) |
| 355 | DEF_GM(return new BlurRectFastGM( "blurrect_5_5_2_outer_fast", 5, 5, kSmall, SkBlurMask::kOuter_Style);) |
| 356 | DEF_GM(return new BlurRectFastGM("blurrect_5_5_20_outer_fast", 5, 5, kBig, SkBlurMask::kOuter_Style);) |
| 357 | DEF_GM(return new BlurRectSlowGM( "blurrect_5_5_2_outer_slow", 5, 5, kSmall, SkBlurMask::kOuter_Style);) |
| 358 | DEF_GM(return new BlurRectSlowGM("blurrect_5_5_20_outer_slow", 5, 5, kBig, SkBlurMask::kOuter_Style);) |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 359 | |
| 360 | |
| 361 | #if 0 |
| 362 | // dont' need to GM the gaussian convolution; it's slow and intended |
| 363 | // as a ground truth comparison only. Leaving these here in case we |
| 364 | // ever want to turn these back on for debugging reasons. |
| 365 | DEF_GM(return new BlurRectGroundTruthGM( "blurrect_25_100_1_simple", 25, 100, 1);) |
| 366 | DEF_GM(return new BlurRectGroundTruthGM( "blurrect_25_100_2_simple", 25, 100, 2);) |
| 367 | DEF_GM(return new BlurRectGroundTruthGM( "blurrect_25_100_3_simple", 25, 100, 3);) |
| 368 | DEF_GM(return new BlurRectGroundTruthGM( "blurrect_25_100_4_simple", 25, 100, 4);) |
| 369 | DEF_GM(return new BlurRectGroundTruthGM( "blurrect_25_100_5_simple", 25, 100, 5);) |
| 370 | DEF_GM(return new BlurRectGroundTruthGM( "blurrect_25_100_6_simple", 25, 100, 6);) |
| 371 | DEF_GM(return new BlurRectGroundTruthGM( "blurrect_25_100_7_simple", 25, 100, 7);) |
| 372 | DEF_GM(return new BlurRectGroundTruthGM( "blurrect_25_100_8_simple", 25, 100, 8);) |
| 373 | DEF_GM(return new BlurRectGroundTruthGM( "blurrect_25_100_9_simple", 25, 100, 9);) |
| 374 | DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_10_simple", 25, 100, 10);) |
| 375 | DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_11_simple", 25, 100, 11);) |
| 376 | DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_12_simple", 25, 100, 12);) |
| 377 | DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_13_simple", 25, 100, 13);) |
| 378 | DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_14_simple", 25, 100, 14);) |
| 379 | DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_15_simple", 25, 100, 15);) |
| 380 | DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_16_simple", 25, 100, 16);) |
| 381 | DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_17_simple", 25, 100, 17);) |
| 382 | DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_18_simple", 25, 100, 18);) |
| 383 | DEF_GM(return new BlurRectGroundTruthGM("blurrect_25_100_19_simple", 25, 100, 19);) |
| 384 | #endif |