OLD | NEW |
---|---|
(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 #include "cc/resources/direct_raster_worker_pool.h" | |
6 | |
7 #include "cc/output/context_provider.h" | |
8 #include "cc/resources/resource.h" | |
9 #include "cc/resources/resource_provider.h" | |
10 #include "gpu/command_buffer/client/gles2_interface.h" | |
11 #include "third_party/skia/include/gpu/GrContext.h" | |
12 | |
13 namespace cc { | |
14 | |
15 // static | |
16 scoped_ptr<RasterWorkerPool> DirectRasterWorkerPool::Create( | |
17 ResourceProvider* resource_provider, | |
18 ContextProvider* context_provider) { | |
19 return make_scoped_ptr<RasterWorkerPool>( | |
20 new DirectRasterWorkerPool(resource_provider, context_provider)); | |
21 } | |
22 | |
23 DirectRasterWorkerPool::DirectRasterWorkerPool( | |
24 ResourceProvider* resource_provider, | |
25 ContextProvider* context_provider) | |
26 : RasterWorkerPool(NULL, resource_provider), | |
27 context_provider_(context_provider), | |
28 run_tasks_on_origin_thread_pending_(false), | |
29 raster_tasks_pending_(false), | |
30 raster_tasks_required_for_activation_pending_(false), | |
31 weak_factory_(this) {} | |
32 | |
33 DirectRasterWorkerPool::~DirectRasterWorkerPool() { | |
34 DCHECK_EQ(0u, completed_tasks_.size()); | |
35 } | |
36 | |
37 void DirectRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { | |
reveman
2014/02/14 16:11:53
Technically this needs to cancel tasks that have n
reveman
2014/02/14 23:30:52
Done.
| |
38 TRACE_EVENT0("cc", "DirectRasterWorkerPool::ScheduleTasks"); | |
39 | |
40 DCHECK_EQ(queue->required_for_activation_count, | |
41 static_cast<size_t>( | |
42 std::count_if(queue->tasks.begin(), | |
43 queue->tasks.end(), | |
44 RasterTaskQueue::Task::IsRequiredForActivation))); | |
45 | |
46 raster_tasks_pending_ = true; | |
47 raster_tasks_required_for_activation_pending_ = true; | |
48 | |
49 scoped_refptr<internal::WorkerPoolTask> | |
50 new_raster_required_for_activation_finished_task( | |
51 CreateRasterRequiredForActivationFinishedTask( | |
52 queue->required_for_activation_count)); | |
53 scoped_refptr<internal::WorkerPoolTask> new_raster_finished_task( | |
54 CreateRasterFinishedTask()); | |
55 | |
56 ScheduleRunTasksOnOriginThread(); | |
57 | |
58 raster_tasks_.Swap(queue); | |
59 | |
60 set_raster_finished_task(new_raster_finished_task); | |
61 set_raster_required_for_activation_finished_task( | |
62 new_raster_required_for_activation_finished_task); | |
63 } | |
64 | |
65 unsigned DirectRasterWorkerPool::GetResourceTarget() const { | |
66 return GL_TEXTURE_2D; | |
67 } | |
68 | |
69 ResourceFormat DirectRasterWorkerPool::GetResourceFormat() const { | |
70 return resource_provider()->best_texture_format(); | |
71 } | |
72 | |
73 void DirectRasterWorkerPool::CheckForCompletedTasks() { | |
74 TRACE_EVENT0("cc", "DirectRasterWorkerPool::CheckForCompletedTasks"); | |
75 | |
76 for (internal::WorkerPoolTask::Vector::const_iterator it = | |
77 completed_tasks_.begin(); | |
78 it != completed_tasks_.end(); | |
79 ++it) { | |
80 internal::WorkerPoolTask* task = it->get(); | |
81 | |
82 task->RunReplyOnOriginThread(); | |
83 } | |
84 completed_tasks_.clear(); | |
85 } | |
86 | |
87 SkCanvas* DirectRasterWorkerPool::AcquireCanvasForRaster( | |
88 internal::RasterWorkerPoolTask* task) { | |
89 return resource_provider()->MapDirectRasterBuffer(task->resource()->id()); | |
90 } | |
91 | |
92 void DirectRasterWorkerPool::OnRasterCompleted( | |
93 internal::RasterWorkerPoolTask* task, | |
94 const PicturePileImpl::Analysis& analysis) { | |
95 resource_provider()->UnmapDirectRasterBuffer(task->resource()->id()); | |
96 } | |
97 | |
98 void DirectRasterWorkerPool::OnRasterTasksFinished() { | |
99 DCHECK(raster_tasks_pending_); | |
100 raster_tasks_pending_ = false; | |
101 client()->DidFinishRunningTasks(); | |
102 } | |
103 | |
104 void DirectRasterWorkerPool::OnRasterTasksRequiredForActivationFinished() { | |
105 DCHECK(raster_tasks_required_for_activation_pending_); | |
106 raster_tasks_required_for_activation_pending_ = false; | |
107 client()->DidFinishRunningTasksRequiredForActivation(); | |
108 } | |
109 | |
110 void DirectRasterWorkerPool::ScheduleRunTasksOnOriginThread() { | |
111 if (run_tasks_on_origin_thread_pending_) | |
112 return; | |
113 | |
114 base::MessageLoopProxy::current()->PostTask( | |
115 FROM_HERE, | |
116 base::Bind(&DirectRasterWorkerPool::RunTasksOnOriginThread, | |
117 weak_factory_.GetWeakPtr())); | |
118 run_tasks_on_origin_thread_pending_ = true; | |
119 } | |
120 | |
121 void DirectRasterWorkerPool::RunTasksOnOriginThread() { | |
122 DCHECK(run_tasks_on_origin_thread_pending_); | |
123 run_tasks_on_origin_thread_pending_ = false; | |
124 | |
125 if (!raster_tasks_.tasks.empty()) { | |
126 GrContext* gr_context = context_provider_->GrContext(); | |
127 // TODO(alokp): Implement TestContextProvider::GrContext(). | |
128 if (gr_context) | |
129 gr_context->resetContext(); | |
130 | |
131 for (RasterTaskQueueIterator it(&raster_tasks_); it; ++it) { | |
132 internal::RasterWorkerPoolTask* task = *it; | |
133 DCHECK(!task->HasCompleted()); | |
134 | |
135 // TODO(reveman): Run image decode tasks on origin thread. | |
136 DCHECK_EQ(0u, task->dependencies().size()); | |
reveman
2014/02/14 23:30:52
Turned out this needs to be implement for unit and
| |
137 | |
138 RunTaskOnOriginThread(task); | |
139 | |
140 completed_tasks_.push_back(task); | |
141 } | |
142 | |
143 // TODO(alokp): Implement TestContextProvider::GrContext(). | |
144 if (gr_context) | |
145 gr_context->flush(); | |
146 } | |
147 | |
148 RunTaskOnOriginThread(raster_finished_task()); | |
149 RunTaskOnOriginThread(raster_required_for_activation_finished_task()); | |
alokp
2014/02/14 18:50:59
shouldn't activation-finished be run before raster
reveman
2014/02/14 23:30:52
Good point. Done. This is not currently required b
| |
150 } | |
151 | |
152 } // namespace cc | |
OLD | NEW |