blob: f073e3305a8ff8a310ff32b9b05743b6325f61da [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 {
bsalomon@google.com82aa7482012-08-13 14:22:17 +000034 return make_isize(WIDTH, HEIGHT);
35 }
36
scroggo@google.com63258862012-08-15 16:32:19 +000037 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
bsalomon@google.com82aa7482012-08-13 14:22:17 +000038 SkPaint paint;
39 paint.setImageFilter(
40 new SkMagnifierImageFilter(
41 SkRect::MakeXYWH(SkIntToScalar(125), SkIntToScalar(125),
42 SkIntToScalar(WIDTH / 2),
43 SkIntToScalar(HEIGHT / 2)),
44 100))->unref();
45 canvas->saveLayer(NULL, &paint);
46 paint.setAntiAlias(true);
47 const char* str = "The quick brown fox jumped over the lazy dog.";
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000048 SkRandom rand;
bsalomon@google.com82aa7482012-08-13 14:22:17 +000049 for (int i = 0; i < 25; ++i) {
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000050 int x = rand.nextULessThan(WIDTH);
51 int y = rand.nextULessThan(HEIGHT);
52 paint.setColor(rand.nextBits(24) | 0xFF000000);
mtklein@google.com26c6d582013-09-16 19:05:44 +000053 paint.setTextSize(rand.nextRangeScalar(0, 300));
bsalomon@google.com82aa7482012-08-13 14:22:17 +000054 canvas->drawText(str, strlen(str), SkIntToScalar(x),
55 SkIntToScalar(y), paint);
56 }
57 canvas->restore();
58 }
59
60private:
61 typedef GM INHERITED;
62};
63
64//////////////////////////////////////////////////////////////////////////////
65
66static GM* MyFactory(void*) { return new ImageMagnifierGM; }
67static GMRegistry reg(MyFactory);
68
69}