blob: e2847b4c67312707b5aa1110a3b87986702a877a [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 {
bsalomon@google.com82aa7482012-08-13 14:22:17 +000038 SkPaint paint;
39 paint.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();
45 canvas->saveLayer(NULL, &paint);
46 paint.setAntiAlias(true);
Cary Clark992c7b02014-07-31 08:58:44 -040047 sk_tool_utils::set_portable_typeface(&paint);
bsalomon@google.com82aa7482012-08-13 14:22:17 +000048 const char* str = "The quick brown fox jumped over the lazy dog.";
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000049 SkRandom rand;
bsalomon@google.com82aa7482012-08-13 14:22:17 +000050 for (int i = 0; i < 25; ++i) {
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000051 int x = rand.nextULessThan(WIDTH);
52 int y = rand.nextULessThan(HEIGHT);
53 paint.setColor(rand.nextBits(24) | 0xFF000000);
mtklein@google.com26c6d582013-09-16 19:05:44 +000054 paint.setTextSize(rand.nextRangeScalar(0, 300));
bsalomon@google.com82aa7482012-08-13 14:22:17 +000055 canvas->drawText(str, strlen(str), SkIntToScalar(x),
56 SkIntToScalar(y), paint);
57 }
58 canvas->restore();
59 }
60
61private:
62 typedef GM INHERITED;
63};
64
65//////////////////////////////////////////////////////////////////////////////
66
67static GM* MyFactory(void*) { return new ImageMagnifierGM; }
68static GMRegistry reg(MyFactory);
69
70}