blob: 28668fe381b22732b1587b28cf1036103f9483aa [file] [log] [blame]
reed@android.com0c9da392010-02-22 19:50:13 +00001#include "SkBenchmark.h"
2#include "SkCanvas.h"
3#include "SkPaint.h"
4#include "SkRandom.h"
5#include "SkString.h"
6
7class FPSBench : public SkBenchmark {
8 int32_t fWidth;
9 int32_t fHeight;
10public:
11 FPSBench(void* p) : INHERITED(p) {
12 fWidth = 640;
13 (void)this->findDefine32("width", &fWidth);
14 fHeight = 480;
15 (void)this->findDefine32("height", &fHeight);
16 }
17
18 int width() const { return fWidth; }
19 int height() const { return fHeight; }
20
21protected:
22 virtual SkIPoint onGetSize() { return SkIPoint::Make(fWidth, fHeight); }
23
24private:
25 typedef SkBenchmark INHERITED;
26};
27
28///////////////////////////////////////////////////////////////////////////////
29
30class Color_FPSBench : public FPSBench {
31public:
32 Color_FPSBench(void* p, SkColor c, const char name[]) : INHERITED(p) {
33 fColor = c;
34 fName = name;
35 }
36
37protected:
38 virtual const char* onGetName() { return fName; }
39 virtual void onDraw(SkCanvas* canvas) {
40 canvas->drawColor(fColor);
41 }
42
43private:
44 const char* fName;
45 SkColor fColor;
46
47 typedef FPSBench INHERITED;
48};
49
50class Bitmap_FPSBench : public FPSBench {
51public:
reed@android.com831f6c62010-02-22 22:03:06 +000052 Bitmap_FPSBench(void* p, SkBitmap::Config config, bool doOpaque, bool doScale) : INHERITED(p) {
reed@android.com0c9da392010-02-22 19:50:13 +000053 fBitmap.setConfig(config, this->width(), this->height());
54 fBitmap.allocPixels();
55 fBitmap.eraseColor(0xFFFF0000);
reed@android.com831f6c62010-02-22 22:03:06 +000056 if (doOpaque) {
57 fBitmap.setIsOpaque(true);
58 }
reed@android.com0c9da392010-02-22 19:50:13 +000059
reed@android.com831f6c62010-02-22 22:03:06 +000060 const char* configStr = "565";
61 if (config == SkBitmap::kARGB_8888_Config) {
62 if (doOpaque) {
63 configStr = "X888";
64 } else {
65 configStr = "8888";
66 }
67 }
68 fName.printf("fps_bitmap_%s_%s", configStr,
reed@android.com0c9da392010-02-22 19:50:13 +000069 doScale ? "scale" : "noscale");
70
71 fMatrix.reset();
72 if (doScale) {
73 fMatrix.setScale(SkIntToScalar(3)/2, SkIntToScalar(3)/2);
74 }
75 }
76
77protected:
78 virtual const char* onGetName() { return fName.c_str(); }
79 virtual void onDraw(SkCanvas* canvas) {
80 canvas->drawBitmapMatrix(fBitmap, fMatrix);
81 }
82
83private:
84 SkBitmap fBitmap;
85 SkMatrix fMatrix;
86 SkString fName;
87
88 typedef FPSBench INHERITED;
89};
90
91static SkBenchmark* FillFactory(void* p) { return SkNEW_ARGS(Color_FPSBench, (p, 0xFFFF0000, "fps_fill")); }
92static SkBenchmark* BlendFactory(void* p) { return SkNEW_ARGS(Color_FPSBench, (p, 0x80FF0000, "fps_blend")); }
reed@android.com831f6c62010-02-22 22:03:06 +000093static SkBenchmark* BMFactory0(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kARGB_8888_Config, false, false)); }
94static SkBenchmark* BMFactory1(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kARGB_8888_Config, false, true)); }
95static SkBenchmark* BMFactory2(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kARGB_8888_Config, true, false)); }
96static SkBenchmark* BMFactory3(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kARGB_8888_Config, true, true)); }
97static SkBenchmark* BMFactory4(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kRGB_565_Config, false, false)); }
98static SkBenchmark* BMFactory5(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kRGB_565_Config, false, true)); }
reed@android.com0c9da392010-02-22 19:50:13 +000099
100static BenchRegistry gFillReg(FillFactory);
101static BenchRegistry gBlendReg(BlendFactory);
102static BenchRegistry gBMReg0(BMFactory0);
103static BenchRegistry gBMReg1(BMFactory1);
104static BenchRegistry gBMReg2(BMFactory2);
105static BenchRegistry gBMReg3(BMFactory3);
reed@android.com831f6c62010-02-22 22:03:06 +0000106static BenchRegistry gBMReg4(BMFactory4);
107static BenchRegistry gBMReg5(BMFactory5);
reed@android.com0c9da392010-02-22 19:50:13 +0000108