aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DMCpuTask.cpp
blob: 14f661ac387f0e2dc23956376bf6bb9b64726947 (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
#include "DMCpuTask.h"
#include "DMReplayTask.h"
#include "DMUtil.h"
#include "SkCommandLineFlags.h"

DEFINE_bool(replay, false, "If true, run replay tests for each CpuTask.");
// TODO(mtklein): add the other various options

namespace DM {

CpuTask::CpuTask(const char* name,
                 Reporter* reporter,
                 TaskRunner* taskRunner,
                 const skiagm::ExpectationsSource& expectations,
                 skiagm::GMRegistry::Factory gmFactory,
                 SkBitmap::Config config)
    : Task(reporter, taskRunner)
    , fGMFactory(gmFactory)
    , fGM(fGMFactory(NULL))
    , fName(underJoin(fGM->shortName(), name))
    , fExpectations(expectations.get(png(fName).c_str()))
    , fConfig(config)
    {}

void CpuTask::draw() {
    SkBitmap bitmap;
    bitmap.setConfig(fConfig, SkScalarCeilToInt(fGM->width()), SkScalarCeilToInt(fGM->height()));
    bitmap.allocPixels();
    bitmap.eraseColor(0x00000000);
    SkCanvas canvas(bitmap);

    canvas.concat(fGM->getInitialTransform());
    fGM->draw(&canvas);
    canvas.flush();

    if (!meetsExpectations(fExpectations, bitmap)) {
        this->fail();
    }

    if (FLAGS_replay) {
        this->spawnChild(SkNEW_ARGS(ReplayTask,
                                   ("replay", *this, fGMFactory(NULL), bitmap)));
    }
}

bool CpuTask::shouldSkip() const {
    if (SkBitmap::kRGB_565_Config == fConfig && (fGM->getFlags() & skiagm::GM::kSkip565_Flag)) {
        return true;
    }
    if (fGM->getFlags() & skiagm::GM::kGPUOnly_Flag) {
        return true;
    }
    return false;
}

}  // namespace DM