2015-08-26 20:07:48 +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.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/private/SkColorData.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
2013-12-02 22:32:47 +00:00
|
|
|
|
|
|
|
template <bool kFast, bool kScale>
|
2014-06-19 19:32:29 +00:00
|
|
|
class FourByteInterpBench : public Benchmark {
|
2013-12-02 22:32:47 +00:00
|
|
|
public:
|
|
|
|
FourByteInterpBench() {
|
|
|
|
fName.set("four_byte_interp");
|
|
|
|
fName.append(kFast ? "_fast" : "_slow");
|
|
|
|
fName.append(kScale ? "_255" : "_256");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-12-02 22:32:47 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override { return fName.c_str(); }
|
2013-12-02 22:32:47 +00:00
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
2013-12-05 16:43:08 +00:00
|
|
|
// A handful of random srcs and dsts.
|
|
|
|
SkRandom rand;
|
|
|
|
for (int i = 0; i < kInputs; i++) {
|
|
|
|
fSrcs[i] = SkPreMultiplyColor(rand.nextU());
|
|
|
|
fDsts[i] = SkPreMultiplyColor(rand.nextU());
|
|
|
|
}
|
|
|
|
|
|
|
|
// We'll exhaustively test all scales instead of using random numbers.
|
|
|
|
for (int i = 0; i <= 256; i++) {
|
|
|
|
fScales[i] = i;
|
|
|
|
}
|
|
|
|
if (kScale) fScales[256] = 255; // We'll just do 255 twice if we're limited to [0,255].
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-12-05 16:43:08 +00:00
|
|
|
// We xor results of FourByteInterp into junk to make sure the function runs.
|
2021-08-05 16:16:07 +00:00
|
|
|
SK_MAYBE_UNUSED volatile SkPMColor junk = 0;
|
2013-12-05 16:43:08 +00:00
|
|
|
|
|
|
|
for (int loop = 0; loop < loops; loop++) {
|
|
|
|
for (int i = 0; i < kInputs; i++) {
|
|
|
|
for (size_t j = 0; j <= 256; j++) {
|
|
|
|
// Note: we really want to load src and dst here and not outside in the i-loop.
|
|
|
|
// If we put the loads there, a clever compiler will do the not-insignificant
|
|
|
|
// work in the FourByteInterps that depends only on src and dst outside this
|
|
|
|
// loop, so we'd only be benchmarking the back half of those functions that also
|
|
|
|
// depends on scale. Even here, these must be volatile arrays to prevent that
|
|
|
|
// clever compiler from hoisting the loads out of the loop on its own.
|
|
|
|
const SkPMColor src = fSrcs[i];
|
|
|
|
const SkPMColor dst = fDsts[i];
|
|
|
|
|
|
|
|
const unsigned scale = fScales[j];
|
|
|
|
|
|
|
|
if (kFast && kScale) {
|
|
|
|
junk ^= SkFastFourByteInterp(src, dst, scale);
|
|
|
|
} else if (kFast) {
|
|
|
|
junk ^= SkFastFourByteInterp256(src, dst, scale);
|
|
|
|
} else if (kScale) {
|
|
|
|
junk ^= SkFourByteInterp(src, dst, scale);
|
|
|
|
} else {
|
|
|
|
junk ^= SkFourByteInterp256(src, dst, scale);
|
|
|
|
}
|
2013-12-02 22:32:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkString fName;
|
2013-12-05 16:43:08 +00:00
|
|
|
static const int kInputs = 10; // Arbitrary.
|
|
|
|
volatile unsigned fSrcs[kInputs];
|
|
|
|
volatile unsigned fDsts[kInputs];
|
2013-12-02 22:32:47 +00:00
|
|
|
unsigned fScales[257]; // We need space for [0, 256].
|
|
|
|
};
|
|
|
|
|
|
|
|
#define COMMA ,
|
2015-08-26 20:07:48 +00:00
|
|
|
DEF_BENCH(return (new FourByteInterpBench<true COMMA true>);)
|
|
|
|
DEF_BENCH(return (new FourByteInterpBench<true COMMA false>);)
|
|
|
|
DEF_BENCH(return (new FourByteInterpBench<false COMMA true>);)
|
|
|
|
DEF_BENCH(return (new FourByteInterpBench<false COMMA false>);)
|
2013-12-02 22:32:47 +00:00
|
|
|
#undef COMMA
|