| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1 | #include "DMUtil.h" |
| 2 | |
| commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 3 | #include "SkPicture.h" |
| 4 | |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 5 | namespace DM { |
| 6 | |
| commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 7 | SkString UnderJoin(const char* a, const char* b) { |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 8 | SkString s; |
| 9 | s.appendf("%s_%s", a, b); |
| 10 | return s; |
| 11 | } |
| 12 | |
| commit-bot@chromium.org | c136242 | 2013-10-30 20:45:28 +0000 | [diff] [blame] | 13 | void RecordPicture(skiagm::GM* gm, SkPicture* picture, uint32_t recordFlags) { |
| rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 14 | const SkISize size = gm->getISize(); |
| 15 | SkCanvas* canvas = picture->beginRecording(size.width(), size.height(), recordFlags); |
| commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 16 | canvas->concat(gm->getInitialTransform()); |
| 17 | gm->draw(canvas); |
| 18 | canvas->flush(); |
| 19 | picture->endRecording(); |
| 20 | } |
| 21 | |
| commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 22 | static void setup_bitmap(SkColorType ct, int width, int height, SkBitmap* bitmap) { |
| 23 | bitmap->allocPixels(SkImageInfo::Make(width, height, ct, kPremul_SkAlphaType)); |
| commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 24 | bitmap->eraseColor(0x00000000); |
| 25 | } |
| 26 | |
| commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 27 | void SetupBitmap(const SkColorType ct, skiagm::GM* gm, SkBitmap* bitmap) { |
| 28 | setup_bitmap(ct, gm->getISize().width(), gm->getISize().height(), bitmap); |
| 29 | } |
| 30 | |
| 31 | void SetupBitmap(const SkColorType ct, SkBenchmark* bench, SkBitmap* bitmap) { |
| 32 | setup_bitmap(ct, bench->getSize().x(), bench->getSize().y(), bitmap); |
| 33 | } |
| 34 | |
| commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 35 | void DrawPicture(SkPicture* picture, SkBitmap* bitmap) { |
| 36 | SkASSERT(picture != NULL); |
| 37 | SkASSERT(bitmap != NULL); |
| 38 | SkCanvas canvas(*bitmap); |
| 39 | canvas.drawPicture(*picture); |
| 40 | canvas.flush(); |
| 41 | } |
| 42 | |
| 43 | bool BitmapsEqual(const SkBitmap& a, const SkBitmap& b) { |
| 44 | const SkAutoLockPixels lockA(a), lockB(b); |
| 45 | return a.getSize() == b.getSize() && 0 == memcmp(a.getPixels(), b.getPixels(), b.getSize()); |
| 46 | } |
| 47 | |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 48 | } // namespace DM |