2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "SkImageFilter.h"
15 #define RESIZE_FACTOR SkIntToScalar(2)
19 class ImageResizeTiledGM : public GM {
21 ImageResizeTiledGM() {
26 SkString onShortName() SK_OVERRIDE {
27 return SkString("imageresizetiled");
30 SkISize onISize() SK_OVERRIDE {
31 return SkISize::Make(WIDTH, HEIGHT);
34 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
37 matrix.setScale(RESIZE_FACTOR, RESIZE_FACTOR);
38 SkAutoTUnref<SkImageFilter> imageFilter(
39 SkImageFilter::CreateMatrixFilter(matrix, kNone_SkFilterQuality));
40 paint.setImageFilter(imageFilter.get());
41 const SkScalar tile_size = SkIntToScalar(100);
43 canvas->getClipBounds(&bounds);
44 for (SkScalar y = 0; y < HEIGHT; y += tile_size) {
45 for (SkScalar x = 0; x < WIDTH; x += tile_size) {
47 canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size));
48 canvas->scale(SkScalarInvert(RESIZE_FACTOR),
49 SkScalarInvert(RESIZE_FACTOR));
50 canvas->saveLayer(NULL, &paint);
58 textPaint.setAntiAlias(true);
59 sk_tool_utils::set_portable_typeface(&textPaint);
60 textPaint.setTextSize(SkIntToScalar(100));
62 for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) {
64 canvas->drawText(str[i], strlen(str[i]), SkIntToScalar(0),
65 SkIntToScalar(posY), textPaint);
77 //////////////////////////////////////////////////////////////////////////////
79 DEF_GM(return new ImageResizeTiledGM(); )