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