2013-10-21 18:40:25 +00:00
|
|
|
#include "DMSerializeTask.h"
|
|
|
|
#include "DMUtil.h"
|
|
|
|
#include "DMWriteTask.h"
|
|
|
|
|
|
|
|
#include "SkCommandLineFlags.h"
|
|
|
|
#include "SkPicture.h"
|
|
|
|
#include "SkPixelRef.h"
|
|
|
|
|
2013-12-02 13:50:38 +00:00
|
|
|
DEFINE_bool(serialize, true, "If true, run picture serialization tests.");
|
2013-10-21 18:40:25 +00:00
|
|
|
|
|
|
|
namespace DM {
|
|
|
|
|
|
|
|
SerializeTask::SerializeTask(const Task& parent,
|
|
|
|
skiagm::GM* gm,
|
|
|
|
SkBitmap reference)
|
2014-02-28 20:31:31 +00:00
|
|
|
: CpuTask(parent)
|
2013-10-21 18:40:25 +00:00
|
|
|
, fName(UnderJoin(parent.name().c_str(), "serialize"))
|
|
|
|
, fGM(gm)
|
|
|
|
, fReference(reference)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void SerializeTask::draw() {
|
2014-04-13 19:09:42 +00:00
|
|
|
SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get()));
|
2013-10-21 18:40:25 +00:00
|
|
|
|
|
|
|
SkDynamicMemoryWStream wStream;
|
2014-04-13 19:09:42 +00:00
|
|
|
recorded->serialize(&wStream, NULL);
|
2013-10-21 18:40:25 +00:00
|
|
|
SkAutoTUnref<SkStream> rStream(wStream.detachAsStream());
|
|
|
|
SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream));
|
|
|
|
|
|
|
|
SkBitmap bitmap;
|
2014-02-16 00:59:25 +00:00
|
|
|
SetupBitmap(fReference.colorType(), fGM.get(), &bitmap);
|
2013-10-21 18:40:25 +00:00
|
|
|
DrawPicture(reconstructed, &bitmap);
|
|
|
|
if (!BitmapsEqual(bitmap, fReference)) {
|
|
|
|
this->fail();
|
|
|
|
this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SerializeTask::shouldSkip() const {
|
|
|
|
return !FLAGS_serialize || fGM->getFlags() & skiagm::GM::kSkipPicture_Flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace DM
|