blob: 2aceb02b8ae01980f862b859acbfa525017a36fb [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#include "DMGpuTask.h"
2
3#include "DMComparisonTask.h"
4#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"
7#include "SkGpuDevice.h"
8#include "SkTLS.h"
9
10namespace DM {
11
12GpuTask::GpuTask(const char* name,
13 Reporter* reporter,
14 TaskRunner* taskRunner,
15 const skiagm::ExpectationsSource& expectations,
16 skiagm::GMRegistry::Factory gmFactory,
17 SkBitmap::Config config,
18 GrContextFactory::GLContextType contextType,
19 int sampleCount)
20 : Task(reporter, taskRunner)
21 , fGM(gmFactory(NULL))
commit-bot@chromium.org192cbf62013-10-21 18:40:25 +000022 , fName(UnderJoin(fGM->shortName(), name))
23 , fExpectations(expectations.get(Png(fName).c_str()))
mtklein@google.comd36522d2013-10-16 13:02:15 +000024 , fConfig(config)
25 , fContextType(contextType)
26 , fSampleCount(sampleCount)
27 {}
28
29static void* new_gr_context_factory() {
30 return SkNEW(GrContextFactory);
31}
32
33static void delete_gr_context_factory(void* factory) {
commit-bot@chromium.org846872f2013-10-16 18:21:03 +000034 SkDELETE((GrContextFactory*) factory);
mtklein@google.comd36522d2013-10-16 13:02:15 +000035}
36
37static GrContextFactory* get_gr_factory() {
38 return reinterpret_cast<GrContextFactory*>(SkTLS::Get(&new_gr_context_factory,
39 &delete_gr_context_factory));
40}
41
42void GpuTask::draw() {
43 GrContext* gr = get_gr_factory()->get(fContextType); // Will be owned by device.
commit-bot@chromium.org846872f2013-10-16 18:21:03 +000044 SkGpuDevice device(gr,
45 fConfig,
46 SkScalarCeilToInt(fGM->width()),
47 SkScalarCeilToInt(fGM->height()),
48 fSampleCount);
mtklein@google.comd36522d2013-10-16 13:02:15 +000049 SkCanvas canvas(&device);
50
51 canvas.concat(fGM->getInitialTransform());
52 fGM->draw(&canvas);
53 canvas.flush();
54
55 SkBitmap bitmap;
commit-bot@chromium.org846872f2013-10-16 18:21:03 +000056 bitmap.setConfig(fConfig, SkScalarCeilToInt(fGM->width()), SkScalarCeilToInt(fGM->height()));
mtklein@google.comd36522d2013-10-16 13:02:15 +000057 canvas.readPixels(&bitmap, 0, 0);
58
59 // We offload checksum comparison to the main CPU threadpool.
60 // This cuts run time by about 30%.
61 this->spawnChild(SkNEW_ARGS(ComparisonTask, (*this, fExpectations, bitmap)));
mtklein@google.coma7a9f372013-10-18 20:52:44 +000062 this->spawnChild(SkNEW_ARGS(WriteTask, (*this, bitmap)));
mtklein@google.comd36522d2013-10-16 13:02:15 +000063}
64
65bool GpuTask::shouldSkip() const {
commit-bot@chromium.org846872f2013-10-16 18:21:03 +000066 return SkToBool(fGM->getFlags() & skiagm::GM::kSkipGPU_Flag);
mtklein@google.comd36522d2013-10-16 13:02:15 +000067}
68
69} // namespace DM