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 | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 60 | class BlurRectGM : public skiagm::GM { |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame^] | 61 | SkAutoTUnref<SkMaskFilter> fMaskFilters[kLastEnum_SkBlurStyle + 1]; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 62 | SkString fName; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 63 | SkAlpha fAlpha; |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 64 | public: |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 65 | BlurRectGM(const char name[], U8CPU alpha) |
| 66 | : fName(name) |
| 67 | , fAlpha(SkToU8(alpha)) { |
reed@google.com | 57850b9 | 2012-12-17 21:20:53 +0000 | [diff] [blame] | 68 | } |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 69 | |
| 70 | protected: |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 71 | virtual void onOnceBeforeDraw() SK_OVERRIDE { |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame^] | 72 | for (int i = 0; i <= kLastEnum_SkBlurStyle; ++i) { |
| 73 | fMaskFilters[i].reset(SkBlurMaskFilter::Create((SkBlurStyle)i, |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 74 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(STROKE_WIDTH/2)), |
| 75 | SkBlurMaskFilter::kHighQuality_BlurFlag)); |
| 76 | } |
| 77 | } |
| 78 | |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 79 | virtual SkString onShortName() { |
reed@google.com | 53007a2 | 2012-11-26 14:39:50 +0000 | [diff] [blame] | 80 | return fName; |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | virtual SkISize onISize() { |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 84 | return SkISize::Make(440, 820); |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | virtual void onDraw(SkCanvas* canvas) { |
| 88 | canvas->translate(STROKE_WIDTH*3/2, STROKE_WIDTH*3/2); |
| 89 | |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 90 | SkRect r = { 0, 0, 100, 50 }; |
| 91 | SkScalar scales[] = { SK_Scalar1, 0.6f }; |
skia.committer@gmail.com | 8ccf590 | 2012-11-27 02:01:19 +0000 | [diff] [blame] | 92 | |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 93 | for (size_t s = 0; s < SK_ARRAY_COUNT(scales); ++s) { |
| 94 | canvas->save(); |
| 95 | for (size_t f = 0; f < SK_ARRAY_COUNT(fMaskFilters); ++f) { |
| 96 | SkPaint paint; |
| 97 | paint.setMaskFilter(fMaskFilters[f]); |
| 98 | paint.setAlpha(fAlpha); |
| 99 | |
| 100 | static const Proc procs[] = { |
| 101 | fill_rect, draw_donut, draw_donut_skewed |
| 102 | }; |
| 103 | |
| 104 | canvas->save(); |
| 105 | canvas->scale(scales[s], scales[s]); |
| 106 | this->drawProcs(canvas, r, paint, false, procs, SK_ARRAY_COUNT(procs)); |
| 107 | canvas->translate(r.width() * 4/3, 0); |
| 108 | this->drawProcs(canvas, r, paint, true, procs, SK_ARRAY_COUNT(procs)); |
| 109 | canvas->restore(); |
| 110 | |
| 111 | canvas->translate(0, SK_ARRAY_COUNT(procs) * r.height() * 4/3 * scales[s]); |
| 112 | } |
| 113 | canvas->restore(); |
| 114 | canvas->translate(2 * r.width() * 4/3 * scales[s], 0); |
reed@google.com | 53007a2 | 2012-11-26 14:39:50 +0000 | [diff] [blame] | 115 | } |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; } |
| 119 | |
| 120 | private: |
| 121 | void drawProcs(SkCanvas* canvas, const SkRect& r, const SkPaint& paint, |
| 122 | bool doClip, const Proc procs[], size_t procsCount) { |
| 123 | SkAutoCanvasRestore acr(canvas, true); |
| 124 | for (size_t i = 0; i < procsCount; ++i) { |
| 125 | if (doClip) { |
| 126 | SkRect clipRect(r); |
| 127 | clipRect.inset(STROKE_WIDTH/2, STROKE_WIDTH/2); |
| 128 | canvas->save(); |
| 129 | canvas->clipRect(r); |
| 130 | } |
| 131 | procs[i](canvas, r, paint); |
| 132 | if (doClip) { |
| 133 | canvas->restore(); |
| 134 | } |
| 135 | canvas->translate(0, r.height() * 4/3); |
| 136 | } |
| 137 | } |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 138 | private: |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 139 | typedef GM INHERITED; |
| 140 | }; |
| 141 | |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 142 | class BlurRectCompareGM : public skiagm::GM { |
| 143 | SkString fName; |
| 144 | unsigned int fRectWidth, fRectHeight; |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 145 | SkScalar fRadius; |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame^] | 146 | SkBlurStyle fStyle; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 147 | public: |
skia.committer@gmail.com | b3ec29d | 2013-09-07 07:01:16 +0000 | [diff] [blame] | 148 | BlurRectCompareGM(const char name[], unsigned int rectWidth, |
| 149 | unsigned int rectHeight, float radius, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame^] | 150 | SkBlurStyle style) |
bsalomon@google.com | 33cdbde | 2013-01-11 20:54:44 +0000 | [diff] [blame] | 151 | : fName(name) |
| 152 | , fRectWidth(rectWidth) |
| 153 | , fRectHeight(rectHeight) |
| 154 | , fRadius(radius) |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 155 | , fStyle(style) { |
| 156 | } |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 157 | int width() const { |
| 158 | return fRectWidth; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 159 | } |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 160 | int height() const { |
| 161 | return fRectHeight; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 162 | } |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 163 | SkScalar radius() const { |
| 164 | return fRadius; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 165 | } |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame^] | 166 | SkBlurStyle style() const { |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 167 | return fStyle; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 168 | } |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 169 | |
| 170 | protected: |
| 171 | virtual SkString onShortName() { |
| 172 | return fName; |
| 173 | } |
| 174 | |
| 175 | virtual SkISize onISize() { |
| 176 | return SkISize::Make(640, 480); |
| 177 | } |
skia.committer@gmail.com | 8ae714b | 2013-01-05 02:02:05 +0000 | [diff] [blame] | 178 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 179 | virtual bool makeMask(SkMask *m, const SkRect&) = 0; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 180 | |
| 181 | virtual void onDraw(SkCanvas* canvas) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 182 | SkRect r; |
| 183 | r.setWH(SkIntToScalar(fRectWidth), SkIntToScalar(fRectHeight)); |
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 | SkISize canvas_size = canvas->getDeviceSize(); |
jvanverth@google.com | d98df1a | 2013-02-20 19:02:34 +0000 | [diff] [blame] | 186 | int center_x = (canvas_size.fWidth - (int)(r.width()))/2; |
| 187 | int center_y = (canvas_size.fHeight - (int)(r.height()))/2; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 188 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 189 | SkMask mask; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 190 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 191 | if (!this->makeMask(&mask, r)) { |
| 192 | SkPaint paint; |
jvanverth@google.com | d98df1a | 2013-02-20 19:02:34 +0000 | [diff] [blame] | 193 | r.offset( SkIntToScalar(center_x), SkIntToScalar(center_y) ); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 194 | canvas->drawRect(r,paint); |
| 195 | return; |
| 196 | } |
| 197 | SkAutoMaskFreeImage amfi(mask.fImage); |
| 198 | |
| 199 | SkBitmap bm; |
commit-bot@chromium.org | dac5225 | 2014-02-17 21:21:46 +0000 | [diff] [blame] | 200 | bm.installMaskPixels(mask); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 201 | |
| 202 | center_x = (canvas_size.fWidth - mask.fBounds.width())/2; |
| 203 | center_y = (canvas_size.fHeight - mask.fBounds.height())/2; |
| 204 | |
jvanverth@google.com | d98df1a | 2013-02-20 19:02:34 +0000 | [diff] [blame] | 205 | canvas->drawBitmap(bm, SkIntToScalar(center_x), SkIntToScalar(center_y), NULL); |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; } |
| 209 | |
| 210 | private: |
| 211 | typedef GM INHERITED; |
| 212 | }; |
| 213 | |
| 214 | class BlurRectFastGM: public BlurRectCompareGM { |
| 215 | public: |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 216 | BlurRectFastGM(const char name[], unsigned int rectWidth, |
| 217 | unsigned int rectHeight, float blurRadius, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame^] | 218 | SkBlurStyle style) : |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 219 | INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 220 | } |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 221 | |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 222 | protected: |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 223 | virtual bool makeMask(SkMask *m, const SkRect& r) SK_OVERRIDE { |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 224 | return SkBlurMask::BlurRect(SkBlurMask::ConvertRadiusToSigma(this->radius()), |
| 225 | m, r, this->style()); |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 226 | } |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 227 | private: |
| 228 | typedef BlurRectCompareGM INHERITED; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | class BlurRectSlowGM: public BlurRectCompareGM { |
| 232 | public: |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 233 | BlurRectSlowGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame^] | 234 | float blurRadius, SkBlurStyle style) |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 235 | : INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 236 | } |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 237 | |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 238 | protected: |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 239 | virtual bool makeMask(SkMask *m, const SkRect& r) SK_OVERRIDE { |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 240 | SkMask src; |
| 241 | r.roundOut(&src.fBounds); |
| 242 | src.fBounds.offset(-src.fBounds.fLeft, -src.fBounds.fTop); // move to origin |
| 243 | src.fFormat = SkMask::kA8_Format; |
| 244 | src.fRowBytes = src.fBounds.width(); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 245 | src.fImage = SkMask::AllocImage(src.computeTotalImageSize()); |
bsalomon@google.com | 33cdbde | 2013-01-11 20:54:44 +0000 | [diff] [blame] | 246 | SkAutoMaskFreeImage amfi(src.fImage); |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 247 | |
bsalomon@google.com | 33cdbde | 2013-01-11 20:54:44 +0000 | [diff] [blame] | 248 | memset(src.fImage, 0xff, src.computeTotalImageSize()); |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 249 | |
skia.committer@gmail.com | b3ec29d | 2013-09-07 07:01:16 +0000 | [diff] [blame] | 250 | return SkBlurMask::BoxBlur(m, src, |
| 251 | SkBlurMask::ConvertRadiusToSigma(this->radius()), |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 252 | this->style(), this->getQuality()); |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 253 | } |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 254 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame^] | 255 | virtual SkBlurQuality getQuality() { |
| 256 | return kHigh_SkBlurQuality; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 257 | } |
| 258 | private: |
| 259 | typedef BlurRectCompareGM INHERITED; |
| 260 | }; |
| 261 | |
| 262 | class BlurRectSlowLowGM: public BlurRectSlowGM { |
| 263 | public: |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 264 | BlurRectSlowLowGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame^] | 265 | float blurRadius, SkBlurStyle style) |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 266 | : INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 267 | } |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 268 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 269 | protected: |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame^] | 270 | virtual SkBlurQuality getQuality() SK_OVERRIDE { |
| 271 | return kLow_SkBlurQuality; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 272 | } |
| 273 | private: |
| 274 | typedef BlurRectSlowGM INHERITED; |
| 275 | }; |
| 276 | |
| 277 | class BlurRectGroundTruthGM: public BlurRectCompareGM { |
| 278 | public: |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 279 | BlurRectGroundTruthGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame^] | 280 | float blurRadius, SkBlurStyle style) |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 281 | : INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 282 | } |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 283 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 284 | protected: |
| 285 | virtual bool makeMask(SkMask *m, const SkRect& r) SK_OVERRIDE { |
| 286 | SkMask src; |
| 287 | r.roundOut(&src.fBounds); |
| 288 | src.fBounds.offset(-src.fBounds.fLeft, -src.fBounds.fTop); // move to origin |
| 289 | src.fFormat = SkMask::kA8_Format; |
| 290 | src.fRowBytes = src.fBounds.width(); |
| 291 | src.fImage = SkMask::AllocImage(src.computeTotalImageSize()); |
| 292 | SkAutoMaskFreeImage amfi(src.fImage); |
| 293 | |
| 294 | memset(src.fImage, 0xff, src.computeTotalImageSize()); |
| 295 | |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 296 | return SkBlurMask::BlurGroundTruth(SkBlurMask::ConvertRadiusToSigma(this->radius()), |
| 297 | m, src, this->style()); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 298 | } |
| 299 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame^] | 300 | virtual SkBlurQuality getQuality() { |
| 301 | return kHigh_SkBlurQuality; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 302 | } |
| 303 | private: |
| 304 | typedef BlurRectCompareGM INHERITED; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 305 | }; |
| 306 | |
| 307 | |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 308 | ////////////////////////////////////////////////////////////////////////////// |
| 309 | |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 310 | DEF_GM(return new BlurRectGM("blurrects", 0xFF);) |
reed@google.com | 57850b9 | 2012-12-17 21:20:53 +0000 | [diff] [blame] | 311 | |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 312 | static const SkScalar kBig = 20; |
| 313 | static const SkScalar kSmall = 2; |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 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 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame^] | 317 | DEF_GM(return new BlurRectFastGM( "blurrect_25_100_2_normal_fast", 25, 100, kSmall, kNormal_SkBlurStyle);) |
| 318 | DEF_GM(return new BlurRectFastGM("blurrect_25_100_20_normal_fast", 25, 100, kBig, kNormal_SkBlurStyle);) |
| 319 | DEF_GM(return new BlurRectSlowGM( "blurrect_25_100_2_normal_slow", 25, 100, kSmall, kNormal_SkBlurStyle);) |
| 320 | DEF_GM(return new BlurRectSlowGM("blurrect_25_100_20_normal_slow", 25, 100, kBig, kNormal_SkBlurStyle);) |
| 321 | DEF_GM(return new BlurRectFastGM( "blurrect_25_100_2_inner_fast", 25, 100, kSmall, kInner_SkBlurStyle);) |
| 322 | DEF_GM(return new BlurRectFastGM("blurrect_25_100_20_inner_fast", 25, 100, kBig, kInner_SkBlurStyle);) |
| 323 | DEF_GM(return new BlurRectSlowGM( "blurrect_25_100_2_inner_slow", 25, 100, kSmall, kInner_SkBlurStyle);) |
| 324 | DEF_GM(return new BlurRectSlowGM("blurrect_25_100_20_inner_slow", 25, 100, kBig, kInner_SkBlurStyle);) |
| 325 | DEF_GM(return new BlurRectFastGM( "blurrect_25_100_2_outer_fast", 25, 100, kSmall, kOuter_SkBlurStyle);) |
| 326 | DEF_GM(return new BlurRectFastGM("blurrect_25_100_20_outer_fast", 25, 100, kBig, kOuter_SkBlurStyle);) |
| 327 | DEF_GM(return new BlurRectSlowGM( "blurrect_25_100_2_outer_slow", 25, 100, kSmall, kOuter_SkBlurStyle);) |
| 328 | DEF_GM(return new BlurRectSlowGM("blurrect_25_100_20_outer_slow", 25, 100, kBig, kOuter_SkBlurStyle);) |
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 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame^] | 332 | DEF_GM(return new BlurRectFastGM( "blurrect_5_100_2_normal_fast", 5, 100, kSmall, kNormal_SkBlurStyle);) |
| 333 | DEF_GM(return new BlurRectFastGM("blurrect_5_100_20_normal_fast", 5, 100, kBig, kNormal_SkBlurStyle);) |
| 334 | DEF_GM(return new BlurRectSlowGM( "blurrect_5_100_2_normal_slow", 5, 100, kSmall, kNormal_SkBlurStyle);) |
| 335 | DEF_GM(return new BlurRectSlowGM("blurrect_5_100_20_normal_slow", 5, 100, kBig, kNormal_SkBlurStyle);) |
| 336 | DEF_GM(return new BlurRectFastGM( "blurrect_5_100_2_inner_fast", 5, 100, kSmall, kInner_SkBlurStyle);) |
| 337 | DEF_GM(return new BlurRectFastGM("blurrect_5_100_20_inner_fast", 5, 100, kBig, kInner_SkBlurStyle);) |
| 338 | DEF_GM(return new BlurRectSlowGM( "blurrect_5_100_2_inner_slow", 5, 100, kSmall, kInner_SkBlurStyle);) |
| 339 | DEF_GM(return new BlurRectSlowGM("blurrect_5_100_20_inner_slow", 5, 100, kBig, kInner_SkBlurStyle);) |
| 340 | DEF_GM(return new BlurRectFastGM( "blurrect_5_100_2_outer_fast", 5, 100, kSmall, kOuter_SkBlurStyle);) |
| 341 | DEF_GM(return new BlurRectFastGM("blurrect_5_100_20_outer_fast", 5, 100, kBig, kOuter_SkBlurStyle);) |
| 342 | DEF_GM(return new BlurRectSlowGM( "blurrect_5_100_2_outer_slow", 5, 100, kSmall, kOuter_SkBlurStyle);) |
| 343 | DEF_GM(return new BlurRectSlowGM("blurrect_5_100_20_outer_slow", 5, 100, kBig, kOuter_SkBlurStyle);) |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 344 | |
| 345 | // tiny rects, blurs overlap in X and Y |
| 346 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame^] | 347 | DEF_GM(return new BlurRectFastGM( "blurrect_5_5_2_normal_fast", 5, 5, kSmall, kNormal_SkBlurStyle);) |
| 348 | DEF_GM(return new BlurRectFastGM("blurrect_5_5_20_normal_fast", 5, 5, kBig, kNormal_SkBlurStyle);) |
| 349 | DEF_GM(return new BlurRectSlowGM( "blurrect_5_5_2_normal_slow", 5, 5, kSmall, kNormal_SkBlurStyle);) |
| 350 | DEF_GM(return new BlurRectSlowGM("blurrect_5_5_20_normal_slow", 5, 5, kBig, kNormal_SkBlurStyle);) |
| 351 | DEF_GM(return new BlurRectFastGM( "blurrect_5_5_2_inner_fast", 5, 5, kSmall, kInner_SkBlurStyle);) |
| 352 | DEF_GM(return new BlurRectFastGM("blurrect_5_5_20_inner_fast", 5, 5, kBig, kInner_SkBlurStyle);) |
| 353 | DEF_GM(return new BlurRectSlowGM( "blurrect_5_5_2_inner_slow", 5, 5, kSmall, kInner_SkBlurStyle);) |
| 354 | DEF_GM(return new BlurRectSlowGM("blurrect_5_5_20_inner_slow", 5, 5, kBig, kInner_SkBlurStyle);) |
| 355 | DEF_GM(return new BlurRectFastGM( "blurrect_5_5_2_outer_fast", 5, 5, kSmall, kOuter_SkBlurStyle);) |
| 356 | DEF_GM(return new BlurRectFastGM("blurrect_5_5_20_outer_fast", 5, 5, kBig, kOuter_SkBlurStyle);) |
| 357 | DEF_GM(return new BlurRectSlowGM( "blurrect_5_5_2_outer_slow", 5, 5, kSmall, kOuter_SkBlurStyle);) |
| 358 | DEF_GM(return new BlurRectSlowGM("blurrect_5_5_20_outer_slow", 5, 5, kBig, kOuter_SkBlurStyle);) |
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 |