blob: 4c44fae970315a3ce71744660c44a0706a671f66 [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
commit-bot@chromium.org99589af2013-12-10 14:53:16 +00003#include "DMExpectationsTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00004#include "DMUtil.h"
mtklein@google.coma7a9f372013-10-18 20:52:44 +00005#include "DMWriteTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00006#include "SkCommandLineFlags.h"
commit-bot@chromium.org15a14052014-02-16 00:59:25 +00007#include "SkSurface.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00008#include "SkTLS.h"
9
10namespace DM {
11
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000012GpuGMTask::GpuGMTask(const char* config,
13 Reporter* reporter,
14 TaskRunner* taskRunner,
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000015 skiagm::GMRegistry::Factory gmFactory,
mtkleine4d3e602014-06-06 09:28:43 -070016 const Expectations& expectations,
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000017 GrContextFactory::GLContextType contextType,
kkinnunen80549fc2014-06-30 06:36:31 -070018 GrGLStandard gpuAPI,
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000019 int sampleCount)
20 : GpuTask(reporter, taskRunner)
mtklein@google.comd36522d2013-10-16 13:02:15 +000021 , fGM(gmFactory(NULL))
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000022 , fName(UnderJoin(fGM->getName(), config))
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000023 , fExpectations(expectations)
mtklein@google.comd36522d2013-10-16 13:02:15 +000024 , fContextType(contextType)
kkinnunen80549fc2014-06-30 06:36:31 -070025 , fGpuAPI(gpuAPI)
mtklein@google.comd36522d2013-10-16 13:02:15 +000026 , fSampleCount(sampleCount)
27 {}
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,
35 fSampleCount));
36 if (!surface) {
37 this->fail("Could not create context for the config and the api.");
38 return;
39 }
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000040 SkCanvas* canvas = surface->getCanvas();
mtklein@google.comd36522d2013-10-16 13:02:15 +000041
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000042 canvas->concat(fGM->getInitialTransform());
43 fGM->draw(canvas);
44 canvas->flush();
mtklein@google.comd36522d2013-10-16 13:02:15 +000045
46 SkBitmap bitmap;
commit-bot@chromium.orga3264e52014-05-30 13:26:10 +000047 bitmap.setInfo(info);
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000048 canvas->readPixels(&bitmap, 0, 0);
mtklein@google.comd36522d2013-10-16 13:02:15 +000049
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000050 this->spawnChild(SkNEW_ARGS(ExpectationsTask, (*this, fExpectations, bitmap)));
mtklein@google.coma7a9f372013-10-18 20:52:44 +000051 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
mtklein@google.comd36522d2013-10-16 13:02:15 +000052}
53
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000054bool GpuGMTask::shouldSkip() const {
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000055 return kGPUDisabled || SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag);
mtklein@google.comd36522d2013-10-16 13:02:15 +000056}
57
58} // namespace DM