2014-05-28 17:30:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 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"
|
|
|
|
#include "include/core/SkFilterQuality.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/Resources.h"
|
2019-05-01 21:28:53 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
2014-05-28 17:30:02 +00:00
|
|
|
|
2019-07-18 17:35:49 +00:00
|
|
|
namespace {
|
2014-05-28 17:30:02 +00:00
|
|
|
static SkSize computeSize(const SkBitmap& bm, const SkMatrix& mat) {
|
|
|
|
SkRect bounds = SkRect::MakeWH(SkIntToScalar(bm.width()),
|
|
|
|
SkIntToScalar(bm.height()));
|
|
|
|
mat.mapRect(&bounds);
|
|
|
|
return SkSize::Make(bounds.width(), bounds.height());
|
|
|
|
}
|
|
|
|
|
2014-12-10 17:02:16 +00:00
|
|
|
static void draw_cell(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat, SkScalar dx,
|
2015-03-16 17:08:34 +00:00
|
|
|
SkFilterQuality lvl) {
|
2014-05-28 17:30:02 +00:00
|
|
|
SkPaint paint;
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(lvl);
|
2014-05-28 17:30:02 +00:00
|
|
|
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
|
|
|
|
canvas->translate(dx, 0);
|
2014-12-10 17:02:16 +00:00
|
|
|
canvas->concat(mat);
|
|
|
|
canvas->drawBitmap(bm, 0, 0, &paint);
|
|
|
|
}
|
2014-05-28 17:30:02 +00:00
|
|
|
|
2014-12-10 17:02:16 +00:00
|
|
|
static void draw_row(SkCanvas* canvas, const SkBitmap& bm, const SkMatrix& mat, SkScalar dx) {
|
2015-03-16 17:08:34 +00:00
|
|
|
draw_cell(canvas, bm, mat, 0 * dx, kNone_SkFilterQuality);
|
|
|
|
draw_cell(canvas, bm, mat, 1 * dx, kLow_SkFilterQuality);
|
|
|
|
draw_cell(canvas, bm, mat, 2 * dx, kMedium_SkFilterQuality);
|
|
|
|
draw_cell(canvas, bm, mat, 3 * dx, kHigh_SkFilterQuality);
|
2014-05-28 17:30:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class FilterIndiaBoxGM : public skiagm::GM {
|
2019-07-18 17:35:49 +00:00
|
|
|
SkBitmap fBM;
|
|
|
|
SkMatrix fMatrix[2];
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2019-07-18 17:35:49 +00:00
|
|
|
constexpr char kResource[] = "images/box.gif";
|
|
|
|
if (!GetResourceAsBitmap(kResource, &fBM)) {
|
|
|
|
fBM.allocN32Pixels(1, 1);
|
|
|
|
fBM.eraseARGB(255, 255, 0 , 0); // red == bad
|
|
|
|
}
|
2020-03-12 14:52:15 +00:00
|
|
|
fBM.setImmutable();
|
2014-05-28 17:30:02 +00:00
|
|
|
|
|
|
|
SkScalar cx = SkScalarHalf(fBM.width());
|
|
|
|
SkScalar cy = SkScalarHalf(fBM.height());
|
|
|
|
|
|
|
|
float vertScale = 30.0f/55.0f;
|
|
|
|
float horizScale = 150.0f/200.0f;
|
|
|
|
|
|
|
|
fMatrix[0].setScale(horizScale, vertScale);
|
|
|
|
fMatrix[1].setRotate(30, cx, cy); fMatrix[1].postScale(horizScale, vertScale);
|
|
|
|
}
|
|
|
|
|
2019-07-18 17:35:49 +00:00
|
|
|
SkString onShortName() override { return SkString("filterindiabox"); }
|
2014-05-28 17:30:02 +00:00
|
|
|
|
2019-07-18 17:35:49 +00:00
|
|
|
SkISize onISize() override { return {680, 130}; }
|
2014-05-28 17:30:02 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-05-28 17:30:02 +00:00
|
|
|
canvas->translate(10, 10);
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fMatrix); ++i) {
|
|
|
|
SkSize size = computeSize(fBM, fMatrix[i]);
|
|
|
|
size.fWidth += 20;
|
|
|
|
size.fHeight += 20;
|
|
|
|
|
|
|
|
draw_row(canvas, fBM, fMatrix[i], size.fWidth);
|
|
|
|
canvas->translate(0, size.fHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2019-07-18 17:35:49 +00:00
|
|
|
} // namespace
|
2014-05-28 17:30:02 +00:00
|
|
|
|
2019-07-18 17:35:49 +00:00
|
|
|
DEF_GM( return new FilterIndiaBoxGM(); )
|