blob: 0966121d0dcd8ed759f121b76e99543d77c0b441 [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"
10
11#define WIDTH 500
12#define HEIGHT 500
13
14namespace skiagm {
15
16class ImageMagnifierGM : public GM {
17public:
18 ImageMagnifierGM() {
19 this->setBGColor(0xFF000000);
20 }
21
22protected:
scroggo@google.com63258862012-08-15 16:32:19 +000023 virtual uint32_t onGetFlags() const SK_OVERRIDE {
24 // Skip tiled drawing until https://code.google.com/p/skia/issues/detail?id=781 is fixed.
25 return this->INHERITED::onGetFlags() | GM::kSkipTiled_Flag;
26 }
27
28 virtual SkString onShortName() SK_OVERRIDE {
bsalomon@google.com82aa7482012-08-13 14:22:17 +000029 return SkString("imagemagnifier");
30 }
31
scroggo@google.com63258862012-08-15 16:32:19 +000032 virtual SkISize onISize() SK_OVERRIDE {
bsalomon@google.com82aa7482012-08-13 14:22:17 +000033 return make_isize(WIDTH, HEIGHT);
34 }
35
scroggo@google.com63258862012-08-15 16:32:19 +000036 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
bsalomon@google.com82aa7482012-08-13 14:22:17 +000037 SkPaint paint;
38 paint.setImageFilter(
39 new SkMagnifierImageFilter(
40 SkRect::MakeXYWH(SkIntToScalar(125), SkIntToScalar(125),
41 SkIntToScalar(WIDTH / 2),
42 SkIntToScalar(HEIGHT / 2)),
43 100))->unref();
44 canvas->saveLayer(NULL, &paint);
45 paint.setAntiAlias(true);
46 const char* str = "The quick brown fox jumped over the lazy dog.";
47 srand(1234);
48 for (int i = 0; i < 25; ++i) {
49 int x = rand() % WIDTH;
50 int y = rand() % HEIGHT;
51 paint.setColor(rand() % 0x1000000 | 0xFF000000);
52 paint.setTextSize(SkIntToScalar(rand() % 300));
53 canvas->drawText(str, strlen(str), SkIntToScalar(x),
54 SkIntToScalar(y), paint);
55 }
56 canvas->restore();
57 }
58
59private:
60 typedef GM INHERITED;
61};
62
63//////////////////////////////////////////////////////////////////////////////
64
65static GM* MyFactory(void*) { return new ImageMagnifierGM; }
66static GMRegistry reg(MyFactory);
67
68}