commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 1 | #include "DMGpuGMTask.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 2 | #include "DMUtil.h" |
mtklein@google.com | a7a9f37 | 2013-10-18 20:52:44 +0000 | [diff] [blame] | 3 | #include "DMWriteTask.h" |
bsalomon | 06cddec | 2014-10-24 10:40:50 -0700 | [diff] [blame^] | 4 | #include "SkCommonFlags.h" |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 5 | #include "SkSurface.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 6 | #include "SkTLS.h" |
| 7 | |
| 8 | namespace DM { |
| 9 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 10 | GpuGMTask::GpuGMTask(const char* config, |
| 11 | Reporter* reporter, |
| 12 | TaskRunner* taskRunner, |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 13 | skiagm::GMRegistry::Factory gmFactory, |
| 14 | GrContextFactory::GLContextType contextType, |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 15 | GrGLStandard gpuAPI, |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 16 | int sampleCount) |
| 17 | : GpuTask(reporter, taskRunner) |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 18 | , fGM(gmFactory(NULL)) |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 19 | , fName(UnderJoin(fGM->getName(), config)) |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 20 | , fContextType(contextType) |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 21 | , fGpuAPI(gpuAPI) |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 22 | , fSampleCount(sampleCount) |
| 23 | {} |
| 24 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 25 | void GpuGMTask::draw(GrContextFactory* grFactory) { |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 26 | SkImageInfo info = SkImageInfo::Make(SkScalarCeilToInt(fGM->width()), |
| 27 | SkScalarCeilToInt(fGM->height()), |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 28 | kN32_SkColorType, |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 29 | kPremul_SkAlphaType); |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 30 | SkAutoTUnref<SkSurface> surface(NewGpuSurface(grFactory, fContextType, fGpuAPI, info, |
| 31 | fSampleCount)); |
| 32 | if (!surface) { |
| 33 | this->fail("Could not create context for the config and the api."); |
| 34 | return; |
| 35 | } |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 36 | SkCanvas* canvas = surface->getCanvas(); |
mtklein | 0b36e6b | 2014-09-11 12:30:12 -0700 | [diff] [blame] | 37 | CanvasPreflight(canvas); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 38 | |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 39 | canvas->concat(fGM->getInitialTransform()); |
| 40 | fGM->draw(canvas); |
| 41 | canvas->flush(); |
bsalomon | 06cddec | 2014-10-24 10:40:50 -0700 | [diff] [blame^] | 42 | #if GR_CACHE_STATS && SK_SUPPORT_GPU |
| 43 | if (FLAGS_veryVerbose) { |
| 44 | grFactory->get(fContextType)->printCacheStats(); |
| 45 | } |
| 46 | #endif |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 47 | |
| 48 | SkBitmap bitmap; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 49 | bitmap.setInfo(info); |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 50 | canvas->readPixels(&bitmap, 0, 0); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 51 | |
mtklein | ea65bfa | 2014-09-09 07:59:46 -0700 | [diff] [blame] | 52 | this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "GM", bitmap))); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 53 | } |
| 54 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 55 | bool GpuGMTask::shouldSkip() const { |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 56 | return kGPUDisabled || SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | } // namespace DM |