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
|
|
|
SkPaint fPaint;
|
|
|
|
SkString fName;
|
|
|
|
bool fDoFilter;
|
|
|
|
bool fDoTrans;
|
2013-01-22 20:29:16 +00:00
|
|
|
bool fDoScale;
|
2013-01-17 19:51:41 +00:00
|
|
|
static const int kWidth = 1;
|
|
|
|
static const int kHeight = 300;
|
|
|
|
|
|
|
|
public:
|
2019-04-03 14:27:45 +00:00
|
|
|
ConstXTileBench(SkTileMode xTile,
|
|
|
|
SkTileMode yTile,
|
2013-01-17 19:51:41 +00:00
|
|
|
bool doFilter,
|
2013-01-22 20:29:16 +00:00
|
|
|
bool doTrans,
|
|
|
|
bool doScale)
|
2013-09-13 19:52:27 +00:00
|
|
|
: fDoFilter(doFilter)
|
2013-01-22 20:29:16 +00:00
|
|
|
, fDoTrans(doTrans)
|
|
|
|
, fDoScale(doScale) {
|
2013-01-17 19:51:41 +00:00
|
|
|
SkBitmap bm;
|
|
|
|
|
2014-06-10 02:52:07 +00:00
|
|
|
bm.allocN32Pixels(kWidth, kHeight, true);
|
2013-01-17 19:51:41 +00:00
|
|
|
bm.eraseColor(SK_ColorWHITE);
|
|
|
|
|
|
|
|
create_gradient(&bm);
|
|
|
|
|
2019-04-08 17:20:23 +00:00
|
|
|
fPaint.setShader(bm.makeShader(xTile, yTile));
|
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
|
|
|
|
|
|
|
if (doFilter) {
|
|
|
|
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:
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
virtual void onDraw(int loops, SkCanvas* canvas) {
|
2013-01-17 19:51:41 +00:00
|
|
|
SkPaint paint(fPaint);
|
|
|
|
this->setupPaint(&paint);
|
2015-03-16 17:08:34 +00:00
|
|
|
paint.setFilterQuality(fDoFilter ? kLow_SkFilterQuality
|
|
|
|
: kNone_SkFilterQuality);
|
2013-01-17 19:51:41 +00:00
|
|
|
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:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
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
|
|
|
|
|
2019-04-03 14:27:45 +00:00
|
|
|
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kRepeat, SkTileMode::kRepeat, false, false, true))
|
|
|
|
DEF_BENCH(return new ConstXTileBench(SkTileMode::kClamp, SkTileMode::kClamp, false, false, false))
|
|
|
|
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kMirror, SkTileMode::kMirror, false, false, true))
|
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, true, false, false))
|
|
|
|
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kClamp, SkTileMode::kClamp, true, false, true))
|
|
|
|
DEF_BENCH(return new ConstXTileBench(SkTileMode::kMirror, SkTileMode::kMirror, true, 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))
|
|
|
|
DEF_BENCH(return new ConstXTileBench(SkTileMode::kClamp, SkTileMode::kClamp, false, true, false))
|
|
|
|
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kMirror, SkTileMode::kMirror, false, true, true))
|
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, true, true, false))
|
|
|
|
//DEF_BENCH(return new ConstXTileBench(SkTileMode::kClamp, SkTileMode::kClamp, true, true, true))
|
|
|
|
DEF_BENCH(return new ConstXTileBench(SkTileMode::kMirror, SkTileMode::kMirror, true, true, false))
|