2013-01-17 19:51:41 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 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 "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkBitmap.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkShader.h"
|
|
|
|
#include "include/core/SkString.h"
|
2013-01-17 19:51:41 +00:00
|
|
|
|
|
|
|
static void create_gradient(SkBitmap* bm) {
|
|
|
|
SkASSERT(1 == bm->width());
|
|
|
|
const int height = bm->height();
|
|
|
|
|
|
|
|
float deltaB = 255.0f / height;
|
|
|
|
float blue = 255.0f;
|
|
|
|
|
|
|
|
for (int y = 0; y < height; y++) {
|
|
|
|
*bm->getAddr32(0, y) = SkColorSetRGB(0, 0, (U8CPU) blue);
|
|
|
|
blue -= deltaB;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test out the special case of a tiled 1xN texture. Test out opacity,
|
|
|
|
// filtering and the different tiling modes
|
2014-06-19 19:32:29 +00:00
|
|
|
class ConstXTileBench : public Benchmark {
|
2013-01-17 19:51:41 +00:00
|
|
|
public:
|
2019-04-03 14:27:45 +00:00
|
|
|
ConstXTileBench(SkTileMode xTile,
|
|
|
|
SkTileMode yTile,
|
2020-12-12 19:31:25 +00:00
|
|
|
SkFilterMode fm,
|
2013-01-22 20:29:16 +00:00
|
|
|
bool doTrans,
|
|
|
|
bool doScale)
|
2021-09-23 18:28:55 +00:00
|
|
|
: fFilterMode{fm}
|
|
|
|
, fXTile{xTile}
|
|
|
|
, fYTile{yTile}
|
|
|
|
, fDoTrans{doTrans}
|
|
|
|
, fDoScale{doScale} {
|
2013-01-17 19:51:41 +00:00
|
|
|
fName.printf("constXTile_");
|
|
|
|
|
2019-04-03 14:27:45 +00:00
|
|
|
static const char* gTileModeStr[kSkTileModeCount] = { "C", "R", "M", "D" };
|
|
|
|
fName.append(gTileModeStr[(unsigned)xTile]);
|
|
|
|
fName.append(gTileModeStr[(unsigned)yTile]);
|
2013-01-17 19:51:41 +00:00
|
|
|
|
2020-12-12 19:31:25 +00:00
|
|
|
if (fm != SkFilterMode::kNearest) {
|
2013-01-17 19:51:41 +00:00
|
|
|
fName.append("_filter");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (doTrans) {
|
|
|
|
fName.append("_trans");
|
|
|
|
}
|
2013-01-22 20:29:16 +00:00
|
|
|
|
|
|
|
if (doScale) {
|
|
|
|
fName.append("_scale");
|
|
|
|
}
|
2013-01-17 19:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2020-07-21 21:03:56 +00:00
|
|
|
const char* onGetName() override {
|
2013-01-17 19:51:41 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2021-09-23 18:28:55 +00:00
|
|
|
void onDelayedSetup() override {
|
|
|
|
SkBitmap bm;
|
|
|
|
|
|
|
|
bm.allocN32Pixels(kWidth, kHeight, true);
|
|
|
|
bm.eraseColor(SK_ColorWHITE);
|
|
|
|
|
|
|
|
create_gradient(&bm);
|
|
|
|
|
|
|
|
fPaint.setShader(bm.makeShader(fXTile, fYTile, SkSamplingOptions(fFilterMode)));
|
|
|
|
}
|
|
|
|
|
2020-07-21 21:03:56 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2013-01-17 19:51:41 +00:00
|
|
|
SkPaint paint(fPaint);
|
|
|
|
this->setupPaint(&paint);
|
|
|
|
if (fDoTrans) {
|
2018-04-24 18:47:16 +00:00
|
|
|
paint.setColor(SkColorSetARGB(0x80, 0xFF, 0xFF, 0xFF));
|
2013-01-17 19:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkRect r;
|
|
|
|
|
2013-01-22 20:29:16 +00:00
|
|
|
if (fDoScale) {
|
2013-01-17 19:51:41 +00:00
|
|
|
r = SkRect::MakeWH(SkIntToScalar(2 * 640), SkIntToScalar(2 * 480));
|
|
|
|
canvas->scale(SK_ScalarHalf, SK_ScalarHalf);
|
|
|
|
} else {
|
|
|
|
r = SkRect::MakeWH(SkIntToScalar(640), SkIntToScalar(480));
|
|
|
|
}
|
|
|
|
|
|
|
|
SkPaint bgPaint;
|
|
|
|
bgPaint.setColor(SK_ColorWHITE);
|
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-01-17 19:51:41 +00:00
|
|
|
if (fDoTrans) {
|
|
|
|
canvas->drawRect(r, bgPaint);
|
|
|
|
}
|
|
|
|
|
|
|
|
canvas->drawRect(r, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2021-10-08 22:48:26 +00:00
|
|
|
inline static constexpr int kWidth = 1;
|
|
|
|
inline static constexpr int kHeight = 300;
|
2021-09-23 18:28:55 +00:00
|
|
|
|
|
|
|
const SkFilterMode fFilterMode;
|
|
|
|
const SkTileMode fXTile,
|
|
|
|
fYTile;
|
|
|
|
const bool fDoTrans,
|
|
|
|
fDoScale;
|
|
|
|
SkPaint fPaint;
|
|
|
|
SkString fName;
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
2013-01-17 19:51:41 +00:00
|
|
|
};
|
|
|
|
|
2014-06-24 22:19:25 +00:00
|
|
|
// Scaled benches are trending towards free. Seems like caching.
|
|
|
|
// TODO(mtklein, reed): fix and reenable
|
|
|
|
|
2020-12-12 19:31:25 +00:00
|
|
|
constexpr SkFilterMode gNN = SkFilterMode::kNearest;
|
|
|
|
constexpr SkFilterMode gLI = SkFilterMode::kLinear;
|
|
|
|
|
2019-04-03 14:27:45 +00:00
|
|
|
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kRepeat, SkTileMode::kRepeat, false, false, true))
|
2020-12-12 19:31:25 +00:00
|
|
|
DEF_BENCH(return new ConstXTileBench(SkTileMode::kClamp, SkTileMode::kClamp, gNN, false, false))
|
2019-04-03 14:27:45 +00:00
|
|
|
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kMirror, SkTileMode::kMirror, false, false, true))
|
2013-01-17 19:51:41 +00:00
|
|
|
|
2020-12-12 19:31:25 +00:00
|
|
|
DEF_BENCH(return new ConstXTileBench(SkTileMode::kRepeat, SkTileMode::kRepeat, gLI, false, false))
|
2019-04-03 14:27:45 +00:00
|
|
|
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kClamp, SkTileMode::kClamp, true, false, true))
|
2020-12-12 19:31:25 +00:00
|
|
|
DEF_BENCH(return new ConstXTileBench(SkTileMode::kMirror, SkTileMode::kMirror, gLI, false, false))
|
2013-01-17 19:51:41 +00:00
|
|
|
|
2019-04-03 14:27:45 +00:00
|
|
|
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kRepeat, SkTileMode::kRepeat, false, true, true))
|
2020-12-12 19:31:25 +00:00
|
|
|
DEF_BENCH(return new ConstXTileBench(SkTileMode::kClamp, SkTileMode::kClamp, gNN, true, false))
|
2019-04-03 14:27:45 +00:00
|
|
|
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kMirror, SkTileMode::kMirror, false, true, true))
|
2013-01-17 19:51:41 +00:00
|
|
|
|
2020-12-12 19:31:25 +00:00
|
|
|
DEF_BENCH(return new ConstXTileBench(SkTileMode::kRepeat, SkTileMode::kRepeat, gLI, true, false))
|
2019-04-03 14:27:45 +00:00
|
|
|
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kClamp, SkTileMode::kClamp, true, true, true))
|
2020-12-12 19:31:25 +00:00
|
|
|
DEF_BENCH(return new ConstXTileBench(SkTileMode::kMirror, SkTileMode::kMirror, gLI, true, false))
|