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"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "include/core/SkFilterQuality.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"
|
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,
|
|
|
|
const SkMatrix& matrix, SkFilterQuality filter) {
|
2014-03-25 17:35:10 +00:00
|
|
|
SkPaint paint;
|
2016-04-05 22:09:00 +00:00
|
|
|
paint.setImageFilter(SkImageFilter::MakeMatrixFilter(matrix, filter, nullptr));
|
2014-03-25 17:35:10 +00:00
|
|
|
canvas->saveLayer(&rect, &paint);
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
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);
|
2015-03-16 17:08:34 +00:00
|
|
|
draw(canvas, srcRect, checkerboard, matrix, kNone_SkFilterQuality);
|
2014-03-25 17:35:10 +00:00
|
|
|
|
|
|
|
canvas->translate(srcRect.width() + margin, 0);
|
2015-03-16 17:08:34 +00:00
|
|
|
draw(canvas, srcRect, checkerboard, matrix, kLow_SkFilterQuality);
|
2014-03-25 17:35:10 +00:00
|
|
|
|
2014-03-25 21:12:18 +00:00
|
|
|
#if 0
|
|
|
|
// This may be causing Mac 10.6 to barf.
|
2014-03-25 17:35:10 +00:00
|
|
|
canvas->translate(srcRect.width() + margin, 0);
|
2015-03-16 17:08:34 +00:00
|
|
|
draw(canvas, srcRect, checkerboard, matrix, kMedium_SkFilterQuality);
|
2014-03-25 17:35:10 +00:00
|
|
|
|
|
|
|
canvas->translate(srcRect.width() + margin, 0);
|
2015-03-16 17:08:34 +00:00
|
|
|
draw(canvas, srcRect, checkerboard, matrix, kHigh_SkFilterQuality);
|
2014-03-25 21:12:18 +00:00
|
|
|
#endif
|
2014-03-25 17:35:10 +00:00
|
|
|
}
|