blob: 73639813a32d16cfc8f19e8c418a2f76a6e00169 [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
halcanary2a243382015-09-09 08:16:41 -070015DEF_SIMPLE_GM_BG(imagemagnifier, canvas, WIDTH, HEIGHT, SK_ColorBLACK) {
senorblancocbf6b6e2014-10-23 15:00:10 -070016 SkPaint filterPaint;
17 filterPaint.setImageFilter(
commit-bot@chromium.orgcac5fd52014-03-10 10:51:58 +000018 SkMagnifierImageFilter::Create(
commit-bot@chromium.orgf642f8c2013-10-21 15:59:26 +000019 SkRect::MakeXYWH(SkIntToScalar(100), SkIntToScalar(100),
bsalomon@google.com82aa7482012-08-13 14:22:17 +000020 SkIntToScalar(WIDTH / 2),
21 SkIntToScalar(HEIGHT / 2)),
22 100))->unref();
halcanary96fcdcc2015-08-27 07:41:13 -070023 canvas->saveLayer(nullptr, &filterPaint);
bsalomon@google.com82aa7482012-08-13 14:22:17 +000024 const char* str = "The quick brown fox jumped over the lazy dog.";
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000025 SkRandom rand;
bsalomon@google.com82aa7482012-08-13 14:22:17 +000026 for (int i = 0; i < 25; ++i) {
mtklein@google.comcfa7ba72013-09-16 18:19:30 +000027 int x = rand.nextULessThan(WIDTH);
28 int y = rand.nextULessThan(HEIGHT);
senorblancocbf6b6e2014-10-23 15:00:10 -070029 SkPaint paint;
caryclark1818acb2015-07-24 12:09:25 -070030 sk_tool_utils::set_portable_typeface(&paint);
caryclarkd2ce1852015-07-16 12:35:58 -070031 paint.setColor(sk_tool_utils::color_to_565(rand.nextBits(24) | 0xFF000000));
mtklein@google.com26c6d582013-09-16 19:05:44 +000032 paint.setTextSize(rand.nextRangeScalar(0, 300));
senorblancocbf6b6e2014-10-23 15:00:10 -070033 paint.setAntiAlias(true);
bsalomon@google.com82aa7482012-08-13 14:22:17 +000034 canvas->drawText(str, strlen(str), SkIntToScalar(x),
35 SkIntToScalar(y), paint);
36 }
37 canvas->restore();
bsalomon@google.com82aa7482012-08-13 14:22:17 +000038}