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) | |
22 , fGM(gmFactory(NULL)) | 21 , fGM(gmFactory(NULL)) |
23 , fName(UnderJoin(fGM->shortName(), name)) | 22 , fName(UnderJoin(fGM->shortName(), name)) |
24 , fExpectations(expectations) | 23 , fExpectations(expectations) |
25 , fColorType(colorType) | 24 , fColorType(colorType) |
26 , fContextType(contextType) | 25 , fContextType(contextType) |
27 , fSampleCount(sampleCount) | 26 , fSampleCount(sampleCount) |
28 {} | 27 {} |
29 | 28 |
| 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 |
30 void GpuTask::draw() { | 42 void GpuTask::draw() { |
| 43 GrContext* gr = get_gr_factory()->get(fContextType); // Will be owned by de
vice. |
31 SkImageInfo info = SkImageInfo::Make(SkScalarCeilToInt(fGM->width()), | 44 SkImageInfo info = SkImageInfo::Make(SkScalarCeilToInt(fGM->width()), |
32 SkScalarCeilToInt(fGM->height()), | 45 SkScalarCeilToInt(fGM->height()), |
33 fColorType, | 46 fColorType, kPremul_SkAlphaType); |
34 kPremul_SkAlphaType); | |
35 GrContext* gr = fTaskRunner->getGrContextFactory()->get(fContextType); // O
wned by surface. | |
36 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(gr, info, fSample
Count)); | 47 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(gr, info, fSample
Count)); |
37 SkCanvas* canvas = surface->getCanvas(); | 48 SkCanvas* canvas = surface->getCanvas(); |
38 | 49 |
39 canvas->concat(fGM->getInitialTransform()); | 50 canvas->concat(fGM->getInitialTransform()); |
40 fGM->draw(canvas); | 51 fGM->draw(canvas); |
41 canvas->flush(); | 52 canvas->flush(); |
42 | 53 |
43 SkBitmap bitmap; | 54 SkBitmap bitmap; |
44 bitmap.setConfig(info); | 55 bitmap.setConfig(info); |
45 canvas->readPixels(&bitmap, 0, 0); | 56 canvas->readPixels(&bitmap, 0, 0); |
46 | 57 |
47 #if GR_CACHE_STATS | 58 #if GR_CACHE_STATS |
48 gr->printCacheStats(); | 59 gr->printCacheStats(); |
49 #endif | 60 #endif |
50 | 61 |
51 this->spawnChild(SkNEW_ARGS(ExpectationsTask, (*this, fExpectations, bitmap)
)); | 62 this->spawnChild(SkNEW_ARGS(ExpectationsTask, (*this, fExpectations, bitmap)
)); |
52 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); | 63 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); |
53 } | 64 } |
54 | 65 |
55 bool GpuTask::shouldSkip() const { | 66 bool GpuTask::shouldSkip() const { |
56 return SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag); | 67 return SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag); |
57 } | 68 } |
58 | 69 |
59 } // namespace DM | 70 } // namespace DM |
OLD | NEW |