blob: e8598df85e00ee6001b3f2571f356a4ae91d7daa [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001#ifndef DMTask_DEFINED
2#define DMTask_DEFINED
3
4#include "DMReporter.h"
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00005#include "GrContextFactory.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00006#include "SkRunnable.h"
7#include "SkThreadPool.h"
8
9// DM will run() these tasks on one of two threadpools, depending on the result
10// of usesGpu(). The subclasses can call fail() to mark this task as failed,
11// or make any number of spawnChild() calls to kick off dependent tasks.
12//
13// Task deletes itself when run.
14
15namespace DM {
16
17class TaskRunner;
18
19class Task : public SkRunnable {
20public:
21 Task(Reporter* reporter, TaskRunner* taskRunner);
rmistry@google.comd6bab022013-12-02 13:50:38 +000022 Task(const Task& parent);
mtklein@google.comd36522d2013-10-16 13:02:15 +000023 virtual ~Task();
24
scroggo@google.com1ecd9cf2013-11-20 16:44:59 +000025 void run() SK_OVERRIDE;
mtklein@google.comd36522d2013-10-16 13:02:15 +000026
27 virtual void draw() = 0;
28 virtual bool usesGpu() const = 0;
29 virtual bool shouldSkip() const = 0;
30 virtual SkString name() const = 0;
31
rmistry@google.comd6bab022013-12-02 13:50:38 +000032 // Returns the number of parents above this task.
33 // Top-level tasks return 0, their children 1, and so on.
34 int depth() const { return fDepth; }
35
mtklein@google.comd36522d2013-10-16 13:02:15 +000036protected:
37 void spawnChild(Task* task);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000038 void fail(const char* msg = NULL);
mtklein@google.comd36522d2013-10-16 13:02:15 +000039
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000040 // This can only be safely called from a GPU task's draw() method.
41 GrContextFactory* getGrContextFactory() const;
42
mtklein@google.comd36522d2013-10-16 13:02:15 +000043private:
44 // Both unowned.
45 Reporter* fReporter;
46 TaskRunner* fTaskRunner;
rmistry@google.comd6bab022013-12-02 13:50:38 +000047 int fDepth;
scroggo@google.com1ecd9cf2013-11-20 16:44:59 +000048
49 typedef SkRunnable INHERITED;
mtklein@google.comd36522d2013-10-16 13:02:15 +000050};
51
52} // namespace DM
53
54#endif // DMTask_DEFINED