2015-07-13 13:18:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 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/SkMatrix.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/private/SkColorData.h"
|
|
|
|
#include "include/private/SkFixed.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
2012-03-07 12:36:07 +00:00
|
|
|
|
|
|
|
#define TILE(x, width) (((x) & 0xFFFF) * width >> 16)
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class InterpBench : public Benchmark {
|
2012-03-07 12:36:07 +00:00
|
|
|
enum {
|
|
|
|
kBuffer = 128,
|
|
|
|
kLoop = 20000
|
|
|
|
};
|
|
|
|
SkString fName;
|
|
|
|
int16_t fDst[kBuffer];
|
|
|
|
float fFx, fDx;
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
InterpBench(const char name[]) {
|
2012-03-07 12:36:07 +00:00
|
|
|
fName.printf("interp_%s", name);
|
2012-04-06 20:01:46 +00:00
|
|
|
fFx = 3.3f;
|
|
|
|
fDx = 0.1257f;
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2012-03-07 12:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void performTest(int16_t dst[], float x, float dx, int count) = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual int mulLoopCount() const { return 1; }
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2012-03-07 12:36:07 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
int n = loops * this->mulLoopCount();
|
2012-03-07 12:36:07 +00:00
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
this->performTest(fDst, fFx, fDx, kBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
2012-03-07 12:36:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Fixed16D16Interp : public InterpBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
Fixed16D16Interp() : INHERITED("16.16") {}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-03-07 12:36:07 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void performTest(int16_t dst[], float fx, float dx, int count) override {
|
2012-03-07 12:36:07 +00:00
|
|
|
SkFixed curr = SkFloatToFixed(fx);
|
|
|
|
SkFixed step = SkFloatToFixed(dx);
|
|
|
|
for (int i = 0; i < count; i += 4) {
|
|
|
|
dst[i + 0] = TILE(curr, count); curr += step;
|
|
|
|
dst[i + 1] = TILE(curr, count); curr += step;
|
|
|
|
dst[i + 2] = TILE(curr, count); curr += step;
|
|
|
|
dst[i + 3] = TILE(curr, count); curr += step;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = InterpBench;
|
2012-03-07 12:36:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Fixed32D32Interp : public InterpBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
Fixed32D32Interp() : INHERITED("32.32") {}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-03-07 12:36:07 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void performTest(int16_t dst[], float fx, float dx, int count) override {
|
2012-03-07 12:36:07 +00:00
|
|
|
int64_t curr = (int64_t)(fx * 65536 * 655536);
|
|
|
|
int64_t step = (int64_t)(dx * 65536 * 655536);
|
|
|
|
SkFixed tmp;
|
|
|
|
for (int i = 0; i < count; i += 4) {
|
2012-08-23 18:09:54 +00:00
|
|
|
tmp = (SkFixed)(curr >> 16);
|
|
|
|
dst[i + 0] = TILE(tmp, count);
|
2012-05-14 16:33:36 +00:00
|
|
|
curr += step;
|
|
|
|
|
2012-08-23 18:09:54 +00:00
|
|
|
tmp = (SkFixed)(curr >> 16);
|
|
|
|
dst[i + 1] = TILE(tmp, count);
|
2012-05-14 16:33:36 +00:00
|
|
|
curr += step;
|
|
|
|
|
2012-08-23 18:09:54 +00:00
|
|
|
tmp = (SkFixed)(curr >> 16);
|
|
|
|
dst[i + 2] = TILE(tmp, count);
|
2012-05-14 16:33:36 +00:00
|
|
|
curr += step;
|
|
|
|
|
2012-08-23 18:09:54 +00:00
|
|
|
tmp = (SkFixed)(curr >> 16);
|
|
|
|
dst[i + 3] = TILE(tmp, count);
|
2012-05-14 16:33:36 +00:00
|
|
|
curr += step;
|
2012-03-07 12:36:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = InterpBench;
|
2012-03-07 12:36:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Fixed16D48Interp : public InterpBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
Fixed16D48Interp() : INHERITED("16.48") {}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-03-07 12:36:07 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void performTest(int16_t dst[], float fx, float dx, int count) override {
|
2012-03-07 12:36:07 +00:00
|
|
|
int64_t curr = (int64_t)(fx * 65536 * 655536 * 65536);
|
|
|
|
int64_t step = (int64_t)(dx * 65536 * 655536 * 65536);
|
|
|
|
SkFixed tmp;
|
|
|
|
for (int i = 0; i < count; i += 4) {
|
2012-06-06 12:11:45 +00:00
|
|
|
tmp = (SkFixed) (curr >> 32); dst[i + 0] = TILE(tmp, count); curr += step;
|
|
|
|
tmp = (SkFixed) (curr >> 32); dst[i + 1] = TILE(tmp, count); curr += step;
|
|
|
|
tmp = (SkFixed) (curr >> 32); dst[i + 2] = TILE(tmp, count); curr += step;
|
|
|
|
tmp = (SkFixed) (curr >> 32); dst[i + 3] = TILE(tmp, count); curr += step;
|
2012-03-07 12:36:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = InterpBench;
|
2012-03-07 12:36:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class FloatInterp : public InterpBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
FloatInterp() : INHERITED("float") {}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-03-07 12:36:07 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void performTest(int16_t dst[], float fx, float dx, int count) override {
|
2012-03-07 12:36:07 +00:00
|
|
|
SkFixed tmp;
|
|
|
|
for (int i = 0; i < count; i += 4) {
|
|
|
|
tmp = SkFloatToFixed(fx); dst[i + 0] = TILE(tmp, count); fx += dx;
|
|
|
|
tmp = SkFloatToFixed(fx); dst[i + 1] = TILE(tmp, count); fx += dx;
|
|
|
|
tmp = SkFloatToFixed(fx); dst[i + 2] = TILE(tmp, count); fx += dx;
|
|
|
|
tmp = SkFloatToFixed(fx); dst[i + 3] = TILE(tmp, count); fx += dx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = InterpBench;
|
2012-03-07 12:36:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DoubleInterp : public InterpBench {
|
|
|
|
public:
|
2013-09-13 19:52:27 +00:00
|
|
|
DoubleInterp() : INHERITED("double") {}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-03-07 12:36:07 +00:00
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
void performTest(int16_t dst[], float fx, float dx, int count) override {
|
2012-03-07 12:36:07 +00:00
|
|
|
double ffx = fx;
|
|
|
|
double ddx = dx;
|
|
|
|
SkFixed tmp;
|
|
|
|
for (int i = 0; i < count; i += 4) {
|
|
|
|
tmp = SkDoubleToFixed(ffx); dst[i + 0] = TILE(tmp, count); ffx += ddx;
|
|
|
|
tmp = SkDoubleToFixed(ffx); dst[i + 1] = TILE(tmp, count); ffx += ddx;
|
|
|
|
tmp = SkDoubleToFixed(ffx); dst[i + 2] = TILE(tmp, count); ffx += ddx;
|
|
|
|
tmp = SkDoubleToFixed(ffx); dst[i + 3] = TILE(tmp, count); ffx += ddx;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = InterpBench;
|
2012-03-07 12:36:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new Fixed16D16Interp(); )
|
|
|
|
DEF_BENCH( return new Fixed32D32Interp(); )
|
|
|
|
DEF_BENCH( return new Fixed16D48Interp(); )
|
|
|
|
DEF_BENCH( return new FloatInterp(); )
|
|
|
|
DEF_BENCH( return new DoubleInterp(); )
|