| 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" |
| commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 7 | #include "SkSurface.h" |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 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, |
| commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 17 | SkColorType colorType, |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 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) |
| commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 24 | , fColorType(colorType) |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 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 | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 44 | SkImageInfo info = SkImageInfo::Make(SkScalarCeilToInt(fGM->width()), |
| 45 | SkScalarCeilToInt(fGM->height()), |
| 46 | fColorType, kPremul_SkAlphaType); |
| 47 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(gr, info, fSampleCount)); |
| 48 | SkCanvas* canvas = surface->getCanvas(); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 49 | |
| commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 50 | canvas->concat(fGM->getInitialTransform()); |
| 51 | fGM->draw(canvas); |
| 52 | canvas->flush(); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 53 | |
| 54 | SkBitmap bitmap; |
| commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 55 | bitmap.setConfig(info); |
| 56 | canvas->readPixels(&bitmap, 0, 0); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 57 | |
| commit-bot@chromium.org | a34b1f8 | 2013-10-24 17:44:43 +0000 | [diff] [blame] | 58 | #if GR_CACHE_STATS |
| 59 | gr->printCacheStats(); |
| 60 | #endif |
| 61 | |
| commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 62 | this->spawnChild(SkNEW_ARGS(ExpectationsTask, (*this, fExpectations, bitmap))); |
| mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 63 | this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap))); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | bool GpuTask::shouldSkip() const { |
| commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 67 | return SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | } // namespace DM |