blob: 52efda3d32f5ed3889e1a6cc8e61e8b21611dd97 [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#include "DMUtil.h"
2
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +00003#include "SkPicture.h"
4
mtklein@google.comd36522d2013-10-16 13:02:15 +00005namespace DM {
6
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +00007SkString UnderJoin(const char* a, const char* b) {
mtklein@google.comd36522d2013-10-16 13:02:15 +00008 SkString s;
9 s.appendf("%s_%s", a, b);
10 return s;
11}
12
commit-bot@chromium.orgc1362422013-10-30 20:45:28 +000013void RecordPicture(skiagm::GM* gm, SkPicture* picture, uint32_t recordFlags) {
rmistry@google.comd6bab022013-12-02 13:50:38 +000014 const SkISize size = gm->getISize();
15 SkCanvas* canvas = picture->beginRecording(size.width(), size.height(), recordFlags);
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000016 canvas->concat(gm->getInitialTransform());
17 gm->draw(canvas);
18 canvas->flush();
19 picture->endRecording();
20}
21
22void SetupBitmap(const SkBitmap::Config config, skiagm::GM* gm, SkBitmap* bitmap) {
rmistry@google.comd6bab022013-12-02 13:50:38 +000023 const SkISize size = gm->getISize();
24 bitmap->setConfig(config, size.width(), size.height());
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000025 bitmap->allocPixels();
26 bitmap->eraseColor(0x00000000);
27}
28
29void 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
37bool 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.comd36522d2013-10-16 13:02:15 +000042} // namespace DM