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"
|
2013-08-16 00:40:34 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class WritePixelsBench : public Benchmark {
|
2013-08-16 00:40:34 +00:00
|
|
|
public:
|
2014-03-07 03:25:16 +00:00
|
|
|
WritePixelsBench(SkColorType ct, SkAlphaType at)
|
|
|
|
: fColorType(ct)
|
|
|
|
, fAlphaType(at)
|
|
|
|
, fName("writepix")
|
|
|
|
{
|
|
|
|
switch (ct) {
|
|
|
|
case kRGBA_8888_SkColorType:
|
|
|
|
fName.append("_RGBA");
|
2013-08-16 00:40:34 +00:00
|
|
|
break;
|
2014-03-07 03:25:16 +00:00
|
|
|
case kBGRA_8888_SkColorType:
|
|
|
|
fName.append("_BGRA");
|
2013-08-16 00:40:34 +00:00
|
|
|
break;
|
2014-03-07 03:25:16 +00:00
|
|
|
default:
|
|
|
|
SkASSERT(0);
|
2013-08-16 00:40:34 +00:00
|
|
|
break;
|
2014-03-07 03:25:16 +00:00
|
|
|
}
|
|
|
|
switch (at) {
|
|
|
|
case kPremul_SkAlphaType:
|
|
|
|
fName.append("_PM");
|
2013-08-16 00:40:34 +00:00
|
|
|
break;
|
2014-03-07 03:25:16 +00:00
|
|
|
case kUnpremul_SkAlphaType:
|
|
|
|
fName.append("_UPM");
|
2013-08-16 00:40:34 +00:00
|
|
|
break;
|
2013-08-16 07:01:49 +00:00
|
|
|
default:
|
2014-03-07 03:25:16 +00:00
|
|
|
SkASSERT(0);
|
2013-08-16 00:40:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
canvas->clear(0xFFFF0000);
|
|
|
|
|
|
|
|
SkBitmap bmp;
|
2014-03-07 03:25:16 +00:00
|
|
|
bmp.allocN32Pixels(size.width(), size.height());
|
2013-08-16 00:40:34 +00:00
|
|
|
canvas->readPixels(&bmp, 0, 0);
|
|
|
|
|
2014-09-03 18:54:58 +00:00
|
|
|
SkImageInfo info = SkImageInfo::Make(bmp.width(), bmp.height(), fColorType, fAlphaType);
|
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;
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType);)
|
|
|
|
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType);)
|