blob: 5a849fb5f6224031cce91b56e947ec6bdffea596 [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
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000022static void setup_bitmap(SkColorType ct, int width, int height, SkBitmap* bitmap) {
23 bitmap->allocPixels(SkImageInfo::Make(width, height, ct, kPremul_SkAlphaType));
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000024 bitmap->eraseColor(0x00000000);
25}
26
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000027void SetupBitmap(const SkColorType ct, skiagm::GM* gm, SkBitmap* bitmap) {
28 setup_bitmap(ct, gm->getISize().width(), gm->getISize().height(), bitmap);
29}
30
31void SetupBitmap(const SkColorType ct, SkBenchmark* bench, SkBitmap* bitmap) {
32 setup_bitmap(ct, bench->getSize().x(), bench->getSize().y(), bitmap);
33}
34
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000035void 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
43bool 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.comd36522d2013-10-16 13:02:15 +000048} // namespace DM