blob: a227ca85841afe9e9c69352cb5dac205359a7e40 [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.org192cbf62013-10-21 18:40:25 +000013SkString Png(SkString s) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000014 s.appendf(".png");
15 return s;
16}
17
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000018bool MeetsExpectations(const skiagm::Expectations& expectations, const SkBitmap bitmap) {
commit-bot@chromium.org66bb3d12013-10-16 19:13:38 +000019 if (expectations.ignoreFailure() || expectations.empty()) {
20 return true;
21 }
22 const skiagm::GmResultDigest digest(bitmap);
23 return expectations.match(digest);
mtklein@google.comd36522d2013-10-16 13:02:15 +000024}
25
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000026void 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
36void 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
42void 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
50bool 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.comd36522d2013-10-16 13:02:15 +000055} // namespace DM