Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Unified Diff: bench/RTreeBench.cpp

Issue 511613002: Convert BBH APIs to use SkRect. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: another in BBH test Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | include/core/SkPicture.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: bench/RTreeBench.cpp
diff --git a/bench/RTreeBench.cpp b/bench/RTreeBench.cpp
index 95f55c9a8f0daf01d8130068a99b60c0281e451c..5442f7e261da6d008c3437aea338ab818037cc75 100644
--- a/bench/RTreeBench.cpp
+++ b/bench/RTreeBench.cpp
@@ -13,12 +13,12 @@
#include "SkString.h"
// confine rectangles to a smallish area, so queries generally hit something, and overlap occurs:
-static const int GENERATE_EXTENTS = 1000;
+static const SkScalar GENERATE_EXTENTS = 1000.0f;
static const int NUM_BUILD_RECTS = 500;
static const int NUM_QUERY_RECTS = 5000;
static const int GRID_WIDTH = 100;
-typedef SkIRect (*MakeRectProc)(SkRandom&, int, int);
+typedef SkRect (*MakeRectProc)(SkRandom&, int, int);
// Time how long it takes to build an R-Tree either bulk-loaded or not
class RTreeBuildBench : public Benchmark {
@@ -115,32 +115,32 @@ protected:
SkRandom rand;
for (int i = 0; i < loops; ++i) {
SkTDArray<void*> hits;
- SkIRect query;
+ SkRect query;
switch(fQuery) {
case kSmall_QueryType:
- query.fLeft = rand.nextU() % GENERATE_EXTENTS;
- query.fTop = rand.nextU() % GENERATE_EXTENTS;
- query.fRight = query.fLeft + (GENERATE_EXTENTS / 20);
- query.fBottom = query.fTop + (GENERATE_EXTENTS / 20);
+ query.fLeft = rand.nextRangeF(0, GENERATE_EXTENTS);
+ query.fTop = rand.nextRangeF(0, GENERATE_EXTENTS);
+ query.fRight = query.fLeft + (GENERATE_EXTENTS / 20);
+ query.fBottom = query.fTop + (GENERATE_EXTENTS / 20);
break;
case kLarge_QueryType:
- query.fLeft = rand.nextU() % GENERATE_EXTENTS;
- query.fTop = rand.nextU() % GENERATE_EXTENTS;
- query.fRight = query.fLeft + (GENERATE_EXTENTS / 2);
- query.fBottom = query.fTop + (GENERATE_EXTENTS / 2);
+ query.fLeft = rand.nextRangeF(0, GENERATE_EXTENTS);
+ query.fTop = rand.nextRangeF(0, GENERATE_EXTENTS);
+ query.fRight = query.fLeft + (GENERATE_EXTENTS / 2);
+ query.fBottom = query.fTop + (GENERATE_EXTENTS / 2);
break;
case kFull_QueryType:
- query.fLeft = -GENERATE_EXTENTS;
- query.fTop = -GENERATE_EXTENTS;
- query.fRight = 2 * GENERATE_EXTENTS;
+ query.fLeft = -GENERATE_EXTENTS;
+ query.fTop = -GENERATE_EXTENTS;
+ query.fRight = 2 * GENERATE_EXTENTS;
query.fBottom = 2 * GENERATE_EXTENTS;
break;
default: // fallthrough
case kRandom_QueryType:
- query.fLeft = rand.nextU() % GENERATE_EXTENTS;
- query.fTop = rand.nextU() % GENERATE_EXTENTS;
- query.fRight = query.fLeft + 1 + rand.nextU() % (GENERATE_EXTENTS / 2);
- query.fBottom = query.fTop + 1 + rand.nextU() % (GENERATE_EXTENTS / 2);
+ query.fLeft = rand.nextRangeF(0, GENERATE_EXTENTS);
+ query.fTop = rand.nextRangeF(0, GENERATE_EXTENTS);
+ query.fRight = query.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/2);
+ query.fBottom = query.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/2);
break;
};
fTree->search(query, &hits);
@@ -155,34 +155,34 @@ private:
typedef Benchmark INHERITED;
};
-static inline SkIRect make_concentric_rects_increasing(SkRandom&, int index, int numRects) {
- SkIRect out = {0, 0, index + 1, index + 1};
+static inline SkRect make_concentric_rects_increasing(SkRandom&, int index, int numRects) {
+ SkRect out = SkRect::MakeWH(SkIntToScalar(index+1), SkIntToScalar(index+1));
return out;
}
-static inline SkIRect make_XYordered_rects(SkRandom& rand, int index, int numRects) {
- SkIRect out;
- out.fLeft = index % GRID_WIDTH;
- out.fTop = index / GRID_WIDTH;
- out.fRight = out.fLeft + 1 + rand.nextU() % (GENERATE_EXTENTS / 3);
- out.fBottom = out.fTop + 1 + rand.nextU() % (GENERATE_EXTENTS / 3);
+static inline SkRect make_XYordered_rects(SkRandom& rand, int index, int numRects) {
+ SkRect out;
+ out.fLeft = SkIntToScalar(index % GRID_WIDTH);
+ out.fTop = SkIntToScalar(index / GRID_WIDTH);
+ out.fRight = out.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/3);
+ out.fBottom = out.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/3);
return out;
}
-static inline SkIRect make_YXordered_rects(SkRandom& rand, int index, int numRects) {
- SkIRect out;
- out.fLeft = index / GRID_WIDTH;
- out.fTop = index % GRID_WIDTH;
- out.fRight = out.fLeft + 1 + rand.nextU() % (GENERATE_EXTENTS / 3);
- out.fBottom = out.fTop + 1 + rand.nextU() % (GENERATE_EXTENTS / 3);
+static inline SkRect make_YXordered_rects(SkRandom& rand, int index, int numRects) {
+ SkRect out;
+ out.fLeft = SkIntToScalar(index / GRID_WIDTH);
+ out.fTop = SkIntToScalar(index % GRID_WIDTH);
+ out.fRight = out.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/3);
+ out.fBottom = out.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/3);
return out;
}
-static inline SkIRect make_random_rects(SkRandom& rand, int index, int numRects) {
- SkIRect out;
- out.fLeft = rand.nextS() % GENERATE_EXTENTS;
- out.fTop = rand.nextS() % GENERATE_EXTENTS;
- out.fRight = out.fLeft + 1 + rand.nextU() % (GENERATE_EXTENTS / 5);
- out.fBottom = out.fTop + 1 + rand.nextU() % (GENERATE_EXTENTS / 5);
+static inline SkRect make_random_rects(SkRandom& rand, int index, int numRects) {
+ SkRect out;
+ out.fLeft = rand.nextRangeF(0, GENERATE_EXTENTS);
+ out.fTop = rand.nextRangeF(0, GENERATE_EXTENTS);
+ out.fRight = out.fLeft + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/5);
+ out.fBottom = out.fTop + 1 + rand.nextRangeF(0, GENERATE_EXTENTS/5);
return out;
}
« no previous file with comments | « no previous file | include/core/SkPicture.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698