| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 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 | static void* new_gr_context_factory() { |
| 29 | return SkNEW(GrContextFactory); |
| 30 | } |
| 31 | |
| 32 | static void delete_gr_context_factory(void* factory) { |
| commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame^] | 33 | SkDELETE((GrContextFactory*) factory); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static GrContextFactory* get_gr_factory() { |
| 37 | return reinterpret_cast<GrContextFactory*>(SkTLS::Get(&new_gr_context_factory, |
| 38 | &delete_gr_context_factory)); |
| 39 | } |
| 40 | |
| 41 | void GpuTask::draw() { |
| 42 | GrContext* gr = get_gr_factory()->get(fContextType); // Will be owned by device. |
| commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame^] | 43 | SkGpuDevice device(gr, |
| 44 | fConfig, |
| 45 | SkScalarCeilToInt(fGM->width()), |
| 46 | SkScalarCeilToInt(fGM->height()), |
| 47 | fSampleCount); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 48 | SkCanvas canvas(&device); |
| 49 | |
| 50 | canvas.concat(fGM->getInitialTransform()); |
| 51 | fGM->draw(&canvas); |
| 52 | canvas.flush(); |
| 53 | |
| 54 | SkBitmap bitmap; |
| commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame^] | 55 | bitmap.setConfig(fConfig, SkScalarCeilToInt(fGM->width()), SkScalarCeilToInt(fGM->height())); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 56 | canvas.readPixels(&bitmap, 0, 0); |
| 57 | |
| 58 | // We offload checksum comparison to the main CPU threadpool. |
| 59 | // This cuts run time by about 30%. |
| 60 | this->spawnChild(SkNEW_ARGS(ComparisonTask, (*this, fExpectations, bitmap))); |
| 61 | } |
| 62 | |
| 63 | bool GpuTask::shouldSkip() const { |
| commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame^] | 64 | return SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | } // namespace DM |