blob: fb170a26b9796ac2404e7d7a8a9d1d2a0fdc1aae [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,
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000016 int sampleCount)
17 : GpuTask(reporter, taskRunner)
mtklein@google.comd36522d2013-10-16 13:02:15 +000018 , fGM(gmFactory(NULL))
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000019 , fName(UnderJoin(fGM->getName(), config))
mtklein@google.comd36522d2013-10-16 13:02:15 +000020 , fContextType(contextType)
kkinnunen80549fc2014-06-30 06:36:31 -070021 , fGpuAPI(gpuAPI)
mtklein@google.comd36522d2013-10-16 13:02:15 +000022 , fSampleCount(sampleCount)
23 {}
24
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000025void GpuGMTask::draw(GrContextFactory* grFactory) {
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000026 SkImageInfo info = SkImageInfo::Make(SkScalarCeilToInt(fGM->width()),
27 SkScalarCeilToInt(fGM->height()),
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +000028 kN32_SkColorType,
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000029 kPremul_SkAlphaType);
kkinnunen80549fc2014-06-30 06:36:31 -070030 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.org15a14052014-02-16 00:59:25 +000036 SkCanvas* canvas = surface->getCanvas();
mtklein0b36e6b2014-09-11 12:30:12 -070037 CanvasPreflight(canvas);
mtklein@google.comd36522d2013-10-16 13:02:15 +000038
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000039 canvas->concat(fGM->getInitialTransform());
40 fGM->draw(canvas);
41 canvas->flush();
bsalomon06cddec2014-10-24 10:40:50 -070042#if GR_CACHE_STATS && SK_SUPPORT_GPU
43 if (FLAGS_veryVerbose) {
44 grFactory->get(fContextType)->printCacheStats();
45 }
46#endif
mtklein@google.comd36522d2013-10-16 13:02:15 +000047
48 SkBitmap bitmap;
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +000049 bitmap.setInfo(info);
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000050 canvas->readPixels(&bitmap, 0, 0);
mtklein@google.comd36522d2013-10-16 13:02:15 +000051
mtkleinea65bfa2014-09-09 07:59:46 -070052 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, "GM", bitmap)));
mtklein@google.comd36522d2013-10-16 13:02:15 +000053}
54
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000055bool GpuGMTask::shouldSkip() const {
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000056 return kGPUDisabled || SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag);
mtklein@google.comd36522d2013-10-16 13:02:15 +000057}
58
59} // namespace DM