2014-02-19 22:10:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkFont.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkImageFilter.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-08-02 19:21:23 +00:00
|
|
|
#include "include/effects/SkImageFilters.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
2014-02-19 22:10:12 +00:00
|
|
|
|
|
|
|
#define WIDTH 640
|
|
|
|
#define HEIGHT 480
|
|
|
|
|
|
|
|
#define RESIZE_FACTOR SkIntToScalar(2)
|
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
DEF_SIMPLE_GM(imageresizetiled, canvas, WIDTH, HEIGHT) {
|
2014-02-19 22:10:12 +00:00
|
|
|
SkPaint paint;
|
2014-03-25 17:35:10 +00:00
|
|
|
SkMatrix matrix;
|
|
|
|
matrix.setScale(RESIZE_FACTOR, RESIZE_FACTOR);
|
2019-08-02 19:21:23 +00:00
|
|
|
paint.setImageFilter(SkImageFilters::MatrixTransform(matrix,
|
2021-02-01 18:07:32 +00:00
|
|
|
SkSamplingOptions(),
|
2016-04-05 22:09:00 +00:00
|
|
|
nullptr));
|
2019-01-07 21:01:22 +00:00
|
|
|
|
2019-03-20 16:12:10 +00:00
|
|
|
SkFont font(ToolUtils::create_portable_typeface(), 100);
|
2014-02-19 22:10:12 +00:00
|
|
|
const SkScalar tile_size = SkIntToScalar(100);
|
|
|
|
for (SkScalar y = 0; y < HEIGHT; y += tile_size) {
|
|
|
|
for (SkScalar x = 0; x < WIDTH; x += tile_size) {
|
|
|
|
canvas->save();
|
|
|
|
canvas->clipRect(SkRect::MakeXYWH(x, y, tile_size, tile_size));
|
|
|
|
canvas->scale(SkScalarInvert(RESIZE_FACTOR),
|
|
|
|
SkScalarInvert(RESIZE_FACTOR));
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->saveLayer(nullptr, &paint);
|
2014-02-19 22:10:12 +00:00
|
|
|
const char* str[] = {
|
|
|
|
"The quick",
|
|
|
|
"brown fox",
|
|
|
|
"jumped over",
|
|
|
|
"the lazy dog.",
|
|
|
|
};
|
2019-01-07 21:01:22 +00:00
|
|
|
float posY = 0;
|
2014-02-19 22:10:12 +00:00
|
|
|
for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) {
|
2019-01-07 21:01:22 +00:00
|
|
|
posY += 100.0f;
|
|
|
|
canvas->drawString(str[i], 0.0f, posY, font, SkPaint());
|
2014-02-19 22:10:12 +00:00
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|