reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 1 | #include "SkBenchmark.h" |
| 2 | #include "SkCanvas.h" |
| 3 | #include "SkPaint.h" |
| 4 | #include "SkRandom.h" |
| 5 | #include "SkString.h" |
| 6 | |
| 7 | class FPSBench : public SkBenchmark { |
| 8 | int32_t fWidth; |
| 9 | int32_t fHeight; |
| 10 | public: |
| 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 | |
| 21 | protected: |
| 22 | virtual SkIPoint onGetSize() { return SkIPoint::Make(fWidth, fHeight); } |
| 23 | |
| 24 | private: |
| 25 | typedef SkBenchmark INHERITED; |
| 26 | }; |
| 27 | |
| 28 | /////////////////////////////////////////////////////////////////////////////// |
| 29 | |
| 30 | class Color_FPSBench : public FPSBench { |
| 31 | public: |
| 32 | Color_FPSBench(void* p, SkColor c, const char name[]) : INHERITED(p) { |
| 33 | fColor = c; |
| 34 | fName = name; |
| 35 | } |
| 36 | |
| 37 | protected: |
| 38 | virtual const char* onGetName() { return fName; } |
| 39 | virtual void onDraw(SkCanvas* canvas) { |
| 40 | canvas->drawColor(fColor); |
| 41 | } |
| 42 | |
| 43 | private: |
| 44 | const char* fName; |
| 45 | SkColor fColor; |
| 46 | |
| 47 | typedef FPSBench INHERITED; |
| 48 | }; |
| 49 | |
| 50 | class Bitmap_FPSBench : public FPSBench { |
| 51 | public: |
reed@android.com | 831f6c6 | 2010-02-22 22:03:06 +0000 | [diff] [blame] | 52 | Bitmap_FPSBench(void* p, SkBitmap::Config config, bool doOpaque, bool doScale) : INHERITED(p) { |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 53 | fBitmap.setConfig(config, this->width(), this->height()); |
| 54 | fBitmap.allocPixels(); |
| 55 | fBitmap.eraseColor(0xFFFF0000); |
reed@android.com | 831f6c6 | 2010-02-22 22:03:06 +0000 | [diff] [blame] | 56 | if (doOpaque) { |
| 57 | fBitmap.setIsOpaque(true); |
| 58 | } |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 59 | |
reed@android.com | 831f6c6 | 2010-02-22 22:03:06 +0000 | [diff] [blame] | 60 | 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.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 69 | doScale ? "scale" : "noscale"); |
| 70 | |
| 71 | fMatrix.reset(); |
| 72 | if (doScale) { |
| 73 | fMatrix.setScale(SkIntToScalar(3)/2, SkIntToScalar(3)/2); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | protected: |
| 78 | virtual const char* onGetName() { return fName.c_str(); } |
| 79 | virtual void onDraw(SkCanvas* canvas) { |
| 80 | canvas->drawBitmapMatrix(fBitmap, fMatrix); |
| 81 | } |
| 82 | |
| 83 | private: |
| 84 | SkBitmap fBitmap; |
| 85 | SkMatrix fMatrix; |
| 86 | SkString fName; |
| 87 | |
| 88 | typedef FPSBench INHERITED; |
| 89 | }; |
| 90 | |
| 91 | static SkBenchmark* FillFactory(void* p) { return SkNEW_ARGS(Color_FPSBench, (p, 0xFFFF0000, "fps_fill")); } |
| 92 | static SkBenchmark* BlendFactory(void* p) { return SkNEW_ARGS(Color_FPSBench, (p, 0x80FF0000, "fps_blend")); } |
reed@android.com | 831f6c6 | 2010-02-22 22:03:06 +0000 | [diff] [blame] | 93 | static SkBenchmark* BMFactory0(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kARGB_8888_Config, false, false)); } |
| 94 | static SkBenchmark* BMFactory1(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kARGB_8888_Config, false, true)); } |
| 95 | static SkBenchmark* BMFactory2(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kARGB_8888_Config, true, false)); } |
| 96 | static SkBenchmark* BMFactory3(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kARGB_8888_Config, true, true)); } |
| 97 | static SkBenchmark* BMFactory4(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kRGB_565_Config, false, false)); } |
| 98 | static SkBenchmark* BMFactory5(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kRGB_565_Config, false, true)); } |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 99 | |
| 100 | static BenchRegistry gFillReg(FillFactory); |
| 101 | static BenchRegistry gBlendReg(BlendFactory); |
| 102 | static BenchRegistry gBMReg0(BMFactory0); |
| 103 | static BenchRegistry gBMReg1(BMFactory1); |
| 104 | static BenchRegistry gBMReg2(BMFactory2); |
| 105 | static BenchRegistry gBMReg3(BMFactory3); |
reed@android.com | 831f6c6 | 2010-02-22 22:03:06 +0000 | [diff] [blame] | 106 | static BenchRegistry gBMReg4(BMFactory4); |
| 107 | static BenchRegistry gBMReg5(BMFactory5); |
reed@android.com | 0c9da39 | 2010-02-22 19:50:13 +0000 | [diff] [blame] | 108 | |