2014-03-25 17:35:10 +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/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkColor.h"
|
2021-01-24 03:07:05 +00:00
|
|
|
#include "include/core/SkImage.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"
|
2021-02-01 18:07:32 +00:00
|
|
|
#include "include/effects/SkImageFilters.h"
|
2014-03-25 17:35:10 +00:00
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
static void draw(SkCanvas* canvas, const SkRect& rect, const SkBitmap& bitmap,
|
2021-02-01 18:07:32 +00:00
|
|
|
const SkMatrix& matrix, const SkSamplingOptions& sampling) {
|
2014-03-25 17:35:10 +00:00
|
|
|
SkPaint paint;
|
2021-02-01 18:07:32 +00:00
|
|
|
paint.setImageFilter(SkImageFilters::MatrixTransform(matrix, sampling, nullptr));
|
2014-03-25 17:35:10 +00:00
|
|
|
canvas->saveLayer(&rect, &paint);
|
2021-02-01 18:07:32 +00:00
|
|
|
canvas->drawImage(bitmap.asImage(), 0, 0, sampling);
|
2014-03-25 17:35:10 +00:00
|
|
|
canvas->restore();
|
2015-09-09 15:16:41 +00:00
|
|
|
}
|
2014-03-25 17:35:10 +00:00
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
static void make_checkerboard(SkBitmap* bitmap) {
|
2014-03-25 17:35:10 +00:00
|
|
|
bitmap->allocN32Pixels(64, 64);
|
|
|
|
SkCanvas canvas(*bitmap);
|
|
|
|
SkPaint darkPaint;
|
2018-08-16 14:17:03 +00:00
|
|
|
darkPaint.setColor(0xFF404040);
|
2014-03-25 17:35:10 +00:00
|
|
|
SkPaint lightPaint;
|
2018-08-16 14:17:03 +00:00
|
|
|
lightPaint.setColor(0xFFA0A0A0);
|
2014-03-25 17:35:10 +00:00
|
|
|
for (int y = 0; y < 64; y += 32) {
|
|
|
|
for (int x = 0; x < 64; x += 32) {
|
|
|
|
canvas.save();
|
|
|
|
canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
|
|
|
|
canvas.drawRect(SkRect::MakeXYWH(0, 0, 16, 16), darkPaint);
|
|
|
|
canvas.drawRect(SkRect::MakeXYWH(16, 0, 16, 16), lightPaint);
|
|
|
|
canvas.drawRect(SkRect::MakeXYWH(0, 16, 16, 16), lightPaint);
|
|
|
|
canvas.drawRect(SkRect::MakeXYWH(16, 16, 16, 16), darkPaint);
|
|
|
|
canvas.restore();
|
|
|
|
}
|
|
|
|
}
|
2015-09-09 15:16:41 +00:00
|
|
|
}
|
2014-03-25 17:35:10 +00:00
|
|
|
|
2015-09-09 15:16:41 +00:00
|
|
|
DEF_SIMPLE_GM_BG(matriximagefilter, canvas, 420, 100, SK_ColorBLACK) {
|
2014-03-25 17:35:10 +00:00
|
|
|
SkMatrix matrix;
|
|
|
|
SkScalar margin = SkIntToScalar(10);
|
|
|
|
matrix.setSkew(SkDoubleToScalar(0.5), SkDoubleToScalar(0.2));
|
|
|
|
SkBitmap checkerboard;
|
|
|
|
make_checkerboard(&checkerboard);
|
|
|
|
|
|
|
|
SkRect srcRect = SkRect::MakeWH(96, 96);
|
|
|
|
|
|
|
|
canvas->translate(margin, margin);
|
2021-02-01 18:07:32 +00:00
|
|
|
draw(canvas, srcRect, checkerboard, matrix, SkSamplingOptions());
|
2014-03-25 17:35:10 +00:00
|
|
|
|
|
|
|
canvas->translate(srcRect.width() + margin, 0);
|
2021-02-01 18:07:32 +00:00
|
|
|
draw(canvas, srcRect, checkerboard, matrix, SkSamplingOptions(SkFilterMode::kLinear));
|
2014-03-25 17:35:10 +00:00
|
|
|
}
|