2015-04-16 13:54:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 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"
|
2015-04-16 13:54:28 +00:00
|
|
|
|
|
|
|
#include "SkShader.h"
|
|
|
|
|
|
|
|
// Inspired by svg/as-border-image/svg-as-border-image.html. Draws a four-color checker board bitmap
|
|
|
|
// such that it is stretched and repeat tiled with different filter qualities. It is testing whether
|
|
|
|
// the bmp filter respects the repeat mode at the tile seams.
|
|
|
|
class BmpFilterQualityRepeat : public skiagm::GM {
|
|
|
|
public:
|
2015-06-15 13:51:08 +00:00
|
|
|
BmpFilterQualityRepeat() { this->setBGColor(sk_tool_utils::color_to_565(0xFFCCBBAA)); }
|
2015-04-16 13:54:28 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
fBmp.allocN32Pixels(40, 40, true);
|
|
|
|
SkCanvas canvas(fBmp);
|
|
|
|
SkBitmap colorBmp;
|
|
|
|
colorBmp.allocN32Pixels(20, 20, true);
|
|
|
|
colorBmp.eraseColor(0xFFFF0000);
|
|
|
|
canvas.drawBitmap(colorBmp, 0, 0);
|
2015-07-29 12:27:47 +00:00
|
|
|
colorBmp.eraseColor(sk_tool_utils::color_to_565(0xFF008200));
|
2015-04-16 13:54:28 +00:00
|
|
|
canvas.drawBitmap(colorBmp, 20, 0);
|
2015-07-29 12:27:47 +00:00
|
|
|
colorBmp.eraseColor(sk_tool_utils::color_to_565(0xFFFF9000));
|
2015-04-16 13:54:28 +00:00
|
|
|
canvas.drawBitmap(colorBmp, 0, 20);
|
2015-07-29 12:27:47 +00:00
|
|
|
colorBmp.eraseColor(sk_tool_utils::color_to_565(0xFF2000FF));
|
2015-04-16 13:54:28 +00:00
|
|
|
canvas.drawBitmap(colorBmp, 20, 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString onShortName() override { return SkString("bmp_filter_quality_repeat"); }
|
|
|
|
|
2016-11-03 18:42:49 +00:00
|
|
|
SkISize onISize() override { return SkISize::Make(1000, 400); }
|
2015-04-16 13:54:28 +00:00
|
|
|
|
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2016-11-03 18:42:49 +00:00
|
|
|
this->drawAll(canvas, 2.5f);
|
|
|
|
canvas->translate(0, 250);
|
|
|
|
canvas->scale(0.5, 0.5);
|
|
|
|
this->drawAll(canvas, 1);
|
|
|
|
}
|
2015-04-16 13:54:28 +00:00
|
|
|
|
2016-11-03 18:42:49 +00:00
|
|
|
private:
|
|
|
|
void drawAll(SkCanvas* canvas, SkScalar scaleX) const {
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr struct {
|
2015-04-16 13:54:28 +00:00
|
|
|
SkFilterQuality fQuality;
|
|
|
|
const char* fName;
|
|
|
|
} kQualities[] = {
|
|
|
|
{kNone_SkFilterQuality, "none"},
|
|
|
|
{kLow_SkFilterQuality, "low"},
|
|
|
|
{kMedium_SkFilterQuality, "medium"},
|
|
|
|
{kHigh_SkFilterQuality, "high"},
|
|
|
|
};
|
|
|
|
|
2016-11-03 18:42:49 +00:00
|
|
|
SkRect rect = SkRect::MakeLTRB(20, 60, 220, 210);
|
|
|
|
SkMatrix lm = SkMatrix::I();
|
|
|
|
lm.setScaleX(scaleX);
|
|
|
|
lm.setTranslateX(423);
|
|
|
|
lm.setTranslateY(330);
|
|
|
|
|
|
|
|
SkPaint textPaint;
|
|
|
|
textPaint.setAntiAlias(true);
|
|
|
|
|
|
|
|
SkPaint bmpPaint(textPaint);
|
2015-04-16 13:54:28 +00:00
|
|
|
|
2019-01-05 21:35:13 +00:00
|
|
|
SkFont font(sk_tool_utils::create_portable_typeface());
|
|
|
|
|
2016-11-03 18:42:49 +00:00
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
|
|
|
|
for (size_t q = 0; q < SK_ARRAY_COUNT(kQualities); ++q) {
|
2016-09-01 18:24:54 +00:00
|
|
|
constexpr SkShader::TileMode kTM = SkShader::kRepeat_TileMode;
|
2016-03-09 17:50:50 +00:00
|
|
|
bmpPaint.setShader(SkShader::MakeBitmapShader(fBmp, kTM, kTM, &lm));
|
2016-11-03 18:42:49 +00:00
|
|
|
bmpPaint.setFilterQuality(kQualities[q].fQuality);
|
2015-04-16 13:54:28 +00:00
|
|
|
canvas->drawRect(rect, bmpPaint);
|
2019-01-05 21:35:13 +00:00
|
|
|
canvas->drawString(kQualities[q].fName, 20, 40, font, textPaint);
|
2015-04-16 13:54:28 +00:00
|
|
|
canvas->translate(250, 0);
|
|
|
|
}
|
2016-11-03 18:42:49 +00:00
|
|
|
|
2015-04-16 13:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap fBmp;
|
|
|
|
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new BmpFilterQualityRepeat;)
|