blob: c8dd5d760c0dc05694c0ceddd0b5927571098020 [file] [log] [blame]
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +00001/*
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
senorblanco@chromium.org54e01b22011-11-16 18:20:47 +000011#define WIDTH 500
12#define HEIGHT 500
13
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000014namespace skiagm {
15
16class ImageBlurGM : public GM {
17public:
18 ImageBlurGM() {
19 this->setBGColor(0xFF000000);
20 }
21
22protected:
23 virtual SkString onShortName() {
24 return SkString("imageblur");
25 }
26
27 virtual SkISize onISize() {
senorblanco@chromium.org54e01b22011-11-16 18:20:47 +000028 return make_isize(WIDTH, HEIGHT);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000029 }
30
31 virtual void onDraw(SkCanvas* canvas) {
32 SkPaint paint;
33 paint.setImageFilter(new SkBlurImageFilter(24.0f, 0.0f))->unref();
34 canvas->saveLayer(NULL, &paint);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000035 paint.setAntiAlias(true);
36 const char* str = "The quick brown fox jumped over the lazy dog.";
37 srand(1234);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000038 for (int i = 0; i < 25; ++i) {
senorblanco@chromium.org54e01b22011-11-16 18:20:47 +000039 int x = rand() % WIDTH;
40 int y = rand() % HEIGHT;
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000041 paint.setColor(rand() % 0x1000000 | 0xFF000000);
tomhudson@google.com75589252012-04-10 17:42:21 +000042 paint.setTextSize(SkIntToScalar(rand() % 300));
43 canvas->drawText(str, strlen(str), SkIntToScalar(x),
44 SkIntToScalar(y), paint);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000045 }
46 canvas->restore();
47 }
48
49private:
50 typedef GM INHERITED;
51};
52
53//////////////////////////////////////////////////////////////////////////////
54
55static GM* MyFactory(void*) { return new ImageBlurGM; }
56static GMRegistry reg(MyFactory);
57
58}