922e2254b1
curr/maxrss loops min median mean max stddev samples config bench 46/46 MB 4 65.4µs 65.5µs 67.1µs 75.5µs 5% █▅▁▁▁▁▁▁▁▁ nonrendering ctconvert_4_4_readpixels 46/46 MB 3 80.4µs 80.7µs 82.2µs 93.8µs 5% █▁▁▁▂▁▁▁▁▁ nonrendering ctconvert_4_4_drawbitmap 46/46 MB 3 76.5µs 76.6µs 80.5µs 93.4µs 8% ▇▁▁▁▁▁█▄▁▂ nonrendering ctconvert_4_6_readpixels 46/46 MB 2 155µs 155µs 157µs 174µs 4% █▁▁▁▁▁▁▁▁▁ nonrendering ctconvert_4_6_drawbitmap Change-Id: Ib53f76a289ee101a85054d773cadcea475baf280 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/237141 Commit-Queue: Florin Malita <fmalita@chromium.org> Reviewed-by: Mike Reed <reed@google.com>
92 lines
2.8 KiB
C++
92 lines
2.8 KiB
C++
/*
|
|
* Copyright 2019 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#include "bench/Benchmark.h"
|
|
#include "include/core/SkCanvas.h"
|
|
#include "include/core/SkImage.h"
|
|
#include "include/core/SkString.h"
|
|
#include "include/core/SkSurface.h"
|
|
#include "src/core/SkAutoPixmapStorage.h"
|
|
|
|
class CTConvertBench : public Benchmark {
|
|
public:
|
|
enum class Mode { kDrawBitmap, kReadPixels };
|
|
|
|
CTConvertBench(SkColorType from, SkColorType to, Mode m)
|
|
: fName(SkStringPrintf("ctconvert_%d_%d_%s", from, to,
|
|
m == Mode::kReadPixels ? "readpixels" : "drawbitmap"))
|
|
, fFrom(from)
|
|
, fTo(to)
|
|
, fMode(m) {}
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
return backend == kNonRendering_Backend;
|
|
}
|
|
|
|
protected:
|
|
const char* onGetName() override {
|
|
return fName.c_str();
|
|
}
|
|
|
|
void onPreDraw(SkCanvas*) override {
|
|
if (fSrc.addr()) return;
|
|
|
|
fSrc.alloc(SkImageInfo::Make(kBMSize, kBMSize, fFrom, kPremul_SkAlphaType));
|
|
fSrc.erase(0x80808080);
|
|
|
|
fDst.alloc(SkImageInfo::Make(kBMSize, kBMSize, fTo , kPremul_SkAlphaType));
|
|
|
|
if (fMode == Mode::kDrawBitmap) {
|
|
fSrcBM.installPixels(fSrc);
|
|
fDstSurf = SkSurface::MakeRasterDirect(fDst.info(), fDst.writable_addr(),
|
|
fDst.info().minRowBytes());
|
|
}
|
|
}
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
switch (fMode) {
|
|
case Mode::kDrawBitmap: {
|
|
SkPaint p;
|
|
p.setBlendMode(SkBlendMode::kSrc);
|
|
for (int i = 0; i < loops; ++i) {
|
|
fDstSurf->getCanvas()->drawBitmap(fSrcBM, 0, 0, &p);
|
|
}
|
|
} break;
|
|
case Mode::kReadPixels: {
|
|
for (int i = 0; i < loops; ++i) {
|
|
fSrc.readPixels(fDst);
|
|
}
|
|
} break;
|
|
}
|
|
}
|
|
|
|
private:
|
|
static constexpr size_t kBMSize = 512;
|
|
|
|
const SkString fName;
|
|
const SkColorType fFrom, fTo;
|
|
const Mode fMode;
|
|
|
|
SkAutoPixmapStorage fSrc, fDst;
|
|
SkBitmap fSrcBM;
|
|
sk_sp<SkSurface> fDstSurf;
|
|
|
|
typedef Benchmark INHERITED;
|
|
};
|
|
|
|
DEF_BENCH( return new CTConvertBench(kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
|
|
CTConvertBench::Mode::kDrawBitmap); )
|
|
|
|
DEF_BENCH( return new CTConvertBench(kRGBA_8888_SkColorType, kBGRA_8888_SkColorType,
|
|
CTConvertBench::Mode::kReadPixels); )
|
|
|
|
DEF_BENCH( return new CTConvertBench(kRGBA_8888_SkColorType, kRGBA_8888_SkColorType,
|
|
CTConvertBench::Mode::kDrawBitmap); )
|
|
|
|
DEF_BENCH( return new CTConvertBench(kRGBA_8888_SkColorType, kRGBA_8888_SkColorType,
|
|
CTConvertBench::Mode::kReadPixels); )
|