OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CC_RASTER_TILE_TASK_RUNNER_H_ | |
6 #define CC_RASTER_TILE_TASK_RUNNER_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <vector> | |
11 | |
12 #include "base/callback.h" | |
13 #include "cc/raster/raster_buffer.h" | |
14 #include "cc/raster/task.h" | |
15 #include "cc/resources/resource_format.h" | |
16 | |
17 namespace cc { | |
18 | |
19 class CC_EXPORT TileTask : public Task { | |
20 public: | |
21 typedef std::vector<scoped_refptr<TileTask>> Vector; | |
22 | |
23 const TileTask::Vector& dependencies() const { return dependencies_; } | |
24 | |
25 // Indicates whether this TileTask can be run at the same time as other tasks | |
26 // in the task graph. If false, this task will be scheduled with | |
27 // TASK_CATEGORY_NONCONCURRENT_FOREGROUND. The base implementation always | |
28 // returns true. | |
29 bool SupportsConcurrentExecution() const { | |
30 return supports_concurrent_execution_; | |
31 } | |
32 | |
33 virtual void ScheduleOnOriginThread(RasterBufferProvider* provider) = 0; | |
34 virtual void CompleteOnOriginThread(RasterBufferProvider* provider) = 0; | |
35 | |
36 void WillSchedule(); | |
37 void DidSchedule(); | |
38 bool HasBeenScheduled() const; | |
39 | |
40 void WillComplete(); | |
41 void DidComplete(); | |
42 bool HasCompleted() const; | |
43 | |
44 protected: | |
45 explicit TileTask(bool supports_concurrent_execution); | |
46 TileTask(bool supports_concurrent_execution, TileTask::Vector* dependencies); | |
47 ~TileTask() override; | |
48 | |
49 const bool supports_concurrent_execution_; | |
50 TileTask::Vector dependencies_; | |
51 bool did_schedule_; | |
52 bool did_complete_; | |
53 }; | |
54 | |
55 // This interface can be used to schedule and run tile tasks. | |
56 // The client can call CheckForCompletedTasks() at any time to dispatch | |
57 // pending completion callbacks for all tasks that have finished running. | |
58 class CC_EXPORT TileTaskRunner { | |
59 public: | |
60 // Tells the worker pool to shutdown after canceling all previously scheduled | |
61 // tasks. Reply callbacks are still guaranteed to run when | |
62 // CheckForCompletedTasks() is called. | |
63 virtual void Shutdown() = 0; | |
64 | |
65 // Schedule running of tile tasks in |graph| and all dependencies. | |
66 // Previously scheduled tasks that are not in |graph| will be canceled unless | |
67 // already running. Once scheduled, reply callbacks are guaranteed to run for | |
68 // all tasks even if they later get canceled by another call to | |
69 // ScheduleTasks(). | |
70 virtual void ScheduleTasks(TaskGraph* graph) = 0; | |
71 | |
72 // Check for completed tasks and dispatch reply callbacks. | |
73 virtual void CheckForCompletedTasks() = 0; | |
74 | |
75 // Returns the format to use for the tiles. | |
76 virtual ResourceFormat GetResourceFormat(bool must_support_alpha) const = 0; | |
77 | |
78 // Determine if the resource requires swizzling. | |
79 virtual bool GetResourceRequiresSwizzle(bool must_support_alpha) const = 0; | |
80 | |
81 // Downcasting routine for RasterBufferProvider interface. | |
82 virtual RasterBufferProvider* AsRasterBufferProvider() = 0; | |
83 | |
84 protected: | |
85 // Check if resource format matches output format. | |
86 static bool ResourceFormatRequiresSwizzle(ResourceFormat format); | |
87 | |
88 virtual ~TileTaskRunner() {} | |
89 }; | |
90 | |
91 } // namespace cc | |
92 | |
93 #endif // CC_RASTER_TILE_TASK_RUNNER_H_ | |
OLD | NEW |