2016-01-29 13:22:59 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Benchmark.h"
|
2016-02-18 20:39:14 +00:00
|
|
|
#include "SkPM4f.h"
|
2016-01-29 13:22:59 +00:00
|
|
|
#include "SkString.h"
|
2016-11-15 21:44:34 +00:00
|
|
|
#include "SkXfermodePriv.h"
|
2016-01-29 13:22:59 +00:00
|
|
|
|
2016-02-03 17:47:46 +00:00
|
|
|
#define USE_AA (1 << 31) // merge with Xfermode::PMFlags w/o conflict
|
|
|
|
|
2016-02-02 17:27:35 +00:00
|
|
|
#define INNER_LOOPS 1000
|
2016-01-29 13:22:59 +00:00
|
|
|
|
|
|
|
// Benchmark that draws non-AA rects or AA text with an SkXfermode::Mode.
|
2016-02-24 14:21:36 +00:00
|
|
|
class XferD32Bench : public Benchmark {
|
2016-01-29 13:22:59 +00:00
|
|
|
public:
|
2016-11-09 15:38:09 +00:00
|
|
|
XferD32Bench(SkBlendMode mode, const char name[], bool doN, uint32_t flags)
|
2016-01-31 02:52:31 +00:00
|
|
|
: fDoN(doN)
|
2016-02-03 17:47:46 +00:00
|
|
|
, fFlags(flags & ~USE_AA)
|
2016-01-31 02:52:31 +00:00
|
|
|
{
|
2016-11-09 15:38:09 +00:00
|
|
|
fMode = mode;
|
|
|
|
fProc1 = SkXfermode::GetD32Proc(fMode, fFlags | SkXfermode::kSrcIsSingle_D32Flag);
|
|
|
|
fProcN = SkXfermode::GetD32Proc(fMode, fFlags);
|
2016-02-03 17:47:46 +00:00
|
|
|
fName.printf("xfer4f_%s_%s_%c_%s_%s",
|
|
|
|
name,
|
|
|
|
(flags & USE_AA) ? "aa" : "bw",
|
|
|
|
fDoN ? 'N' : '1',
|
2016-02-24 14:21:36 +00:00
|
|
|
(flags & SkXfermode::kSrcIsOpaque_D32Flag) ? "opaque" : "alpha",
|
|
|
|
(flags & SkXfermode::kDstIsSRGB_D32Flag) ? "srgb" : "linear");
|
2016-01-29 13:22:59 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < N; ++i) {
|
2016-01-31 02:52:31 +00:00
|
|
|
fSrc[i] = {{ 1, 1, 1, 1 }};
|
2016-01-29 13:22:59 +00:00
|
|
|
fDst[i] = 0;
|
2016-02-03 17:47:46 +00:00
|
|
|
fAAStorage[i] = i * 255 / (N - 1);
|
|
|
|
}
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2016-02-03 17:47:46 +00:00
|
|
|
if (flags & USE_AA) {
|
|
|
|
fAA = fAAStorage;
|
|
|
|
} else {
|
|
|
|
fAA = nullptr;
|
2016-01-29 13:22:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
|
|
|
|
|
|
|
|
const char* onGetName() override { return fName.c_str(); }
|
|
|
|
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2016-01-31 02:52:31 +00:00
|
|
|
for (int i = 0; i < loops * INNER_LOOPS; ++i) {
|
|
|
|
if (fDoN) {
|
2016-11-09 15:38:09 +00:00
|
|
|
fProcN(fMode, fDst, fSrc, N, fAA);
|
2016-01-31 02:52:31 +00:00
|
|
|
} else {
|
2016-11-09 15:38:09 +00:00
|
|
|
fProc1(fMode, fDst, fSrc, N, fAA);
|
2016-01-29 13:22:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-11-09 15:38:09 +00:00
|
|
|
SkBlendMode fMode;
|
2016-02-24 14:21:36 +00:00
|
|
|
SkString fName;
|
|
|
|
SkXfermode::D32Proc fProc1;
|
|
|
|
SkXfermode::D32Proc fProcN;
|
|
|
|
const SkAlpha* fAA;
|
|
|
|
bool fDoN;
|
|
|
|
uint32_t fFlags;
|
2016-01-29 13:22:59 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
N = 1000,
|
|
|
|
};
|
|
|
|
SkPM4f fSrc[N];
|
|
|
|
SkPMColor fDst[N];
|
2016-02-03 17:47:46 +00:00
|
|
|
uint8_t fAAStorage[N];
|
2016-01-29 13:22:59 +00:00
|
|
|
|
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
2016-01-31 02:52:31 +00:00
|
|
|
#define F00 0
|
2016-02-24 14:21:36 +00:00
|
|
|
#define F01 (SkXfermode::kSrcIsOpaque_D32Flag)
|
|
|
|
#define F10 (SkXfermode::kDstIsSRGB_D32Flag)
|
|
|
|
#define F11 (SkXfermode::kSrcIsOpaque_D32Flag | SkXfermode::kDstIsSRGB_D32Flag)
|
|
|
|
|
2016-11-09 15:38:09 +00:00
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F10); )
|
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F00); )
|
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F11); )
|
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F01); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F10); )
|
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F00); )
|
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F11); )
|
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F01); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F10 | USE_AA); )
|
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F00 | USE_AA); )
|
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F11 | USE_AA); )
|
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", false, F01 | USE_AA); )
|
|
|
|
|
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F10 | USE_AA); )
|
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F00 | USE_AA); )
|
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F11 | USE_AA); )
|
|
|
|
DEF_BENCH( return new XferD32Bench(SkBlendMode::kSrcOver, "srcover", true, F01 | USE_AA); )
|