blob: 4c3f42d825ce194d502013740c9e7a8fd48423ed [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"
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000010#include "SkRandom.h"
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000011
senorblanco@chromium.org54e01b22011-11-16 18:20:47 +000012#define WIDTH 500
13#define HEIGHT 500
14
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000015namespace skiagm {
16
17class ImageBlurGM : public GM {
18public:
commit-bot@chromium.orgc45ece52014-01-13 08:16:45 +000019 ImageBlurGM(SkScalar sigmaX, SkScalar sigmaY, const char* suffix)
20 : fSigmaX(sigmaX), fSigmaY(sigmaY) {
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000021 this->setBGColor(0xFF000000);
commit-bot@chromium.orgc45ece52014-01-13 08:16:45 +000022 fName.printf("imageblur%s", suffix);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000023 }
rmistry@google.comd6176b02012-08-23 18:14:13 +000024
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000025protected:
26 virtual SkString onShortName() {
commit-bot@chromium.orgc45ece52014-01-13 08:16:45 +000027 return fName;
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000028 }
29
30 virtual SkISize onISize() {
senorblanco@chromium.org54e01b22011-11-16 18:20:47 +000031 return make_isize(WIDTH, HEIGHT);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000032 }
33
34 virtual void onDraw(SkCanvas* canvas) {
35 SkPaint paint;
commit-bot@chromium.orgc45ece52014-01-13 08:16:45 +000036 paint.setImageFilter(new SkBlurImageFilter(fSigmaX, fSigmaY))->unref();
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000037 canvas->saveLayer(NULL, &paint);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000038 const char* str = "The quick brown fox jumped over the lazy dog.";
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000039
40 SkRandom rand;
senorblanco@chromium.org1e95d712012-07-18 19:52:53 +000041 SkPaint textPaint;
42 textPaint.setAntiAlias(true);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000043 for (int i = 0; i < 25; ++i) {
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000044 int x = rand.nextULessThan(WIDTH);
45 int y = rand.nextULessThan(HEIGHT);
46 textPaint.setColor(rand.nextBits(24) | 0xFF000000);
mtklein@google.com26c6d582013-09-16 19:05:44 +000047 textPaint.setTextSize(rand.nextRangeScalar(0, 300));
tomhudson@google.com75589252012-04-10 17:42:21 +000048 canvas->drawText(str, strlen(str), SkIntToScalar(x),
senorblanco@chromium.org1e95d712012-07-18 19:52:53 +000049 SkIntToScalar(y), textPaint);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000050 }
51 canvas->restore();
52 }
rmistry@google.comd6176b02012-08-23 18:14:13 +000053
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000054private:
commit-bot@chromium.orgc45ece52014-01-13 08:16:45 +000055 SkScalar fSigmaX;
56 SkScalar fSigmaY;
57 SkString fName;
58
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000059 typedef GM INHERITED;
60};
61
62//////////////////////////////////////////////////////////////////////////////
63
commit-bot@chromium.orgc45ece52014-01-13 08:16:45 +000064static GM* MyFactory1(void*) { return new ImageBlurGM(24.0f, 0.0f, ""); }
65static GMRegistry reg1(MyFactory1);
66
67static GM* MyFactory2(void*) { return new ImageBlurGM(80.0f, 80.0f, "_large"); }
68static GMRegistry reg2(MyFactory2);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000069
70}