1 #include "DMGpuTask.h"
2
3 #include "DMExpectationsTask.h"
4 #include "DMUtil.h"
5 #include "DMWriteTask.h"
6 #include "SkCommandLineFlags.h"
7 #include "SkGpuDevice.h"
8 #include "SkTLS.h"
9
10 namespace DM {
11
GpuTask(const char * name,Reporter * reporter,TaskRunner * taskRunner,const Expectations & expectations,skiagm::GMRegistry::Factory gmFactory,SkBitmap::Config config,GrContextFactory::GLContextType contextType,int sampleCount)12 GpuTask::GpuTask(const char* name,
13 Reporter* reporter,
14 TaskRunner* taskRunner,
15 const Expectations& expectations,
16 skiagm::GMRegistry::Factory gmFactory,
17 SkBitmap::Config config,
18 GrContextFactory::GLContextType contextType,
19 int sampleCount)
20 : Task(reporter, taskRunner)
21 , fGM(gmFactory(NULL))
22 , fName(UnderJoin(fGM->shortName(), name))
23 , fExpectations(expectations)
24 , fConfig(config)
25 , fContextType(contextType)
26 , fSampleCount(sampleCount)
27 {}
28
new_gr_context_factory()29 static void* new_gr_context_factory() {
30 return SkNEW(GrContextFactory);
31 }
32
delete_gr_context_factory(void * factory)33 static void delete_gr_context_factory(void* factory) {
34 SkDELETE((GrContextFactory*) factory);
35 }
36
get_gr_factory()37 static GrContextFactory* get_gr_factory() {
38 return reinterpret_cast<GrContextFactory*>(SkTLS::Get(&new_gr_context_factory,
39 &delete_gr_context_factory));
40 }
41
draw()42 void GpuTask::draw() {
43 GrContext* gr = get_gr_factory()->get(fContextType); // Will be owned by device.
44 SkGpuDevice device(gr,
45 fConfig,
46 SkScalarCeilToInt(fGM->width()),
47 SkScalarCeilToInt(fGM->height()),
48 fSampleCount);
49 SkCanvas canvas(&device);
50
51 canvas.concat(fGM->getInitialTransform());
52 fGM->draw(&canvas);
53 canvas.flush();
54
55 SkBitmap bitmap;
56 bitmap.setConfig(fConfig, SkScalarCeilToInt(fGM->width()), SkScalarCeilToInt(fGM->height()));
57 canvas.readPixels(&bitmap, 0, 0);
58
59 #if GR_CACHE_STATS
60 gr->printCacheStats();
61 #endif
62
63 this->spawnChild(SkNEW_ARGS(ExpectationsTask, (*this, fExpectations, bitmap)));
64 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
65 }
66
shouldSkip() const67 bool GpuTask::shouldSkip() const {
68 return SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag);
69 }
70
71 } // namespace DM
72