blob: 0580405dfea99d099d3a01689e71fc9c8954e661 [file] [log] [blame]
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +00001/*
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
15namespace skiagm {
16
17class ImageBlurTiledGM : public GM {
18public:
19 ImageBlurTiledGM(SkScalar sigmaX, SkScalar sigmaY)
20 : fSigmaX(sigmaX), fSigmaY(sigmaY) {
21 }
22
23protected:
24 virtual SkString onShortName() {
25 return SkString("imageblurtiled");
26 }
27
28 virtual SkISize onISize() {
tfarinaf5393182014-06-09 23:59:03 -070029 return SkISize::Make(WIDTH, HEIGHT);
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000030 }
31
32 virtual void onDraw(SkCanvas* canvas) {
33 SkPaint paint;
commit-bot@chromium.orgcac5fd52014-03-10 10:51:58 +000034 paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY))->unref();
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000035 const SkScalar tile_size = SkIntToScalar(128);
36 SkRect bounds;
reed@google.com76b12b72014-04-10 21:15:30 +000037 if (!canvas->getClipBounds(&bounds)) {
38 bounds.setEmpty();
39 }
senorblanco@chromium.orgc4b12f12014-02-05 17:51:22 +000040 for (SkScalar y = bounds.top(); y < bounds.bottom(); y += tile_size) {
41 for (SkScalar x = bounds.left(); x < bounds.right(); x += tile_size) {
42 canvas->save();
43 canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size));
44 canvas->saveLayer(NULL, &paint);
45 const char* str[] = {
46 "The quick",
47 "brown fox",
48 "jumped over",
49 "the lazy dog.",
50 };
51 SkPaint textPaint;
52 textPaint.setAntiAlias(true);
53 textPaint.setTextSize(SkIntToScalar(100));
54 int posY = 0;
55 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) {
56 posY += 100;
57 canvas->drawText(str[i], strlen(str[i]), SkIntToScalar(0),
58 SkIntToScalar(posY), textPaint);
59 }
60 canvas->restore();
61 canvas->restore();
62 }
63 }
64 }
65
66private:
67 SkScalar fSigmaX;
68 SkScalar fSigmaY;
69
70 typedef GM INHERITED;
71};
72
73//////////////////////////////////////////////////////////////////////////////
74
75static GM* MyFactory1(void*) { return new ImageBlurTiledGM(3.0f, 3.0f); }
76static GMRegistry reg1(MyFactory1);
77
78}