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

Unified Diff: cc/resources/raster_worker_pool.h

Issue 14689004: Re-land: cc: Cancel and re-prioritize worker pool tasks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: move alignment check to RP Created 7 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: cc/resources/raster_worker_pool.h
diff --git a/cc/resources/raster_worker_pool.h b/cc/resources/raster_worker_pool.h
index 8d3691d8ef534b49453907fdbd4623c691c60e82..bc156a08c4227996fb7cd8eb499e3a307b7577bc 100644
--- a/cc/resources/raster_worker_pool.h
+++ b/cc/resources/raster_worker_pool.h
@@ -5,17 +5,86 @@
#ifndef CC_RESOURCES_RASTER_WORKER_POOL_H_
#define CC_RESOURCES_RASTER_WORKER_POOL_H_
-#include <string>
+#include <deque>
#include "cc/base/worker_pool.h"
namespace cc {
class PicturePileImpl;
+namespace internal {
+
+class RasterWorkerPoolTask : public WorkerPoolTask {
+ public:
+ typedef base::Callback<void(bool)> Reply;
+
+ // Overridden from internal::WorkerPoolTask:
+ virtual void DispatchCompletionCallback() OVERRIDE;
+
+ void DidSchedule();
+
+ protected:
+ explicit RasterWorkerPoolTask(const Reply& reply);
+ virtual ~RasterWorkerPoolTask();
+
+ void WillRun();
+ void DidRun();
+
+ const Reply reply_;
+ bool did_schedule_;
+ bool did_run_;
+ bool did_complete_;
+};
+
+} // namespace internal
+
// A worker thread pool that runs raster tasks.
class RasterWorkerPool : public WorkerPool {
public:
- typedef base::Callback<void(PicturePileImpl* picture_pile)> RasterCallback;
+ class Task {
+ public:
+ typedef base::Callback<void(bool)> Reply;
+
+ class Queue {
+ public:
+ Queue();
+ ~Queue();
+
+ void Append(const Task& task);
+
+ unsigned size() const { return tasks_.size(); }
+
+ private:
+ friend class RasterWorkerPool;
+
+ typedef std::deque<scoped_refptr<internal::RasterWorkerPoolTask> > Deque;
+ Deque tasks_;
+ };
+
+ Task();
+ Task(const base::Closure& callback, const Reply& reply);
+ ~Task();
+
+ // Returns true if Task is null (doesn't refer to anything).
+ bool is_null() const { return !internal_; }
+
+ // Returns the Task into an uninitialized state.
+ void Reset();
+
+ protected:
+ explicit Task(scoped_refptr<internal::RasterWorkerPoolTask> internal);
+
+ scoped_refptr<internal::RasterWorkerPoolTask> internal_;
+ };
+
+ class PictureTask : public Task {
+ public:
+ typedef base::Callback<void(PicturePileImpl*)> Callback;
+
+ PictureTask(PicturePileImpl* picture_pile,
+ const Callback& callback,
+ const Reply& reply);
+ };
virtual ~RasterWorkerPool();
@@ -24,9 +93,12 @@ class RasterWorkerPool : public WorkerPool {
return make_scoped_ptr(new RasterWorkerPool(client, num_threads));
}
- void PostRasterTaskAndReply(PicturePileImpl* picture_pile,
- const RasterCallback& task,
- const base::Closure& reply);
+ // Schedule running of tasks in |queue|. All tasks previously scheduled
+ // but not present in |queue| will be canceled. Once scheduled,
+ // reply callbacks are guaranteed to run for all tasks even if they
+ // later get canceled by another call to ScheduleTasks(). This consumed
+ // all tasks and queue will be empty when function returns.
+ void ScheduleTasks(Task::Queue* queue);
private:
RasterWorkerPool(WorkerPoolClient* client, size_t num_threads);

Powered by Google App Engine
This is Rietveld 408576698