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, |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 16 | int sampleCount, |
| 17 | bool useDFText) |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 18 | : GpuTask(reporter, taskRunner) |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 19 | , fGM(gmFactory(NULL)) |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 20 | , fName(UnderJoin(fGM->getName(), config)) |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 21 | , fContextType(contextType) |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 22 | , fGpuAPI(gpuAPI) |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 23 | , fSampleCount(sampleCount) |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 24 | , fUseDFText(useDFText) |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 25 | {} |
| 26 | |
mtklein | 2ecf86e | 2014-11-06 08:06:39 -0800 | [diff] [blame] | 27 | static bool gAlreadyWarned[GrContextFactory::kGLContextTypeCnt][kGrGLStandardCnt]; |
| 28 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 29 | void GpuGMTask::draw(GrContextFactory* grFactory) { |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 30 | SkImageInfo info = SkImageInfo::Make(SkScalarCeilToInt(fGM->width()), |
| 31 | SkScalarCeilToInt(fGM->height()), |
commit-bot@chromium.org | 28fcae2 | 2014-04-11 17:15:40 +0000 | [diff] [blame] | 32 | kN32_SkColorType, |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 33 | kPremul_SkAlphaType); |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 34 | SkAutoTUnref<SkSurface> surface(NewGpuSurface(grFactory, fContextType, fGpuAPI, info, |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 35 | fSampleCount, fUseDFText)); |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 36 | if (!surface) { |
mtklein | 2ecf86e | 2014-11-06 08:06:39 -0800 | [diff] [blame] | 37 | if (!gAlreadyWarned[fContextType][fGpuAPI]) { |
| 38 | SkDebugf("FYI: couldn't create GPU context, type %d API %d. Will skip.\n", |
| 39 | fContextType, fGpuAPI); |
| 40 | gAlreadyWarned[fContextType][fGpuAPI] = true; |
| 41 | } |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 42 | return; |
| 43 | } |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 44 | SkCanvas* canvas = surface->getCanvas(); |
mtklein | 0b36e6b | 2014-09-11 12:30:12 -0700 | [diff] [blame] | 45 | CanvasPreflight(canvas); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 46 | |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 47 | canvas->concat(fGM->getInitialTransform()); |
| 48 | fGM->draw(canvas); |
| 49 | canvas->flush(); |
bsalomon | 06cddec | 2014-10-24 10:40:50 -0700 | [diff] [blame] | 50 | #if GR_CACHE_STATS && SK_SUPPORT_GPU |
| 51 | if (FLAGS_veryVerbose) { |
| 52 | grFactory->get(fContextType)->printCacheStats(); |
| 53 | } |
| 54 | #endif |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 55 | |
| 56 | SkBitmap bitmap; |
commit-bot@chromium.org | a3264e5 | 2014-05-30 13:26:10 +0000 | [diff] [blame] | 57 | bitmap.setInfo(info); |
commit-bot@chromium.org | 15a1405 | 2014-02-16 00:59:25 +0000 | [diff] [blame] | 58 | canvas->readPixels(&bitmap, 0, 0); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 59 | |
mtklein | ea65bfa | 2014-09-09 07:59:46 -0700 | [diff] [blame] | 60 | this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "GM", bitmap))); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 61 | } |
| 62 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 63 | bool GpuGMTask::shouldSkip() const { |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 64 | return kGPUDisabled || 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 |