blob: 9205cb996bfa736a218eb8976803b5faee15da2b [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#include "DMGpuTask.h"
2
3#include "DMComparisonTask.h"
4#include "DMUtil.h"
5#include "SkCommandLineFlags.h"
6#include "SkGpuDevice.h"
7#include "SkTLS.h"
8
9namespace DM {
10
11GpuTask::GpuTask(const char* name,
12 Reporter* reporter,
13 TaskRunner* taskRunner,
14 const skiagm::ExpectationsSource& expectations,
15 skiagm::GMRegistry::Factory gmFactory,
16 SkBitmap::Config config,
17 GrContextFactory::GLContextType contextType,
18 int sampleCount)
19 : Task(reporter, taskRunner)
20 , fGM(gmFactory(NULL))
21 , fName(underJoin(fGM->shortName(), name))
22 , fExpectations(expectations.get(png(fName).c_str()))
23 , fConfig(config)
24 , fContextType(contextType)
25 , fSampleCount(sampleCount)
26 {}
27
28static void* new_gr_context_factory() {
29 return SkNEW(GrContextFactory);
30}
31
32static void delete_gr_context_factory(void* factory) {
33 return SkDELETE((GrContextFactory*) factory);
34}
35
36static GrContextFactory* get_gr_factory() {
37 return reinterpret_cast<GrContextFactory*>(SkTLS::Get(&new_gr_context_factory,
38 &delete_gr_context_factory));
39}
40
41void GpuTask::draw() {
42 GrContext* gr = get_gr_factory()->get(fContextType); // Will be owned by device.
43 SkGpuDevice device(gr, fConfig, fGM->width(), fGM->height(), fSampleCount);
44 SkCanvas canvas(&device);
45
46 canvas.concat(fGM->getInitialTransform());
47 fGM->draw(&canvas);
48 canvas.flush();
49
50 SkBitmap bitmap;
51 bitmap.setConfig(fConfig, fGM->width(), fGM->height());
52 canvas.readPixels(&bitmap, 0, 0);
53
54 // We offload checksum comparison to the main CPU threadpool.
55 // This cuts run time by about 30%.
56 this->spawnChild(SkNEW_ARGS(ComparisonTask, (*this, fExpectations, bitmap)));
57}
58
59bool GpuTask::shouldSkip() const {
60 return fGM->getFlags() & skiagm::GM::kSkipGPU_Flag;
61}
62
63} // namespace DM