• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 #include "SkRandom.h"
11 
12 #define WIDTH 500
13 #define HEIGHT 500
14 
15 namespace skiagm {
16 
17 class ImageMagnifierGM : public GM {
18 public:
ImageMagnifierGM()19     ImageMagnifierGM() {
20         this->setBGColor(0xFF000000);
21     }
22 
23 protected:
24 
onShortName()25     SkString onShortName() override {
26         return SkString("imagemagnifier");
27     }
28 
onISize()29     SkISize onISize() override {
30         return SkISize::Make(WIDTH, HEIGHT);
31     }
32 
onDraw(SkCanvas * canvas)33     void onDraw(SkCanvas* canvas) override {
34         SkPaint filterPaint;
35         filterPaint.setImageFilter(
36             SkMagnifierImageFilter::Create(
37                 SkRect::MakeXYWH(SkIntToScalar(100), SkIntToScalar(100),
38                                  SkIntToScalar(WIDTH / 2),
39                                  SkIntToScalar(HEIGHT / 2)),
40                 100))->unref();
41         canvas->saveLayer(NULL, &filterPaint);
42         const char* str = "The quick brown fox jumped over the lazy dog.";
43         SkRandom rand;
44         for (int i = 0; i < 25; ++i) {
45             int x = rand.nextULessThan(WIDTH);
46             int y = rand.nextULessThan(HEIGHT);
47             SkPaint paint;
48             sk_tool_utils::set_portable_typeface(&paint);
49             paint.setColor(rand.nextBits(24) | 0xFF000000);
50             paint.setTextSize(rand.nextRangeScalar(0, 300));
51             paint.setAntiAlias(true);
52             canvas->drawText(str, strlen(str), SkIntToScalar(x),
53                              SkIntToScalar(y), paint);
54         }
55         canvas->restore();
56     }
57 
58 private:
59     typedef GM INHERITED;
60 };
61 
62 //////////////////////////////////////////////////////////////////////////////
63 
MyFactory(void *)64 static GM* MyFactory(void*) { return new ImageMagnifierGM; }
65 static GMRegistry reg(MyFactory);
66 
67 }
68