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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
2014-03-25 17:35:10 +00:00
|
|
|
#include "SkMatrixImageFilter.h"
|
2014-02-19 22:10:12 +00:00
|
|
|
#include "SkRandom.h"
|
|
|
|
|
|
|
|
#define WIDTH 640
|
|
|
|
#define HEIGHT 480
|
|
|
|
|
|
|
|
#define RESIZE_FACTOR SkIntToScalar(2)
|
|
|
|
|
|
|
|
namespace skiagm {
|
|
|
|
|
|
|
|
class ImageResizeTiledGM : public GM {
|
|
|
|
public:
|
|
|
|
ImageResizeTiledGM() {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2014-07-09 20:10:58 +00:00
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
SkString onShortName() SK_OVERRIDE {
|
2014-02-19 22:10:12 +00:00
|
|
|
return SkString("imageresizetiled");
|
|
|
|
}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
SkISize onISize() SK_OVERRIDE {
|
2014-06-10 06:59:03 +00:00
|
|
|
return SkISize::Make(WIDTH, HEIGHT);
|
2014-02-19 22:10:12 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
void onDraw(SkCanvas* canvas) SK_OVERRIDE {
|
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);
|
2014-02-19 22:10:12 +00:00
|
|
|
SkAutoTUnref<SkImageFilter> imageFilter(
|
2015-03-16 17:08:34 +00:00
|
|
|
SkMatrixImageFilter::Create(matrix, kNone_SkFilterQuality));
|
2014-02-19 22:10:12 +00:00
|
|
|
paint.setImageFilter(imageFilter.get());
|
|
|
|
const SkScalar tile_size = SkIntToScalar(100);
|
|
|
|
SkRect bounds;
|
|
|
|
canvas->getClipBounds(&bounds);
|
|
|
|
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));
|
|
|
|
canvas->saveLayer(NULL, &paint);
|
|
|
|
const char* str[] = {
|
|
|
|
"The quick",
|
|
|
|
"brown fox",
|
|
|
|
"jumped over",
|
|
|
|
"the lazy dog.",
|
|
|
|
};
|
|
|
|
SkPaint textPaint;
|
|
|
|
textPaint.setAntiAlias(true);
|
2014-07-31 12:58:44 +00:00
|
|
|
sk_tool_utils::set_portable_typeface(&textPaint);
|
2014-02-19 22:10:12 +00:00
|
|
|
textPaint.setTextSize(SkIntToScalar(100));
|
|
|
|
int posY = 0;
|
|
|
|
for (unsigned i = 0; i < SK_ARRAY_COUNT(str); i++) {
|
|
|
|
posY += 100;
|
|
|
|
canvas->drawText(str[i], strlen(str[i]), SkIntToScalar(0),
|
|
|
|
SkIntToScalar(posY), textPaint);
|
|
|
|
}
|
|
|
|
canvas->restore();
|
|
|
|
canvas->restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
DEF_GM(return new ImageResizeTiledGM(); )
|
|
|
|
|
|
|
|
}
|