blob: 5e4835033a548fab729f3dab2c30b7f767ad544a [file] [log] [blame]
bsalomon@google.com82aa7482012-08-13 14:22:17 +00001/*
2 * Copyright 2012 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 "SkMagnifierImageFilter.h"
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000010#include "SkRandom.h"
bsalomon@google.com82aa7482012-08-13 14:22:17 +000011
12#define WIDTH 500
13#define HEIGHT 500
14
15namespace skiagm {
16
17class ImageMagnifierGM : public GM {
18public:
19 ImageMagnifierGM() {
20 this->setBGColor(0xFF000000);
21 }
22
23protected:
scroggo@google.com63258862012-08-15 16:32:19 +000024
mtklein36352bf2015-03-25 18:17:31 -070025 SkString onShortName() override {
bsalomon@google.com82aa7482012-08-13 14:22:17 +000026 return SkString("imagemagnifier");
27 }
28
mtklein36352bf2015-03-25 18:17:31 -070029 SkISize onISize() override {
tfarinaf5393182014-06-09 23:59:03 -070030 return SkISize::Make(WIDTH, HEIGHT);
bsalomon@google.com82aa7482012-08-13 14:22:17 +000031 }
32
mtklein36352bf2015-03-25 18:17:31 -070033 void onDraw(SkCanvas* canvas) override {
senorblancocbf6b6e2014-10-23 15:00:10 -070034 SkPaint filterPaint;
35 filterPaint.setImageFilter(
commit-bot@chromium.orgcac5fd52014-03-10 10:51:58 +000036 SkMagnifierImageFilter::Create(
commit-bot@chromium.orgf642f8c2013-10-21 15:59:26 +000037 SkRect::MakeXYWH(SkIntToScalar(100), SkIntToScalar(100),
bsalomon@google.com82aa7482012-08-13 14:22:17 +000038 SkIntToScalar(WIDTH / 2),
39 SkIntToScalar(HEIGHT / 2)),
40 100))->unref();
senorblancocbf6b6e2014-10-23 15:00:10 -070041 canvas->saveLayer(NULL, &filterPaint);
bsalomon@google.com82aa7482012-08-13 14:22:17 +000042 const char* str = "The quick brown fox jumped over the lazy dog.";
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000043 SkRandom rand;
bsalomon@google.com82aa7482012-08-13 14:22:17 +000044 for (int i = 0; i < 25; ++i) {
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000045 int x = rand.nextULessThan(WIDTH);
46 int y = rand.nextULessThan(HEIGHT);
senorblancocbf6b6e2014-10-23 15:00:10 -070047 SkPaint paint;
48 sk_tool_utils::set_portable_typeface(&paint);
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000049 paint.setColor(rand.nextBits(24) | 0xFF000000);
mtklein@google.com26c6d582013-09-16 19:05:44 +000050 paint.setTextSize(rand.nextRangeScalar(0, 300));
senorblancocbf6b6e2014-10-23 15:00:10 -070051 paint.setAntiAlias(true);
bsalomon@google.com82aa7482012-08-13 14:22:17 +000052 canvas->drawText(str, strlen(str), SkIntToScalar(x),
53 SkIntToScalar(y), paint);
54 }
55 canvas->restore();
56 }
57
58private:
59 typedef GM INHERITED;
60};
61
62//////////////////////////////////////////////////////////////////////////////
63
64static GM* MyFactory(void*) { return new ImageMagnifierGM; }
65static GMRegistry reg(MyFactory);
66
67}