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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_RESOURCES_RASTER_WORKER_POOL_H_ 5 #ifndef CC_RESOURCES_RASTER_WORKER_POOL_H_
6 #define CC_RESOURCES_RASTER_WORKER_POOL_H_ 6 #define CC_RESOURCES_RASTER_WORKER_POOL_H_
7 7
8 #include <string> 8 #include <deque>
9 9
10 #include "cc/base/worker_pool.h" 10 #include "cc/base/worker_pool.h"
11 11
12 namespace cc { 12 namespace cc {
13 class PicturePileImpl; 13 class PicturePileImpl;
14 14
15 namespace internal {
16
17 class RasterWorkerPoolTask : public WorkerPoolTask {
18 public:
19 typedef base::Callback<void(bool)> Reply;
20
21 // Overridden from internal::WorkerPoolTask:
22 virtual void DispatchCompletionCallback() OVERRIDE;
23
24 void DidSchedule();
25
26 protected:
27 explicit RasterWorkerPoolTask(const Reply& reply);
28 virtual ~RasterWorkerPoolTask();
29
30 void WillRun();
31 void DidRun();
32
33 const Reply reply_;
34 bool did_schedule_;
35 bool did_run_;
36 bool did_complete_;
37 };
38
39 } // namespace internal
40
15 // A worker thread pool that runs raster tasks. 41 // A worker thread pool that runs raster tasks.
16 class RasterWorkerPool : public WorkerPool { 42 class RasterWorkerPool : public WorkerPool {
17 public: 43 public:
18 typedef base::Callback<void(PicturePileImpl* picture_pile)> RasterCallback; 44 class Task {
45 public:
46 typedef base::Callback<void(bool)> Reply;
47
48 class Queue {
49 public:
50 Queue();
51 ~Queue();
52
53 void Append(const Task& task);
54
55 unsigned size() const { return tasks_.size(); }
56
57 private:
58 friend class RasterWorkerPool;
59
60 typedef std::deque<scoped_refptr<internal::RasterWorkerPoolTask> > Deque;
61 Deque tasks_;
62 };
63
64 Task();
65 Task(const base::Closure& callback, const Reply& reply);
66 ~Task();
67
68 // Returns true if Task is null (doesn't refer to anything).
69 bool is_null() const { return !internal_; }
70
71 // Returns the Task into an uninitialized state.
72 void Reset();
73
74 protected:
75 explicit Task(scoped_refptr<internal::RasterWorkerPoolTask> internal);
76
77 scoped_refptr<internal::RasterWorkerPoolTask> internal_;
78 };
79
80 class PictureTask : public Task {
81 public:
82 typedef base::Callback<void(PicturePileImpl*)> Callback;
83
84 PictureTask(PicturePileImpl* picture_pile,
85 const Callback& callback,
86 const Reply& reply);
87 };
19 88
20 virtual ~RasterWorkerPool(); 89 virtual ~RasterWorkerPool();
21 90
22 static scoped_ptr<RasterWorkerPool> Create( 91 static scoped_ptr<RasterWorkerPool> Create(
23 WorkerPoolClient* client, size_t num_threads) { 92 WorkerPoolClient* client, size_t num_threads) {
24 return make_scoped_ptr(new RasterWorkerPool(client, num_threads)); 93 return make_scoped_ptr(new RasterWorkerPool(client, num_threads));
25 } 94 }
26 95
27 void PostRasterTaskAndReply(PicturePileImpl* picture_pile, 96 // Schedule running of tasks in |queue|. All tasks previously scheduled
28 const RasterCallback& task, 97 // but not present in |queue| will be canceled. Once scheduled,
29 const base::Closure& reply); 98 // reply callbacks are guaranteed to run for all tasks even if they
99 // later get canceled by another call to ScheduleTasks(). This consumed
100 // all tasks and queue will be empty when function returns.
101 void ScheduleTasks(Task::Queue* queue);
30 102
31 private: 103 private:
32 RasterWorkerPool(WorkerPoolClient* client, size_t num_threads); 104 RasterWorkerPool(WorkerPoolClient* client, size_t num_threads);
33 105
34 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPool); 106 DISALLOW_COPY_AND_ASSIGN(RasterWorkerPool);
35 }; 107 };
36 108
37 } // namespace cc 109 } // namespace cc
38 110
39 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_ 111 #endif // CC_RESOURCES_RASTER_WORKER_POOL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698