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 | |
| 22 | void SetupBitmap(const SkBitmap::Config config, skiagm::GM* gm, SkBitmap* bitmap) { |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 23 | const SkISize size = gm->getISize(); |
| 24 | bitmap->setConfig(config, size.width(), size.height()); |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 25 | bitmap->allocPixels(); |
| 26 | bitmap->eraseColor(0x00000000); |
| 27 | } |
| 28 | |
| 29 | void DrawPicture(SkPicture* picture, SkBitmap* bitmap) { |
| 30 | SkASSERT(picture != NULL); |
| 31 | SkASSERT(bitmap != NULL); |
| 32 | SkCanvas canvas(*bitmap); |
| 33 | canvas.drawPicture(*picture); |
| 34 | canvas.flush(); |
| 35 | } |
| 36 | |
| 37 | bool BitmapsEqual(const SkBitmap& a, const SkBitmap& b) { |
| 38 | const SkAutoLockPixels lockA(a), lockB(b); |
| 39 | return a.getSize() == b.getSize() && 0 == memcmp(a.getPixels(), b.getPixels(), b.getSize()); |
| 40 | } |
| 41 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 42 | } // namespace DM |