blob: f103dc1b4d02395fee9ac7538aa802f39f716cc5 [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:
52 Bitmap_FPSBench(void* p, SkBitmap::Config config, bool doScale) : INHERITED(p) {
53 fBitmap.setConfig(config, this->width(), this->height());
54 fBitmap.allocPixels();
55 fBitmap.eraseColor(0xFFFF0000);
56
57 fName.printf("fps_bitmap_%d_%s", fBitmap.bytesPerPixel(),
58 doScale ? "scale" : "noscale");
59
60 fMatrix.reset();
61 if (doScale) {
62 fMatrix.setScale(SkIntToScalar(3)/2, SkIntToScalar(3)/2);
63 }
64 }
65
66protected:
67 virtual const char* onGetName() { return fName.c_str(); }
68 virtual void onDraw(SkCanvas* canvas) {
69 canvas->drawBitmapMatrix(fBitmap, fMatrix);
70 }
71
72private:
73 SkBitmap fBitmap;
74 SkMatrix fMatrix;
75 SkString fName;
76
77 typedef FPSBench INHERITED;
78};
79
80static SkBenchmark* FillFactory(void* p) { return SkNEW_ARGS(Color_FPSBench, (p, 0xFFFF0000, "fps_fill")); }
81static SkBenchmark* BlendFactory(void* p) { return SkNEW_ARGS(Color_FPSBench, (p, 0x80FF0000, "fps_blend")); }
82static SkBenchmark* BMFactory0(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kARGB_8888_Config, false)); }
83static SkBenchmark* BMFactory1(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kARGB_8888_Config, true)); }
84static SkBenchmark* BMFactory2(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kRGB_565_Config, false)); }
85static SkBenchmark* BMFactory3(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kRGB_565_Config, true)); }
86
87static BenchRegistry gFillReg(FillFactory);
88static BenchRegistry gBlendReg(BlendFactory);
89static BenchRegistry gBMReg0(BMFactory0);
90static BenchRegistry gBMReg1(BMFactory1);
91static BenchRegistry gBMReg2(BMFactory2);
92static BenchRegistry gBMReg3(BMFactory3);
93