blob: c285d88fd708d5f9cb1a916dded79f66cc648f99 [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#include "DMGpuTask.h"
2
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.org38aeb0f2014-02-26 23:01:57 +000012GpuTask::GpuTask(const char* config,
mtklein@google.comd36522d2013-10-16 13:02:15 +000013 Reporter* reporter,
14 TaskRunner* taskRunner,
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000015 const Expectations& expectations,
mtklein@google.comd36522d2013-10-16 13:02:15 +000016 skiagm::GMRegistry::Factory gmFactory,
mtklein@google.comd36522d2013-10-16 13:02:15 +000017 GrContextFactory::GLContextType contextType,
18 int sampleCount)
19 : Task(reporter, taskRunner)
20 , 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
mtklein@google.comd36522d2013-10-16 13:02:15 +000027void GpuTask::draw() {
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(
33 this->getGrContextFactory()->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
52bool GpuTask::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