blob: 371b3088f9e57c378e811183cd0745c5910c88b2 [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 virtual uint32_t onGetFlags() const SK_OVERRIDE {
25 // Skip tiled drawing until https://code.google.com/p/skia/issues/detail?id=781 is fixed.
26 return this->INHERITED::onGetFlags() | GM::kSkipTiled_Flag;
27 }
28
29 virtual SkString onShortName() SK_OVERRIDE {
bsalomon@google.com82aa7482012-08-13 14:22:17 +000030 return SkString("imagemagnifier");
31 }
32
scroggo@google.com63258862012-08-15 16:32:19 +000033 virtual SkISize onISize() SK_OVERRIDE {
tfarinaf5393182014-06-09 23:59:03 -070034 return SkISize::Make(WIDTH, HEIGHT);
bsalomon@google.com82aa7482012-08-13 14:22:17 +000035 }
36
scroggo@google.com63258862012-08-15 16:32:19 +000037 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
senorblancocbf6b6e2014-10-23 15:00:10 -070038 SkPaint filterPaint;
39 filterPaint.setImageFilter(
commit-bot@chromium.orgcac5fd52014-03-10 10:51:58 +000040 SkMagnifierImageFilter::Create(
commit-bot@chromium.orgf642f8c2013-10-21 15:59:26 +000041 SkRect::MakeXYWH(SkIntToScalar(100), SkIntToScalar(100),
bsalomon@google.com82aa7482012-08-13 14:22:17 +000042 SkIntToScalar(WIDTH / 2),
43 SkIntToScalar(HEIGHT / 2)),
44 100))->unref();
senorblancocbf6b6e2014-10-23 15:00:10 -070045 canvas->saveLayer(NULL, &filterPaint);
bsalomon@google.com82aa7482012-08-13 14:22:17 +000046 const char* str = "The quick brown fox jumped over the lazy dog.";
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000047 SkRandom rand;
bsalomon@google.com82aa7482012-08-13 14:22:17 +000048 for (int i = 0; i < 25; ++i) {
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000049 int x = rand.nextULessThan(WIDTH);
50 int y = rand.nextULessThan(HEIGHT);
senorblancocbf6b6e2014-10-23 15:00:10 -070051 SkPaint paint;
52 sk_tool_utils::set_portable_typeface(&paint);
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000053 paint.setColor(rand.nextBits(24) | 0xFF000000);
mtklein@google.com26c6d582013-09-16 19:05:44 +000054 paint.setTextSize(rand.nextRangeScalar(0, 300));
senorblancocbf6b6e2014-10-23 15:00:10 -070055 paint.setAntiAlias(true);
bsalomon@google.com82aa7482012-08-13 14:22:17 +000056 canvas->drawText(str, strlen(str), SkIntToScalar(x),
57 SkIntToScalar(y), paint);
58 }
59 canvas->restore();
60 }
61
62private:
63 typedef GM INHERITED;
64};
65
66//////////////////////////////////////////////////////////////////////////////
67
68static GM* MyFactory(void*) { return new ImageMagnifierGM; }
69static GMRegistry reg(MyFactory);
70
71}