1 /* 2 * Copyright 2011 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 500 13 #define HEIGHT 500 14 15 namespace skiagm { 16 17 class ImageBlurGM : public GM { 18 public: 19 ImageBlurGM(SkScalar sigmaX, SkScalar sigmaY, const char* suffix) 20 : fSigmaX(sigmaX), fSigmaY(sigmaY) { 21 this->setBGColor(0xFF000000); 22 fName.printf("imageblur%s", suffix); 23 } 24 25 protected: 26 virtual uint32_t onGetFlags() const SK_OVERRIDE { 27 return kSkipTiled_Flag; 28 } 29 30 virtual SkString onShortName() { 31 return fName; 32 } 33 34 virtual SkISize onISize() { 35 return SkISize::Make(WIDTH, HEIGHT); 36 } 37 38 virtual void onDraw(SkCanvas* canvas) { 39 SkPaint paint; 40 paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY))->unref(); 41 canvas->saveLayer(NULL, &paint); 42 const char* str = "The quick brown fox jumped over the lazy dog."; 43 44 SkRandom rand; 45 SkPaint textPaint; 46 textPaint.setAntiAlias(true); 47 for (int i = 0; i < 25; ++i) { 48 int x = rand.nextULessThan(WIDTH); 49 int y = rand.nextULessThan(HEIGHT); 50 textPaint.setColor(rand.nextBits(24) | 0xFF000000); 51 textPaint.setTextSize(rand.nextRangeScalar(0, 300)); 52 canvas->drawText(str, strlen(str), SkIntToScalar(x), 53 SkIntToScalar(y), textPaint); 54 } 55 canvas->restore(); 56 } 57 58 private: 59 SkScalar fSigmaX; 60 SkScalar fSigmaY; 61 SkString fName; 62 63 typedef GM INHERITED; 64 }; 65 66 ////////////////////////////////////////////////////////////////////////////// 67 68 static GM* MyFactory1(void*) { return new ImageBlurGM(24.0f, 0.0f, ""); } 69 static GMRegistry reg1(MyFactory1); 70 71 static GM* MyFactory2(void*) { return new ImageBlurGM(80.0f, 80.0f, "_large"); } 72 static GMRegistry reg2(MyFactory2); 73 74 } 75