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 | |
joshualitt | 341400e | 2014-12-18 11:54:13 -0800 | [diff] [blame^] | 58 | /* |
| 59 | * Spits out a dummy gradient to test blur with shader on paint |
| 60 | */ |
| 61 | static SkShader* MakeRadial() { |
| 62 | SkPoint pts[2] = { |
| 63 | { 0, 0 }, |
| 64 | { SkIntToScalar(100), SkIntToScalar(100) } |
| 65 | }; |
| 66 | SkShader::TileMode tm = SkShader::kClamp_TileMode; |
| 67 | const SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, }; |
| 68 | const SkScalar pos[] = { SK_Scalar1/4, SK_Scalar1*3/4 }; |
| 69 | SkMatrix scale; |
| 70 | scale.setScale(0.5f, 0.5f); |
| 71 | scale.postTranslate(25.f, 25.f); |
| 72 | SkPoint center0, center1; |
| 73 | center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
| 74 | SkScalarAve(pts[0].fY, pts[1].fY)); |
| 75 | center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 76 | SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
| 77 | return SkGradientShader::CreateTwoPointRadial(center1, (pts[1].fX - pts[0].fX) / 7, |
| 78 | center0, (pts[1].fX - pts[0].fX) / 2, |
| 79 | colors, pos, SK_ARRAY_COUNT(colors), tm, |
| 80 | 0, &scale); |
| 81 | } |
| 82 | |
reed@google.com | 53007a2 | 2012-11-26 14:39:50 +0000 | [diff] [blame] | 83 | typedef void (*PaintProc)(SkPaint*, SkScalar width); |
| 84 | |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 85 | class BlurRectGM : public skiagm::GM { |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 86 | SkAutoTUnref<SkMaskFilter> fMaskFilters[kLastEnum_SkBlurStyle + 1]; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 87 | SkString fName; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 88 | SkAlpha fAlpha; |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 89 | public: |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 90 | BlurRectGM(const char name[], U8CPU alpha) |
| 91 | : fName(name) |
| 92 | , fAlpha(SkToU8(alpha)) { |
reed@google.com | 57850b9 | 2012-12-17 21:20:53 +0000 | [diff] [blame] | 93 | } |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 94 | |
| 95 | protected: |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 96 | virtual void onOnceBeforeDraw() SK_OVERRIDE { |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 97 | for (int i = 0; i <= kLastEnum_SkBlurStyle; ++i) { |
| 98 | fMaskFilters[i].reset(SkBlurMaskFilter::Create((SkBlurStyle)i, |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 99 | SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(STROKE_WIDTH/2)), |
| 100 | SkBlurMaskFilter::kHighQuality_BlurFlag)); |
| 101 | } |
| 102 | } |
| 103 | |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 104 | virtual SkString onShortName() { |
reed@google.com | 53007a2 | 2012-11-26 14:39:50 +0000 | [diff] [blame] | 105 | return fName; |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | virtual SkISize onISize() { |
joshualitt | 341400e | 2014-12-18 11:54:13 -0800 | [diff] [blame^] | 109 | return SkISize::Make(860, 820); |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | virtual void onDraw(SkCanvas* canvas) { |
| 113 | canvas->translate(STROKE_WIDTH*3/2, STROKE_WIDTH*3/2); |
| 114 | |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 115 | SkRect r = { 0, 0, 100, 50 }; |
| 116 | SkScalar scales[] = { SK_Scalar1, 0.6f }; |
skia.committer@gmail.com | 8ccf590 | 2012-11-27 02:01:19 +0000 | [diff] [blame] | 117 | |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 118 | for (size_t s = 0; s < SK_ARRAY_COUNT(scales); ++s) { |
| 119 | canvas->save(); |
| 120 | for (size_t f = 0; f < SK_ARRAY_COUNT(fMaskFilters); ++f) { |
| 121 | SkPaint paint; |
| 122 | paint.setMaskFilter(fMaskFilters[f]); |
| 123 | paint.setAlpha(fAlpha); |
| 124 | |
joshualitt | 341400e | 2014-12-18 11:54:13 -0800 | [diff] [blame^] | 125 | SkPaint paintWithRadial = paint; |
| 126 | paintWithRadial.setShader(MakeRadial())->unref(); |
| 127 | |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 128 | static const Proc procs[] = { |
| 129 | fill_rect, draw_donut, draw_donut_skewed |
| 130 | }; |
| 131 | |
| 132 | canvas->save(); |
| 133 | canvas->scale(scales[s], scales[s]); |
| 134 | this->drawProcs(canvas, r, paint, false, procs, SK_ARRAY_COUNT(procs)); |
| 135 | canvas->translate(r.width() * 4/3, 0); |
joshualitt | 341400e | 2014-12-18 11:54:13 -0800 | [diff] [blame^] | 136 | this->drawProcs(canvas, r, paintWithRadial, false, procs, SK_ARRAY_COUNT(procs)); |
| 137 | canvas->translate(r.width() * 4/3, 0); |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 138 | this->drawProcs(canvas, r, paint, true, procs, SK_ARRAY_COUNT(procs)); |
joshualitt | 341400e | 2014-12-18 11:54:13 -0800 | [diff] [blame^] | 139 | canvas->translate(r.width() * 4/3, 0); |
| 140 | this->drawProcs(canvas, r, paintWithRadial, true, procs, SK_ARRAY_COUNT(procs)); |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 141 | canvas->restore(); |
| 142 | |
| 143 | canvas->translate(0, SK_ARRAY_COUNT(procs) * r.height() * 4/3 * scales[s]); |
| 144 | } |
| 145 | canvas->restore(); |
joshualitt | 341400e | 2014-12-18 11:54:13 -0800 | [diff] [blame^] | 146 | canvas->translate(4 * r.width() * 4/3 * scales[s], 0); |
reed@google.com | 53007a2 | 2012-11-26 14:39:50 +0000 | [diff] [blame] | 147 | } |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 148 | } |
| 149 | |
joshualitt | 341400e | 2014-12-18 11:54:13 -0800 | [diff] [blame^] | 150 | virtual uint32_t onGetFlags() const { return kSkipPipe_Flag | kSkipTiled_Flag; } |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 151 | |
| 152 | private: |
| 153 | void drawProcs(SkCanvas* canvas, const SkRect& r, const SkPaint& paint, |
| 154 | bool doClip, const Proc procs[], size_t procsCount) { |
| 155 | SkAutoCanvasRestore acr(canvas, true); |
| 156 | for (size_t i = 0; i < procsCount; ++i) { |
| 157 | if (doClip) { |
| 158 | SkRect clipRect(r); |
| 159 | clipRect.inset(STROKE_WIDTH/2, STROKE_WIDTH/2); |
| 160 | canvas->save(); |
| 161 | canvas->clipRect(r); |
| 162 | } |
| 163 | procs[i](canvas, r, paint); |
| 164 | if (doClip) { |
| 165 | canvas->restore(); |
| 166 | } |
| 167 | canvas->translate(0, r.height() * 4/3); |
| 168 | } |
| 169 | } |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 170 | private: |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 171 | typedef GM INHERITED; |
| 172 | }; |
| 173 | |
commit-bot@chromium.org | 3c1594a | 2014-05-28 21:52:12 +0000 | [diff] [blame] | 174 | |
| 175 | class BlurRectDirectGM : public skiagm::GM { |
| 176 | SkString fName; |
| 177 | int fGMWidth, fGMHeight; |
| 178 | int fPadding, fMargin; |
| 179 | public: |
| 180 | BlurRectDirectGM(const char name[]) |
| 181 | : fName(name), |
| 182 | fGMWidth(1200), |
| 183 | fGMHeight(1024), |
| 184 | fPadding(10), |
| 185 | fMargin(100) |
| 186 | { |
| 187 | } |
| 188 | |
| 189 | protected: |
| 190 | virtual SkString onShortName() { |
| 191 | return fName; |
| 192 | } |
| 193 | |
| 194 | virtual SkISize onISize() { |
| 195 | return SkISize::Make(fGMWidth, fGMHeight); |
| 196 | } |
| 197 | |
| 198 | virtual void onDraw(SkCanvas* canvas) { |
| 199 | const int widths[] = {25, 5, 5, 100, 150, 25}; |
| 200 | const int heights[] = {100, 100, 5, 25, 150, 25}; |
| 201 | const SkBlurStyle styles[] = {kNormal_SkBlurStyle, kInner_SkBlurStyle, kOuter_SkBlurStyle}; |
| 202 | const float radii[] = {20, 5, 10}; |
| 203 | |
| 204 | canvas->translate(50,20); |
| 205 | |
| 206 | int cur_x = 0; |
| 207 | int cur_y = 0; |
| 208 | |
| 209 | int max_height = 0; |
| 210 | |
| 211 | for (size_t i = 0 ; i < SK_ARRAY_COUNT(widths) ; i++) { |
| 212 | int width = widths[i]; |
| 213 | int height = heights[i]; |
| 214 | SkRect r; |
| 215 | r.setWH(SkIntToScalar(width), SkIntToScalar(height)); |
| 216 | SkAutoCanvasRestore autoRestore(canvas, true); |
| 217 | |
| 218 | for (size_t j = 0 ; j < SK_ARRAY_COUNT(radii) ; j++) { |
| 219 | float radius = radii[j]; |
| 220 | for (size_t k = 0 ; k < SK_ARRAY_COUNT(styles) ; k++) { |
| 221 | SkBlurStyle style = styles[k]; |
| 222 | |
| 223 | SkMask mask; |
| 224 | SkBlurMask::BlurRect(SkBlurMask::ConvertRadiusToSigma(radius), &mask, r, style); |
| 225 | |
| 226 | SkAutoMaskFreeImage amfi(mask.fImage); |
| 227 | |
| 228 | SkBitmap bm; |
| 229 | bm.installMaskPixels(mask); |
| 230 | |
| 231 | if (cur_x + bm.width() >= fGMWidth - fMargin) { |
| 232 | cur_x = 0; |
| 233 | cur_y += max_height + fPadding; |
| 234 | max_height = 0; |
| 235 | } |
| 236 | |
| 237 | canvas->save(); |
commit-bot@chromium.org | 793ddd9 | 2014-05-28 22:42:31 +0000 | [diff] [blame] | 238 | canvas->translate((SkScalar)cur_x, (SkScalar)cur_y); |
commit-bot@chromium.org | 3c1594a | 2014-05-28 21:52:12 +0000 | [diff] [blame] | 239 | canvas->translate(-(bm.width() - r.width())/2, -(bm.height()-r.height())/2); |
| 240 | canvas->drawBitmap(bm, 0.f, 0.f, NULL); |
| 241 | canvas->restore(); |
| 242 | |
| 243 | cur_x += bm.width() + fPadding; |
| 244 | if (bm.height() > max_height) |
| 245 | max_height = bm.height(); |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; } |
| 252 | |
| 253 | private: |
| 254 | typedef GM INHERITED; |
| 255 | }; |
| 256 | |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 257 | class BlurRectCompareGM : public skiagm::GM { |
| 258 | SkString fName; |
| 259 | unsigned int fRectWidth, fRectHeight; |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 260 | SkScalar fRadius; |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 261 | SkBlurStyle fStyle; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 262 | public: |
skia.committer@gmail.com | b3ec29d | 2013-09-07 07:01:16 +0000 | [diff] [blame] | 263 | BlurRectCompareGM(const char name[], unsigned int rectWidth, |
| 264 | unsigned int rectHeight, float radius, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 265 | SkBlurStyle style) |
bsalomon@google.com | 33cdbde | 2013-01-11 20:54:44 +0000 | [diff] [blame] | 266 | : fName(name) |
| 267 | , fRectWidth(rectWidth) |
| 268 | , fRectHeight(rectHeight) |
| 269 | , fRadius(radius) |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 270 | , fStyle(style) { |
| 271 | } |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 272 | int width() const { |
| 273 | return fRectWidth; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 274 | } |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 275 | int height() const { |
| 276 | return fRectHeight; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 277 | } |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 278 | SkScalar radius() const { |
| 279 | return fRadius; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 280 | } |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 281 | SkBlurStyle style() const { |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 282 | return fStyle; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 283 | } |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 284 | |
| 285 | protected: |
| 286 | virtual SkString onShortName() { |
| 287 | return fName; |
| 288 | } |
| 289 | |
| 290 | virtual SkISize onISize() { |
| 291 | return SkISize::Make(640, 480); |
| 292 | } |
skia.committer@gmail.com | 8ae714b | 2013-01-05 02:02:05 +0000 | [diff] [blame] | 293 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 294 | virtual bool makeMask(SkMask *m, const SkRect&) = 0; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 295 | |
| 296 | virtual void onDraw(SkCanvas* canvas) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 297 | SkRect r; |
| 298 | r.setWH(SkIntToScalar(fRectWidth), SkIntToScalar(fRectHeight)); |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 299 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 300 | SkISize canvas_size = canvas->getDeviceSize(); |
jvanverth@google.com | d98df1a | 2013-02-20 19:02:34 +0000 | [diff] [blame] | 301 | int center_x = (canvas_size.fWidth - (int)(r.width()))/2; |
| 302 | int center_y = (canvas_size.fHeight - (int)(r.height()))/2; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 303 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 304 | SkMask mask; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 305 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 306 | if (!this->makeMask(&mask, r)) { |
| 307 | SkPaint paint; |
jvanverth@google.com | d98df1a | 2013-02-20 19:02:34 +0000 | [diff] [blame] | 308 | r.offset( SkIntToScalar(center_x), SkIntToScalar(center_y) ); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 309 | canvas->drawRect(r,paint); |
| 310 | return; |
| 311 | } |
| 312 | SkAutoMaskFreeImage amfi(mask.fImage); |
| 313 | |
| 314 | SkBitmap bm; |
commit-bot@chromium.org | dac5225 | 2014-02-17 21:21:46 +0000 | [diff] [blame] | 315 | bm.installMaskPixels(mask); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 316 | |
| 317 | center_x = (canvas_size.fWidth - mask.fBounds.width())/2; |
| 318 | center_y = (canvas_size.fHeight - mask.fBounds.height())/2; |
| 319 | |
jvanverth@google.com | d98df1a | 2013-02-20 19:02:34 +0000 | [diff] [blame] | 320 | canvas->drawBitmap(bm, SkIntToScalar(center_x), SkIntToScalar(center_y), NULL); |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | virtual uint32_t onGetFlags() const { return kSkipPipe_Flag; } |
| 324 | |
| 325 | private: |
| 326 | typedef GM INHERITED; |
| 327 | }; |
| 328 | |
| 329 | class BlurRectFastGM: public BlurRectCompareGM { |
| 330 | public: |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 331 | BlurRectFastGM(const char name[], unsigned int rectWidth, |
| 332 | unsigned int rectHeight, float blurRadius, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 333 | SkBlurStyle style) : |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 334 | INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 335 | } |
robertphillips@google.com | 7ce661d | 2013-08-27 16:14:03 +0000 | [diff] [blame] | 336 | |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 337 | protected: |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 338 | virtual bool makeMask(SkMask *m, const SkRect& r) SK_OVERRIDE { |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 339 | return SkBlurMask::BlurRect(SkBlurMask::ConvertRadiusToSigma(this->radius()), |
| 340 | m, r, this->style()); |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 341 | } |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 342 | private: |
| 343 | typedef BlurRectCompareGM INHERITED; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 344 | }; |
| 345 | |
| 346 | class BlurRectSlowGM: public BlurRectCompareGM { |
| 347 | public: |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 348 | BlurRectSlowGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 349 | float blurRadius, SkBlurStyle style) |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 350 | : INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 351 | } |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 352 | |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 353 | protected: |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 354 | virtual bool makeMask(SkMask *m, const SkRect& r) SK_OVERRIDE { |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 355 | SkMask src; |
| 356 | r.roundOut(&src.fBounds); |
| 357 | src.fBounds.offset(-src.fBounds.fLeft, -src.fBounds.fTop); // move to origin |
| 358 | src.fFormat = SkMask::kA8_Format; |
| 359 | src.fRowBytes = src.fBounds.width(); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 360 | src.fImage = SkMask::AllocImage(src.computeTotalImageSize()); |
bsalomon@google.com | 33cdbde | 2013-01-11 20:54:44 +0000 | [diff] [blame] | 361 | SkAutoMaskFreeImage amfi(src.fImage); |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 362 | |
bsalomon@google.com | 33cdbde | 2013-01-11 20:54:44 +0000 | [diff] [blame] | 363 | memset(src.fImage, 0xff, src.computeTotalImageSize()); |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 364 | |
skia.committer@gmail.com | b3ec29d | 2013-09-07 07:01:16 +0000 | [diff] [blame] | 365 | return SkBlurMask::BoxBlur(m, src, |
| 366 | SkBlurMask::ConvertRadiusToSigma(this->radius()), |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 367 | this->style(), this->getQuality()); |
reed@google.com | 140d728 | 2013-01-07 20:25:04 +0000 | [diff] [blame] | 368 | } |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 369 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 370 | virtual SkBlurQuality getQuality() { |
| 371 | return kHigh_SkBlurQuality; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 372 | } |
| 373 | private: |
| 374 | typedef BlurRectCompareGM INHERITED; |
| 375 | }; |
| 376 | |
| 377 | class BlurRectSlowLowGM: public BlurRectSlowGM { |
| 378 | public: |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 379 | BlurRectSlowLowGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 380 | float blurRadius, SkBlurStyle style) |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 381 | : INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 382 | } |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 383 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 384 | protected: |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 385 | virtual SkBlurQuality getQuality() SK_OVERRIDE { |
| 386 | return kLow_SkBlurQuality; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 387 | } |
| 388 | private: |
| 389 | typedef BlurRectSlowGM INHERITED; |
| 390 | }; |
| 391 | |
| 392 | class BlurRectGroundTruthGM: public BlurRectCompareGM { |
| 393 | public: |
skia.committer@gmail.com | d454ec1 | 2013-02-21 07:15:03 +0000 | [diff] [blame] | 394 | BlurRectGroundTruthGM(const char name[], unsigned int rectWidth, unsigned int rectHeight, |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 395 | float blurRadius, SkBlurStyle style) |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 396 | : INHERITED(name, rectWidth, rectHeight, blurRadius, style) { |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 397 | } |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 398 | |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 399 | protected: |
| 400 | virtual bool makeMask(SkMask *m, const SkRect& r) SK_OVERRIDE { |
| 401 | SkMask src; |
| 402 | r.roundOut(&src.fBounds); |
| 403 | src.fBounds.offset(-src.fBounds.fLeft, -src.fBounds.fTop); // move to origin |
| 404 | src.fFormat = SkMask::kA8_Format; |
| 405 | src.fRowBytes = src.fBounds.width(); |
| 406 | src.fImage = SkMask::AllocImage(src.computeTotalImageSize()); |
| 407 | SkAutoMaskFreeImage amfi(src.fImage); |
| 408 | |
| 409 | memset(src.fImage, 0xff, src.computeTotalImageSize()); |
| 410 | |
robertphillips@google.com | b706117 | 2013-09-06 14:16:12 +0000 | [diff] [blame] | 411 | return SkBlurMask::BlurGroundTruth(SkBlurMask::ConvertRadiusToSigma(this->radius()), |
| 412 | m, src, this->style()); |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 413 | } |
| 414 | |
commit-bot@chromium.org | e396455 | 2014-04-28 16:25:35 +0000 | [diff] [blame] | 415 | virtual SkBlurQuality getQuality() { |
| 416 | return kHigh_SkBlurQuality; |
humper@google.com | a99a92c | 2013-02-20 16:42:06 +0000 | [diff] [blame] | 417 | } |
| 418 | private: |
| 419 | typedef BlurRectCompareGM INHERITED; |
humper@google.com | 7c7292c | 2013-01-04 20:29:03 +0000 | [diff] [blame] | 420 | }; |
| 421 | |
| 422 | |
reed@google.com | db87c96 | 2012-11-02 21:11:12 +0000 | [diff] [blame] | 423 | ////////////////////////////////////////////////////////////////////////////// |
| 424 | |
commit-bot@chromium.org | 7cced56 | 2014-01-10 23:10:13 +0000 | [diff] [blame] | 425 | DEF_GM(return new BlurRectGM("blurrects", 0xFF);) |
commit-bot@chromium.org | 3c1594a | 2014-05-28 21:52:12 +0000 | [diff] [blame] | 426 | DEF_GM(return new BlurRectDirectGM("blurrect_gallery");) |