2013-10-16 13:02:15 +00:00
|
|
|
#include "DMUtil.h"
|
|
|
|
|
2013-10-21 18:40:25 +00:00
|
|
|
#include "SkPicture.h"
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-10-21 18:40:25 +00:00
|
|
|
SkString Png(SkString s) {
|
2013-10-16 13:02:15 +00:00
|
|
|
s.appendf(".png");
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2013-12-02 13:36:22 +00:00
|
|
|
bool MeetsExpectations(const skiagm::Expectations& expectations, const SkBitmap bitmap) {
|
|
|
|
if (expectations.ignoreFailure() || expectations.empty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const skiagm::GmResultDigest digest(bitmap);
|
|
|
|
return expectations.match(digest);
|
|
|
|
}
|
|
|
|
|
2013-10-30 20:45:28 +00:00
|
|
|
void RecordPicture(skiagm::GM* gm, SkPicture* picture, uint32_t recordFlags) {
|
2013-12-02 13:36:22 +00:00
|
|
|
SkCanvas* canvas = picture->beginRecording(SkScalarCeilToInt(gm->width()),
|
|
|
|
SkScalarCeilToInt(gm->height()),
|
|
|
|
recordFlags);
|
2013-10-21 18:40:25 +00:00
|
|
|
canvas->concat(gm->getInitialTransform());
|
|
|
|
gm->draw(canvas);
|
|
|
|
canvas->flush();
|
|
|
|
picture->endRecording();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupBitmap(const SkBitmap::Config config, skiagm::GM* gm, SkBitmap* bitmap) {
|
2013-12-02 13:36:22 +00:00
|
|
|
bitmap->setConfig(config, SkScalarCeilToInt(gm->width()), SkScalarCeilToInt(gm->height()));
|
2013-10-21 18:40:25 +00:00
|
|
|
bitmap->allocPixels();
|
|
|
|
bitmap->eraseColor(0x00000000);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|