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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gm.h"
|
2017-03-22 17:47:51 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2014-05-28 17:30:02 +00:00
|
|
|
|
2014-06-18 21:32:48 +00:00
|
|
|
#include "Resources.h"
|
|
|
|
#include "SkBitmapProcState.h"
|
|
|
|
#include "SkBitmapScaler.h"
|
|
|
|
#include "SkGradientShader.h"
|
2014-05-28 17:30:02 +00:00
|
|
|
#include "SkImageEncoder.h"
|
2014-06-18 21:32:48 +00:00
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkTypeface.h"
|
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 {
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2014-05-28 17:30:02 +00:00
|
|
|
this->makeBitmap();
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
SkBitmap fBM;
|
|
|
|
SkMatrix fMatrix[2];
|
|
|
|
SkString fName;
|
|
|
|
|
2014-06-13 00:40:00 +00:00
|
|
|
FilterIndiaBoxGM() {
|
2015-06-15 13:51:08 +00:00
|
|
|
this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
|
2014-05-28 17:30:02 +00:00
|
|
|
}
|
|
|
|
|
2014-06-13 00:40:00 +00:00
|
|
|
FilterIndiaBoxGM(const char filename[]) : fFilename(filename) {
|
2014-05-28 17:30:02 +00:00
|
|
|
fName.printf("filterindiabox");
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2014-05-28 17:30:02 +00:00
|
|
|
return fName;
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-05-28 17:30:02 +00:00
|
|
|
return SkISize::Make(1024, 768);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkString fFilename;
|
|
|
|
int fSize;
|
|
|
|
|
|
|
|
SkScalar getScale() {
|
|
|
|
return 192.f/fSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
void makeBitmap() {
|
2016-03-18 19:13:47 +00:00
|
|
|
if (!GetResourceAsBitmap(fFilename.c_str(), &fBM)) {
|
|
|
|
fBM.allocN32Pixels(1, 1);
|
|
|
|
fBM.eraseARGB(255, 255, 0 , 0); // red == bad
|
|
|
|
}
|
|
|
|
fSize = fBM.height();
|
2014-05-28 17:30:02 +00:00
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
DEF_GM( return new FilterIndiaBoxGM("box.gif"); )
|