blob: 0b1ab3077ffd3ea347bbddef8798ccfd4cea93ac [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:
commit-bot@chromium.orga90c6802014-04-30 13:20:45 +000026 virtual uint32_t onGetFlags() const SK_OVERRIDE {
27 return kSkipTiled_Flag;
28 }
29
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000030 virtual SkString onShortName() {
commit-bot@chromium.orgc45ece52014-01-13 08:16:45 +000031 return fName;
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000032 }
33
34 virtual SkISize onISize() {
senorblanco@chromium.org54e01b22011-11-16 18:20:47 +000035 return make_isize(WIDTH, HEIGHT);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000036 }
37
38 virtual void onDraw(SkCanvas* canvas) {
39 SkPaint paint;
commit-bot@chromium.orgcac5fd52014-03-10 10:51:58 +000040 paint.setImageFilter(SkBlurImageFilter::Create(fSigmaX, fSigmaY))->unref();
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000041 canvas->saveLayer(NULL, &paint);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000042 const char* str = "The quick brown fox jumped over the lazy dog.";
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000043
44 SkRandom rand;
senorblanco@chromium.org1e95d712012-07-18 19:52:53 +000045 SkPaint textPaint;
46 textPaint.setAntiAlias(true);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000047 for (int i = 0; i < 25; ++i) {
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000048 int x = rand.nextULessThan(WIDTH);
49 int y = rand.nextULessThan(HEIGHT);
50 textPaint.setColor(rand.nextBits(24) | 0xFF000000);
mtklein@google.com26c6d582013-09-16 19:05:44 +000051 textPaint.setTextSize(rand.nextRangeScalar(0, 300));
tomhudson@google.com75589252012-04-10 17:42:21 +000052 canvas->drawText(str, strlen(str), SkIntToScalar(x),
senorblanco@chromium.org1e95d712012-07-18 19:52:53 +000053 SkIntToScalar(y), textPaint);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000054 }
55 canvas->restore();
56 }
rmistry@google.comd6176b02012-08-23 18:14:13 +000057
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000058private:
commit-bot@chromium.orgc45ece52014-01-13 08:16:45 +000059 SkScalar fSigmaX;
60 SkScalar fSigmaY;
61 SkString fName;
62
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000063 typedef GM INHERITED;
64};
65
66//////////////////////////////////////////////////////////////////////////////
67
commit-bot@chromium.orgc45ece52014-01-13 08:16:45 +000068static GM* MyFactory1(void*) { return new ImageBlurGM(24.0f, 0.0f, ""); }
69static GMRegistry reg1(MyFactory1);
70
71static GM* MyFactory2(void*) { return new ImageBlurGM(80.0f, 80.0f, "_large"); }
72static GMRegistry reg2(MyFactory2);
senorblanco@chromium.org60014ca2011-11-09 16:05:58 +000073
74}