skia2/dm/DMSerializeTask.cpp
mtklein a9ceaf5364 Don't test the old picture backend anymore.
This saves a bunch of CPU time in DM, and even better, lets us tear it down!

BUG=skia:
R=robertphillips@google.com, mtklein@google.com

Author: mtklein@chromium.org

Review URL: https://codereview.chromium.org/612603002
2014-09-29 08:44:46 -07:00

45 lines
1.2 KiB
C++

#include "DMSerializeTask.h"
#include "DMUtil.h"
#include "DMWriteTask.h"
#include "SkCommandLineFlags.h"
#include "SkPicture.h"
#include "SkPixelRef.h"
DEFINE_bool(serialize, true, "If true, run picture serialization tests via SkPictureData.");
namespace DM {
SerializeTask::SerializeTask(const Task& parent, skiagm::GM* gm, SkBitmap reference)
: CpuTask(parent)
, fName(UnderJoin(parent.name().c_str(), "serialize"))
, fGM(gm)
, fReference(reference)
{}
void SerializeTask::draw() {
SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get(), NULL/*no BBH*/));
SkDynamicMemoryWStream wStream;
recorded->serialize(&wStream, NULL);
SkAutoTUnref<SkStream> rStream(wStream.detachAsStream());
SkAutoTUnref<SkPicture> reconstructed(SkPicture::CreateFromStream(rStream));
SkBitmap bitmap;
AllocatePixels(fReference, &bitmap);
DrawPicture(*reconstructed, &bitmap);
if (!BitmapsEqual(bitmap, fReference)) {
this->fail();
this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "GM", bitmap)));
}
}
bool SerializeTask::shouldSkip() const {
if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) {
return true;
}
return !FLAGS_serialize;
}
} // namespace DM