Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: cc/resources/rasterizer.h

Issue 228173002: cc: Separate RasterWorkerPool interface from implementation details. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review feedback Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/resources/raster_worker_pool_unittest.cc ('k') | cc/resources/rasterizer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_RESOURCES_RASTERIZER_H_
6 #define CC_RESOURCES_RASTERIZER_H_
7
8 #include <vector>
9
10 #include "base/callback.h"
11 #include "cc/resources/resource_format.h"
12 #include "cc/resources/task_graph_runner.h"
13
14 class SkCanvas;
15
16 namespace cc {
17 class Resource;
18
19 namespace internal {
20 class RasterTask;
21
22 class CC_EXPORT RasterizerTaskClient {
23 public:
24 virtual SkCanvas* AcquireCanvasForRaster(RasterTask* task) = 0;
25 virtual void ReleaseCanvasForRaster(RasterTask* task) = 0;
26
27 protected:
28 virtual ~RasterizerTaskClient() {}
29 };
30
31 class ImageDecodeTask;
32
33 class CC_EXPORT RasterizerTask : public Task {
34 public:
35 typedef std::vector<scoped_refptr<RasterizerTask> > Vector;
36
37 virtual void ScheduleOnOriginThread(RasterizerTaskClient* client) = 0;
38 virtual void RunOnOriginThread() = 0;
39 virtual void CompleteOnOriginThread(RasterizerTaskClient* client) = 0;
40 virtual void RunReplyOnOriginThread() = 0;
41
42 // Type-checking downcast routines.
43 virtual ImageDecodeTask* AsImageDecodeTask();
44 virtual RasterTask* AsRasterTask();
45
46 void WillSchedule();
47 void DidSchedule();
48 bool HasBeenScheduled() const;
49
50 void WillComplete();
51 void DidComplete();
52 bool HasCompleted() const;
53
54 protected:
55 RasterizerTask();
56 virtual ~RasterizerTask();
57
58 bool did_schedule_;
59 bool did_complete_;
60 };
61
62 class CC_EXPORT ImageDecodeTask : public RasterizerTask {
63 public:
64 typedef std::vector<scoped_refptr<ImageDecodeTask> > Vector;
65
66 // Overridden from RasterizerTask:
67 virtual ImageDecodeTask* AsImageDecodeTask() OVERRIDE;
68
69 protected:
70 ImageDecodeTask();
71 virtual ~ImageDecodeTask();
72 };
73
74 class CC_EXPORT RasterTask : public RasterizerTask {
75 public:
76 typedef std::vector<scoped_refptr<RasterTask> > Vector;
77
78 // Overridden from RasterizerTask:
79 virtual RasterTask* AsRasterTask() OVERRIDE;
80
81 const Resource* resource() const { return resource_; }
82 const ImageDecodeTask::Vector& dependencies() const { return dependencies_; }
83
84 protected:
85 RasterTask(const Resource* resource, ImageDecodeTask::Vector* dependencies);
86 virtual ~RasterTask();
87
88 private:
89 const Resource* resource_;
90 ImageDecodeTask::Vector dependencies_;
91 };
92
93 } // namespace internal
94
95 class CC_EXPORT RasterizerClient {
96 public:
97 virtual bool ShouldForceTasksRequiredForActivationToComplete() const = 0;
98 virtual void DidFinishRunningTasks() = 0;
99 virtual void DidFinishRunningTasksRequiredForActivation() = 0;
100
101 protected:
102 virtual ~RasterizerClient() {}
103 };
104
105 struct CC_EXPORT RasterTaskQueue {
106 struct CC_EXPORT Item {
107 class TaskComparator {
108 public:
109 explicit TaskComparator(const internal::RasterTask* task) : task_(task) {}
110
111 bool operator()(const Item& item) const { return item.task == task_; }
112
113 private:
114 const internal::RasterTask* task_;
115 };
116
117 typedef std::vector<Item> Vector;
118
119 Item(internal::RasterTask* task, bool required_for_activation);
120 ~Item();
121
122 static bool IsRequiredForActivation(const Item& item) {
123 return item.required_for_activation;
124 }
125
126 internal::RasterTask* task;
127 bool required_for_activation;
128 };
129
130 RasterTaskQueue();
131 ~RasterTaskQueue();
132
133 void Swap(RasterTaskQueue* other);
134 void Reset();
135
136 Item::Vector items;
137 size_t required_for_activation_count;
138 };
139
140 // This interface can be used to schedule and run raster tasks. The client will
141 // be notified asynchronously when the set of tasks marked as "required for
142 // activation" have finished running and when all scheduled tasks have finished
143 // running. The client can call CheckForCompletedTasks() at any time to dispatch
144 // pending completion callbacks for all tasks that have finished running.
145 class CC_EXPORT Rasterizer {
146 public:
147 // Set the client instance to be notified when finished running tasks.
148 virtual void SetClient(RasterizerClient* client) = 0;
149
150 // Tells the worker pool to shutdown after canceling all previously scheduled
151 // tasks. Reply callbacks are still guaranteed to run when
152 // CheckForCompletedTasks() is called.
153 virtual void Shutdown() = 0;
154
155 // Schedule running of raster tasks in |queue| and all dependencies.
156 // Previously scheduled tasks that are not in |queue| will be canceled unless
157 // already running. Once scheduled, reply callbacks are guaranteed to run for
158 // all tasks even if they later get canceled by another call to
159 // ScheduleTasks().
160 virtual void ScheduleTasks(RasterTaskQueue* queue) = 0;
161
162 // Check for completed tasks and dispatch reply callbacks.
163 virtual void CheckForCompletedTasks() = 0;
164
165 // Returns the target that needs to be used for raster task resources.
166 virtual unsigned GetResourceTarget() const = 0;
167
168 // Returns the format that needs to be used for raster task resources.
169 virtual ResourceFormat GetResourceFormat() const = 0;
170
171 protected:
172 virtual ~Rasterizer() {}
173 };
174
175 } // namespace cc
176
177 #endif // CC_RESOURCES_RASTERIZER_H_
OLDNEW
« no previous file with comments | « cc/resources/raster_worker_pool_unittest.cc ('k') | cc/resources/rasterizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698