blob: 9347ebdfe95017a002ab6297b66253769d7f2bc5 [file] [log] [blame]
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +00001#include "DMGpuGMTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00002#include "DMUtil.h"
mtklein@google.coma7a9f372013-10-18 20:52:44 +00003#include "DMWriteTask.h"
bsalomon06cddec2014-10-24 10:40:50 -07004#include "SkCommonFlags.h"
commit-bot@chromium.org15a14052014-02-16 00:59:25 +00005#include "SkSurface.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00006#include "SkTLS.h"
7
8namespace DM {
9
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000010GpuGMTask::GpuGMTask(const char* config,
11 Reporter* reporter,
12 TaskRunner* taskRunner,
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000013 skiagm::GMRegistry::Factory gmFactory,
14 GrContextFactory::GLContextType contextType,
kkinnunen80549fc2014-06-30 06:36:31 -070015 GrGLStandard gpuAPI,
jvanverth4736e142014-11-07 07:12:46 -080016 int sampleCount,
17 bool useDFText)
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000018 : GpuTask(reporter, taskRunner)
mtklein@google.comd36522d2013-10-16 13:02:15 +000019 , fGM(gmFactory(NULL))
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000020 , fName(UnderJoin(fGM->getName(), config))
mtklein@google.comd36522d2013-10-16 13:02:15 +000021 , fContextType(contextType)
kkinnunen80549fc2014-06-30 06:36:31 -070022 , fGpuAPI(gpuAPI)
mtklein@google.comd36522d2013-10-16 13:02:15 +000023 , fSampleCount(sampleCount)
jvanverth4736e142014-11-07 07:12:46 -080024 , fUseDFText(useDFText)
mtklein@google.comd36522d2013-10-16 13:02:15 +000025 {}
26
mtklein2ecf86e2014-11-06 08:06:39 -080027static bool gAlreadyWarned[GrContextFactory::kGLContextTypeCnt][kGrGLStandardCnt];
28
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000029void GpuGMTask::draw(GrContextFactory* grFactory) {
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000030 SkImageInfo info = SkImageInfo::Make(SkScalarCeilToInt(fGM->width()),
31 SkScalarCeilToInt(fGM->height()),
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +000032 kN32_SkColorType,
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000033 kPremul_SkAlphaType);
kkinnunen80549fc2014-06-30 06:36:31 -070034 SkAutoTUnref<SkSurface> surface(NewGpuSurface(grFactory, fContextType, fGpuAPI, info,
jvanverth4736e142014-11-07 07:12:46 -080035 fSampleCount, fUseDFText));
kkinnunen80549fc2014-06-30 06:36:31 -070036 if (!surface) {
mtklein2ecf86e2014-11-06 08:06:39 -080037 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 }
kkinnunen80549fc2014-06-30 06:36:31 -070042 return;
43 }
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000044 SkCanvas* canvas = surface->getCanvas();
mtklein0b36e6b2014-09-11 12:30:12 -070045 CanvasPreflight(canvas);
mtklein@google.comd36522d2013-10-16 13:02:15 +000046
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000047 canvas->concat(fGM->getInitialTransform());
48 fGM->draw(canvas);
49 canvas->flush();
bsalomon06cddec2014-10-24 10:40:50 -070050#if GR_CACHE_STATS && SK_SUPPORT_GPU
51 if (FLAGS_veryVerbose) {
52 grFactory->get(fContextType)->printCacheStats();
53 }
54#endif
mtklein@google.comd36522d2013-10-16 13:02:15 +000055
56 SkBitmap bitmap;
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +000057 bitmap.setInfo(info);
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000058 canvas->readPixels(&bitmap, 0, 0);
mtklein@google.comd36522d2013-10-16 13:02:15 +000059
mtkleinea65bfa2014-09-09 07:59:46 -070060 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "GM", bitmap)));
mtklein@google.comd36522d2013-10-16 13:02:15 +000061}
62
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000063bool GpuGMTask::shouldSkip() const {
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000064 return kGPUDisabled || SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag);
mtklein@google.comd36522d2013-10-16 13:02:15 +000065}
66
67} // namespace DM