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