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 "sk_tool_utils.h" 10 #include "SkBlurImageFilter.h" 11 #include "SkRandom.h" 12 13 #define WIDTH 640 14 #define HEIGHT 480 15 16 namespace skiagm { 17 18 class ImageBlurTiledGM : public GM { 19 public: ImageBlurTiledGM(SkScalar sigmaX,SkScalar sigmaY)20 ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY) 21 : fSigmaX(sigmaX), fSigmaY(sigmaY) { 22 } 23 24 protected: onShortName()25 SkString onShortName() override { 26 return SkString("imageblurtiled"); 27 } 28 onISize()29 SkISize onISize() override { 30 return SkISize::Make(WIDTH, HEIGHT); 31 } 32 onDraw(SkCanvas * canvas)33 void onDraw(SkCanvas* canvas) override { 34 SkPaint paint; 35 paint.setImageFilter(SkBlurImageFilter::Make(fSigmaX, fSigmaY, nullptr)); 36 const SkScalar tileSize = SkIntToScalar(128); 37 SkRect bounds = canvas->getLocalClipBounds(); 38 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tileSize) { 39 for (SkScalar x = bounds.left(); x < bounds.right(); x += tileSize) { 40 canvas->save(); 41 canvas->clipRect(SkRect::MakeXYWH(x, y, tileSize, tileSize)); 42 canvas->saveLayer(nullptr, &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 sk_tool_utils::set_portable_typeface(&textPaint); 52 textPaint.setTextSize(SkIntToScalar(100)); 53 int posY = 0; 54 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) { 55 posY += 100; 56 canvas->drawString(str[i], SkIntToScalar(0), 57 SkIntToScalar(posY), textPaint); 58 } 59 canvas->restore(); 60 canvas->restore(); 61 } 62 } 63 } 64 65 private: 66 SkScalar fSigmaX; 67 SkScalar fSigmaY; 68 69 typedef GM INHERITED; 70 }; 71 72 ////////////////////////////////////////////////////////////////////////////// 73 74 DEF_GM(return new ImageBlurTiledGM(3.0f, 3.0f);) 75 76 } 77