blob: 257e0b259c008108df4072506e1257eb3d8d1b5b [file] [log] [blame]
senorblanco@chromium.org897b73f2014-02-19 22:10:12 +00001/*
2 * Copyright 2014 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"
Mike Klein33d20552017-03-22 13:47:51 -04009#include "sk_tool_utils.h"
senorblanco8c874ee2015-03-20 06:38:17 -070010#include "SkImageFilter.h"
senorblanco@chromium.org897b73f2014-02-19 22:10:12 +000011#include "SkRandom.h"
12
13#define WIDTH 640
14#define HEIGHT 480
15
16#define RESIZE_FACTOR SkIntToScalar(2)
17
halcanary2a243382015-09-09 08:16:41 -070018DEF_SIMPLE_GM(imageresizetiled, canvas, WIDTH, HEIGHT) {
senorblanco@chromium.org897b73f2014-02-19 22:10:12 +000019 SkPaint paint;
senorblanco@chromium.orgfd0ec2c2014-03-25 17:35:10 +000020 SkMatrix matrix;
21 matrix.setScale(RESIZE_FACTOR, RESIZE_FACTOR);
robertphillipsae8c9332016-04-05 15:09:00 -070022 paint.setImageFilter(SkImageFilter::MakeMatrixFilter(matrix,
23 kNone_SkFilterQuality,
24 nullptr));
senorblanco@chromium.org897b73f2014-02-19 22:10:12 +000025 const SkScalar tile_size = SkIntToScalar(100);
senorblanco@chromium.org897b73f2014-02-19 22:10:12 +000026 for (SkScalar y = 0; y < HEIGHT; y += tile_size) {
27 for (SkScalar x = 0; x < WIDTH; x += tile_size) {
28 canvas->save();
29 canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size));
30 canvas->scale(SkScalarInvert(RESIZE_FACTOR),
31 SkScalarInvert(RESIZE_FACTOR));
halcanary96fcdcc2015-08-27 07:41:13 -070032 canvas->saveLayer(nullptr, &paint);
senorblanco@chromium.org897b73f2014-02-19 22:10:12 +000033 const char* str[] = {
34 "The quick",
35 "brown fox",
36 "jumped over",
37 "the lazy dog.",
38 };
39 SkPaint textPaint;
40 textPaint.setAntiAlias(true);
caryclark1818acb2015-07-24 12:09:25 -070041 sk_tool_utils::set_portable_typeface(&textPaint);
senorblanco@chromium.org897b73f2014-02-19 22:10:12 +000042 textPaint.setTextSize(SkIntToScalar(100));
43 int posY = 0;
44 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) {
45 posY += 100;
Cary Clark2a475ea2017-04-28 15:35:12 -040046 canvas->drawString(str[i], SkIntToScalar(0),
senorblanco@chromium.org897b73f2014-02-19 22:10:12 +000047 SkIntToScalar(posY), textPaint);
48 }
49 canvas->restore();
50 canvas->restore();
51 }
52 }
senorblanco@chromium.org897b73f2014-02-19 22:10:12 +000053}