OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 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 */ |
| 7 |
| 8 #include "gm.h" |
| 9 #include "SkBlurImageFilter.h" |
| 10 #include "SkRandom.h" |
| 11 |
| 12 #define WIDTH 640 |
| 13 #define HEIGHT 480 |
| 14 |
| 15 namespace skiagm { |
| 16 |
| 17 class ImageBlurTiledGM : public GM { |
| 18 public: |
| 19 ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY) |
| 20 : fSigmaX(sigmaX), fSigmaY(sigmaY) { |
| 21 } |
| 22 |
| 23 protected: |
| 24 virtual SkString onShortName() { |
| 25 return SkString("imageblurtiled"); |
| 26 } |
| 27 |
| 28 virtual SkISize onISize() { |
| 29 return make_isize(WIDTH, HEIGHT); |
| 30 } |
| 31 |
| 32 virtual void onDraw(SkCanvas* canvas) { |
| 33 SkPaint paint; |
| 34 paint.setImageFilter(new SkBlurImageFilter(fSigmaX, fSigmaY))->unref(); |
| 35 const SkScalar tile_size = SkIntToScalar(128); |
| 36 SkRect bounds; |
| 37 canvas->getClipBounds(&bounds); |
| 38 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tile_size) { |
| 39 for (SkScalar x = bounds.left(); x < bounds.right(); x += tile_size)
{ |
| 40 canvas->save(); |
| 41 canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size)); |
| 42 canvas->saveLayer(NULL, &paint); |
| 43 const char* str[] = { |
| 44 "The quick", |
| 45 "brown fox", |
| 46 "jumped over", |
| 47 "the lazy dog.", |
| 48 }; |
| 49 SkPaint textPaint; |
| 50 textPaint.setAntiAlias(true); |
| 51 textPaint.setTextSize(SkIntToScalar(100)); |
| 52 int posY = 0; |
| 53 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) { |
| 54 posY += 100; |
| 55 canvas->drawText(str[i], strlen(str[i]), SkIntToScalar(0), |
| 56 SkIntToScalar(posY), textPaint); |
| 57 } |
| 58 canvas->restore(); |
| 59 canvas->restore(); |
| 60 } |
| 61 } |
| 62 } |
| 63 |
| 64 private: |
| 65 SkScalar fSigmaX; |
| 66 SkScalar fSigmaY; |
| 67 |
| 68 typedef GM INHERITED; |
| 69 }; |
| 70 |
| 71 ////////////////////////////////////////////////////////////////////////////// |
| 72 |
| 73 static GM* MyFactory1(void*) { return new ImageBlurTiledGM(3.0f, 3.0f); } |
| 74 static GMRegistry reg1(MyFactory1); |
| 75 |
| 76 } |
OLD | NEW |