blob: cffa2291c53f7a6303e7f282a220e6cc4e3b7f71 [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.org38aeb0f2014-02-26 23:01:57 +000030 kPMColor_SkColorType,
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000031 kPremul_SkAlphaType);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000032 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000033 grFactory->get(fContextType), info, fSampleCount));
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000034 SkCanvas* canvas = surface->getCanvas();
mtklein@google.comd36522d2013-10-16 13:02:15 +000035
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000036 canvas->concat(fGM->getInitialTransform());
37 fGM->draw(canvas);
38 canvas->flush();
mtklein@google.comd36522d2013-10-16 13:02:15 +000039
40 SkBitmap bitmap;
commit-bot@chromium.org15a14052014-02-16 00:59:25 +000041 bitmap.setConfig(info);
42 canvas->readPixels(&bitmap, 0, 0);
mtklein@google.comd36522d2013-10-16 13:02:15 +000043
commit-bot@chromium.orga34b1f82013-10-24 17:44:43 +000044#if GR_CACHE_STATS
45 gr->printCacheStats();
46#endif
47
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000048 this->spawnChild(SkNEW_ARGS(ExpectationsTask, (*this, fExpectations, bitmap)));
mtklein@google.coma7a9f372013-10-18 20:52:44 +000049 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
mtklein@google.comd36522d2013-10-16 13:02:15 +000050}
51
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000052bool GpuGMTask::shouldSkip() const {
commit-bot@chromium.org846872f2013-10-16 18:21:03 +000053 return SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag);
mtklein@google.comd36522d2013-10-16 13:02:15 +000054}
55
56} // namespace DM