summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authorreveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-05 07:59:40 +0000
committerreveman@chromium.org <reveman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-05 07:59:40 +0000
commit3f3180b50d1174dbf07c77170bfdc1f85a86bdea (patch)
tree67b18b9ef1565fa073494cbdc2f0073109459f46 /cc
parent2a4497da7a17cbabb8e11aa6ad1ceeda4c7e564c (diff)
downloadchromium_src-3f3180b50d1174dbf07c77170bfdc1f85a86bdea.zip
chromium_src-3f3180b50d1174dbf07c77170bfdc1f85a86bdea.tar.gz
chromium_src-3f3180b50d1174dbf07c77170bfdc1f85a86bdea.tar.bz2
cc: Remove idle signal from WorkerPool.
Idle detection is easy to do outside the worker pool now that we have a task graph. This moves idle detection to the RasterWorkerPool class. BUG=246175 TEST=cc_unittest --gtest_filter=BasicRasterWorkerPoolTest.* Review URL: https://chromiumcodereview.appspot.com/15969008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204201 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/base/worker_pool.cc81
-rw-r--r--cc/base/worker_pool.h1
-rw-r--r--cc/resources/image_raster_worker_pool.cc33
-rw-r--r--cc/resources/image_raster_worker_pool.h2
-rw-r--r--cc/resources/pixel_buffer_raster_worker_pool.cc94
-rw-r--r--cc/resources/pixel_buffer_raster_worker_pool.h10
-rw-r--r--cc/resources/raster_worker_pool.cc34
-rw-r--r--cc/resources/raster_worker_pool.h22
8 files changed, 148 insertions, 129 deletions
diff --git a/cc/base/worker_pool.cc b/cc/base/worker_pool.cc
index ab7d869..46eeb31 100644
--- a/cc/base/worker_pool.cc
+++ b/cc/base/worker_pool.cc
@@ -153,18 +153,9 @@ class WorkerPool::Inner : public base::DelegateSimpleThread::Delegate {
// before calling this function. Returns true if idle.
bool CollectCompletedTasksWithLockAcquired(TaskDeque* completed_tasks);
- // Schedule an OnIdleOnOriginThread callback if not already pending.
- // Lock must already be acquired before calling this function.
- void ScheduleOnIdleWithLockAcquired();
- void OnIdleOnOriginThread();
-
// Overridden from base::DelegateSimpleThread:
virtual void Run() OVERRIDE;
- // Pointer to worker pool. Can only be used on origin thread.
- // Not guarded by |lock_|.
- WorkerPool* worker_pool_on_origin_thread_;
-
// This lock protects all members of this class except
// |worker_pool_on_origin_thread_|. Do not read or modify anything
// without holding this lock. Do not block while holding this lock.
@@ -174,15 +165,6 @@ class WorkerPool::Inner : public base::DelegateSimpleThread::Delegate {
// tasks are ready to run or shutdown starts.
base::ConditionVariable has_ready_to_run_tasks_cv_;
- // Target message loop used for posting callbacks.
- scoped_refptr<base::MessageLoopProxy> origin_loop_;
-
- base::WeakPtrFactory<Inner> weak_ptr_factory_;
-
- const base::Closure on_idle_callback_;
- // Set when a OnIdleOnOriginThread() callback is pending.
- bool on_idle_pending_;
-
// Provides each running thread loop with a unique index. First thread
// loop index is 0.
unsigned next_thread_index_;
@@ -216,14 +198,8 @@ class WorkerPool::Inner : public base::DelegateSimpleThread::Delegate {
WorkerPool::Inner::Inner(WorkerPool* worker_pool,
size_t num_threads,
const std::string& thread_name_prefix)
- : worker_pool_on_origin_thread_(worker_pool),
- lock_(),
+ : lock_(),
has_ready_to_run_tasks_cv_(&lock_),
- origin_loop_(base::MessageLoopProxy::current()),
- weak_ptr_factory_(this),
- on_idle_callback_(base::Bind(&WorkerPool::Inner::OnIdleOnOriginThread,
- weak_ptr_factory_.GetWeakPtr())),
- on_idle_pending_(false),
next_thread_index_(0),
shutdown_(false) {
base::AutoLock lock(lock_);
@@ -271,9 +247,6 @@ void WorkerPool::Inner::Shutdown() {
base::ThreadRestrictions::ScopedAllowIO allow_io;
worker->Join();
}
-
- // Cancel any pending OnIdle callback.
- weak_ptr_factory_.InvalidateWeakPtrs();
}
void WorkerPool::Inner::ScheduleTasks(internal::WorkerPoolTask* root) {
@@ -367,34 +340,6 @@ bool WorkerPool::Inner::CollectCompletedTasksWithLockAcquired(
return running_tasks_.empty() && pending_tasks_.empty();
}
-void WorkerPool::Inner::ScheduleOnIdleWithLockAcquired() {
- lock_.AssertAcquired();
-
- if (on_idle_pending_)
- return;
- origin_loop_->PostTask(FROM_HERE, on_idle_callback_);
- on_idle_pending_ = true;
-}
-
-void WorkerPool::Inner::OnIdleOnOriginThread() {
- TaskDeque completed_tasks;
-
- {
- base::AutoLock lock(lock_);
-
- DCHECK(on_idle_pending_);
- on_idle_pending_ = false;
-
- // Early out if no longer idle.
- if (!running_tasks_.empty() || !pending_tasks_.empty())
- return;
-
- CollectCompletedTasksWithLockAcquired(&completed_tasks);
- }
-
- worker_pool_on_origin_thread_->OnIdle(&completed_tasks);
-}
-
void WorkerPool::Inner::Run() {
#if defined(OS_ANDROID)
base::PlatformThread::SetThreadPriority(
@@ -409,15 +354,9 @@ void WorkerPool::Inner::Run() {
while (true) {
if (ready_to_run_tasks_.empty()) {
- if (pending_tasks_.empty()) {
- // Exit when shutdown is set and no more tasks are pending.
- if (shutdown_)
- break;
-
- // Schedule an idle callback if no tasks are running.
- if (running_tasks_.empty())
- ScheduleOnIdleWithLockAcquired();
- }
+ // Exit when shutdown is set and no more tasks are pending.
+ if (shutdown_ && pending_tasks_.empty())
+ break;
// Wait for more tasks.
has_ready_to_run_tasks_cv_.Wait();
@@ -565,18 +504,6 @@ void WorkerPool::Shutdown() {
DispatchCompletionCallbacks(&completed_tasks);
}
-void WorkerPool::OnIdle(TaskDeque* completed_tasks) {
- TRACE_EVENT0("cc", "WorkerPool::OnIdle");
-
- DCHECK(!in_dispatch_completion_callbacks_);
-
- DispatchCompletionCallbacks(completed_tasks);
-
- // Cancel any pending check for completed tasks.
- check_for_completed_tasks_callback_.Cancel();
- check_for_completed_tasks_pending_ = false;
-}
-
void WorkerPool::ScheduleCheckForCompletedTasks() {
if (check_for_completed_tasks_pending_)
return;
diff --git a/cc/base/worker_pool.h b/cc/base/worker_pool.h
index 72a4f7e..758302c 100644
--- a/cc/base/worker_pool.h
+++ b/cc/base/worker_pool.h
@@ -94,7 +94,6 @@ class CC_EXPORT WorkerPool {
typedef std::deque<scoped_refptr<internal::WorkerPoolTask> > TaskDeque;
- void OnIdle(TaskDeque* completed_tasks);
void ScheduleCheckForCompletedTasks();
void DispatchCompletionCallbacks(TaskDeque* completed_tasks);
diff --git a/cc/resources/image_raster_worker_pool.cc b/cc/resources/image_raster_worker_pool.cc
index e846e91..4ce87df 100644
--- a/cc/resources/image_raster_worker_pool.cc
+++ b/cc/resources/image_raster_worker_pool.cc
@@ -71,27 +71,28 @@ ImageRasterWorkerPool::~ImageRasterWorkerPool() {
void ImageRasterWorkerPool::ScheduleTasks(RasterTask::Queue* queue) {
TRACE_EVENT0("cc", "ImageRasterWorkerPool::ScheduleTasks");
- internal::WorkerPoolTask::TaskVector raster_tasks;
+ internal::WorkerPoolTask::TaskVector tasks;
RasterWorkerPool::SetRasterTasks(queue);
- for (RasterTask::Queue::TaskVector::iterator it = raster_tasks_.begin();
- it != raster_tasks_.end(); ++it) {
+ for (RasterTask::Queue::TaskVector::const_iterator it =
+ raster_tasks().begin();
+ it != raster_tasks().end(); ++it) {
internal::RasterWorkerPoolTask* task = *it;
TaskMap::iterator image_it = image_tasks_.find(task);
if (image_it != image_tasks_.end()) {
internal::WorkerPoolTask* image_task = image_it->second;
- raster_tasks.push_back(image_task);
+ tasks.push_back(image_task);
continue;
}
// Acquire image for resource.
- resource_provider_->AcquireImage(task->resource()->id());
+ resource_provider()->AcquireImage(task->resource()->id());
// Map image for raster.
- uint8* buffer = resource_provider_->MapImage(task->resource()->id());
- int stride = resource_provider_->GetImageStride(task->resource()->id());
+ uint8* buffer = resource_provider()->MapImage(task->resource()->id());
+ int stride = resource_provider()->GetImageStride(task->resource()->id());
// TODO(reveman): Avoid having to make a copy of dependencies.
internal::WorkerPoolTask::TaskVector dependencies = task->dependencies();
@@ -106,10 +107,16 @@ void ImageRasterWorkerPool::ScheduleTasks(RasterTask::Queue* queue) {
make_scoped_refptr(task))));
image_tasks_[task] = image_task;
- raster_tasks.push_back(image_task);
+ tasks.push_back(image_task);
}
- ScheduleRasterTasks(&raster_tasks);
+ if (tasks.empty()) {
+ ScheduleRasterTasks(RootTask());
+ return;
+ }
+
+ RootTask root(&tasks);
+ ScheduleRasterTasks(root);
}
void ImageRasterWorkerPool::OnRasterTaskCompleted(
@@ -121,19 +128,19 @@ void ImageRasterWorkerPool::OnRasterTaskCompleted(
DCHECK(image_tasks_.find(task) != image_tasks_.end());
// Balanced with MapImage() call in ScheduleTasks().
- resource_provider_->UnmapImage(task->resource()->id());
+ resource_provider()->UnmapImage(task->resource()->id());
// Bind image to resource.
- resource_provider_->BindImage(task->resource()->id());
+ resource_provider()->BindImage(task->resource()->id());
if (!was_canceled)
task->DidRun();
- DidFinishRasterTask(task);
+ DidCompleteRasterTask(task);
image_tasks_.erase(task);
}
-void ImageRasterWorkerPool::DidFinishRasterTask(
+void ImageRasterWorkerPool::DidCompleteRasterTask(
internal::RasterWorkerPoolTask* task) {
task->DidComplete();
task->DispatchCompletionCallback();
diff --git a/cc/resources/image_raster_worker_pool.h b/cc/resources/image_raster_worker_pool.h
index 353c722..0d4c23b 100644
--- a/cc/resources/image_raster_worker_pool.h
+++ b/cc/resources/image_raster_worker_pool.h
@@ -32,7 +32,7 @@ class CC_EXPORT ImageRasterWorkerPool : public RasterWorkerPool,
void OnRasterTaskCompleted(
scoped_refptr<internal::RasterWorkerPoolTask> task, bool was_canceled);
- void DidFinishRasterTask(internal::RasterWorkerPoolTask* task);
+ void DidCompleteRasterTask(internal::RasterWorkerPoolTask* task);
TaskMap image_tasks_;
diff --git a/cc/resources/pixel_buffer_raster_worker_pool.cc b/cc/resources/pixel_buffer_raster_worker_pool.cc
index 6d47099..c5d0941 100644
--- a/cc/resources/pixel_buffer_raster_worker_pool.cc
+++ b/cc/resources/pixel_buffer_raster_worker_pool.cc
@@ -83,7 +83,9 @@ PixelBufferRasterWorkerPool::PixelBufferRasterWorkerPool(
ResourceProvider* resource_provider,
size_t num_threads) : RasterWorkerPool(resource_provider, num_threads),
bytes_pending_upload_(0),
- has_performed_uploads_since_last_flush_(false) {
+ has_performed_uploads_since_last_flush_(false),
+ weak_ptr_factory_(this),
+ schedule_more_tasks_count_(0) {
// TODO(reveman): Remove WorkerPool client interface.
WorkerPool::SetClient(this);
}
@@ -102,9 +104,11 @@ void PixelBufferRasterWorkerPool::Shutdown() {
DCHECK(!it->second);
// Everything else has been canceled.
- DidFinishRasterTask(task);
+ DidCompleteRasterTask(task);
}
pixel_buffer_tasks_.clear();
+ // Cancel any pending OnRasterFinished callback.
+ weak_ptr_factory_.InvalidateWeakPtrs();
}
void PixelBufferRasterWorkerPool::ScheduleTasks(RasterTask::Queue* queue) {
@@ -114,8 +118,9 @@ void PixelBufferRasterWorkerPool::ScheduleTasks(RasterTask::Queue* queue) {
// Build new pixel buffer task set.
TaskMap new_pixel_buffer_tasks;
- for (RasterTask::Queue::TaskVector::iterator it = raster_tasks_.begin();
- it != raster_tasks_.end(); ++it) {
+ for (RasterTask::Queue::TaskVector::const_iterator it =
+ raster_tasks().begin();
+ it != raster_tasks().end(); ++it) {
internal::RasterWorkerPoolTask* task = *it;
DCHECK(new_pixel_buffer_tasks.find(task) == new_pixel_buffer_tasks.end());
DCHECK(!task->HasCompleted());
@@ -144,7 +149,7 @@ void PixelBufferRasterWorkerPool::ScheduleTasks(RasterTask::Queue* queue) {
}
// Everything else can be canceled.
- DidFinishRasterTask(task);
+ DidCompleteRasterTask(task);
}
pixel_buffer_tasks_.swap(new_pixel_buffer_tasks);
@@ -161,16 +166,16 @@ void PixelBufferRasterWorkerPool::CheckForCompletedTasks() {
internal::RasterWorkerPoolTask* task = tasks_with_pending_upload_.front();
// Uploads complete in the order they are issued.
- if (!resource_provider_->DidSetPixelsComplete(task->resource()->id()))
+ if (!resource_provider()->DidSetPixelsComplete(task->resource()->id()))
break;
// It's now safe to release the pixel buffer and the shared memory.
- resource_provider_->ReleasePixelBuffer(task->resource()->id());
+ resource_provider()->ReleasePixelBuffer(task->resource()->id());
bytes_pending_upload_ -= task->resource()->bytes();
task->DidRun();
- DidFinishRasterTask(task);
+ DidCompleteRasterTask(task);
pixel_buffer_tasks_.erase(task);
tasks_with_pending_upload_.pop_front();
@@ -185,7 +190,7 @@ bool PixelBufferRasterWorkerPool::ForceUploadToComplete(
it != tasks_with_pending_upload_.end(); ++it) {
internal::RasterWorkerPoolTask* task = *it;
if (task == raster_task.internal_) {
- resource_provider_->ForceSetPixelsToComplete(task->resource()->id());
+ resource_provider()->ForceSetPixelsToComplete(task->resource()->id());
return true;
}
}
@@ -197,7 +202,7 @@ void PixelBufferRasterWorkerPool::
DidFinishDispatchingWorkerPoolCompletionCallbacks() {
// If a flush is needed, do it now before starting to dispatch more tasks.
if (has_performed_uploads_since_last_flush_) {
- resource_provider_->ShallowFlushIfSupported();
+ resource_provider()->ShallowFlushIfSupported();
has_performed_uploads_since_last_flush_ = false;
}
}
@@ -214,10 +219,11 @@ bool PixelBufferRasterWorkerPool::CanScheduleRasterTask(
void PixelBufferRasterWorkerPool::ScheduleMoreTasks() {
TRACE_EVENT0("cc", "PixelBufferRasterWorkerPool::ScheduleMoreTasks");
- internal::WorkerPoolTask::TaskVector raster_tasks;
+ internal::WorkerPoolTask::TaskVector tasks;
- for (RasterTask::Queue::TaskVector::iterator it = raster_tasks_.begin();
- it != raster_tasks_.end(); ++it) {
+ for (RasterTask::Queue::TaskVector::const_iterator it =
+ raster_tasks().begin();
+ it != raster_tasks().end(); ++it) {
internal::RasterWorkerPoolTask* task = *it;
TaskMap::iterator pixel_buffer_it = pixel_buffer_tasks_.find(task);
@@ -228,7 +234,7 @@ void PixelBufferRasterWorkerPool::ScheduleMoreTasks() {
pixel_buffer_it->second);
if (pixel_buffer_task) {
if (!pixel_buffer_task->HasCompleted())
- raster_tasks.push_back(pixel_buffer_task);
+ tasks.push_back(pixel_buffer_task);
continue;
}
@@ -236,12 +242,13 @@ void PixelBufferRasterWorkerPool::ScheduleMoreTasks() {
break;
// Request a pixel buffer. This will reserve shared memory.
- resource_provider_->AcquirePixelBuffer(task->resource()->id());
+ resource_provider()->AcquirePixelBuffer(task->resource()->id());
// MapPixelBuffer() returns NULL if context was lost at the time
// AcquirePixelBuffer() was called. For simplicity we still post
// a raster task that is essentially a noop in these situations.
- uint8* buffer = resource_provider_->MapPixelBuffer(task->resource()->id());
+ uint8* buffer = resource_provider()->MapPixelBuffer(
+ task->resource()->id());
// TODO(reveman): Avoid having to make a copy of dependencies.
internal::WorkerPoolTask::TaskVector dependencies = task->dependencies();
@@ -255,10 +262,24 @@ void PixelBufferRasterWorkerPool::ScheduleMoreTasks() {
make_scoped_refptr(task))));
pixel_buffer_tasks_[task] = pixel_buffer_task;
- raster_tasks.push_back(pixel_buffer_task);
+ tasks.push_back(pixel_buffer_task);
}
- ScheduleRasterTasks(&raster_tasks);
+ ++schedule_more_tasks_count_;
+
+ if (tasks.empty()) {
+ ScheduleRasterTasks(RootTask());
+ return;
+ }
+
+ RootTask root(
+ base::Bind(&PixelBufferRasterWorkerPool::RunRasterFinishedTask,
+ base::MessageLoopProxy::current(),
+ base::Bind(&PixelBufferRasterWorkerPool::OnRasterFinished,
+ weak_ptr_factory_.GetWeakPtr(),
+ schedule_more_tasks_count_)),
+ &tasks);
+ ScheduleRasterTasks(root);
}
void PixelBufferRasterWorkerPool::OnRasterTaskCompleted(
@@ -272,20 +293,20 @@ void PixelBufferRasterWorkerPool::OnRasterTaskCompleted(
DCHECK(pixel_buffer_tasks_.find(task) != pixel_buffer_tasks_.end());
// Balanced with MapPixelBuffer() call in ScheduleMoreTasks().
- resource_provider_->UnmapPixelBuffer(task->resource()->id());
+ resource_provider()->UnmapPixelBuffer(task->resource()->id());
if (!needs_upload) {
- resource_provider_->ReleasePixelBuffer(task->resource()->id());
+ resource_provider()->ReleasePixelBuffer(task->resource()->id());
// No upload needed. Dispatch completion callback.
if (!was_canceled)
task->DidRun();
- DidFinishRasterTask(task);
+ DidCompleteRasterTask(task);
pixel_buffer_tasks_.erase(task);
return;
}
- resource_provider_->BeginSetPixels(task->resource()->id());
+ resource_provider()->BeginSetPixels(task->resource()->id());
has_performed_uploads_since_last_flush_ = true;
bytes_pending_upload_ += task->resource()->bytes();
@@ -296,23 +317,44 @@ void PixelBufferRasterWorkerPool::AbortPendingUploads() {
while (!tasks_with_pending_upload_.empty()) {
internal::RasterWorkerPoolTask* task = tasks_with_pending_upload_.front();
- resource_provider_->AbortSetPixels(task->resource()->id());
- resource_provider_->ReleasePixelBuffer(task->resource()->id());
+ resource_provider()->AbortSetPixels(task->resource()->id());
+ resource_provider()->ReleasePixelBuffer(task->resource()->id());
bytes_pending_upload_ -= task->resource()->bytes();
// Need to run the reply callback even though task was aborted.
- DidFinishRasterTask(task);
+ DidCompleteRasterTask(task);
pixel_buffer_tasks_.erase(task);
tasks_with_pending_upload_.pop_front();
}
}
-void PixelBufferRasterWorkerPool::DidFinishRasterTask(
+void PixelBufferRasterWorkerPool::DidCompleteRasterTask(
internal::RasterWorkerPoolTask* task) {
task->DidComplete();
task->DispatchCompletionCallback();
}
+void PixelBufferRasterWorkerPool::OnRasterFinished(
+ int64 schedule_more_tasks_count) {
+ TRACE_EVENT1("cc",
+ "PixelBufferRasterWorkerPool::OnRasterFinishedTasks",
+ "schedule_more_tasks_count", schedule_more_tasks_count);
+ DCHECK_GE(schedule_more_tasks_count_, schedule_more_tasks_count);
+ // Call CheckForCompletedTasks() when we've finished running all raster
+ // tasks needed since last time ScheduleMoreTasks() was called. This
+ // reduces latency when processing only a small number of raster tasks.
+ if (schedule_more_tasks_count_ == schedule_more_tasks_count)
+ CheckForCompletedTasks();
+}
+
+// static
+void PixelBufferRasterWorkerPool::RunRasterFinishedTask(
+ scoped_refptr<base::MessageLoopProxy> origin_loop,
+ const base::Closure& on_raster_finished_callback) {
+ TRACE_EVENT0("cc", "RasterWorkerPool::RunRasterFinishedTask");
+ origin_loop->PostTask(FROM_HERE, on_raster_finished_callback);
+}
+
} // namespace cc
diff --git a/cc/resources/pixel_buffer_raster_worker_pool.h b/cc/resources/pixel_buffer_raster_worker_pool.h
index 429bd7d..0a519c7 100644
--- a/cc/resources/pixel_buffer_raster_worker_pool.h
+++ b/cc/resources/pixel_buffer_raster_worker_pool.h
@@ -44,7 +44,12 @@ class CC_EXPORT PixelBufferRasterWorkerPool : public RasterWorkerPool,
bool was_canceled,
bool needs_upload);
void AbortPendingUploads();
- void DidFinishRasterTask(internal::RasterWorkerPoolTask* task);
+ void DidCompleteRasterTask(internal::RasterWorkerPoolTask* task);
+ void OnRasterFinished(int64 schedule_more_tasks_count);
+
+ static void RunRasterFinishedTask(
+ scoped_refptr<base::MessageLoopProxy> origin_loop,
+ const base::Closure& on_raster_finished_callback);
TaskMap pixel_buffer_tasks_;
@@ -55,6 +60,9 @@ class CC_EXPORT PixelBufferRasterWorkerPool : public RasterWorkerPool,
bool has_performed_uploads_since_last_flush_;
bool did_dispatch_completion_callback_;
+ base::WeakPtrFactory<PixelBufferRasterWorkerPool> weak_ptr_factory_;
+ int64 schedule_more_tasks_count_;
+
DISALLOW_COPY_AND_ASSIGN(PixelBufferRasterWorkerPool);
};
diff --git a/cc/resources/raster_worker_pool.cc b/cc/resources/raster_worker_pool.cc
index 9748958..b275644 100644
--- a/cc/resources/raster_worker_pool.cc
+++ b/cc/resources/raster_worker_pool.cc
@@ -25,6 +25,12 @@ class WorkerPoolTaskImpl : public internal::WorkerPoolTask {
callback_(base::Bind(&Noop)),
reply_(base::Bind(&Noop)) {
}
+ WorkerPoolTaskImpl(const base::Closure& callback,
+ internal::WorkerPoolTask::TaskVector* dependencies)
+ : internal::WorkerPoolTask(dependencies),
+ callback_(callback),
+ reply_(base::Bind(&Noop)) {
+ }
// Overridden from internal::WorkerPoolTask:
virtual void RunOnThread(unsigned thread_index) OVERRIDE {
@@ -175,6 +181,23 @@ void RasterWorkerPool::RasterTask::Reset() {
RasterWorkerPool::RasterTask::~RasterTask() {
}
+RasterWorkerPool::RootTask::RootTask() {
+}
+
+RasterWorkerPool::RootTask::RootTask(
+ internal::WorkerPoolTask::TaskVector* dependencies)
+ : internal_(new WorkerPoolTaskImpl(dependencies)) {
+}
+
+RasterWorkerPool::RootTask::RootTask(
+ const base::Closure& callback,
+ internal::WorkerPoolTask::TaskVector* dependencies)
+ : internal_(new WorkerPoolTaskImpl(callback, dependencies)) {
+}
+
+RasterWorkerPool::RootTask::~RootTask() {
+}
+
RasterWorkerPool::RasterWorkerPool(ResourceProvider* resource_provider,
size_t num_threads)
: WorkerPool(
@@ -200,15 +223,8 @@ void RasterWorkerPool::SetRasterTasks(RasterTask::Queue* queue) {
raster_tasks_.swap(queue->tasks_);
}
-void RasterWorkerPool::ScheduleRasterTasks(
- internal::WorkerPoolTask::TaskVector* raster_tasks) {
- if (raster_tasks->empty()) {
- WorkerPool::ScheduleTasks(NULL);
- return;
- }
-
- scoped_refptr<WorkerPoolTaskImpl> root(new WorkerPoolTaskImpl(raster_tasks));
- WorkerPool::ScheduleTasks(root);
+void RasterWorkerPool::ScheduleRasterTasks(const RootTask& root) {
+ WorkerPool::ScheduleTasks(root.internal_);
}
} // namespace cc
diff --git a/cc/resources/raster_worker_pool.h b/cc/resources/raster_worker_pool.h
index ed42a76..acdfd77 100644
--- a/cc/resources/raster_worker_pool.h
+++ b/cc/resources/raster_worker_pool.h
@@ -167,6 +167,20 @@ class CC_EXPORT RasterWorkerPool : public WorkerPool {
virtual bool ForceUploadToComplete(const RasterTask& raster_task);
protected:
+ class RootTask {
+ public:
+ RootTask();
+ explicit RootTask(internal::WorkerPoolTask::TaskVector* dependencies);
+ RootTask(const base::Closure& callback,
+ internal::WorkerPoolTask::TaskVector* dependencies);
+ ~RootTask();
+
+ protected:
+ friend class RasterWorkerPool;
+
+ scoped_refptr<internal::WorkerPoolTask> internal_;
+ };
+
typedef internal::RasterWorkerPoolTask* TaskMapKey;
typedef base::hash_map<TaskMapKey,
scoped_refptr<internal::WorkerPoolTask> > TaskMap;
@@ -174,8 +188,14 @@ class CC_EXPORT RasterWorkerPool : public WorkerPool {
RasterWorkerPool(ResourceProvider* resource_provider, size_t num_threads);
void SetRasterTasks(RasterTask::Queue* queue);
- void ScheduleRasterTasks(internal::WorkerPoolTask::TaskVector* raster_tasks);
+ void ScheduleRasterTasks(const RootTask& root);
+ ResourceProvider* resource_provider() const { return resource_provider_; }
+ const RasterTask::Queue::TaskVector& raster_tasks() const {
+ return raster_tasks_;
+ }
+
+ private:
ResourceProvider* resource_provider_;
RasterTask::Queue::TaskVector raster_tasks_;
};