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
DEF_SIMPLE_GM_BG(imagemagnifier,canvas,WIDTH,HEIGHT,SK_ColorBLACK)15 DEF_SIMPLE_GM_BG(imagemagnifier, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
16 SkPaint filterPaint;
17 filterPaint.setImageFilter(
18 SkMagnifierImageFilter::Create(
19 SkRect::MakeXYWH(SkIntToScalar(100), SkIntToScalar(100),
20 SkIntToScalar(WIDTH / 2),
21 SkIntToScalar(HEIGHT / 2)),
22 100))->unref();
23 canvas->saveLayer(nullptr, &filterPaint);
24 const char* str = "The quick brown fox jumped over the lazy dog.";
25 SkRandom rand;
26 for (int i = 0; i < 25; ++i) {
27 int x = rand.nextULessThan(WIDTH);
28 int y = rand.nextULessThan(HEIGHT);
29 SkPaint paint;
30 sk_tool_utils::set_portable_typeface(&paint);
31 paint.setColor(sk_tool_utils::color_to_565(rand.nextBits(24) | 0xFF000000));
32 paint.setTextSize(rand.nextRangeScalar(0, 300));
33 paint.setAntiAlias(true);
34 canvas->drawText(str, strlen(str), SkIntToScalar(x),
35 SkIntToScalar(y), paint);
36 }
37 canvas->restore();
38 }
39