2013-08-16 00:40:34 +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.
|
|
|
|
*/
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2017-05-03 19:16:58 +00:00
|
|
|
#include "SkBitmap.h"
|
2013-08-16 00:40:34 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
2019-03-21 19:55:05 +00:00
|
|
|
// Time variants of write-pixels
|
|
|
|
// [ colortype ][ alphatype ][ colorspace ]
|
|
|
|
// Different combinations can trigger fast or slow paths in the impls
|
|
|
|
//
|
2014-06-19 19:32:29 +00:00
|
|
|
class WritePixelsBench : public Benchmark {
|
2013-08-16 00:40:34 +00:00
|
|
|
public:
|
2019-03-21 19:55:05 +00:00
|
|
|
WritePixelsBench(SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs)
|
2014-03-07 03:25:16 +00:00
|
|
|
: fColorType(ct)
|
|
|
|
, fAlphaType(at)
|
2019-03-21 19:55:05 +00:00
|
|
|
, fCS(cs)
|
2014-03-07 03:25:16 +00:00
|
|
|
{
|
2019-03-21 19:55:05 +00:00
|
|
|
fName.printf("writepix_%s_%s_%s",
|
|
|
|
at == kPremul_SkAlphaType ? "pm" : "um",
|
|
|
|
ct == kRGBA_8888_SkColorType ? "rgba" : "bgra",
|
|
|
|
cs ? "srgb" : "null");
|
2013-08-16 00:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-08-16 00:40:34 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2017-02-22 18:21:42 +00:00
|
|
|
SkISize size = canvas->getBaseLayerSize();
|
2013-08-16 00:40:34 +00:00
|
|
|
|
2019-03-21 19:55:05 +00:00
|
|
|
SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), fColorType, fAlphaType,
|
|
|
|
fCS);
|
2013-08-16 00:40:34 +00:00
|
|
|
SkBitmap bmp;
|
2019-03-21 19:55:05 +00:00
|
|
|
bmp.allocPixels(info);
|
|
|
|
bmp.eraseColor(SK_ColorBLACK);
|
2014-03-08 03:02:06 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int loop = 0; loop < loops; ++loop) {
|
2014-03-07 03:25:16 +00:00
|
|
|
canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0);
|
2013-08-16 00:40:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-03-07 03:25:16 +00:00
|
|
|
SkColorType fColorType;
|
|
|
|
SkAlphaType fAlphaType;
|
2019-03-21 19:55:05 +00:00
|
|
|
sk_sp<SkColorSpace> fCS;
|
2014-03-07 03:25:16 +00:00
|
|
|
SkString fName;
|
2013-08-16 00:40:34 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-08-16 00:40:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-03-21 19:55:05 +00:00
|
|
|
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);)
|
|
|
|
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr);)
|
|
|
|
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());)
|
|
|
|
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());)
|
|
|
|
|
|
|
|
DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, nullptr);)
|
|
|
|
DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr);)
|
|
|
|
DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());)
|
|
|
|
DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());)
|