blob: 9a4765abb09d15cbad420e1c280d1c17fd0f1e1b [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"
robertphillips@google.com770963f2014-04-18 18:04:41 +00004#include "SkPictureRecorder.h"
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +00005
mtklein@google.comd36522d2013-10-16 13:02:15 +00006namespace DM {
7
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +00008SkString UnderJoin(const char* a, const char* b) {
mtklein@google.comd36522d2013-10-16 13:02:15 +00009 SkString s;
10 s.appendf("%s_%s", a, b);
11 return s;
12}
13
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +000014SkPicture* RecordPicture(skiagm::GM* gm, uint32_t recordFlags, SkBBHFactory* factory) {
rmistry@google.comd6bab022013-12-02 13:50:38 +000015 const SkISize size = gm->getISize();
commit-bot@chromium.org5fb2ce32014-04-17 23:35:06 +000016 SkPictureRecorder recorder;
17 SkCanvas* canvas = recorder.beginRecording(size.width(), size.height(), factory, recordFlags);
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000018 canvas->concat(gm->getInitialTransform());
19 gm->draw(canvas);
20 canvas->flush();
robertphillips@google.com84b18c72014-04-13 19:09:42 +000021 return recorder.endRecording();
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000022}
23
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000024static void setup_bitmap(SkColorType ct, int width, int height, SkBitmap* bitmap) {
25 bitmap->allocPixels(SkImageInfo::Make(width, height, ct, kPremul_SkAlphaType));
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000026 bitmap->eraseColor(0x00000000);
27}
28
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000029void SetupBitmap(const SkColorType ct, skiagm::GM* gm, SkBitmap* bitmap) {
30 setup_bitmap(ct, gm->getISize().width(), gm->getISize().height(), bitmap);
31}
32
33void SetupBitmap(const SkColorType ct, SkBenchmark* bench, SkBitmap* bitmap) {
34 setup_bitmap(ct, bench->getSize().x(), bench->getSize().y(), bitmap);
35}
36
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000037void DrawPicture(SkPicture* picture, SkBitmap* bitmap) {
38 SkASSERT(picture != NULL);
39 SkASSERT(bitmap != NULL);
40 SkCanvas canvas(*bitmap);
41 canvas.drawPicture(*picture);
42 canvas.flush();
43}
44
45bool BitmapsEqual(const SkBitmap& a, const SkBitmap& b) {
46 const SkAutoLockPixels lockA(a), lockB(b);
47 return a.getSize() == b.getSize() && 0 == memcmp(a.getPixels(), b.getPixels(), b.getSize());
48}
49
mtklein@google.comd36522d2013-10-16 13:02:15 +000050} // namespace DM