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 | |
mtklein | 7cdc1ee | 2014-07-07 10:41:04 -0700 | [diff] [blame] | 118 | virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; } |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 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 | |
commit-bot@chromium.org | 3c1594a | 2014-05-28 21:52:12 +0000 | [diff] [blame] | 142 | |
| 143 | class BlurRectDirectGM : public skiagm::GM { |
| 144 | SkString fName; |
| 145 | int fGMWidth, fGMHeight; |
| 146 | int fPadding, fMargin; |
| 147 | public: |
| 148 | BlurRectDirectGM(const char name[]) |
| 149 | : fName(name), |
| 150 | fGMWidth(1200), |
| 151 | fGMHeight(1024), |
| 152 | fPadding(10), |
| 153 | fMargin(100) |
| 154 | { |
| 155 | } |
| 156 | |
| 157 | protected: |
| 158 | virtual SkString onShortName() { |
| 159 | return fName; |
| 160 | } |
| 161 | |
| 162 | virtual SkISize onISize() { |
| 163 | return SkISize::Make(fGMWidth, fGMHeight); |
| 164 | } |
| 165 | |
| 166 | virtual void onDraw(SkCanvas* canvas) { |
| 167 | const int widths[] = {25, 5, 5, 100, 150, 25}; |
| 168 | const int heights[] = {100, 100, 5, 25, 150, 25}; |
| 169 | const SkBlurStyle styles[] = {kNormal_SkBlurStyle, kInner_SkBlurStyle, kOuter_SkBlurStyle}; |
| 170 | const float radii[] = {20, 5, 10}; |
| 171 | |
| 172 | canvas->translate(50,20); |
| 173 | |
| 174 | int cur_x = 0; |
| 175 | int cur_y = 0; |
| 176 | |
| 177 | int max_height = 0; |
| 178 | |
| 179 | for (size_t i = 0 ; i < SK_ARRAY_COUNT(widths) ; i++) { |
| 180 | int width = widths[i]; |
| 181 | int height = heights[i]; |
| 182 | SkRect r; |
| 183 | r.setWH(SkIntToScalar(width), SkIntToScalar(height)); |
| 184 | SkAutoCanvasRestore autoRestore(canvas, true); |
| 185 | |
| 186 | for (size_t j = 0 ; j < SK_ARRAY_COUNT(radii) ; j++) { |
| 187 | float radius = radii[j]; |
| 188 | for (size_t k = 0 ; k < SK_ARRAY_COUNT(styles) ; k++) { |
| 189 | SkBlurStyle style = styles[k]; |
| 190 | |
| 191 | SkMask mask; |
| 192 | SkBlurMask::BlurRect(SkBlurMask::ConvertRadiusToSigma(radius), &mask, r, style); |
| 193 | |
| 194 | SkAutoMaskFreeImage amfi(mask.fImage); |
| 195 | |
| 196 | SkBitmap bm; |
| 197 | bm.installMaskPixels(mask); |
| 198 | |
| 199 | if (cur_x + bm.width() >= fGMWidth - fMargin) { |
| 200 | cur_x = 0; |
| 201 | cur_y += max_height + fPadding; |
| 202 | max_height = 0; |
| 203 | } |
| 204 | |
| 205 | canvas->save(); |
commit-bot@chromium.org | 793ddd9 | 2014-05-28 22:42:31 +0000 | [diff] [blame] | 206 | canvas->translate((SkScalar)cur_x, (SkScalar)cur_y); |
commit-bot@chromium.org | 3c1594a | 2014-05-28 21:52:12 +0000 | [diff] [blame] | 207 | canvas->translate(-(bm.width() - r.width())/2, -(bm.height()-r.height())/2); |
| 208 | canvas->drawBitmap(bm, 0.f, 0.f, NULL); |
| 209 | canvas->restore(); |
| 210 | |
| 211 | cur_x += bm.width() + fPadding; |
| 212 | if (bm.height() > max_height) |
| 213 | max_height = bm.height(); |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; } |
| 220 | |
| 221 | private: |
| 222 | typedef GM INHERITED; |
| 223 | }; |
| 224 | |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 225 | class BlurRectCompareGM : public skiagm::GM { |
| 226 | SkString fName; |
| 227 | unsigned int fRectWidth, fRectHeight; |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 228 | SkScalar fRadius; |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 229 | SkBlurStyle fStyle; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 230 | public: |
skia.committer@gmail.com | b3ec29d | 2013-09-07 07:01:16 +0000 | [diff] [blame] | 231 | BlurRectCompareGM(const char name[], unsigned int rectWidth, |
| 232 | unsigned int rectHeight, float radius, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 233 | SkBlurStyle style) |
bsalomon@google.com | 33cdbde | 2013-01-11 20:54:44 +0000 | [diff] [blame] | 234 | : fName(name) |
| 235 | , fRectWidth(rectWidth) |
| 236 | , fRectHeight(rectHeight) |
| 237 | , fRadius(radius) |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 238 | , fStyle(style) { |
| 239 | } |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 240 | int width() const { |
| 241 | return fRectWidth; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 242 | } |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 243 | int height() const { |
| 244 | return fRectHeight; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 245 | } |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 246 | SkScalar radius() const { |
| 247 | return fRadius; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 248 | } |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 249 | SkBlurStyle style() const { |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 250 | return fStyle; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 251 | } |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 252 | |
| 253 | protected: |
| 254 | virtual SkString onShortName() { |
| 255 | return fName; |
| 256 | } |
| 257 | |
| 258 | virtual SkISize onISize() { |
| 259 | return SkISize::Make(640, 480); |
| 260 | } |
skia.committer@gmail.com | 8ae714b | 2013-01-05 02:02:05 +0000 | [diff] [blame] | 261 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 262 | virtual bool makeMask(SkMask *m, const SkRect&) = 0; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 263 | |
| 264 | virtual void onDraw(SkCanvas* canvas) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 265 | SkRect r; |
| 266 | r.setWH(SkIntToScalar(fRectWidth), SkIntToScalar(fRectHeight)); |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 267 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 268 | SkISize canvas_size = canvas->getDeviceSize(); |
jvanverth@google.com | d98df1a | 2013-02-20 19:02:34 +0000 | [diff] [blame] | 269 | int center_x = (canvas_size.fWidth - (int)(r.width()))/2; |
| 270 | int center_y = (canvas_size.fHeight - (int)(r.height()))/2; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 271 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 272 | SkMask mask; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 273 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 274 | if (!this->makeMask(&mask, r)) { |
| 275 | SkPaint paint; |
jvanverth@google.com | d98df1a | 2013-02-20 19:02:34 +0000 | [diff] [blame] | 276 | r.offset( SkIntToScalar(center_x), SkIntToScalar(center_y) ); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 277 | canvas->drawRect(r,paint); |
| 278 | return; |
| 279 | } |
| 280 | SkAutoMaskFreeImage amfi(mask.fImage); |
| 281 | |
| 282 | SkBitmap bm; |
commit-bot@chromium.org | dac5225 | 2014-02-17 21:21:46 +0000 | [diff] [blame] | 283 | bm.installMaskPixels(mask); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 284 | |
| 285 | center_x = (canvas_size.fWidth - mask.fBounds.width())/2; |
| 286 | center_y = (canvas_size.fHeight - mask.fBounds.height())/2; |
| 287 | |
jvanverth@google.com | d98df1a | 2013-02-20 19:02:34 +0000 | [diff] [blame] | 288 | canvas->drawBitmap(bm, SkIntToScalar(center_x), SkIntToScalar(center_y), NULL); |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; } |
| 292 | |
| 293 | private: |
| 294 | typedef GM INHERITED; |
| 295 | }; |
| 296 | |
| 297 | class BlurRectFastGM: public BlurRectCompareGM { |
| 298 | public: |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 299 | BlurRectFastGM(const char name[], unsigned int rectWidth, |
| 300 | unsigned int rectHeight, float blurRadius, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 301 | SkBlurStyle style) : |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 302 | INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 303 | } |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 304 | |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 305 | protected: |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 306 | virtual bool makeMask(SkMask *m, const SkRect& r) SK_OVERRIDE { |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 307 | return SkBlurMask::BlurRect(SkBlurMask::ConvertRadiusToSigma(this->radius()), |
| 308 | m, r, this->style()); |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 309 | } |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 310 | private: |
| 311 | typedef BlurRectCompareGM INHERITED; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 312 | }; |
| 313 | |
| 314 | class BlurRectSlowGM: public BlurRectCompareGM { |
| 315 | public: |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 316 | BlurRectSlowGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 317 | float blurRadius, SkBlurStyle style) |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 318 | : INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 319 | } |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 320 | |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 321 | protected: |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 322 | virtual bool makeMask(SkMask *m, const SkRect& r) SK_OVERRIDE { |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 323 | SkMask src; |
| 324 | r.roundOut(&src.fBounds); |
| 325 | src.fBounds.offset(-src.fBounds.fLeft, -src.fBounds.fTop); // move to origin |
| 326 | src.fFormat = SkMask::kA8_Format; |
| 327 | src.fRowBytes = src.fBounds.width(); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 328 | src.fImage = SkMask::AllocImage(src.computeTotalImageSize()); |
bsalomon@google.com | 33cdbde | 2013-01-11 20:54:44 +0000 | [diff] [blame] | 329 | SkAutoMaskFreeImage amfi(src.fImage); |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 330 | |
bsalomon@google.com | 33cdbde | 2013-01-11 20:54:44 +0000 | [diff] [blame] | 331 | memset(src.fImage, 0xff, src.computeTotalImageSize()); |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 332 | |
skia.committer@gmail.com | b3ec29d | 2013-09-07 07:01:16 +0000 | [diff] [blame] | 333 | return SkBlurMask::BoxBlur(m, src, |
| 334 | SkBlurMask::ConvertRadiusToSigma(this->radius()), |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 335 | this->style(), this->getQuality()); |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 336 | } |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 337 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 338 | virtual SkBlurQuality getQuality() { |
| 339 | return kHigh_SkBlurQuality; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 340 | } |
| 341 | private: |
| 342 | typedef BlurRectCompareGM INHERITED; |
| 343 | }; |
| 344 | |
| 345 | class BlurRectSlowLowGM: public BlurRectSlowGM { |
| 346 | public: |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 347 | BlurRectSlowLowGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 348 | float blurRadius, SkBlurStyle style) |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 349 | : INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 350 | } |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 351 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 352 | protected: |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 353 | virtual SkBlurQuality getQuality() SK_OVERRIDE { |
| 354 | return kLow_SkBlurQuality; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 355 | } |
| 356 | private: |
| 357 | typedef BlurRectSlowGM INHERITED; |
| 358 | }; |
| 359 | |
| 360 | class BlurRectGroundTruthGM: public BlurRectCompareGM { |
| 361 | public: |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 362 | BlurRectGroundTruthGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 363 | float blurRadius, SkBlurStyle style) |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 364 | : INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 365 | } |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 366 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 367 | protected: |
| 368 | virtual bool makeMask(SkMask *m, const SkRect& r) SK_OVERRIDE { |
| 369 | SkMask src; |
| 370 | r.roundOut(&src.fBounds); |
| 371 | src.fBounds.offset(-src.fBounds.fLeft, -src.fBounds.fTop); // move to origin |
| 372 | src.fFormat = SkMask::kA8_Format; |
| 373 | src.fRowBytes = src.fBounds.width(); |
| 374 | src.fImage = SkMask::AllocImage(src.computeTotalImageSize()); |
| 375 | SkAutoMaskFreeImage amfi(src.fImage); |
| 376 | |
| 377 | memset(src.fImage, 0xff, src.computeTotalImageSize()); |
| 378 | |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 379 | return SkBlurMask::BlurGroundTruth(SkBlurMask::ConvertRadiusToSigma(this->radius()), |
| 380 | m, src, this->style()); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 381 | } |
| 382 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 383 | virtual SkBlurQuality getQuality() { |
| 384 | return kHigh_SkBlurQuality; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 385 | } |
| 386 | private: |
| 387 | typedef BlurRectCompareGM INHERITED; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 388 | }; |
| 389 | |
| 390 | |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 391 | ////////////////////////////////////////////////////////////////////////////// |
| 392 | |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 393 | DEF_GM(return new BlurRectGM("blurrects", 0xFF);) |
commit-bot@chromium.org | 3c1594a | 2014-05-28 21:52:12 +0000 | [diff] [blame] | 394 | DEF_GM(return new BlurRectDirectGM("blurrect_gallery");) |