aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DMRecordTask.cpp
blob: 95a8bbd217cc781c7357660a703a1043164e92d4 (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
#include "DMRecordTask.h"
#include "DMUtil.h"
#include "DMWriteTask.h"
#include "SkCommandLineFlags.h"
#include "SkRecording.h"

DEFINE_bool(skr, false, "If true, run SKR tests.");

namespace DM {

RecordTask::RecordTask(const Task& parent, skiagm::GM* gm, SkBitmap reference)
    : CpuTask(parent)
    , fName(UnderJoin(parent.name().c_str(), "skr"))
    , fGM(gm)
    , fReference(reference)
    {}

void RecordTask::draw() {
    using EXPERIMENTAL::SkRecording;
    using EXPERIMENTAL::SkPlayback;

    // Record the GM into an SkRecord.
    SkRecording* recording = SkRecording::Create(fReference.width(), fReference.height());
    fGM->draw(recording->canvas());
    SkAutoTDelete<const SkPlayback> playback(SkRecording::Delete(recording));

    // Draw the SkRecord back into a bitmap.
    SkBitmap bitmap;
    SetupBitmap(fReference.colorType(), fGM.get(), &bitmap);
    SkCanvas target(bitmap);
    playback->draw(&target);

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

bool RecordTask::shouldSkip() const {
    return !FLAGS_skr;
}

}  // namespace DM