blob: c72f6756609864a6649f2f4474fde72c02d57af1 [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,
15 const Expectations& expectations,
16 skiagm::GMRegistry::Factory gmFactory,
17 GrContextFactory::GLContextType contextType,
18 int sampleCount)
19 : GpuTask(reporter, taskRunner)
mtklein@google.comd36522d2013-10-16 13:02:15 +000020 , fGM(gmFactory(NULL))
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000021 , fName(UnderJoin(fGM->getName(), config))
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000022 , fExpectations(expectations)
mtklein@google.comd36522d2013-10-16 13:02:15 +000023 , fContextType(contextType)
24 , fSampleCount(sampleCount)
25 {}
26
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000027void GpuGMTask::draw(GrContextFactory* grFactory) {
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000028 SkImageInfo info = SkImageInfo::Make(SkScalarCeilToInt(fGM->width()),
29 SkScalarCeilToInt(fGM->height()),
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +000030 kN32_SkColorType,
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000031 kPremul_SkAlphaType);
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000032 SkAutoTUnref<SkSurface> surface(NewGpuSurface(grFactory, fContextType, info, fSampleCount));
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000033 SkCanvas* canvas = surface->getCanvas();
mtklein@google.comd36522d2013-10-16 13:02:15 +000034
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000035 canvas->concat(fGM->getInitialTransform());
36 fGM->draw(canvas);
37 canvas->flush();
mtklein@google.comd36522d2013-10-16 13:02:15 +000038
39 SkBitmap bitmap;
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000040 bitmap.setConfig(info);
41 canvas->readPixels(&bitmap, 0, 0);
mtklein@google.comd36522d2013-10-16 13:02:15 +000042
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000043 this->spawnChild(SkNEW_ARGS(ExpectationsTask, (*this, fExpectations, bitmap)));
mtklein@google.coma7a9f372013-10-18 20:52:44 +000044 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
mtklein@google.comd36522d2013-10-16 13:02:15 +000045}
46
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000047bool GpuGMTask::shouldSkip() const {
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000048 return kGPUDisabled || SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag);
mtklein@google.comd36522d2013-10-16 13:02:15 +000049}
50
51} // namespace DM