aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DMGpuTask.cpp
blob: c0502eeed5e4282c99bb9a1ba22298d278b9f500 (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
60
61
62
63
64
65
66
67
68
69
70
71
#include "DMGpuTask.h"

#include "DMExpectationsTask.h"
#include "DMUtil.h"
#include "DMWriteTask.h"
#include "SkCommandLineFlags.h"
#include "SkGpuDevice.h"
#include "SkTLS.h"

namespace DM {

GpuTask::GpuTask(const char* name,
                 Reporter* reporter,
                 TaskRunner* taskRunner,
                 const Expectations& expectations,
                 skiagm::GMRegistry::Factory gmFactory,
                 SkBitmap::Config config,
                 GrContextFactory::GLContextType contextType,
                 int sampleCount)
    : Task(reporter, taskRunner)
    , fGM(gmFactory(NULL))
    , fName(UnderJoin(fGM->shortName(), name))
    , fExpectations(expectations)
    , fConfig(config)
    , fContextType(contextType)
    , fSampleCount(sampleCount)
    {}

static void* new_gr_context_factory() {
    return SkNEW(GrContextFactory);
}

static void delete_gr_context_factory(void* factory) {
    SkDELETE((GrContextFactory*) factory);
}

static GrContextFactory* get_gr_factory() {
    return reinterpret_cast<GrContextFactory*>(SkTLS::Get(&new_gr_context_factory,
                                                          &delete_gr_context_factory));
}

void GpuTask::draw() {
    GrContext* gr = get_gr_factory()->get(fContextType);  // Will be owned by device.
    SkGpuDevice device(gr,
                       fConfig,
                       SkScalarCeilToInt(fGM->width()),
                       SkScalarCeilToInt(fGM->height()),
                       fSampleCount);
    SkCanvas canvas(&device);

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

    SkBitmap bitmap;
    bitmap.setConfig(fConfig, SkScalarCeilToInt(fGM->width()), SkScalarCeilToInt(fGM->height()));
    canvas.readPixels(&bitmap, 0, 0);

#if GR_CACHE_STATS
    gr->printCacheStats();
#endif

    this->spawnChild(SkNEW_ARGS(ExpectationsTask, (*this, fExpectations, bitmap)));
    this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
}

bool GpuTask::shouldSkip() const {
    return SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag);
}

}  // namespace DM