OLD | NEW |
| (Empty) |
1 #ifndef DMTask_DEFINED | |
2 #define DMTask_DEFINED | |
3 | |
4 #include "DMGpuSupport.h" | |
5 #include "DMReporter.h" | |
6 #include "SkRunnable.h" | |
7 #include "SkTaskGroup.h" | |
8 #include "SkTime.h" | |
9 | |
10 // DM will run() these tasks on one of two threadpools. | |
11 // Subclasses can call fail() to mark this task as failed, or make any number of
spawnChild() calls | |
12 // to kick off dependent tasks. | |
13 // | |
14 // Tasks delete themselves when run. | |
15 | |
16 namespace DM { | |
17 | |
18 class TaskRunner; | |
19 | |
20 class CpuTask; | |
21 | |
22 class Task { | |
23 public: | |
24 virtual bool shouldSkip() const = 0; | |
25 virtual SkString name() const = 0; | |
26 | |
27 // Returns the number of parents above this task. | |
28 // Top-level tasks return 0, their children 1, and so on. | |
29 int depth() const { return fDepth; } | |
30 | |
31 protected: | |
32 Task(Reporter* reporter, TaskRunner* taskRunner); | |
33 Task(const Task& parent); | |
34 virtual ~Task(); | |
35 | |
36 void start(); | |
37 void fail(const char* msg = NULL); | |
38 void finish(); | |
39 | |
40 void reallySpawnChild(CpuTask* task); // For now we don't allow GPU child t
asks. | |
41 | |
42 private: | |
43 Reporter* fReporter; // Unowned. | |
44 TaskRunner* fTaskRunner; // Unowned. | |
45 int fDepth; | |
46 SkMSec fStart; | |
47 }; | |
48 | |
49 class CpuTask : public Task, public SkRunnable { | |
50 public: | |
51 CpuTask(Reporter* reporter, TaskRunner* taskRunner); | |
52 CpuTask(const Task& parent); | |
53 virtual ~CpuTask() {} | |
54 | |
55 void run() SK_OVERRIDE; | |
56 virtual void draw() = 0; | |
57 | |
58 void spawnChild(CpuTask* task); | |
59 }; | |
60 | |
61 class GpuTask : public Task { | |
62 public: | |
63 GpuTask(Reporter* reporter, TaskRunner* taskRunner); | |
64 virtual ~GpuTask() {} | |
65 | |
66 void run(GrContextFactory*); | |
67 virtual void draw(GrContextFactory*) = 0; | |
68 | |
69 void spawnChild(CpuTask* task); | |
70 }; | |
71 | |
72 } // namespace DM | |
73 | |
74 #endif // DMTask_DEFINED | |
OLD | NEW |