aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/BitmapRectBench.cpp37
-rw-r--r--bench/RTreeBench.cpp41
-rw-r--r--bench/RepeatTileBench.cpp69
3 files changed, 81 insertions, 66 deletions
diff --git a/bench/BitmapRectBench.cpp b/bench/BitmapRectBench.cpp
index f9f46b817c..c147da2349 100644
--- a/bench/BitmapRectBench.cpp
+++ b/bench/BitmapRectBench.cpp
@@ -13,7 +13,7 @@
#include "SkRandom.h"
#include "SkString.h"
-static void drawIntoBitmap(const SkBitmap& bm) {
+static void draw_into_bitmap(const SkBitmap& bm) {
const int w = bm.width();
const int h = bm.height();
@@ -45,6 +45,8 @@ class BitmapRectBench : public SkBenchmark {
uint8_t fAlpha;
SkString fName;
SkRect fSrcR, fDstR;
+ static const int kWidth = 128;
+ static const int kHeight = 128;
enum { N = SkBENCHLOOP(300) };
public:
BitmapRectBench(void* param, U8CPU alpha, bool doFilter, bool slightMatrix) : INHERITED(param) {
@@ -52,37 +54,38 @@ public:
fDoFilter = doFilter;
fSlightMatrix = slightMatrix;
- const int w = 128;
- const int h = 128;
+ fBitmap.setConfig(SkBitmap::kARGB_8888_Config, kWidth, kHeight);
+ }
+
+protected:
+ virtual const char* onGetName() SK_OVERRIDE {
+ fName.printf("bitmaprect_%02X_%sfilter_%s",
+ fAlpha, fDoFilter ? "" : "no",
+ fSlightMatrix ? "trans" : "identity");
+ return fName.c_str();
+ }
- fBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h);
+ virtual void onPreDraw() SK_OVERRIDE {
fBitmap.allocPixels();
fBitmap.setIsOpaque(true);
fBitmap.eraseColor(SK_ColorBLACK);
- drawIntoBitmap(fBitmap);
+ draw_into_bitmap(fBitmap);
- fSrcR.iset(0, 0, w, h);
- fDstR.iset(0, 0, w, h);
+ fSrcR.iset(0, 0, kWidth, kHeight);
+ fDstR.iset(0, 0, kWidth, kHeight);
- if (slightMatrix) {
+ if (fSlightMatrix) {
// want fractional translate
fDstR.offset(SK_Scalar1 / 3, SK_Scalar1 * 5 / 7);
// want enough to create a scale matrix, but not enough to scare
// off our sniffer which tries to see if the matrix is "effectively"
// translate-only.
- fDstR.fRight += SK_Scalar1 / (w * 60);
+ fDstR.fRight += SK_Scalar1 / (kWidth * 60);
}
}
-protected:
- virtual const char* onGetName() {
- fName.printf("bitmaprect_%02X_%sfilter_%s",
- fAlpha, fDoFilter ? "" : "no",
- fSlightMatrix ? "trans" : "identity");
- return fName.c_str();
- }
- virtual void onDraw(SkCanvas* canvas) {
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkRandom rand;
SkPaint paint;
diff --git a/bench/RTreeBench.cpp b/bench/RTreeBench.cpp
index 53dbe28982..bce1b67513 100644
--- a/bench/RTreeBench.cpp
+++ b/bench/RTreeBench.cpp
@@ -18,7 +18,7 @@ static const int NUM_BUILD_RECTS = 500;
static const int NUM_QUERY_RECTS = 5000;
static const int NUM_QUERIES = 1000;
-typedef SkIRect (*MakeRectProc)(SkRandom&, int, int);
+typedef SkIRect (*MakeRectProc)(SkMWCRandom&, int, int);
// Time how long it takes to build an R-Tree either bulk-loaded or not
class BBoxBuildBench : public SkBenchmark {
@@ -41,11 +41,11 @@ public:
fTree->unref();
}
protected:
- virtual const char* onGetName() {
+ virtual const char* onGetName() SK_OVERRIDE {
return fName.c_str();
}
- virtual void onDraw(SkCanvas* canvas) {
- SkRandom rand;
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ SkMWCRandom rand;
for (int i = 0; i < SkBENCHLOOP(100); ++i) {
for (int j = 0; j < NUM_BUILD_RECTS; ++j) {
fTree->insert(reinterpret_cast<void*>(j), fProc(rand, j, NUM_BUILD_RECTS),
@@ -86,23 +86,26 @@ public:
if (fBulkLoad) {
fName.append("_bulk");
}
- SkRandom rand;
- for (int j = 0; j < SkBENCHLOOP(NUM_QUERY_RECTS); ++j) {
- fTree->insert(reinterpret_cast<void*>(j), fProc(rand, j,
- SkBENCHLOOP(NUM_QUERY_RECTS)), fBulkLoad);
- }
- fTree->flushDeferredInserts();
fIsRendering = false;
}
virtual ~BBoxQueryBench() {
fTree->unref();
}
protected:
- virtual const char* onGetName() {
+ virtual const char* onGetName() SK_OVERRIDE {
return fName.c_str();
}
- virtual void onDraw(SkCanvas* canvas) {
- SkRandom rand;
+ virtual void onPreDraw() SK_OVERRIDE {
+ SkMWCRandom rand;
+ for (int j = 0; j < SkBENCHLOOP(NUM_QUERY_RECTS); ++j) {
+ fTree->insert(reinterpret_cast<void*>(j), fProc(rand, j,
+ SkBENCHLOOP(NUM_QUERY_RECTS)), fBulkLoad);
+ }
+ fTree->flushDeferredInserts();
+ }
+
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ SkMWCRandom rand;
for (int i = 0; i < SkBENCHLOOP(NUM_QUERIES); ++i) {
SkTDArray<void*> hits;
SkIRect query;
@@ -145,22 +148,22 @@ private:
typedef SkBenchmark INHERITED;
};
-static inline SkIRect make_simple_rect(SkRandom&, int index, int numRects) {
+static inline SkIRect make_simple_rect(SkMWCRandom&, int index, int numRects) {
SkIRect out = {0, 0, GENERATE_EXTENTS, GENERATE_EXTENTS};
return out;
}
-static inline SkIRect make_concentric_rects_increasing(SkRandom&, int index, int numRects) {
+static inline SkIRect make_concentric_rects_increasing(SkMWCRandom&, int index, int numRects) {
SkIRect out = {0, 0, index + 1, index + 1};
return out;
}
-static inline SkIRect make_concentric_rects_decreasing(SkRandom&, int index, int numRects) {
+static inline SkIRect make_concentric_rects_decreasing(SkMWCRandom&, int index, int numRects) {
SkIRect out = {0, 0, numRects - index, numRects - index};
return out;
}
-static inline SkIRect make_point_rects(SkRandom& rand, int index, int numRects) {
+static inline SkIRect make_point_rects(SkMWCRandom& rand, int index, int numRects) {
SkIRect out;
out.fLeft = rand.nextU() % GENERATE_EXTENTS;
out.fTop = rand.nextU() % GENERATE_EXTENTS;
@@ -169,7 +172,7 @@ static inline SkIRect make_point_rects(SkRandom& rand, int index, int numRects)
return out;
}
-static inline SkIRect make_random_rects(SkRandom& rand, int index, int numRects) {
+static inline SkIRect make_random_rects(SkMWCRandom& rand, int index, int numRects) {
SkIRect out;
out.fLeft = rand.nextS() % GENERATE_EXTENTS;
out.fTop = rand.nextS() % GENERATE_EXTENTS;
@@ -178,7 +181,7 @@ static inline SkIRect make_random_rects(SkRandom& rand, int index, int numRects)
return out;
}
-static inline SkIRect make_large_rects(SkRandom& rand, int index, int numRects) {
+static inline SkIRect make_large_rects(SkMWCRandom& rand, int index, int numRects) {
SkIRect out;
out.fLeft = rand.nextU() % GENERATE_EXTENTS;
out.fTop = rand.nextU() % GENERATE_EXTENTS;
diff --git a/bench/RepeatTileBench.cpp b/bench/RepeatTileBench.cpp
index 11dd6f899b..348f906676 100644
--- a/bench/RepeatTileBench.cpp
+++ b/bench/RepeatTileBench.cpp
@@ -17,7 +17,7 @@ static const char* gConfigName[] = {
"ERROR", "a1", "a8", "index8", "565", "4444", "8888"
};
-static void drawIntoBitmap(const SkBitmap& bm) {
+static void draw_into_bitmap(const SkBitmap& bm) {
const int w = bm.width();
const int h = bm.height();
@@ -36,32 +36,32 @@ static void drawIntoBitmap(const SkBitmap& bm) {
canvas.drawRect(r, p);
}
-static int conv6ToByte(int x) {
+static int conv_6_to_byte(int x) {
return x * 0xFF / 5;
}
-static int convByteTo6(int x) {
+static int conv_byte_to_6(int x) {
return x * 5 / 255;
}
-static uint8_t compute666Index(SkPMColor c) {
+static uint8_t compute_666_index(SkPMColor c) {
int r = SkGetPackedR32(c);
int g = SkGetPackedG32(c);
int b = SkGetPackedB32(c);
- return convByteTo6(r) * 36 + convByteTo6(g) * 6 + convByteTo6(b);
+ return conv_byte_to_6(r) * 36 + conv_byte_to_6(g) * 6 + conv_byte_to_6(b);
}
-static void convertToIndex666(const SkBitmap& src, SkBitmap* dst) {
+static void convert_to_index666(const SkBitmap& src, SkBitmap* dst) {
SkColorTable* ctable = new SkColorTable(216);
SkPMColor* colors = ctable->lockColors();
// rrr ggg bbb
for (int r = 0; r < 6; r++) {
- int rr = conv6ToByte(r);
+ int rr = conv_6_to_byte(r);
for (int g = 0; g < 6; g++) {
- int gg = conv6ToByte(g);
+ int gg = conv_6_to_byte(g);
for (int b = 0; b < 6; b++) {
- int bb = conv6ToByte(b);
+ int bb = conv_6_to_byte(b);
*colors++ = SkPreMultiplyARGB(0xFF, rr, gg, bb);
}
}
@@ -78,51 +78,60 @@ static void convertToIndex666(const SkBitmap& src, SkBitmap* dst) {
const SkPMColor* srcP = src.getAddr32(0, y);
uint8_t* dstP = dst->getAddr8(0, y);
for (int x = src.width() - 1; x >= 0; --x) {
- *dstP++ = compute666Index(*srcP++);
+ *dstP++ = compute_666_index(*srcP++);
}
}
}
class RepeatTileBench : public SkBenchmark {
- SkPaint fPaint;
- SkString fName;
+ SkPaint fPaint;
+ SkString fName;
+ SkBitmap fBitmap;
+ bool fIsOpaque;
+ SkBitmap::Config fConfig;
enum { N = SkBENCHLOOP(20) };
public:
RepeatTileBench(void* param, SkBitmap::Config c, bool isOpaque = false) : INHERITED(param) {
const int w = 50;
const int h = 50;
- SkBitmap bm;
+ fConfig = c;
+ fIsOpaque = isOpaque;
- if (SkBitmap::kIndex8_Config == c) {
- bm.setConfig(SkBitmap::kARGB_8888_Config, w, h);
+ if (SkBitmap::kIndex8_Config == fConfig) {
+ fBitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h);
} else {
- bm.setConfig(c, w, h);
+ fBitmap.setConfig(fConfig, w, h);
}
- bm.allocPixels();
- bm.eraseColor(isOpaque ? SK_ColorWHITE : 0);
- bm.setIsOpaque(isOpaque);
+ fName.printf("repeatTile_%s_%c",
+ gConfigName[fBitmap.config()], isOpaque ? 'X' : 'A');
+ }
+
+protected:
+ virtual const char* onGetName() SK_OVERRIDE {
+ return fName.c_str();
+ }
- drawIntoBitmap(bm);
+ virtual void onPreDraw() SK_OVERRIDE {
+ fBitmap.allocPixels();
+ fBitmap.eraseColor(fIsOpaque ? SK_ColorWHITE : 0);
+ fBitmap.setIsOpaque(fIsOpaque);
- if (SkBitmap::kIndex8_Config == c) {
+ draw_into_bitmap(fBitmap);
+
+ if (SkBitmap::kIndex8_Config == fConfig) {
SkBitmap tmp;
- convertToIndex666(bm, &tmp);
- bm = tmp;
+ convert_to_index666(fBitmap, &tmp);
+ fBitmap = tmp;
}
- SkShader* s = SkShader::CreateBitmapShader(bm,
+ SkShader* s = SkShader::CreateBitmapShader(fBitmap,
SkShader::kRepeat_TileMode,
SkShader::kRepeat_TileMode);
fPaint.setShader(s)->unref();
- fName.printf("repeatTile_%s_%c", gConfigName[bm.config()], isOpaque ? 'X' : 'A');
}
-protected:
- virtual const char* onGetName() {
- return fName.c_str();
- }
- virtual void onDraw(SkCanvas* canvas) {
+ virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
SkPaint paint(fPaint);
this->setupPaint(&paint);