mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1 | #include "DMGpuTask.h" |
| 2 | |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 3 | #include "DMExpectationsTask.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 4 | #include "DMUtil.h" |
mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 5 | #include "DMWriteTask.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 6 | #include "SkCommandLineFlags.h" |
| 7 | #include "SkGpuDevice.h" |
| 8 | #include "SkTLS.h" |
| 9 | |
| 10 | namespace DM { |
| 11 | |
| 12 | GpuTask::GpuTask(const char* name, |
| 13 | Reporter* reporter, |
| 14 | TaskRunner* taskRunner, |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 15 | const Expectations& expectations, |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 16 | skiagm::GMRegistry::Factory gmFactory, |
| 17 | SkBitmap::Config config, |
| 18 | GrContextFactory::GLContextType contextType, |
| 19 | int sampleCount) |
| 20 | : Task(reporter, taskRunner) |
| 21 | , fGM(gmFactory(NULL)) |
commit-bot@chromium.org | 192cbf6 | 2013-10-21 18:40:25 +0000 | [diff] [blame] | 22 | , fName(UnderJoin(fGM->shortName(), name)) |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 23 | , fExpectations(expectations) |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 24 | , fConfig(config) |
| 25 | , fContextType(contextType) |
| 26 | , fSampleCount(sampleCount) |
| 27 | {} |
| 28 | |
| 29 | static void* new_gr_context_factory() { |
| 30 | return SkNEW(GrContextFactory); |
| 31 | } |
| 32 | |
| 33 | static void delete_gr_context_factory(void* factory) { |
commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 34 | SkDELETE((GrContextFactory*) factory); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | static GrContextFactory* get_gr_factory() { |
| 38 | return reinterpret_cast<GrContextFactory*>(SkTLS::Get(&new_gr_context_factory, |
| 39 | &delete_gr_context_factory)); |
| 40 | } |
| 41 | |
| 42 | void GpuTask::draw() { |
| 43 | 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] | 44 | SkGpuDevice device(gr, |
| 45 | fConfig, |
| 46 | SkScalarCeilToInt(fGM->width()), |
| 47 | SkScalarCeilToInt(fGM->height()), |
| 48 | fSampleCount); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 49 | SkCanvas canvas(&device); |
| 50 | |
| 51 | canvas.concat(fGM->getInitialTransform()); |
| 52 | fGM->draw(&canvas); |
| 53 | canvas.flush(); |
| 54 | |
| 55 | SkBitmap bitmap; |
commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 56 | bitmap.setConfig(fConfig, SkScalarCeilToInt(fGM->width()), SkScalarCeilToInt(fGM->height())); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 57 | canvas.readPixels(&bitmap, 0, 0); |
| 58 | |
commit-bot@chromium.org | a34b1f8 | 2013-10-24 17:44:43 +0000 | [diff] [blame] | 59 | #if GR_CACHE_STATS |
| 60 | gr->printCacheStats(); |
| 61 | #endif |
| 62 | |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 63 | this->spawnChild(SkNEW_ARGS(ExpectationsTask, (*this, fExpectations, bitmap))); |
mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 64 | this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | bool GpuTask::shouldSkip() const { |
commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 68 | return SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | } // namespace DM |