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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkFont.h"
|
|
|
|
#include "include/core/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkShader.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/core/SkTileMode.h"
|
|
|
|
#include "include/core/SkTypeface.h"
|
|
|
|
#include "include/core/SkTypes.h"
|
|
|
|
#include "tools/ToolUtils.h"
|
2015-04-16 13:54:28 +00:00
|
|
|
|
|
|
|
// 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:
|
2019-03-20 16:12:10 +00:00
|
|
|
BmpFilterQualityRepeat() { this->setBGColor(ToolUtils::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);
|
2021-01-24 03:07:05 +00:00
|
|
|
canvas.drawImage(colorBmp.asImage(), 0, 0);
|
2019-03-20 16:12:10 +00:00
|
|
|
colorBmp.eraseColor(ToolUtils::color_to_565(0xFF008200));
|
2021-01-24 03:07:05 +00:00
|
|
|
canvas.drawImage(colorBmp.asImage(), 20, 0);
|
2019-03-20 16:12:10 +00:00
|
|
|
colorBmp.eraseColor(ToolUtils::color_to_565(0xFFFF9000));
|
2021-01-24 03:07:05 +00:00
|
|
|
canvas.drawImage(colorBmp.asImage(), 0, 20);
|
2019-03-20 16:12:10 +00:00
|
|
|
colorBmp.eraseColor(ToolUtils::color_to_565(0xFF2000FF));
|
2021-01-24 03:07:05 +00:00
|
|
|
canvas.drawImage(colorBmp.asImage(), 20, 20);
|
2015-04-16 13:54:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
|
|
|
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-03-20 16:12:10 +00:00
|
|
|
SkFont font(ToolUtils::create_portable_typeface());
|
2019-01-05 21:35:13 +00:00
|
|
|
|
2016-11-03 18:42:49 +00:00
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
|
2021-07-17 02:19:26 +00:00
|
|
|
const struct {
|
|
|
|
const char* name;
|
|
|
|
SkSamplingOptions sampling;
|
|
|
|
} recs[] = {
|
|
|
|
{ "none", SkSamplingOptions(SkFilterMode::kNearest) },
|
|
|
|
{ "low", SkSamplingOptions(SkFilterMode::kLinear) },
|
|
|
|
{ "medium", SkSamplingOptions(SkFilterMode::kLinear, SkMipmapMode::kLinear) },
|
|
|
|
{ "high", SkSamplingOptions(SkCubicResampler::Mitchell()) },
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const auto& rec : recs) {
|
2019-04-03 14:27:45 +00:00
|
|
|
constexpr SkTileMode kTM = SkTileMode::kRepeat;
|
2021-07-17 02:19:26 +00:00
|
|
|
bmpPaint.setShader(fBmp.makeShader(kTM, kTM, rec.sampling, lm));
|
2015-04-16 13:54:28 +00:00
|
|
|
canvas->drawRect(rect, bmpPaint);
|
2021-07-17 02:19:26 +00:00
|
|
|
canvas->drawString(rec.name, 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;
|
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = skiagm::GM;
|
2015-04-16 13:54:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_GM(return new BmpFilterQualityRepeat;)
|