1 /*
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"
9 #include "sk_tool_utils.h"
10 #include "SkImageFilter.h"
11 #include "SkRandom.h"
12
13 #define WIDTH 640
14 #define HEIGHT 480
15
16 #define RESIZE_FACTOR SkIntToScalar(2)
17
DEF_SIMPLE_GM(imageresizetiled,canvas,WIDTH,HEIGHT)18 DEF_SIMPLE_GM(imageresizetiled, canvas, WIDTH, HEIGHT) {
19 SkPaint paint;
20 SkMatrix matrix;
21 matrix.setScale(RESIZE_FACTOR, RESIZE_FACTOR);
22 paint.setImageFilter(SkImageFilter::MakeMatrixFilter(matrix,
23 kNone_SkFilterQuality,
24 nullptr));
25
26 SkFont font(sk_tool_utils::create_portable_typeface(), 100);
27 const SkScalar tile_size = SkIntToScalar(100);
28 for (SkScalar y = 0; y < HEIGHT; y += tile_size) {
29 for (SkScalar x = 0; x < WIDTH; x += tile_size) {
30 canvas->save();
31 canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size));
32 canvas->scale(SkScalarInvert(RESIZE_FACTOR),
33 SkScalarInvert(RESIZE_FACTOR));
34 canvas->saveLayer(nullptr, &paint);
35 const char* str[] = {
36 "The quick",
37 "brown fox",
38 "jumped over",
39 "the lazy dog.",
40 };
41 float posY = 0;
42 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) {
43 posY += 100.0f;
44 canvas->drawString(str[i], 0.0f, posY, font, SkPaint());
45 }
46 canvas->restore();
47 canvas->restore();
48 }
49 }
50 }
51