| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/resources/one_copy_raster_worker_pool.h" | 5 #include "cc/resources/one_copy_tile_task_worker_pool.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/debug/trace_event_argument.h" | 11 #include "base/debug/trace_event_argument.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "cc/debug/traced_value.h" | 13 #include "cc/debug/traced_value.h" |
| 14 #include "cc/resources/raster_buffer.h" | 14 #include "cc/resources/raster_buffer.h" |
| 15 #include "cc/resources/resource_pool.h" | 15 #include "cc/resources/resource_pool.h" |
| 16 #include "cc/resources/scoped_resource.h" | 16 #include "cc/resources/scoped_resource.h" |
| 17 #include "gpu/command_buffer/client/gles2_interface.h" | 17 #include "gpu/command_buffer/client/gles2_interface.h" |
| 18 #include "ui/gfx/gpu_memory_buffer.h" | 18 #include "ui/gfx/gpu_memory_buffer.h" |
| 19 | 19 |
| 20 namespace cc { | 20 namespace cc { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class RasterBufferImpl : public RasterBuffer { | 23 class RasterBufferImpl : public RasterBuffer { |
| 24 public: | 24 public: |
| 25 RasterBufferImpl(OneCopyRasterWorkerPool* worker_pool, | 25 RasterBufferImpl(OneCopyTileTaskWorkerPool* worker_pool, |
| 26 ResourceProvider* resource_provider, | 26 ResourceProvider* resource_provider, |
| 27 ResourcePool* resource_pool, | 27 ResourcePool* resource_pool, |
| 28 const Resource* resource) | 28 const Resource* resource) |
| 29 : worker_pool_(worker_pool), | 29 : worker_pool_(worker_pool), |
| 30 resource_provider_(resource_provider), | 30 resource_provider_(resource_provider), |
| 31 resource_pool_(resource_pool), | 31 resource_pool_(resource_pool), |
| 32 resource_(resource), | 32 resource_(resource), |
| 33 raster_resource_(resource_pool->AcquireResource(resource->size())), | 33 raster_resource_(resource_pool->AcquireResource(resource->size())), |
| 34 lock_(new ResourceProvider::ScopedWriteLockGpuMemoryBuffer( | 34 lock_(new ResourceProvider::ScopedWriteLockGpuMemoryBuffer( |
| 35 resource_provider_, | 35 resource_provider_, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 54 // Overridden from RasterBuffer: | 54 // Overridden from RasterBuffer: |
| 55 void Playback(const RasterSource* raster_source, | 55 void Playback(const RasterSource* raster_source, |
| 56 const gfx::Rect& rect, | 56 const gfx::Rect& rect, |
| 57 float scale) override { | 57 float scale) override { |
| 58 sequence_ = worker_pool_->PlaybackAndScheduleCopyOnWorkerThread( | 58 sequence_ = worker_pool_->PlaybackAndScheduleCopyOnWorkerThread( |
| 59 lock_.Pass(), raster_resource_.Pass(), resource_, raster_source, rect, | 59 lock_.Pass(), raster_resource_.Pass(), resource_, raster_source, rect, |
| 60 scale); | 60 scale); |
| 61 } | 61 } |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 OneCopyRasterWorkerPool* worker_pool_; | 64 OneCopyTileTaskWorkerPool* worker_pool_; |
| 65 ResourceProvider* resource_provider_; | 65 ResourceProvider* resource_provider_; |
| 66 ResourcePool* resource_pool_; | 66 ResourcePool* resource_pool_; |
| 67 const Resource* resource_; | 67 const Resource* resource_; |
| 68 scoped_ptr<ScopedResource> raster_resource_; | 68 scoped_ptr<ScopedResource> raster_resource_; |
| 69 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> lock_; | 69 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> lock_; |
| 70 CopySequenceNumber sequence_; | 70 CopySequenceNumber sequence_; |
| 71 | 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | 72 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 // Flush interval when performing copy operations. | 75 // Flush interval when performing copy operations. |
| 76 const int kCopyFlushPeriod = 4; | 76 const int kCopyFlushPeriod = 4; |
| 77 | 77 |
| 78 // Number of in-flight copy operations to allow. | 78 // Number of in-flight copy operations to allow. |
| 79 const int kMaxCopyOperations = 16; | 79 const int kMaxCopyOperations = 16; |
| 80 | 80 |
| 81 // Delay been checking for copy operations to complete. | 81 // Delay been checking for copy operations to complete. |
| 82 const int kCheckForCompletedCopyOperationsTickRateMs = 1; | 82 const int kCheckForCompletedCopyOperationsTickRateMs = 1; |
| 83 | 83 |
| 84 // Number of failed attempts to allow before we perform a check that will | 84 // Number of failed attempts to allow before we perform a check that will |
| 85 // wait for copy operations to complete if needed. | 85 // wait for copy operations to complete if needed. |
| 86 const int kFailedAttemptsBeforeWaitIfNeeded = 256; | 86 const int kFailedAttemptsBeforeWaitIfNeeded = 256; |
| 87 | 87 |
| 88 } // namespace | 88 } // namespace |
| 89 | 89 |
| 90 OneCopyRasterWorkerPool::CopyOperation::CopyOperation( | 90 OneCopyTileTaskWorkerPool::CopyOperation::CopyOperation( |
| 91 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock, | 91 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock, |
| 92 scoped_ptr<ScopedResource> src, | 92 scoped_ptr<ScopedResource> src, |
| 93 const Resource* dst) | 93 const Resource* dst) |
| 94 : write_lock(write_lock.Pass()), src(src.Pass()), dst(dst) { | 94 : write_lock(write_lock.Pass()), src(src.Pass()), dst(dst) { |
| 95 } | 95 } |
| 96 | 96 |
| 97 OneCopyRasterWorkerPool::CopyOperation::~CopyOperation() { | 97 OneCopyTileTaskWorkerPool::CopyOperation::~CopyOperation() { |
| 98 } | 98 } |
| 99 | 99 |
| 100 // static | 100 // static |
| 101 scoped_ptr<RasterWorkerPool> OneCopyRasterWorkerPool::Create( | 101 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( |
| 102 base::SequencedTaskRunner* task_runner, | 102 base::SequencedTaskRunner* task_runner, |
| 103 TaskGraphRunner* task_graph_runner, | 103 TaskGraphRunner* task_graph_runner, |
| 104 ContextProvider* context_provider, | 104 ContextProvider* context_provider, |
| 105 ResourceProvider* resource_provider, | 105 ResourceProvider* resource_provider, |
| 106 ResourcePool* resource_pool) { | 106 ResourcePool* resource_pool) { |
| 107 return make_scoped_ptr<RasterWorkerPool>( | 107 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool( |
| 108 new OneCopyRasterWorkerPool(task_runner, | 108 task_runner, task_graph_runner, context_provider, resource_provider, |
| 109 task_graph_runner, | 109 resource_pool)); |
| 110 context_provider, | |
| 111 resource_provider, | |
| 112 resource_pool)); | |
| 113 } | 110 } |
| 114 | 111 |
| 115 OneCopyRasterWorkerPool::OneCopyRasterWorkerPool( | 112 OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool( |
| 116 base::SequencedTaskRunner* task_runner, | 113 base::SequencedTaskRunner* task_runner, |
| 117 TaskGraphRunner* task_graph_runner, | 114 TaskGraphRunner* task_graph_runner, |
| 118 ContextProvider* context_provider, | 115 ContextProvider* context_provider, |
| 119 ResourceProvider* resource_provider, | 116 ResourceProvider* resource_provider, |
| 120 ResourcePool* resource_pool) | 117 ResourcePool* resource_pool) |
| 121 : task_runner_(task_runner), | 118 : task_runner_(task_runner), |
| 122 task_graph_runner_(task_graph_runner), | 119 task_graph_runner_(task_graph_runner), |
| 123 namespace_token_(task_graph_runner->GetNamespaceToken()), | 120 namespace_token_(task_graph_runner->GetNamespaceToken()), |
| 124 context_provider_(context_provider), | 121 context_provider_(context_provider), |
| 125 resource_provider_(resource_provider), | 122 resource_provider_(resource_provider), |
| 126 resource_pool_(resource_pool), | 123 resource_pool_(resource_pool), |
| 127 last_issued_copy_operation_(0), | 124 last_issued_copy_operation_(0), |
| 128 last_flushed_copy_operation_(0), | 125 last_flushed_copy_operation_(0), |
| 129 lock_(), | 126 lock_(), |
| 130 copy_operation_count_cv_(&lock_), | 127 copy_operation_count_cv_(&lock_), |
| 131 scheduled_copy_operation_count_(0), | 128 scheduled_copy_operation_count_(0), |
| 132 issued_copy_operation_count_(0), | 129 issued_copy_operation_count_(0), |
| 133 next_copy_operation_sequence_(1), | 130 next_copy_operation_sequence_(1), |
| 134 check_for_completed_copy_operations_pending_(false), | 131 check_for_completed_copy_operations_pending_(false), |
| 135 shutdown_(false), | 132 shutdown_(false), |
| 136 weak_ptr_factory_(this), | 133 weak_ptr_factory_(this), |
| 137 raster_finished_weak_ptr_factory_(this) { | 134 task_set_finished_weak_ptr_factory_(this) { |
| 138 DCHECK(context_provider_); | 135 DCHECK(context_provider_); |
| 139 } | 136 } |
| 140 | 137 |
| 141 OneCopyRasterWorkerPool::~OneCopyRasterWorkerPool() { | 138 OneCopyTileTaskWorkerPool::~OneCopyTileTaskWorkerPool() { |
| 142 DCHECK_EQ(scheduled_copy_operation_count_, 0u); | 139 DCHECK_EQ(scheduled_copy_operation_count_, 0u); |
| 143 } | 140 } |
| 144 | 141 |
| 145 Rasterizer* OneCopyRasterWorkerPool::AsRasterizer() { | 142 TileTaskRunner* OneCopyTileTaskWorkerPool::AsTileTaskRunner() { |
| 146 return this; | 143 return this; |
| 147 } | 144 } |
| 148 | 145 |
| 149 void OneCopyRasterWorkerPool::SetClient(RasterizerClient* client) { | 146 void OneCopyTileTaskWorkerPool::SetClient(TileTaskRunnerClient* client) { |
| 150 client_ = client; | 147 client_ = client; |
| 151 } | 148 } |
| 152 | 149 |
| 153 void OneCopyRasterWorkerPool::Shutdown() { | 150 void OneCopyTileTaskWorkerPool::Shutdown() { |
| 154 TRACE_EVENT0("cc", "OneCopyRasterWorkerPool::Shutdown"); | 151 TRACE_EVENT0("cc", "OneCopyTileTaskWorkerPool::Shutdown"); |
| 155 | 152 |
| 156 { | 153 { |
| 157 base::AutoLock lock(lock_); | 154 base::AutoLock lock(lock_); |
| 158 | 155 |
| 159 shutdown_ = true; | 156 shutdown_ = true; |
| 160 copy_operation_count_cv_.Signal(); | 157 copy_operation_count_cv_.Signal(); |
| 161 } | 158 } |
| 162 | 159 |
| 163 TaskGraph empty; | 160 TaskGraph empty; |
| 164 task_graph_runner_->ScheduleTasks(namespace_token_, &empty); | 161 task_graph_runner_->ScheduleTasks(namespace_token_, &empty); |
| 165 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); | 162 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); |
| 166 } | 163 } |
| 167 | 164 |
| 168 void OneCopyRasterWorkerPool::ScheduleTasks(RasterTaskQueue* queue) { | 165 void OneCopyTileTaskWorkerPool::ScheduleTasks(TileTaskQueue* queue) { |
| 169 TRACE_EVENT0("cc", "OneCopyRasterWorkerPool::ScheduleTasks"); | 166 TRACE_EVENT0("cc", "OneCopyTileTaskWorkerPool::ScheduleTasks"); |
| 170 | 167 |
| 171 if (raster_pending_.none()) | 168 if (tasks_pending_.none()) |
| 172 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); | 169 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); |
| 173 | 170 |
| 174 // Mark all task sets as pending. | 171 // Mark all task sets as pending. |
| 175 raster_pending_.set(); | 172 tasks_pending_.set(); |
| 176 | 173 |
| 177 unsigned priority = kRasterTaskPriorityBase; | 174 unsigned priority = kTileTaskPriorityBase; |
| 178 | 175 |
| 179 graph_.Reset(); | 176 graph_.Reset(); |
| 180 | 177 |
| 181 // Cancel existing OnRasterFinished callbacks. | 178 // Cancel existing OnTaskSetFinished callbacks. |
| 182 raster_finished_weak_ptr_factory_.InvalidateWeakPtrs(); | 179 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); |
| 183 | 180 |
| 184 scoped_refptr<RasterizerTask> new_raster_finished_tasks[kNumberOfTaskSets]; | 181 scoped_refptr<TileTask> new_task_set_finished_tasks[kNumberOfTaskSets]; |
| 185 | 182 |
| 186 size_t task_count[kNumberOfTaskSets] = {0}; | 183 size_t task_count[kNumberOfTaskSets] = {0}; |
| 187 | 184 |
| 188 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { | 185 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { |
| 189 new_raster_finished_tasks[task_set] = CreateRasterFinishedTask( | 186 new_task_set_finished_tasks[task_set] = CreateTaskSetFinishedTask( |
| 190 task_runner_.get(), | 187 task_runner_.get(), |
| 191 base::Bind(&OneCopyRasterWorkerPool::OnRasterFinished, | 188 base::Bind(&OneCopyTileTaskWorkerPool::OnTaskSetFinished, |
| 192 raster_finished_weak_ptr_factory_.GetWeakPtr(), | 189 task_set_finished_weak_ptr_factory_.GetWeakPtr(), task_set)); |
| 193 task_set)); | |
| 194 } | 190 } |
| 195 | 191 |
| 196 resource_pool_->CheckBusyResources(false); | 192 resource_pool_->CheckBusyResources(false); |
| 197 | 193 |
| 198 for (RasterTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); | 194 for (TileTaskQueue::Item::Vector::const_iterator it = queue->items.begin(); |
| 199 it != queue->items.end(); | 195 it != queue->items.end(); ++it) { |
| 200 ++it) { | 196 const TileTaskQueue::Item& item = *it; |
| 201 const RasterTaskQueue::Item& item = *it; | |
| 202 RasterTask* task = item.task; | 197 RasterTask* task = item.task; |
| 203 DCHECK(!task->HasCompleted()); | 198 DCHECK(!task->HasCompleted()); |
| 204 | 199 |
| 205 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { | 200 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { |
| 206 if (!item.task_sets[task_set]) | 201 if (!item.task_sets[task_set]) |
| 207 continue; | 202 continue; |
| 208 | 203 |
| 209 ++task_count[task_set]; | 204 ++task_count[task_set]; |
| 210 | 205 |
| 211 graph_.edges.push_back( | 206 graph_.edges.push_back( |
| 212 TaskGraph::Edge(task, new_raster_finished_tasks[task_set].get())); | 207 TaskGraph::Edge(task, new_task_set_finished_tasks[task_set].get())); |
| 213 } | 208 } |
| 214 | 209 |
| 215 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++); | 210 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++); |
| 216 } | 211 } |
| 217 | 212 |
| 218 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { | 213 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { |
| 219 InsertNodeForTask(&graph_, | 214 InsertNodeForTask(&graph_, new_task_set_finished_tasks[task_set].get(), |
| 220 new_raster_finished_tasks[task_set].get(), | 215 kTaskSetFinishedTaskPriority, task_count[task_set]); |
| 221 kRasterFinishedTaskPriority, | |
| 222 task_count[task_set]); | |
| 223 } | 216 } |
| 224 | 217 |
| 225 ScheduleTasksOnOriginThread(this, &graph_); | 218 ScheduleTasksOnOriginThread(this, &graph_); |
| 226 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_); | 219 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_); |
| 227 | 220 |
| 228 std::copy(new_raster_finished_tasks, | 221 std::copy(new_task_set_finished_tasks, |
| 229 new_raster_finished_tasks + kNumberOfTaskSets, | 222 new_task_set_finished_tasks + kNumberOfTaskSets, |
| 230 raster_finished_tasks_); | 223 task_set_finished_tasks_); |
| 231 | 224 |
| 232 resource_pool_->ReduceResourceUsage(); | 225 resource_pool_->ReduceResourceUsage(); |
| 233 | 226 |
| 234 TRACE_EVENT_ASYNC_STEP_INTO1( | 227 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", |
| 235 "cc", "ScheduledTasks", this, "rasterizing", "state", StateAsValue()); | 228 StateAsValue()); |
| 236 } | 229 } |
| 237 | 230 |
| 238 void OneCopyRasterWorkerPool::CheckForCompletedTasks() { | 231 void OneCopyTileTaskWorkerPool::CheckForCompletedTasks() { |
| 239 TRACE_EVENT0("cc", "OneCopyRasterWorkerPool::CheckForCompletedTasks"); | 232 TRACE_EVENT0("cc", "OneCopyTileTaskWorkerPool::CheckForCompletedTasks"); |
| 240 | 233 |
| 241 task_graph_runner_->CollectCompletedTasks(namespace_token_, | 234 task_graph_runner_->CollectCompletedTasks(namespace_token_, |
| 242 &completed_tasks_); | 235 &completed_tasks_); |
| 243 | 236 |
| 244 for (Task::Vector::const_iterator it = completed_tasks_.begin(); | 237 for (Task::Vector::const_iterator it = completed_tasks_.begin(); |
| 245 it != completed_tasks_.end(); | 238 it != completed_tasks_.end(); ++it) { |
| 246 ++it) { | 239 TileTask* task = static_cast<TileTask*>(it->get()); |
| 247 RasterizerTask* task = static_cast<RasterizerTask*>(it->get()); | |
| 248 | 240 |
| 249 task->WillComplete(); | 241 task->WillComplete(); |
| 250 task->CompleteOnOriginThread(this); | 242 task->CompleteOnOriginThread(this); |
| 251 task->DidComplete(); | 243 task->DidComplete(); |
| 252 | 244 |
| 253 task->RunReplyOnOriginThread(); | 245 task->RunReplyOnOriginThread(); |
| 254 } | 246 } |
| 255 completed_tasks_.clear(); | 247 completed_tasks_.clear(); |
| 256 } | 248 } |
| 257 | 249 |
| 258 scoped_ptr<RasterBuffer> OneCopyRasterWorkerPool::AcquireBufferForRaster( | 250 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster( |
| 259 const Resource* resource) { | 251 const Resource* resource) { |
| 260 DCHECK_EQ(resource->format(), resource_pool_->resource_format()); | 252 DCHECK_EQ(resource->format(), resource_pool_->resource_format()); |
| 261 return make_scoped_ptr<RasterBuffer>( | 253 return make_scoped_ptr<RasterBuffer>( |
| 262 new RasterBufferImpl(this, resource_provider_, resource_pool_, resource)); | 254 new RasterBufferImpl(this, resource_provider_, resource_pool_, resource)); |
| 263 } | 255 } |
| 264 | 256 |
| 265 void OneCopyRasterWorkerPool::ReleaseBufferForRaster( | 257 void OneCopyTileTaskWorkerPool::ReleaseBufferForRaster( |
| 266 scoped_ptr<RasterBuffer> buffer) { | 258 scoped_ptr<RasterBuffer> buffer) { |
| 267 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 259 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
| 268 } | 260 } |
| 269 | 261 |
| 270 CopySequenceNumber | 262 CopySequenceNumber |
| 271 OneCopyRasterWorkerPool::PlaybackAndScheduleCopyOnWorkerThread( | 263 OneCopyTileTaskWorkerPool::PlaybackAndScheduleCopyOnWorkerThread( |
| 272 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock, | 264 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock, |
| 273 scoped_ptr<ScopedResource> src, | 265 scoped_ptr<ScopedResource> src, |
| 274 const Resource* dst, | 266 const Resource* dst, |
| 275 const RasterSource* raster_source, | 267 const RasterSource* raster_source, |
| 276 const gfx::Rect& rect, | 268 const gfx::Rect& rect, |
| 277 float scale) { | 269 float scale) { |
| 278 base::AutoLock lock(lock_); | 270 base::AutoLock lock(lock_); |
| 279 | 271 |
| 280 int failed_attempts = 0; | 272 int failed_attempts = 0; |
| 281 while ((scheduled_copy_operation_count_ + issued_copy_operation_count_) >= | 273 while ((scheduled_copy_operation_count_ + issued_copy_operation_count_) >= |
| (...skipping 24 matching lines...) Expand all Loading... |
| 306 ++scheduled_copy_operation_count_; | 298 ++scheduled_copy_operation_count_; |
| 307 | 299 |
| 308 // There may be more work available, so wake up another worker thread. | 300 // There may be more work available, so wake up another worker thread. |
| 309 copy_operation_count_cv_.Signal(); | 301 copy_operation_count_cv_.Signal(); |
| 310 | 302 |
| 311 { | 303 { |
| 312 base::AutoUnlock unlock(lock_); | 304 base::AutoUnlock unlock(lock_); |
| 313 | 305 |
| 314 gfx::GpuMemoryBuffer* gpu_memory_buffer = write_lock->GetGpuMemoryBuffer(); | 306 gfx::GpuMemoryBuffer* gpu_memory_buffer = write_lock->GetGpuMemoryBuffer(); |
| 315 if (gpu_memory_buffer) { | 307 if (gpu_memory_buffer) { |
| 316 RasterWorkerPool::PlaybackToMemory(gpu_memory_buffer->Map(), | 308 TileTaskWorkerPool::PlaybackToMemory( |
| 317 src->format(), | 309 gpu_memory_buffer->Map(), src->format(), src->size(), |
| 318 src->size(), | 310 gpu_memory_buffer->GetStride(), raster_source, rect, scale); |
| 319 gpu_memory_buffer->GetStride(), | |
| 320 raster_source, | |
| 321 rect, | |
| 322 scale); | |
| 323 gpu_memory_buffer->Unmap(); | 311 gpu_memory_buffer->Unmap(); |
| 324 } | 312 } |
| 325 } | 313 } |
| 326 | 314 |
| 327 pending_copy_operations_.push_back( | 315 pending_copy_operations_.push_back( |
| 328 make_scoped_ptr(new CopyOperation(write_lock.Pass(), src.Pass(), dst))); | 316 make_scoped_ptr(new CopyOperation(write_lock.Pass(), src.Pass(), dst))); |
| 329 | 317 |
| 330 // Acquire a sequence number for this copy operation. | 318 // Acquire a sequence number for this copy operation. |
| 331 CopySequenceNumber sequence = next_copy_operation_sequence_++; | 319 CopySequenceNumber sequence = next_copy_operation_sequence_++; |
| 332 | 320 |
| 333 // Post task that will advance last flushed copy operation to |sequence| | 321 // Post task that will advance last flushed copy operation to |sequence| |
| 334 // if we have reached the flush period. | 322 // if we have reached the flush period. |
| 335 if ((sequence % kCopyFlushPeriod) == 0) { | 323 if ((sequence % kCopyFlushPeriod) == 0) { |
| 336 task_runner_->PostTask( | 324 task_runner_->PostTask( |
| 337 FROM_HERE, | 325 FROM_HERE, |
| 338 base::Bind(&OneCopyRasterWorkerPool::AdvanceLastFlushedCopyTo, | 326 base::Bind(&OneCopyTileTaskWorkerPool::AdvanceLastFlushedCopyTo, |
| 339 weak_ptr_factory_.GetWeakPtr(), | 327 weak_ptr_factory_.GetWeakPtr(), sequence)); |
| 340 sequence)); | |
| 341 } | 328 } |
| 342 | 329 |
| 343 return sequence; | 330 return sequence; |
| 344 } | 331 } |
| 345 | 332 |
| 346 void OneCopyRasterWorkerPool::AdvanceLastIssuedCopyTo( | 333 void OneCopyTileTaskWorkerPool::AdvanceLastIssuedCopyTo( |
| 347 CopySequenceNumber sequence) { | 334 CopySequenceNumber sequence) { |
| 348 if (last_issued_copy_operation_ >= sequence) | 335 if (last_issued_copy_operation_ >= sequence) |
| 349 return; | 336 return; |
| 350 | 337 |
| 351 IssueCopyOperations(sequence - last_issued_copy_operation_); | 338 IssueCopyOperations(sequence - last_issued_copy_operation_); |
| 352 last_issued_copy_operation_ = sequence; | 339 last_issued_copy_operation_ = sequence; |
| 353 } | 340 } |
| 354 | 341 |
| 355 void OneCopyRasterWorkerPool::AdvanceLastFlushedCopyTo( | 342 void OneCopyTileTaskWorkerPool::AdvanceLastFlushedCopyTo( |
| 356 CopySequenceNumber sequence) { | 343 CopySequenceNumber sequence) { |
| 357 if (last_flushed_copy_operation_ >= sequence) | 344 if (last_flushed_copy_operation_ >= sequence) |
| 358 return; | 345 return; |
| 359 | 346 |
| 360 AdvanceLastIssuedCopyTo(sequence); | 347 AdvanceLastIssuedCopyTo(sequence); |
| 361 | 348 |
| 362 // Flush all issued copy operations. | 349 // Flush all issued copy operations. |
| 363 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); | 350 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); |
| 364 last_flushed_copy_operation_ = last_issued_copy_operation_; | 351 last_flushed_copy_operation_ = last_issued_copy_operation_; |
| 365 } | 352 } |
| 366 | 353 |
| 367 void OneCopyRasterWorkerPool::OnRasterFinished(TaskSet task_set) { | 354 void OneCopyTileTaskWorkerPool::OnTaskSetFinished(TaskSet task_set) { |
| 368 TRACE_EVENT1( | 355 TRACE_EVENT1("cc", "OneCopyTileTaskWorkerPool::OnTaskSetFinished", "task_set", |
| 369 "cc", "OneCopyRasterWorkerPool::OnRasterFinished", "task_set", task_set); | 356 task_set); |
| 370 | 357 |
| 371 DCHECK(raster_pending_[task_set]); | 358 DCHECK(tasks_pending_[task_set]); |
| 372 raster_pending_[task_set] = false; | 359 tasks_pending_[task_set] = false; |
| 373 if (raster_pending_.any()) { | 360 if (tasks_pending_.any()) { |
| 374 TRACE_EVENT_ASYNC_STEP_INTO1( | 361 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", |
| 375 "cc", "ScheduledTasks", this, "rasterizing", "state", StateAsValue()); | 362 "state", StateAsValue()); |
| 376 } else { | 363 } else { |
| 377 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); | 364 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); |
| 378 } | 365 } |
| 379 client_->DidFinishRunningTasks(task_set); | 366 client_->DidFinishRunningTileTasks(task_set); |
| 380 } | 367 } |
| 381 | 368 |
| 382 void OneCopyRasterWorkerPool::IssueCopyOperations(int64 count) { | 369 void OneCopyTileTaskWorkerPool::IssueCopyOperations(int64 count) { |
| 383 TRACE_EVENT1( | 370 TRACE_EVENT1("cc", "OneCopyTileTaskWorkerPool::IssueCopyOperations", "count", |
| 384 "cc", "OneCopyRasterWorkerPool::IssueCopyOperations", "count", count); | 371 count); |
| 385 | 372 |
| 386 CopyOperation::Deque copy_operations; | 373 CopyOperation::Deque copy_operations; |
| 387 | 374 |
| 388 { | 375 { |
| 389 base::AutoLock lock(lock_); | 376 base::AutoLock lock(lock_); |
| 390 | 377 |
| 391 for (int64 i = 0; i < count; ++i) { | 378 for (int64 i = 0; i < count; ++i) { |
| 392 DCHECK(!pending_copy_operations_.empty()); | 379 DCHECK(!pending_copy_operations_.empty()); |
| 393 copy_operations.push_back(pending_copy_operations_.take_front()); | 380 copy_operations.push_back(pending_copy_operations_.take_front()); |
| 394 } | 381 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 410 // Copy contents of source resource to destination resource. | 397 // Copy contents of source resource to destination resource. |
| 411 resource_provider_->CopyResource(copy_operation->src->id(), | 398 resource_provider_->CopyResource(copy_operation->src->id(), |
| 412 copy_operation->dst->id()); | 399 copy_operation->dst->id()); |
| 413 | 400 |
| 414 // Return source resource to pool where it can be reused once copy | 401 // Return source resource to pool where it can be reused once copy |
| 415 // operation has completed and resource is no longer busy. | 402 // operation has completed and resource is no longer busy. |
| 416 resource_pool_->ReleaseResource(copy_operation->src.Pass()); | 403 resource_pool_->ReleaseResource(copy_operation->src.Pass()); |
| 417 } | 404 } |
| 418 } | 405 } |
| 419 | 406 |
| 420 void OneCopyRasterWorkerPool:: | 407 void OneCopyTileTaskWorkerPool:: |
| 421 ScheduleCheckForCompletedCopyOperationsWithLockAcquired( | 408 ScheduleCheckForCompletedCopyOperationsWithLockAcquired( |
| 422 bool wait_if_needed) { | 409 bool wait_if_needed) { |
| 423 lock_.AssertAcquired(); | 410 lock_.AssertAcquired(); |
| 424 | 411 |
| 425 if (check_for_completed_copy_operations_pending_) | 412 if (check_for_completed_copy_operations_pending_) |
| 426 return; | 413 return; |
| 427 | 414 |
| 428 base::TimeTicks now = base::TimeTicks::Now(); | 415 base::TimeTicks now = base::TimeTicks::Now(); |
| 429 | 416 |
| 430 // Schedule a check for completed copy operations as soon as possible but | 417 // Schedule a check for completed copy operations as soon as possible but |
| 431 // don't allow two consecutive checks to be scheduled to run less than the | 418 // don't allow two consecutive checks to be scheduled to run less than the |
| 432 // tick rate apart. | 419 // tick rate apart. |
| 433 base::TimeTicks next_check_for_completed_copy_operations_time = | 420 base::TimeTicks next_check_for_completed_copy_operations_time = |
| 434 std::max(last_check_for_completed_copy_operations_time_ + | 421 std::max(last_check_for_completed_copy_operations_time_ + |
| 435 base::TimeDelta::FromMilliseconds( | 422 base::TimeDelta::FromMilliseconds( |
| 436 kCheckForCompletedCopyOperationsTickRateMs), | 423 kCheckForCompletedCopyOperationsTickRateMs), |
| 437 now); | 424 now); |
| 438 | 425 |
| 439 task_runner_->PostDelayedTask( | 426 task_runner_->PostDelayedTask( |
| 440 FROM_HERE, | 427 FROM_HERE, |
| 441 base::Bind(&OneCopyRasterWorkerPool::CheckForCompletedCopyOperations, | 428 base::Bind(&OneCopyTileTaskWorkerPool::CheckForCompletedCopyOperations, |
| 442 weak_ptr_factory_.GetWeakPtr(), | 429 weak_ptr_factory_.GetWeakPtr(), wait_if_needed), |
| 443 wait_if_needed), | |
| 444 next_check_for_completed_copy_operations_time - now); | 430 next_check_for_completed_copy_operations_time - now); |
| 445 | 431 |
| 446 last_check_for_completed_copy_operations_time_ = | 432 last_check_for_completed_copy_operations_time_ = |
| 447 next_check_for_completed_copy_operations_time; | 433 next_check_for_completed_copy_operations_time; |
| 448 check_for_completed_copy_operations_pending_ = true; | 434 check_for_completed_copy_operations_pending_ = true; |
| 449 } | 435 } |
| 450 | 436 |
| 451 void OneCopyRasterWorkerPool::CheckForCompletedCopyOperations( | 437 void OneCopyTileTaskWorkerPool::CheckForCompletedCopyOperations( |
| 452 bool wait_if_needed) { | 438 bool wait_if_needed) { |
| 453 TRACE_EVENT1("cc", | 439 TRACE_EVENT1("cc", |
| 454 "OneCopyRasterWorkerPool::CheckForCompletedCopyOperations", | 440 "OneCopyTileTaskWorkerPool::CheckForCompletedCopyOperations", |
| 455 "wait_if_needed", | 441 "wait_if_needed", wait_if_needed); |
| 456 wait_if_needed); | |
| 457 | 442 |
| 458 resource_pool_->CheckBusyResources(wait_if_needed); | 443 resource_pool_->CheckBusyResources(wait_if_needed); |
| 459 | 444 |
| 460 { | 445 { |
| 461 base::AutoLock lock(lock_); | 446 base::AutoLock lock(lock_); |
| 462 | 447 |
| 463 DCHECK(check_for_completed_copy_operations_pending_); | 448 DCHECK(check_for_completed_copy_operations_pending_); |
| 464 check_for_completed_copy_operations_pending_ = false; | 449 check_for_completed_copy_operations_pending_ = false; |
| 465 | 450 |
| 466 // The number of busy resources in the pool reflects the number of issued | 451 // The number of busy resources in the pool reflects the number of issued |
| 467 // copy operations that have not yet completed. | 452 // copy operations that have not yet completed. |
| 468 issued_copy_operation_count_ = resource_pool_->busy_resource_count(); | 453 issued_copy_operation_count_ = resource_pool_->busy_resource_count(); |
| 469 | 454 |
| 470 // There may be work blocked on too many in-flight copy operations, so wake | 455 // There may be work blocked on too many in-flight copy operations, so wake |
| 471 // up a worker thread. | 456 // up a worker thread. |
| 472 copy_operation_count_cv_.Signal(); | 457 copy_operation_count_cv_.Signal(); |
| 473 } | 458 } |
| 474 } | 459 } |
| 475 | 460 |
| 476 scoped_refptr<base::debug::ConvertableToTraceFormat> | 461 scoped_refptr<base::debug::ConvertableToTraceFormat> |
| 477 OneCopyRasterWorkerPool::StateAsValue() const { | 462 OneCopyTileTaskWorkerPool::StateAsValue() const { |
| 478 scoped_refptr<base::debug::TracedValue> state = | 463 scoped_refptr<base::debug::TracedValue> state = |
| 479 new base::debug::TracedValue(); | 464 new base::debug::TracedValue(); |
| 480 | 465 |
| 481 state->BeginArray("tasks_pending"); | 466 state->BeginArray("tasks_pending"); |
| 482 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) | 467 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) |
| 483 state->AppendBoolean(raster_pending_[task_set]); | 468 state->AppendBoolean(tasks_pending_[task_set]); |
| 484 state->EndArray(); | 469 state->EndArray(); |
| 485 state->BeginDictionary("staging_state"); | 470 state->BeginDictionary("staging_state"); |
| 486 StagingStateAsValueInto(state.get()); | 471 StagingStateAsValueInto(state.get()); |
| 487 state->EndDictionary(); | 472 state->EndDictionary(); |
| 488 | 473 |
| 489 return state; | 474 return state; |
| 490 } | 475 } |
| 491 | 476 |
| 492 void OneCopyRasterWorkerPool::StagingStateAsValueInto( | 477 void OneCopyTileTaskWorkerPool::StagingStateAsValueInto( |
| 493 base::debug::TracedValue* staging_state) const { | 478 base::debug::TracedValue* staging_state) const { |
| 494 staging_state->SetInteger("staging_resource_count", | 479 staging_state->SetInteger("staging_resource_count", |
| 495 resource_pool_->total_resource_count()); | 480 resource_pool_->total_resource_count()); |
| 496 staging_state->SetInteger("bytes_used_for_staging_resources", | 481 staging_state->SetInteger("bytes_used_for_staging_resources", |
| 497 resource_pool_->total_memory_usage_bytes()); | 482 resource_pool_->total_memory_usage_bytes()); |
| 498 staging_state->SetInteger("pending_copy_count", | 483 staging_state->SetInteger("pending_copy_count", |
| 499 resource_pool_->total_resource_count() - | 484 resource_pool_->total_resource_count() - |
| 500 resource_pool_->acquired_resource_count()); | 485 resource_pool_->acquired_resource_count()); |
| 501 staging_state->SetInteger("bytes_pending_copy", | 486 staging_state->SetInteger("bytes_pending_copy", |
| 502 resource_pool_->total_memory_usage_bytes() - | 487 resource_pool_->total_memory_usage_bytes() - |
| 503 resource_pool_->acquired_memory_usage_bytes()); | 488 resource_pool_->acquired_memory_usage_bytes()); |
| 504 } | 489 } |
| 505 | 490 |
| 506 } // namespace cc | 491 } // namespace cc |
| OLD | NEW |