2012-03-07 12:36:07 +00:00
|
|
|
#include "SkBenchmark.h"
|
|
|
|
#include "SkColorPriv.h"
|
|
|
|
#include "SkMatrix.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
#include "SkPaint.h"
|
|
|
|
|
|
|
|
#define TILE(x, width) (((x) & 0xFFFF) * width >> 16)
|
|
|
|
|
|
|
|
class InterpBench : public SkBenchmark {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
|
|
|
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; }
|
|
|
|
|
|
|
|
virtual const char* onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:50:01 +00:00
|
|
|
virtual void onDraw(SkCanvas*) {
|
2013-09-10 19:23:38 +00:00
|
|
|
int n = this->getLoops() * this->mulLoopCount();
|
2012-03-07 12:36:07 +00:00
|
|
|
for (int i = 0; i < n; i++) {
|
|
|
|
this->performTest(fDst, fFx, fDx, kBuffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef SkBenchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
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:
|
|
|
|
virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE {
|
|
|
|
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:
|
|
|
|
typedef InterpBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
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:
|
|
|
|
virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE {
|
|
|
|
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:
|
|
|
|
typedef InterpBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
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:
|
|
|
|
virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE {
|
|
|
|
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:
|
|
|
|
typedef InterpBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
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:
|
|
|
|
virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE {
|
|
|
|
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:
|
|
|
|
typedef InterpBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
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:
|
|
|
|
virtual void performTest(int16_t dst[], float fx, float dx, int count) SK_OVERRIDE {
|
|
|
|
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:
|
|
|
|
typedef InterpBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
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(); )
|