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