2013-06-13 10:18:02 +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-06-13 10:18:02 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkString.h"
|
2019-03-20 16:12:10 +00:00
|
|
|
#include "ToolUtils.h"
|
2013-06-13 10:18:02 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class PremulAndUnpremulAlphaOpsBench : public Benchmark {
|
2014-03-17 21:31:26 +00:00
|
|
|
enum {
|
|
|
|
W = 256,
|
|
|
|
H = 256,
|
|
|
|
};
|
|
|
|
SkBitmap fBmp1, fBmp2;
|
2014-03-18 03:02:11 +00:00
|
|
|
|
2013-06-13 10:18:02 +00:00
|
|
|
public:
|
2014-03-17 21:31:26 +00:00
|
|
|
PremulAndUnpremulAlphaOpsBench(SkColorType ct) {
|
|
|
|
fColorType = ct;
|
2019-03-20 16:12:10 +00:00
|
|
|
fName.printf("premul_and_unpremul_alpha_%s", ToolUtils::colortype_name(ct));
|
2013-06-13 10:18:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-06-13 10:18:02 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
2014-07-11 17:45:11 +00:00
|
|
|
SkImageInfo info = SkImageInfo::Make(W, H, fColorType, kUnpremul_SkAlphaType);
|
2014-03-17 21:31:26 +00:00
|
|
|
fBmp1.allocPixels(info); // used in writePixels
|
2013-06-13 10:18:02 +00:00
|
|
|
|
2014-03-17 21:31:26 +00:00
|
|
|
for (int h = 0; h < H; ++h) {
|
|
|
|
for (int w = 0; w < W; ++w) {
|
|
|
|
// SkColor places A in the right slot for either RGBA or BGRA
|
|
|
|
*fBmp1.getAddr32(w, h) = SkColorSetARGB(h & 0xFF, w & 0xFF, w & 0xFF, w & 0xFF);
|
|
|
|
}
|
2013-06-13 10:18:02 +00:00
|
|
|
}
|
2014-03-18 03:02:11 +00:00
|
|
|
|
2014-03-17 21:31:26 +00:00
|
|
|
fBmp2.allocPixels(info); // used in readPixels()
|
|
|
|
}
|
2013-06-13 10:18:02 +00:00
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2014-03-17 21:31:26 +00:00
|
|
|
canvas->clear(SK_ColorBLACK);
|
2014-03-07 03:25:16 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int loop = 0; loop < loops; ++loop) {
|
2013-06-13 10:18:02 +00:00
|
|
|
// Unpremul -> Premul
|
2014-03-17 21:31:26 +00:00
|
|
|
canvas->writePixels(fBmp1.info(), fBmp1.getPixels(), fBmp1.rowBytes(), 0, 0);
|
2013-06-13 10:18:02 +00:00
|
|
|
// Premul -> Unpremul
|
2014-03-17 21:31:26 +00:00
|
|
|
canvas->readPixels(fBmp2.info(), fBmp2.getPixels(), fBmp2.rowBytes(), 0, 0);
|
2013-06-13 10:18:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-03-17 21:31:26 +00:00
|
|
|
SkColorType fColorType;
|
2013-06-13 10:18:02 +00:00
|
|
|
SkString fName;
|
2014-03-17 21:31:26 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-06-13 10:18:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-03-17 21:31:26 +00:00
|
|
|
DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(kRGBA_8888_SkColorType));
|
|
|
|
DEF_BENCH(return new PremulAndUnpremulAlphaOpsBench(kBGRA_8888_SkColorType));
|