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