2014-10-09 21:29:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 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"
|
|
|
|
#include "SkGeometry.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkRect.h"
|
|
|
|
|
|
|
|
class GeometryBench : public Benchmark {
|
|
|
|
public:
|
|
|
|
GeometryBench(const char suffix[]) : fVolatileInt(0) {
|
|
|
|
fName.printf("geo_%s", suffix);
|
|
|
|
}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
const char* onGetName() SK_OVERRIDE {
|
2014-10-09 21:29:01 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-01-09 18:06:39 +00:00
|
|
|
bool isSuitableFor(Backend backend) SK_OVERRIDE {
|
2014-10-09 21:29:01 +00:00
|
|
|
return kNonRendering_Backend == backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
volatile int fVolatileInt;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Subclasses can call this to try to defeat the optimizer (with some result of their
|
|
|
|
* inner loop), since it will fool the compiler into assuming that "n" is actually
|
|
|
|
* needed somewhere, and since this method is not const, the member fields cannot
|
|
|
|
* be assumed to be const before and after the call.
|
|
|
|
*/
|
|
|
|
virtual void virtualCallToFoilOptimizers(int n) { fVolatileInt += n; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkString fName;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GeoRectBench : public GeometryBench {
|
|
|
|
public:
|
|
|
|
GeoRectBench(const char suffix[]) : GeometryBench(suffix) {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkRect fRects[2048];
|
|
|
|
|
|
|
|
virtual void onPreDraw() {
|
|
|
|
const SkScalar min = -100;
|
|
|
|
const SkScalar max = 100;
|
|
|
|
SkRandom rand;
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) {
|
|
|
|
SkScalar x = rand.nextRangeScalar(min, max);
|
|
|
|
SkScalar y = rand.nextRangeScalar(min, max);
|
|
|
|
SkScalar w = rand.nextRangeScalar(min, max);
|
|
|
|
SkScalar h = rand.nextRangeScalar(min, max);
|
|
|
|
fRects[i].setXYWH(x, y, w, h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class GeoRectBench_intersect : public GeoRectBench {
|
|
|
|
public:
|
|
|
|
GeoRectBench_intersect() : GeoRectBench("rect_intersect") {}
|
|
|
|
|
|
|
|
protected:
|
2015-01-09 18:06:39 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
2014-10-09 21:29:01 +00:00
|
|
|
for (int outer = 0; outer < loops; ++outer) {
|
|
|
|
int count = 0;
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) {
|
|
|
|
SkRect r = fRects[0];
|
|
|
|
count += r.intersect(fRects[i]);
|
|
|
|
}
|
|
|
|
this->virtualCallToFoilOptimizers(count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class GeoRectBench_intersect_rect : public GeoRectBench {
|
|
|
|
public:
|
|
|
|
GeoRectBench_intersect_rect() : GeoRectBench("rect_intersect_rect") {}
|
|
|
|
|
|
|
|
protected:
|
2015-01-09 18:06:39 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
2014-10-09 21:29:01 +00:00
|
|
|
for (int outer = 0; outer < loops; ++outer) {
|
|
|
|
int count = 0;
|
|
|
|
SkRect r;
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) {
|
|
|
|
count += r.intersect(fRects[0], fRects[i]);
|
|
|
|
}
|
|
|
|
this->virtualCallToFoilOptimizers(count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class GeoRectBench_Intersects : public GeoRectBench {
|
|
|
|
public:
|
|
|
|
GeoRectBench_Intersects() : GeoRectBench("rect_Intersects") {}
|
2014-10-20 17:43:55 +00:00
|
|
|
|
2014-10-09 21:29:01 +00:00
|
|
|
protected:
|
2015-01-09 18:06:39 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
2014-10-09 21:29:01 +00:00
|
|
|
for (int outer = 0; outer < loops; ++outer) {
|
|
|
|
int count = 0;
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) {
|
|
|
|
count += SkRect::Intersects(fRects[0], fRects[i]);
|
|
|
|
}
|
|
|
|
this->virtualCallToFoilOptimizers(count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-10 12:50:15 +00:00
|
|
|
class GeoRectBench_sort : public GeoRectBench {
|
|
|
|
public:
|
|
|
|
GeoRectBench_sort() : GeoRectBench("rect_sort") {}
|
2014-10-20 17:43:55 +00:00
|
|
|
|
2014-10-10 12:50:15 +00:00
|
|
|
protected:
|
2015-01-09 18:06:39 +00:00
|
|
|
void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
2014-10-10 12:50:15 +00:00
|
|
|
for (int outer = 0; outer < loops; ++outer) {
|
|
|
|
for (size_t i = 0; i < SK_ARRAY_COUNT(fRects); ++i) {
|
|
|
|
fRects[i].sort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-10-09 21:29:01 +00:00
|
|
|
DEF_BENCH( return new GeoRectBench_intersect; )
|
|
|
|
DEF_BENCH( return new GeoRectBench_intersect_rect; )
|
|
|
|
DEF_BENCH( return new GeoRectBench_Intersects; )
|
2014-10-10 12:50:15 +00:00
|
|
|
|
|
|
|
DEF_BENCH( return new GeoRectBench_sort; )
|
2015-03-19 17:18:47 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2015-03-20 13:01:08 +00:00
|
|
|
class QuadBenchBase : public GeometryBench {
|
|
|
|
protected:
|
2015-03-19 17:18:47 +00:00
|
|
|
SkPoint fPts[3];
|
|
|
|
public:
|
2015-03-20 13:01:08 +00:00
|
|
|
QuadBenchBase(const char name[]) : GeometryBench(name) {
|
2015-03-19 17:18:47 +00:00
|
|
|
SkRandom rand;
|
|
|
|
for (int i = 0; i < 3; ++i) {
|
|
|
|
fPts[i].set(rand.nextUScalar1(), rand.nextUScalar1());
|
|
|
|
}
|
|
|
|
}
|
2015-03-20 13:01:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class EvalQuadAt0 : public QuadBenchBase {
|
|
|
|
public:
|
|
|
|
EvalQuadAt0() : QuadBenchBase("evalquadat0") {}
|
2015-03-19 17:18:47 +00:00
|
|
|
protected:
|
|
|
|
void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
|
|
|
SkPoint result;
|
|
|
|
for (int outer = 0; outer < loops; ++outer) {
|
2015-03-20 13:01:08 +00:00
|
|
|
SkEvalQuadAt(fPts, 0.5f, &result);
|
|
|
|
SkEvalQuadAt(fPts, 0.5f, &result);
|
|
|
|
SkEvalQuadAt(fPts, 0.5f, &result);
|
|
|
|
SkEvalQuadAt(fPts, 0.5f, &result);
|
2015-03-19 17:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
DEF_BENCH( return new EvalQuadAt0; )
|
|
|
|
|
2015-03-20 13:01:08 +00:00
|
|
|
class EvalQuadAt1 : public QuadBenchBase {
|
2015-03-19 17:18:47 +00:00
|
|
|
public:
|
2015-03-20 13:01:08 +00:00
|
|
|
EvalQuadAt1() : QuadBenchBase("evalquadat1") {}
|
|
|
|
protected:
|
|
|
|
void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
|
|
|
SkPoint result;
|
|
|
|
for (int outer = 0; outer < loops; ++outer) {
|
|
|
|
result = SkEvalQuadAt(fPts, 0.5f);
|
|
|
|
result = SkEvalQuadAt(fPts, 0.5f);
|
|
|
|
result = SkEvalQuadAt(fPts, 0.5f);
|
|
|
|
result = SkEvalQuadAt(fPts, 0.5f);
|
2015-03-19 17:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-20 13:01:08 +00:00
|
|
|
};
|
|
|
|
DEF_BENCH( return new EvalQuadAt1; )
|
|
|
|
|
|
|
|
////////
|
|
|
|
|
|
|
|
class EvalQuadTangentAt0 : public QuadBenchBase {
|
|
|
|
public:
|
|
|
|
EvalQuadTangentAt0() : QuadBenchBase("evalquadtangentat0") {}
|
2015-03-19 17:18:47 +00:00
|
|
|
protected:
|
|
|
|
void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
2015-03-20 13:01:08 +00:00
|
|
|
SkPoint result;
|
2015-03-19 17:18:47 +00:00
|
|
|
for (int outer = 0; outer < loops; ++outer) {
|
2015-03-20 13:01:08 +00:00
|
|
|
SkEvalQuadAt(fPts, 0.5f, NULL, &result);
|
|
|
|
SkEvalQuadAt(fPts, 0.5f, NULL, &result);
|
|
|
|
SkEvalQuadAt(fPts, 0.5f, NULL, &result);
|
|
|
|
SkEvalQuadAt(fPts, 0.5f, NULL, &result);
|
2015-03-19 17:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-03-20 13:01:08 +00:00
|
|
|
DEF_BENCH( return new EvalQuadTangentAt0; )
|
|
|
|
|
|
|
|
class EvalQuadTangentAt1 : public QuadBenchBase {
|
|
|
|
public:
|
|
|
|
EvalQuadTangentAt1() : QuadBenchBase("evalquadtangentat1") {}
|
|
|
|
protected:
|
|
|
|
void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
|
|
|
SkPoint result;
|
|
|
|
for (int outer = 0; outer < loops; ++outer) {
|
|
|
|
result = SkEvalQuadTangentAt(fPts, 0.5f);
|
|
|
|
result = SkEvalQuadTangentAt(fPts, 0.5f);
|
|
|
|
result = SkEvalQuadTangentAt(fPts, 0.5f);
|
|
|
|
result = SkEvalQuadTangentAt(fPts, 0.5f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
DEF_BENCH( return new EvalQuadTangentAt1; )
|
|
|
|
|
|
|
|
////////
|
|
|
|
|
|
|
|
class ChopQuadAt0 : public QuadBenchBase {
|
|
|
|
public:
|
|
|
|
ChopQuadAt0() : QuadBenchBase("chopquadat0") {}
|
|
|
|
protected:
|
|
|
|
void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
|
|
|
SkPoint dst[5];
|
|
|
|
for (int outer = 0; outer < loops; ++outer) {
|
|
|
|
SkChopQuadAt(fPts, dst, 0.5f);
|
|
|
|
SkChopQuadAt(fPts, dst, 0.5f);
|
|
|
|
SkChopQuadAt(fPts, dst, 0.5f);
|
|
|
|
SkChopQuadAt(fPts, dst, 0.5f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
DEF_BENCH( return new ChopQuadAt0; )
|
|
|
|
|
|
|
|
class ChopQuadAt1 : public QuadBenchBase {
|
|
|
|
public:
|
|
|
|
ChopQuadAt1() : QuadBenchBase("chopquadat1") {}
|
|
|
|
protected:
|
|
|
|
void onDraw(const int loops, SkCanvas* canvas) SK_OVERRIDE {
|
|
|
|
SkPoint dst[5];
|
|
|
|
for (int outer = 0; outer < loops; ++outer) {
|
|
|
|
SkChopQuadAt2(fPts, dst, 0.5f);
|
|
|
|
SkChopQuadAt2(fPts, dst, 0.5f);
|
|
|
|
SkChopQuadAt2(fPts, dst, 0.5f);
|
|
|
|
SkChopQuadAt2(fPts, dst, 0.5f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
DEF_BENCH( return new ChopQuadAt1; )
|
2015-03-19 17:18:47 +00:00
|
|
|
|