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 | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 13 | SkString Png(SkString s) { |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 14 | s.appendf(".png"); |
| 15 | return s; |
| 16 | } |
| 17 | |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 18 | bool MeetsExpectations(const skiagm::Expectations& expectations, const SkBitmap bitmap) { |
commit-bot@chromium.org | 66bb3d1 | 2013-10-16 19:13:38 +0000 | [diff] [blame] | 19 | if (expectations.ignoreFailure() || expectations.empty()) { |
| 20 | return true; |
| 21 | } |
| 22 | const skiagm::GmResultDigest digest(bitmap); |
| 23 | return expectations.match(digest); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 24 | } |
| 25 | |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 26 | void RecordPicture(skiagm::GM* gm, SkPicture* picture) { |
| 27 | SkCanvas* canvas = picture->beginRecording(SkScalarCeilToInt(gm->width()), |
| 28 | SkScalarCeilToInt(gm->height()), |
| 29 | 0 /*flags*/); |
| 30 | canvas->concat(gm->getInitialTransform()); |
| 31 | gm->draw(canvas); |
| 32 | canvas->flush(); |
| 33 | picture->endRecording(); |
| 34 | } |
| 35 | |
| 36 | void SetupBitmap(const SkBitmap::Config config, skiagm::GM* gm, SkBitmap* bitmap) { |
| 37 | bitmap->setConfig(config, SkScalarCeilToInt(gm->width()), SkScalarCeilToInt(gm->height())); |
| 38 | bitmap->allocPixels(); |
| 39 | bitmap->eraseColor(0x00000000); |
| 40 | } |
| 41 | |
| 42 | void DrawPicture(SkPicture* picture, SkBitmap* bitmap) { |
| 43 | SkASSERT(picture != NULL); |
| 44 | SkASSERT(bitmap != NULL); |
| 45 | SkCanvas canvas(*bitmap); |
| 46 | canvas.drawPicture(*picture); |
| 47 | canvas.flush(); |
| 48 | } |
| 49 | |
| 50 | bool BitmapsEqual(const SkBitmap& a, const SkBitmap& b) { |
| 51 | const SkAutoLockPixels lockA(a), lockB(b); |
| 52 | return a.getSize() == b.getSize() && 0 == memcmp(a.getPixels(), b.getPixels(), b.getSize()); |
| 53 | } |
| 54 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 55 | } // namespace DM |