OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #include "cc/raster_worker_pool.h" | 5 #include "cc/raster_worker_pool.h" |
6 | 6 |
7 #include "cc/picture_pile_impl.h" | 7 #include "cc/picture_pile_impl.h" |
8 | 8 |
9 namespace cc { | 9 namespace cc { |
10 | 10 |
11 namespace { | 11 namespace { |
12 | 12 |
13 class RasterWorkerPoolTaskImpl : public internal::WorkerPoolTask { | 13 class RasterWorkerPoolTaskImpl : public internal::WorkerPoolTask { |
14 public: | 14 public: |
15 RasterWorkerPoolTaskImpl(PicturePileImpl* picture_pile, | 15 RasterWorkerPoolTaskImpl(PicturePileImpl* picture_pile, |
16 const RasterWorkerPool::RasterCallback& task, | 16 const RasterWorkerPool::RasterCallback& task, |
17 const base::Closure& reply) | 17 const base::Closure& reply) |
18 : internal::WorkerPoolTask(reply), | 18 : internal::WorkerPoolTask(reply), |
19 picture_pile_(picture_pile), | 19 picture_pile_(picture_pile), |
20 task_(task) { | 20 task_(task) { |
21 DCHECK(picture_pile_); | 21 DCHECK(picture_pile_); |
22 } | 22 } |
23 | 23 |
24 virtual void Run(RenderingStats* rendering_stats) OVERRIDE { | 24 virtual void Run(RenderingStats* rendering_stats) OVERRIDE { |
25 task_.Run(picture_pile_.get(), rendering_stats); | 25 task_.Run(picture_pile_, rendering_stats); |
26 base::subtle::Release_Store(&completed_, 1); | 26 base::subtle::Release_Store(&completed_, 1); |
27 } | 27 } |
28 | 28 |
29 virtual void DeferToThread(base::Thread* thread) OVERRIDE { | |
30 picture_pile_clone_ = picture_pile_ = | |
31 picture_pile_->GetCloneForDrawingOnThread(thread); | |
reveman
2013/02/14 21:10:49
DCHECK(!picture_pile_clone_) before this statement
Sami
2013/02/15 16:41:22
Good idea. This handles multiple calls fine, but w
| |
32 } | |
33 | |
29 private: | 34 private: |
30 scoped_refptr<PicturePileImpl> picture_pile_; | 35 PicturePileImpl* picture_pile_; |
36 scoped_refptr<PicturePileImpl> picture_pile_clone_; | |
31 RasterWorkerPool::RasterCallback task_; | 37 RasterWorkerPool::RasterCallback task_; |
32 }; | 38 }; |
33 | 39 |
34 } // namespace | 40 } // namespace |
35 | 41 |
36 RasterWorkerPool::RasterWorkerPool( | 42 RasterWorkerPool::RasterWorkerPool( |
37 WorkerPoolClient* client, size_t num_threads) | 43 WorkerPoolClient* client, size_t num_threads) |
38 : WorkerPool(client, num_threads) { | 44 : WorkerPool(client, num_threads) { |
39 } | 45 } |
40 | 46 |
41 RasterWorkerPool::~RasterWorkerPool() { | 47 RasterWorkerPool::~RasterWorkerPool() { |
42 } | 48 } |
43 | 49 |
44 void RasterWorkerPool::PostRasterTaskAndReply(PicturePileImpl* picture_pile, | 50 void RasterWorkerPool::PostRasterTaskAndReply(PicturePileImpl* picture_pile, |
51 bool is_cheap, | |
45 const RasterCallback& task, | 52 const RasterCallback& task, |
46 const base::Closure& reply) { | 53 const base::Closure& reply) { |
54 scoped_ptr<internal::WorkerPoolTask> worker_task( | |
55 new RasterWorkerPoolTaskImpl(picture_pile, task, reply)); | |
56 | |
57 if (is_cheap && CanPostCheapTask()) { | |
58 PostCheapTask(worker_task.Pass()); | |
59 return; | |
60 } | |
61 | |
47 Worker* worker = GetWorkerForNextTask(); | 62 Worker* worker = GetWorkerForNextTask(); |
48 | 63 worker_task->DeferToThread(worker); |
reveman
2013/02/14 21:10:49
can we call this from WorkerPool::Worker::PostTask
Sami
2013/02/15 16:41:22
Yeah, that's much cleaner.
| |
49 scoped_refptr<PicturePileImpl> picture_pile_clone = | 64 worker->PostTask(worker_task.Pass()); |
50 picture_pile->GetCloneForDrawingOnThread(worker); | |
51 | |
52 worker->PostTask( | |
53 make_scoped_ptr(new RasterWorkerPoolTaskImpl( | |
54 picture_pile_clone.get(), | |
55 task, | |
56 reply)).PassAs<internal::WorkerPoolTask>()); | |
57 } | 65 } |
58 | 66 |
59 } // namespace cc | 67 } // namespace cc |
OLD | NEW |