3 #include "DMWriteTask.h"
5 #include "SkCommandLineFlags.h"
6 #include "SkPictureRecorder.h"
8 DEFINE_bool(skr, true, "Test that SKPs draw the same when re-recorded with SkRecord backend.");
9 DEFINE_int32(skpMaxWidth, 1000, "Max SKPTask viewport width.");
10 DEFINE_int32(skpMaxHeight, 1000, "Max SKPTask viewport height.");
14 // Test that an SkPicture plays back the same when re-recorded into an
15 // SkPicture backed by SkRecord.
16 class SkrComparisonTask : public CpuTask {
18 SkrComparisonTask(const Task& parent, const SkPicture* picture, SkBitmap reference)
20 , fPicture(SkRef(picture))
21 , fReference(reference)
22 , fName(UnderJoin(parent.name().c_str(), "skr")) {}
24 virtual bool shouldSkip() const SK_OVERRIDE { return !FLAGS_skr; }
25 virtual SkString name() const SK_OVERRIDE { return fName; }
27 virtual void draw() SK_OVERRIDE {
28 SkPictureRecorder recorder;
29 fPicture->draw(recorder.EXPERIMENTAL_beginRecording(fPicture->width(), fPicture->height()));
30 SkAutoTDelete<const SkPicture> skrPicture(recorder.endRecording());
33 AllocatePixels(kN32_SkColorType, fReference.width(), fReference.height(), &bitmap);
34 DrawPicture(*skrPicture, &bitmap);
36 if (!BitmapsEqual(fReference, bitmap)) {
38 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
43 SkAutoTUnref<const SkPicture> fPicture;
44 const SkBitmap fReference;
49 SKPTask::SKPTask(Reporter* r, TaskRunner* tr, const SkPicture* pic, SkString filename)
50 : CpuTask(r, tr), fPicture(SkRef(pic)), fName(FileToTaskName(filename)) {}
52 void SKPTask::draw() {
53 const int width = SkTMin(fPicture->width(), FLAGS_skpMaxWidth),
54 height = SkTMin(fPicture->height(), FLAGS_skpMaxHeight);
56 AllocatePixels(kN32_SkColorType, width, height, &bitmap);
57 DrawPicture(*fPicture, &bitmap);
59 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
60 this->spawnChild(SkNEW_ARGS(SkrComparisonTask, (*this, fPicture.get(), bitmap)));