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: |
| 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 | |
| 66 | protected: |
| 67 | virtual const char* onGetName() { return fName.c_str(); } |
| 68 | virtual void onDraw(SkCanvas* canvas) { |
| 69 | canvas->drawBitmapMatrix(fBitmap, fMatrix); |
| 70 | } |
| 71 | |
| 72 | private: |
| 73 | SkBitmap fBitmap; |
| 74 | SkMatrix fMatrix; |
| 75 | SkString fName; |
| 76 | |
| 77 | typedef FPSBench INHERITED; |
| 78 | }; |
| 79 | |
| 80 | static SkBenchmark* FillFactory(void* p) { return SkNEW_ARGS(Color_FPSBench, (p, 0xFFFF0000, "fps_fill")); } |
| 81 | static SkBenchmark* BlendFactory(void* p) { return SkNEW_ARGS(Color_FPSBench, (p, 0x80FF0000, "fps_blend")); } |
| 82 | static SkBenchmark* BMFactory0(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kARGB_8888_Config, false)); } |
| 83 | static SkBenchmark* BMFactory1(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kARGB_8888_Config, true)); } |
| 84 | static SkBenchmark* BMFactory2(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kRGB_565_Config, false)); } |
| 85 | static SkBenchmark* BMFactory3(void* p) { return SkNEW_ARGS(Bitmap_FPSBench, (p, SkBitmap::kRGB_565_Config, true)); } |
| 86 | |
| 87 | static BenchRegistry gFillReg(FillFactory); |
| 88 | static BenchRegistry gBlendReg(BlendFactory); |
| 89 | static BenchRegistry gBMReg0(BMFactory0); |
| 90 | static BenchRegistry gBMReg1(BMFactory1); |
| 91 | static BenchRegistry gBMReg2(BMFactory2); |
| 92 | static BenchRegistry gBMReg3(BMFactory3); |
| 93 | |