OLD | NEW |
(Empty) | |
| 1 #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 |
| 9 namespace DM { |
| 10 |
| 11 GpuTask::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 |
| 28 GrContextFactory* GpuTask::GetGrFactory() { |
| 29 return reinterpret_cast<GrContextFactory*>(SkTLS::Get(&NewGrContextFactory, |
| 30 &DeleteGrContextFactor
y)); |
| 31 } |
| 32 |
| 33 void* GpuTask::NewGrContextFactory() { |
| 34 return SkNEW(GrContextFactory); |
| 35 } |
| 36 |
| 37 void GpuTask::DeleteGrContextFactory(void* factory) { |
| 38 return SkDELETE((GrContextFactory*) factory); |
| 39 } |
| 40 |
| 41 void GpuTask::draw() { |
| 42 GrContext* gr = GetGrFactory()->get(fContextType); // Will be owned by devi
ce. |
| 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 |
| 59 bool GpuTask::shouldSkip() const { |
| 60 return fGM->getFlags() & skiagm::GM::kSkipGPU_Flag; |
| 61 } |
| 62 |
| 63 } // namespace DM |
OLD | NEW |