2013-10-16 13:02:15 +00:00
|
|
|
#include "DMUtil.h"
|
|
|
|
|
2013-10-21 18:40:25 +00:00
|
|
|
#include "SkPicture.h"
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2013-10-21 18:40:25 +00:00
|
|
|
|
2013-10-16 13:02:15 +00:00
|
|
|
namespace DM {
|
|
|
|
|
2013-10-21 18:40:25 +00:00
|
|
|
SkString UnderJoin(const char* a, const char* b) {
|
2013-10-16 13:02:15 +00:00
|
|
|
SkString s;
|
|
|
|
s.appendf("%s_%s", a, b);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2014-04-17 23:35:06 +00:00
|
|
|
SkPicture* RecordPicture(skiagm::GM* gm, uint32_t recordFlags, SkBBHFactory* factory) {
|
2013-12-02 13:50:38 +00:00
|
|
|
const SkISize size = gm->getISize();
|
2014-04-17 23:35:06 +00:00
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkCanvas* canvas = recorder.beginRecording(size.width(), size.height(), factory, recordFlags);
|
2013-10-21 18:40:25 +00:00
|
|
|
canvas->concat(gm->getInitialTransform());
|
|
|
|
gm->draw(canvas);
|
|
|
|
canvas->flush();
|
2014-04-13 19:09:42 +00:00
|
|
|
return recorder.endRecording();
|
2013-10-21 18:40:25 +00:00
|
|
|
}
|
|
|
|
|
2014-02-26 23:01:57 +00:00
|
|
|
static void setup_bitmap(SkColorType ct, int width, int height, SkBitmap* bitmap) {
|
|
|
|
bitmap->allocPixels(SkImageInfo::Make(width, height, ct, kPremul_SkAlphaType));
|
2013-10-21 18:40:25 +00:00
|
|
|
bitmap->eraseColor(0x00000000);
|
|
|
|
}
|
|
|
|
|
2014-05-14 17:55:32 +00:00
|
|
|
void SetupBitmap(SkColorType ct, skiagm::GM* gm, SkBitmap* bitmap) {
|
2014-02-26 23:01:57 +00:00
|
|
|
setup_bitmap(ct, gm->getISize().width(), gm->getISize().height(), bitmap);
|
|
|
|
}
|
|
|
|
|
2014-05-14 17:55:32 +00:00
|
|
|
void SetupBitmap(SkColorType ct, SkBenchmark* bench, SkBitmap* bitmap) {
|
2014-02-26 23:01:57 +00:00
|
|
|
setup_bitmap(ct, bench->getSize().x(), bench->getSize().y(), bitmap);
|
|
|
|
}
|
|
|
|
|
2014-05-14 17:55:32 +00:00
|
|
|
void SetupBitmap(SkColorType ct, const SkPicture& pic, SkBitmap* bitmap) {
|
|
|
|
setup_bitmap(ct, pic.width(), pic.height(), bitmap);
|
|
|
|
}
|
|
|
|
|
2013-10-21 18:40:25 +00:00
|
|
|
void DrawPicture(SkPicture* picture, SkBitmap* bitmap) {
|
|
|
|
SkASSERT(picture != NULL);
|
|
|
|
SkASSERT(bitmap != NULL);
|
|
|
|
SkCanvas canvas(*bitmap);
|
|
|
|
canvas.drawPicture(*picture);
|
|
|
|
canvas.flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BitmapsEqual(const SkBitmap& a, const SkBitmap& b) {
|
|
|
|
const SkAutoLockPixels lockA(a), lockB(b);
|
|
|
|
return a.getSize() == b.getSize() && 0 == memcmp(a.getPixels(), b.getPixels(), b.getSize());
|
|
|
|
}
|
|
|
|
|
2013-10-16 13:02:15 +00:00
|
|
|
} // namespace DM
|