aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DMReplayTask.cpp
blob: 736cd5cf1869c928963cd47a891b240bc8f3f25a (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
#include "DMReplayTask.h"
#include "DMWriteTask.h"
#include "DMUtil.h"

#include "SkCommandLineFlags.h"
#include "SkPicture.h"
#include "SkRTreePicture.h"

DEFINE_bool(replay, true, "If true, run picture replay tests.");
DEFINE_bool(rtree,  true, "If true, run picture replay tests with an rtree.");

namespace DM {

ReplayTask::ReplayTask(const Task& parent,
                       skiagm::GM* gm,
                       SkBitmap reference,
                       bool useRTree)
    : CpuTask(parent)
    , fName(UnderJoin(parent.name().c_str(), useRTree ? "rtree" : "replay"))
    , fGM(gm)
    , fReference(reference)
    , fUseRTree(useRTree)
    {}

void ReplayTask::draw() {
    SkAutoTUnref<SkPictureFactory> factory;
    if (fUseRTree) {
        factory.reset(SkNEW(SkRTreePictureFactory));
    }
    SkAutoTUnref<SkPicture> recorded(RecordPicture(fGM.get(), 0, factory));

    SkBitmap bitmap;
    SetupBitmap(fReference.colorType(), fGM.get(), &bitmap);
    DrawPicture(recorded, &bitmap);
    if (!BitmapsEqual(bitmap, fReference)) {
        this->fail();
        this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
    }
}

bool ReplayTask::shouldSkip() const {
    if (fGM->getFlags() & skiagm::GM::kSkipPicture_Flag) {
        return true;
    }

    if (FLAGS_rtree && fUseRTree) {
        return (fGM->getFlags() & skiagm::GM::kSkipTiled_Flag) != 0;
    }
    if (FLAGS_replay && !fUseRTree) {
        return false;
    }
    return true;
}

}  // namespace DM