reed@android.com | bd700c3 | 2009-01-05 03:34:50 +0000 | [diff] [blame^] | 1 | //#include <iostream> |
| 2 | #include "SkCanvas.h" |
| 3 | #include "SkImageDecoder.h" |
| 4 | #include "SkString.h" |
| 5 | |
| 6 | #include "SkBenchmark.h" |
| 7 | |
| 8 | typedef SkTRegistry<SkBenchmark> BenchRegistry; |
| 9 | |
| 10 | class Iter { |
| 11 | public: |
| 12 | Iter() { |
| 13 | fBench = BenchRegistry::Head(); |
| 14 | } |
| 15 | |
| 16 | SkBenchmark* next() { |
| 17 | if (fBench) { |
| 18 | BenchRegistry::Factory f = fBench->factory(); |
| 19 | fBench = fBench->next(); |
| 20 | return f(); |
| 21 | } |
| 22 | return NULL; |
| 23 | } |
| 24 | |
| 25 | private: |
| 26 | const BenchRegistry* fBench; |
| 27 | }; |
| 28 | |
| 29 | static void make_filename(const char name[], SkString* path) { |
| 30 | path->set(name); |
| 31 | for (int i = 0; name[i]; i++) { |
| 32 | switch (name[i]) { |
| 33 | case '/': |
| 34 | case '\\': |
| 35 | case ' ': |
| 36 | case ':': |
| 37 | path->writable_str()[i] = '-'; |
| 38 | break; |
| 39 | default: |
| 40 | break; |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | int main (int argc, char * const argv[]) { |
| 46 | const int w = 640; |
| 47 | const int h = 480; |
| 48 | |
| 49 | SkBitmap bm; |
| 50 | bm.setConfig(SkBitmap::kARGB_8888_Config, w, h); |
| 51 | bm.allocPixels(); |
| 52 | |
| 53 | SkCanvas canvas(bm); |
| 54 | |
| 55 | Iter iter; |
| 56 | SkBenchmark* bench; |
| 57 | while ((bench = iter.next()) != NULL) { |
| 58 | canvas.drawColor(SK_ColorWHITE); |
| 59 | bench->draw(&canvas); |
| 60 | |
| 61 | SkString str; |
| 62 | make_filename(bench->getName(), &str); |
| 63 | str.prepend("/skimages/"); |
| 64 | str.append(".png"); |
| 65 | ::remove(str.c_str()); |
| 66 | SkImageEncoder::EncodeFile(str.c_str(), bm, SkImageEncoder::kPNG_Type); |
| 67 | } |
| 68 | |
| 69 | return 0; |
| 70 | } |