skia2/bench/ReadPixBench.cpp
Mike Reed af990f3bb9 update/add benches to look at colorspace as well as alphatype
Example run:

  24/24  MB	14	332µs	338µs	337µs	341µs	gl	readpix_um_bgra_srgb
  24/24  MB	9	568µs	581µs	581µs	595µs	glsrgb	readpix_um_bgra_srgb
  29/29  MB	10	334µs	340µs	340µs	351µs	gl	readpix_um_bgra_null
  28/29  MB	8	553µs	593µs	592µs	626µs	glsrgb	readpix_um_bgra_null
  32/32  MB	15	334µs	338µs	344µs	388µs	gl	readpix_um_rgba_srgb
  31/32  MB	9	546µs	574µs	571µs	595µs	glsrgb	readpix_um_rgba_srgb
  32/32  MB	10	332µs	340µs	340µs	351µs	gl	readpix_um_rgba_null
  31/32  MB	8	553µs	587µs	589µs	629µs	glsrgb	readpix_um_rgba_null

  54/54  MB	14	364µs	369µs	370µs	383µs	gl	writepix_um_bgra_srgb
  24/54  MB	19	278µs	290µs	288µs	294µs	glsrgb	writepix_um_bgra_srgb
  58/58  MB	14	365µs	376µs	375µs	381µs	gl	writepix_um_bgra_null
  27/58  MB	19	280µs	291µs	291µs	314µs	glsrgb	writepix_um_bgra_null
  59/59  MB	14	368µs	374µs	375µs	382µs	gl	writepix_um_rgba_srgb
  27/59  MB	19	280µs	298µs	295µs	324µs	glsrgb	writepix_um_rgba_srgb
  62/62  MB	14	367µs	378µs	376µs	384µs	gl	writepix_um_rgba_null
  30/62  MB	16	289µs	293µs	296µs	310µs	glsrgb	writepix_um_rgba_null

Bug: skia:
Change-Id: I36e4f68e60a39087c07cf5ff63045a29b56da8f7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/202703
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Mike Reed <reed@google.com>
2019-03-22 12:16:40 +00:00

147 lines
4.4 KiB
C++

/*
* Copyright 2012 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Benchmark.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkColorSpace.h"
// Time variants of read-pixels
// [ colortype ][ alphatype ][ colorspace ]
// Different combinations can trigger fast or slow paths in the impls
//
class ReadPixBench : public Benchmark {
public:
ReadPixBench(SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs)
: fCT(ct), fAT(at), fCS(cs)
{
fName.printf("readpix_%s_%s_%s",
at == kPremul_SkAlphaType ? "pm" : "um",
ct == kRGBA_8888_SkColorType ? "rgba" : "bgra",
cs ? "srgb" : "null");
}
protected:
const char* onGetName() override {
return fName.c_str();
}
void onDraw(int loops, SkCanvas* canvas) override {
canvas->clear(0x80000000);
SkISize size = canvas->getBaseLayerSize();
auto info = SkImageInfo::Make(size.width(), size.height(), fCT, fAT, fCS);
SkBitmap bitmap;
bitmap.allocPixels(info);
for (int i = 0; i < loops; i++) {
canvas->readPixels(bitmap.info(), bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
}
}
private:
SkColorType fCT;
SkAlphaType fAT;
sk_sp<SkColorSpace> fCS;
SkString fName;
typedef Benchmark INHERITED;
};
DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); )
DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr); )
DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB()); )
DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB()); )
DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, nullptr); )
DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr); )
DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB()); )
DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB()); )
////////////////////////////////////////////////////////////////////////////////
#include "SkBitmap.h"
#include "SkPixmapPriv.h"
class PixmapOrientBench : public Benchmark {
public:
PixmapOrientBench() {}
protected:
void onDelayedSetup() override {
const SkImageInfo info = SkImageInfo::MakeN32Premul(2048, 1024);
fSrc.allocPixels(info);
fSrc.eraseColor(SK_ColorBLACK);
fDst.allocPixels(info.makeWH(info.height(), info.width()));
}
const char* onGetName() override {
return "orient_pixmap";
}
bool isSuitableFor(Backend backend) override {
return backend == kNonRendering_Backend;
}
void onDraw(int loops, SkCanvas*) override {
SkPixmap src, dst;
fSrc.peekPixels(&src);
fDst.peekPixels(&dst);
for (int i = 0; i < loops; ++i) {
SkPixmapPriv::Orient(dst, src, kTopRight_SkEncodedOrigin);
}
}
private:
SkBitmap fSrc, fDst;
typedef Benchmark INHERITED;
};
DEF_BENCH( return new PixmapOrientBench(); )
class GetAlphafBench : public Benchmark {
SkString fName;
SkColorType fCT;
public:
GetAlphafBench(SkColorType ct, const char label[]) : fCT(ct) {
fName.printf("getalphaf_%s", label);
}
protected:
void onDelayedSetup() override {
fBM.allocPixels(SkImageInfo::Make(1024, 1024, fCT, kPremul_SkAlphaType));
fBM.eraseColor(0x88112233);
}
const char* onGetName() override {
return fName.c_str();
}
bool isSuitableFor(Backend backend) override {
return backend == kNonRendering_Backend;
}
void onDraw(int loops, SkCanvas*) override {
for (int i = 0; i < loops; ++i) {
for (int y = 0; y < fBM.height(); ++y) {
for (int x = 0; x < fBM.width(); ++x) {
fBM.getAlphaf(x, y);
}
}
}
}
private:
SkBitmap fBM;
typedef Benchmark INHERITED;
};
DEF_BENCH( return new GetAlphafBench(kN32_SkColorType, "rgba"); )
DEF_BENCH( return new GetAlphafBench(kRGB_888x_SkColorType, "rgbx"); )
DEF_BENCH( return new GetAlphafBench(kRGBA_F16_SkColorType, "f16"); )
DEF_BENCH( return new GetAlphafBench(kRGBA_F32_SkColorType, "f32"); )