aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DMSKPTask.cpp
blob: 295499b96168b9dcfdb723887cfdde27caaf9898 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "DMSKPTask.h"
#include "DMUtil.h"
#include "DMWriteTask.h"

#include "SkCommandLineFlags.h"
#include "SkPictureRecorder.h"

DEFINE_bool(skr, true, "Test that SKPs draw the same when re-recorded with SkRecord backend.");

namespace DM {

// Test that an SkPicture plays back the same when re-recorded into an
// SkPicture backed by SkRecord.
class SkrComparisonTask : public CpuTask {
public:
    SkrComparisonTask(const Task& parent, const SkPicture* picture, SkBitmap reference)
        : CpuTask(parent)
        , fPicture(picture)
        , fReference(reference)
        , fName(UnderJoin(parent.name().c_str(), "skr")) {}

    virtual bool shouldSkip() const SK_OVERRIDE { return !FLAGS_skr; }
    virtual SkString name() const SK_OVERRIDE { return fName; }

    virtual void draw() SK_OVERRIDE {
        SkPictureRecorder recorder;
        fPicture->draw(recorder.EXPERIMENTAL_beginRecording(fPicture->width(), fPicture->height()));
        SkAutoTDelete<const SkPicture> skrPicture(recorder.endRecording());

        SkBitmap bitmap;
        AllocatePixels(kN32_SkColorType, fPicture->width(), fPicture->height(), &bitmap);
        DrawPicture(*skrPicture, &bitmap);

        if (!BitmapsEqual(fReference, bitmap)) {
            this->fail();
            this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
        }
    }

private:
    SkAutoTUnref<const SkPicture> fPicture;
    const SkBitmap fReference;
    const SkString fName;
};


SKPTask::SKPTask(Reporter* r, TaskRunner* tr, const SkPicture* pic, SkString filename)
    : CpuTask(r, tr), fPicture(SkRef(pic)), fName(FileToTaskName(filename)) {}

void SKPTask::draw() {
    SkBitmap bitmap;
    AllocatePixels(kN32_SkColorType, fPicture->width(), fPicture->height(), &bitmap);
    DrawPicture(*fPicture, &bitmap);

    this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
    this->spawnChild(SkNEW_ARGS(SkrComparisonTask, (*this, fPicture.get(), bitmap)));
}

}  // namespace DM