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-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2014-10-09 21:29:01 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) 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];
|
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
virtual void onDelayedSetup() {
|
2014-10-09 21:29:01 +00:00
|
|
|
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-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) 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-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) 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") {}
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2014-10-09 21:29:01 +00:00
|
|
|
protected:
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) 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") {}
|
2016-03-29 16:03:52 +00:00
|
|
|
|
2014-10-10 12:50:15 +00:00
|
|
|
protected:
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) 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-25 02:24:34 +00:00
|
|
|
SkPoint fPts[4];
|
2015-03-19 17:18:47 +00:00
|
|
|
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;
|
2015-03-25 02:24:34 +00:00
|
|
|
for (int i = 0; i < 4; ++i) {
|
2015-03-19 17:18:47 +00:00
|
|
|
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:
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2015-03-19 17:18:47 +00:00
|
|
|
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:
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2015-03-20 13:01:08 +00:00
|
|
|
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:
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) 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-08-27 14:41:13 +00:00
|
|
|
SkEvalQuadAt(fPts, 0.5f, nullptr, &result);
|
|
|
|
SkEvalQuadAt(fPts, 0.5f, nullptr, &result);
|
|
|
|
SkEvalQuadAt(fPts, 0.5f, nullptr, &result);
|
|
|
|
SkEvalQuadAt(fPts, 0.5f, nullptr, &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:
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2015-03-20 13:01:08 +00:00
|
|
|
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; )
|
|
|
|
|
|
|
|
////////
|
|
|
|
|
2015-03-26 14:26:08 +00:00
|
|
|
class ChopQuadAt : public QuadBenchBase {
|
2015-03-20 13:01:08 +00:00
|
|
|
public:
|
2015-03-26 14:26:08 +00:00
|
|
|
ChopQuadAt() : QuadBenchBase("chopquadat") {}
|
2015-03-20 13:01:08 +00:00
|
|
|
protected:
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2015-03-20 13:01:08 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-03-26 14:26:08 +00:00
|
|
|
DEF_BENCH( return new ChopQuadAt; )
|
2015-03-20 13:01:08 +00:00
|
|
|
|
2015-03-26 14:26:08 +00:00
|
|
|
class ChopCubicAt : public QuadBenchBase {
|
2015-03-20 13:01:08 +00:00
|
|
|
public:
|
2015-03-26 14:26:08 +00:00
|
|
|
ChopCubicAt() : QuadBenchBase("chopcubicat0") {}
|
2015-03-25 02:24:34 +00:00
|
|
|
protected:
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2015-03-25 02:24:34 +00:00
|
|
|
SkPoint dst[7];
|
|
|
|
for (int outer = 0; outer < loops; ++outer) {
|
|
|
|
SkChopCubicAt(fPts, dst, 0.5f);
|
|
|
|
SkChopCubicAt(fPts, dst, 0.5f);
|
|
|
|
SkChopCubicAt(fPts, dst, 0.5f);
|
|
|
|
SkChopCubicAt(fPts, dst, 0.5f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-03-26 14:26:08 +00:00
|
|
|
DEF_BENCH( return new ChopCubicAt; )
|