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/raster/one_copy_tile_task_worker_pool.h" | 5 #include "cc/raster/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/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
12 #include "base/trace_event/trace_event_argument.h" | 12 #include "base/trace_event/trace_event_argument.h" |
13 #include "cc/base/math_util.h" | 13 #include "cc/base/math_util.h" |
14 #include "cc/debug/traced_value.h" | 14 #include "cc/debug/traced_value.h" |
15 #include "cc/raster/raster_buffer.h" | 15 #include "cc/raster/raster_buffer.h" |
16 #include "cc/resources/platform_color.h" | 16 #include "cc/resources/platform_color.h" |
17 #include "cc/resources/resource_pool.h" | 17 #include "cc/resources/resource_pool.h" |
18 #include "cc/resources/scoped_resource.h" | 18 #include "cc/resources/scoped_resource.h" |
19 #include "gpu/command_buffer/client/gles2_interface.h" | 19 #include "gpu/command_buffer/client/gles2_interface.h" |
20 #include "ui/gfx/gpu_memory_buffer.h" | 20 #include "ui/gfx/gpu_memory_buffer.h" |
21 | 21 |
22 using gpu::gles2::GLES2Interface; | |
23 | |
22 namespace cc { | 24 namespace cc { |
23 namespace { | 25 namespace { |
24 | 26 |
25 class RasterBufferImpl : public RasterBuffer { | 27 class RasterBufferImpl : public RasterBuffer { |
26 public: | 28 public: |
27 RasterBufferImpl(OneCopyTileTaskWorkerPool* worker_pool, | 29 RasterBufferImpl(OneCopyTileTaskWorkerPool* worker_pool, |
28 ResourceProvider* resource_provider, | 30 ResourceProvider* resource_provider, |
29 ResourcePool* resource_pool, | 31 ResourcePool* resource_pool, |
30 ResourceFormat resource_format, | 32 ResourceFormat resource_format, |
31 const Resource* output_resource, | 33 const Resource* output_resource, |
32 uint64_t previous_content_id) | 34 uint64_t previous_content_id) |
33 : worker_pool_(worker_pool), | 35 : worker_pool_(worker_pool), |
34 resource_provider_(resource_provider), | 36 resource_provider_(resource_provider), |
35 resource_pool_(resource_pool), | 37 resource_pool_(resource_pool), |
36 output_resource_(output_resource), | 38 output_resource_(output_resource), |
37 raster_content_id_(0), | 39 raster_content_id_(0) { |
38 sequence_(0) { | |
39 if (worker_pool->have_persistent_gpu_memory_buffers() && | 40 if (worker_pool->have_persistent_gpu_memory_buffers() && |
40 previous_content_id) { | 41 previous_content_id) { |
41 raster_resource_ = | 42 raster_resource_ = |
42 resource_pool->TryAcquireResourceWithContentId(previous_content_id); | 43 resource_pool->TryAcquireResourceWithContentId(previous_content_id); |
43 } | 44 } |
44 if (raster_resource_) { | 45 if (raster_resource_) { |
45 raster_content_id_ = previous_content_id; | 46 raster_content_id_ = previous_content_id; |
46 DCHECK_EQ(resource_format, raster_resource_->format()); | 47 DCHECK_EQ(resource_format, raster_resource_->format()); |
47 DCHECK_EQ(output_resource->size().ToString(), | 48 DCHECK_EQ(output_resource->size().ToString(), |
48 raster_resource_->size().ToString()); | 49 raster_resource_->size().ToString()); |
49 } else { | 50 } else { |
50 raster_resource_ = resource_pool->AcquireResource(output_resource->size(), | 51 raster_resource_ = resource_pool->AcquireResource(output_resource->size(), |
51 resource_format); | 52 resource_format); |
52 } | 53 } |
53 | 54 |
54 lock_.reset(new ResourceProvider::ScopedWriteLockGpuMemoryBuffer( | 55 ResourceProvider::ScopedWriteLockGL gl_lock(resource_provider_, |
55 resource_provider_, raster_resource_->id())); | 56 output_resource_->id()); |
piman
2015/07/08 23:12:13
So, it's only valid to write to (copy to) the reso
sohanjg
2015/07/09 10:04:56
Done.
| |
57 | |
58 lock_.reset(new ResourceProvider::ScopedWriteLockGpuMemoryBufferForThread( | |
59 resource_provider_, raster_resource_->id(), gl_lock.texture_id())); | |
56 } | 60 } |
57 | 61 |
58 ~RasterBufferImpl() override { | 62 ~RasterBufferImpl() override { |
59 // Release write lock in case a copy was never scheduled. | 63 // Release write lock in case a copy was never scheduled. |
60 lock_.reset(); | 64 lock_.reset(); |
61 | 65 |
62 // Make sure any scheduled copy operations are issued before we release the | |
63 // raster resource. | |
64 if (sequence_) | |
65 worker_pool_->AdvanceLastIssuedCopyTo(sequence_); | |
66 | |
67 // Return resources to pool so they can be used by another RasterBuffer | 66 // Return resources to pool so they can be used by another RasterBuffer |
68 // instance. | 67 // instance. |
69 resource_pool_->ReleaseResource(raster_resource_.Pass(), | 68 resource_pool_->ReleaseResource(raster_resource_.Pass(), |
70 raster_content_id_); | 69 raster_content_id_); |
71 } | 70 } |
72 | 71 |
73 // Overridden from RasterBuffer: | 72 // Overridden from RasterBuffer: |
74 void Playback(const RasterSource* raster_source, | 73 void Playback(const RasterSource* raster_source, |
75 const gfx::Rect& raster_full_rect, | 74 const gfx::Rect& raster_full_rect, |
76 const gfx::Rect& raster_dirty_rect, | 75 const gfx::Rect& raster_dirty_rect, |
77 uint64_t new_content_id, | 76 uint64_t new_content_id, |
78 float scale) override { | 77 float scale) override { |
79 // If there's a raster_content_id_, we are reusing a resource with that | 78 // If there's a raster_content_id_, we are reusing a resource with that |
80 // content id. | 79 // content id. |
81 bool reusing_raster_resource = raster_content_id_ != 0; | 80 bool reusing_raster_resource = raster_content_id_ != 0; |
82 sequence_ = worker_pool_->PlaybackAndScheduleCopyOnWorkerThread( | 81 worker_pool_->PlaybackAndCopyOnWorkerThread( |
83 reusing_raster_resource, lock_.Pass(), raster_resource_.get(), | 82 reusing_raster_resource, lock_.Pass(), raster_resource_.get(), |
84 output_resource_, raster_source, raster_full_rect, raster_dirty_rect, | 83 output_resource_, raster_source, raster_full_rect, raster_dirty_rect, |
85 scale); | 84 scale); |
86 // Store the content id of the resource to return to the pool. | 85 // Store the content id of the resource to return to the pool. |
87 raster_content_id_ = new_content_id; | 86 raster_content_id_ = new_content_id; |
88 } | 87 } |
89 | 88 |
90 private: | 89 private: |
91 OneCopyTileTaskWorkerPool* worker_pool_; | 90 OneCopyTileTaskWorkerPool* worker_pool_; |
92 ResourceProvider* resource_provider_; | 91 ResourceProvider* resource_provider_; |
93 ResourcePool* resource_pool_; | 92 ResourcePool* resource_pool_; |
94 const Resource* output_resource_; | 93 const Resource* output_resource_; |
95 uint64_t raster_content_id_; | 94 uint64_t raster_content_id_; |
96 scoped_ptr<ScopedResource> raster_resource_; | 95 scoped_ptr<ScopedResource> raster_resource_; |
97 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> lock_; | 96 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBufferForThread> lock_; |
98 CopySequenceNumber sequence_; | |
99 | 97 |
100 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); | 98 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); |
101 }; | 99 }; |
102 | 100 |
103 // Number of in-flight copy operations to allow. | |
104 const int kMaxCopyOperations = 32; | |
105 | |
106 // Delay been checking for copy operations to complete. | |
107 const int kCheckForCompletedCopyOperationsTickRateMs = 1; | |
108 | |
109 // Number of failed attempts to allow before we perform a check that will | |
110 // wait for copy operations to complete if needed. | |
111 const int kFailedAttemptsBeforeWaitIfNeeded = 256; | |
112 | |
113 // 4MiB is the size of 4 512x512 tiles, which has proven to be a good | 101 // 4MiB is the size of 4 512x512 tiles, which has proven to be a good |
114 // default batch size for copy operations. | 102 // default batch size for copy operations. |
115 const int kMaxBytesPerCopyOperation = 1024 * 1024 * 4; | 103 const int kMaxBytesPerCopyOperation = 1024 * 1024 * 4; |
116 | 104 |
117 } // namespace | 105 } // namespace |
118 | 106 |
119 OneCopyTileTaskWorkerPool::CopyOperation::CopyOperation( | |
120 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> src_write_lock, | |
121 const Resource* src, | |
122 const Resource* dst, | |
123 const gfx::Rect& rect) | |
124 : src_write_lock(src_write_lock.Pass()), src(src), dst(dst), rect(rect) { | |
125 } | |
126 | |
127 OneCopyTileTaskWorkerPool::CopyOperation::~CopyOperation() { | |
128 } | |
129 | |
130 // static | 107 // static |
131 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( | 108 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( |
132 base::SequencedTaskRunner* task_runner, | 109 base::SequencedTaskRunner* task_runner, |
133 TaskGraphRunner* task_graph_runner, | 110 TaskGraphRunner* task_graph_runner, |
134 ContextProvider* context_provider, | 111 ContextProvider* context_provider, |
135 ResourceProvider* resource_provider, | 112 ResourceProvider* resource_provider, |
136 ResourcePool* resource_pool, | 113 ResourcePool* resource_pool, |
137 int max_copy_texture_chromium_size, | 114 int max_copy_texture_chromium_size, |
138 bool have_persistent_gpu_memory_buffers) { | 115 bool have_persistent_gpu_memory_buffers) { |
139 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool( | 116 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool( |
(...skipping 15 matching lines...) Expand all Loading... | |
155 namespace_token_(task_graph_runner->GetNamespaceToken()), | 132 namespace_token_(task_graph_runner->GetNamespaceToken()), |
156 context_provider_(context_provider), | 133 context_provider_(context_provider), |
157 resource_provider_(resource_provider), | 134 resource_provider_(resource_provider), |
158 resource_pool_(resource_pool), | 135 resource_pool_(resource_pool), |
159 max_bytes_per_copy_operation_( | 136 max_bytes_per_copy_operation_( |
160 max_copy_texture_chromium_size | 137 max_copy_texture_chromium_size |
161 ? std::min(kMaxBytesPerCopyOperation, | 138 ? std::min(kMaxBytesPerCopyOperation, |
162 max_copy_texture_chromium_size) | 139 max_copy_texture_chromium_size) |
163 : kMaxBytesPerCopyOperation), | 140 : kMaxBytesPerCopyOperation), |
164 have_persistent_gpu_memory_buffers_(have_persistent_gpu_memory_buffers), | 141 have_persistent_gpu_memory_buffers_(have_persistent_gpu_memory_buffers), |
165 last_issued_copy_operation_(0), | |
166 last_flushed_copy_operation_(0), | |
167 lock_(), | 142 lock_(), |
168 copy_operation_count_cv_(&lock_), | |
169 bytes_scheduled_since_last_flush_(0), | |
170 issued_copy_operation_count_(0), | |
171 next_copy_operation_sequence_(1), | |
172 check_for_completed_copy_operations_pending_(false), | |
173 shutdown_(false), | 143 shutdown_(false), |
174 weak_ptr_factory_(this), | 144 weak_ptr_factory_(this), |
175 task_set_finished_weak_ptr_factory_(this) { | 145 task_set_finished_weak_ptr_factory_(this) { |
176 DCHECK(context_provider_); | 146 DCHECK(context_provider_); |
177 } | 147 } |
178 | 148 |
179 OneCopyTileTaskWorkerPool::~OneCopyTileTaskWorkerPool() { | 149 OneCopyTileTaskWorkerPool::~OneCopyTileTaskWorkerPool() { |
180 DCHECK_EQ(pending_copy_operations_.size(), 0u); | |
181 } | 150 } |
182 | 151 |
183 TileTaskRunner* OneCopyTileTaskWorkerPool::AsTileTaskRunner() { | 152 TileTaskRunner* OneCopyTileTaskWorkerPool::AsTileTaskRunner() { |
184 return this; | 153 return this; |
185 } | 154 } |
186 | 155 |
187 void OneCopyTileTaskWorkerPool::SetClient(TileTaskRunnerClient* client) { | 156 void OneCopyTileTaskWorkerPool::SetClient(TileTaskRunnerClient* client) { |
188 client_ = client; | 157 client_ = client; |
189 } | 158 } |
190 | 159 |
191 void OneCopyTileTaskWorkerPool::Shutdown() { | 160 void OneCopyTileTaskWorkerPool::Shutdown() { |
192 TRACE_EVENT0("cc", "OneCopyTileTaskWorkerPool::Shutdown"); | 161 TRACE_EVENT0("cc", "OneCopyTileTaskWorkerPool::Shutdown"); |
193 | 162 |
194 { | 163 { |
195 base::AutoLock lock(lock_); | 164 base::AutoLock lock(lock_); |
196 | 165 |
197 shutdown_ = true; | 166 shutdown_ = true; |
198 copy_operation_count_cv_.Signal(); | |
199 } | 167 } |
200 | 168 |
201 TaskGraph empty; | 169 TaskGraph empty; |
202 task_graph_runner_->ScheduleTasks(namespace_token_, &empty); | 170 task_graph_runner_->ScheduleTasks(namespace_token_, &empty); |
203 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); | 171 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); |
204 } | 172 } |
205 | 173 |
206 void OneCopyTileTaskWorkerPool::ScheduleTasks(TileTaskQueue* queue) { | 174 void OneCopyTileTaskWorkerPool::ScheduleTasks(TileTaskQueue* queue) { |
207 TRACE_EVENT0("cc", "OneCopyTileTaskWorkerPool::ScheduleTasks"); | 175 TRACE_EVENT0("cc", "OneCopyTileTaskWorkerPool::ScheduleTasks"); |
208 | 176 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++); | 226 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++); |
259 } | 227 } |
260 | 228 |
261 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { | 229 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { |
262 InsertNodeForTask(&graph_, new_task_set_finished_tasks[task_set].get(), | 230 InsertNodeForTask(&graph_, new_task_set_finished_tasks[task_set].get(), |
263 kTaskSetFinishedTaskPriorityBase + task_set, | 231 kTaskSetFinishedTaskPriorityBase + task_set, |
264 task_count[task_set]); | 232 task_count[task_set]); |
265 } | 233 } |
266 | 234 |
267 ScheduleTasksOnOriginThread(this, &graph_); | 235 ScheduleTasksOnOriginThread(this, &graph_); |
236 | |
237 // Barrier to sync any new resources to the worker context. | |
238 resource_provider_->output_surface() | |
239 ->context_provider() | |
240 ->ContextGL() | |
241 ->OrderingBarrierCHROMIUM(); | |
242 | |
268 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_); | 243 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_); |
269 | 244 |
270 std::copy(new_task_set_finished_tasks, | 245 std::copy(new_task_set_finished_tasks, |
271 new_task_set_finished_tasks + kNumberOfTaskSets, | 246 new_task_set_finished_tasks + kNumberOfTaskSets, |
272 task_set_finished_tasks_); | 247 task_set_finished_tasks_); |
273 | 248 |
274 resource_pool_->ReduceResourceUsage(); | 249 resource_pool_->ReduceResourceUsage(); |
275 | 250 |
276 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", | 251 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", |
277 StateAsValue()); | 252 StateAsValue()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 new RasterBufferImpl(this, resource_provider_, resource_pool_, | 290 new RasterBufferImpl(this, resource_provider_, resource_pool_, |
316 resource_provider_->best_texture_format(), resource, | 291 resource_provider_->best_texture_format(), resource, |
317 previous_content_id)); | 292 previous_content_id)); |
318 } | 293 } |
319 | 294 |
320 void OneCopyTileTaskWorkerPool::ReleaseBufferForRaster( | 295 void OneCopyTileTaskWorkerPool::ReleaseBufferForRaster( |
321 scoped_ptr<RasterBuffer> buffer) { | 296 scoped_ptr<RasterBuffer> buffer) { |
322 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. | 297 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. |
323 } | 298 } |
324 | 299 |
325 CopySequenceNumber | 300 void OneCopyTileTaskWorkerPool::PlaybackAndCopyOnWorkerThread( |
326 OneCopyTileTaskWorkerPool::PlaybackAndScheduleCopyOnWorkerThread( | |
327 bool reusing_raster_resource, | 301 bool reusing_raster_resource, |
328 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> | 302 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBufferForThread> |
329 raster_resource_write_lock, | 303 raster_resource_write_lock, |
330 const Resource* raster_resource, | 304 const Resource* raster_resource, |
331 const Resource* output_resource, | 305 const Resource* output_resource, |
332 const RasterSource* raster_source, | 306 const RasterSource* raster_source, |
333 const gfx::Rect& raster_full_rect, | 307 const gfx::Rect& raster_full_rect, |
334 const gfx::Rect& raster_dirty_rect, | 308 const gfx::Rect& raster_dirty_rect, |
335 float scale) { | 309 float scale) { |
310 TRACE_EVENT0("cc", | |
311 "OneCopyTileTaskWorkerPool::PlaybackAndCopyOnWorkerThread"); | |
312 ContextProvider* context_provider = | |
313 raster_resource_write_lock->worker_context(); | |
314 if (!context_provider) { | |
315 return; | |
316 } | |
317 GLES2Interface* gl = context_provider->ContextGL(); | |
336 gfx::GpuMemoryBuffer* gpu_memory_buffer = | 318 gfx::GpuMemoryBuffer* gpu_memory_buffer = |
337 raster_resource_write_lock->GetGpuMemoryBuffer(); | 319 raster_resource_write_lock->GetGpuMemoryBuffer(); |
320 | |
338 if (gpu_memory_buffer) { | 321 if (gpu_memory_buffer) { |
339 void* data = NULL; | 322 void* data = NULL; |
340 bool rv = gpu_memory_buffer->Map(&data); | 323 bool rv = gpu_memory_buffer->Map(&data); |
341 DCHECK(rv); | 324 DCHECK(rv); |
342 int stride; | 325 int stride; |
343 gpu_memory_buffer->GetStride(&stride); | 326 gpu_memory_buffer->GetStride(&stride); |
344 // TileTaskWorkerPool::PlaybackToMemory only supports unsigned strides. | 327 // TileTaskWorkerPool::PlaybackToMemory only supports unsigned strides. |
345 DCHECK_GE(stride, 0); | 328 DCHECK_GE(stride, 0); |
346 | 329 |
347 gfx::Rect playback_rect = raster_full_rect; | 330 gfx::Rect playback_rect = raster_full_rect; |
348 if (reusing_raster_resource) { | 331 if (reusing_raster_resource) { |
349 playback_rect.Intersect(raster_dirty_rect); | 332 playback_rect.Intersect(raster_dirty_rect); |
350 } | 333 } |
351 DCHECK(!playback_rect.IsEmpty()) | 334 DCHECK(!playback_rect.IsEmpty()) |
352 << "Why are we rastering a tile that's not dirty?"; | 335 << "Why are we rastering a tile that's not dirty?"; |
353 TileTaskWorkerPool::PlaybackToMemory( | 336 TileTaskWorkerPool::PlaybackToMemory( |
354 data, raster_resource->format(), raster_resource->size(), | 337 data, raster_resource_write_lock->format(), |
355 static_cast<size_t>(stride), raster_source, raster_full_rect, | 338 raster_resource_write_lock->size(), static_cast<size_t>(stride), |
356 playback_rect, scale); | 339 raster_source, raster_full_rect, playback_rect, scale); |
357 gpu_memory_buffer->Unmap(); | 340 gpu_memory_buffer->Unmap(); |
358 } | 341 } |
359 | 342 |
360 base::AutoLock lock(lock_); | 343 raster_resource_write_lock->CreateAndBindImage(); |
361 | 344 |
362 CopySequenceNumber sequence = 0; | 345 int bytes_per_row = (BitsPerPixel(raster_resource_write_lock->format()) * |
363 int bytes_per_row = (BitsPerPixel(raster_resource->format()) * | 346 raster_resource_write_lock->size().width()) / |
364 raster_resource->size().width()) / | |
365 8; | 347 8; |
366 int chunk_size_in_rows = | 348 int chunk_size_in_rows = |
367 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); | 349 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); |
368 // Align chunk size to 4. Required to support compressed texture formats. | 350 // Align chunk size to 4. Required to support compressed texture formats. |
369 chunk_size_in_rows = MathUtil::RoundUp(chunk_size_in_rows, 4); | 351 chunk_size_in_rows = MathUtil::RoundUp(chunk_size_in_rows, 4); |
370 int y = 0; | 352 int y = 0; |
371 int height = raster_resource->size().height(); | 353 int height = raster_resource_write_lock->size().height(); |
372 while (y < height) { | 354 while (y < height) { |
373 int failed_attempts = 0; | 355 base::AutoLock context_lock(*context_provider->GetLock()); |
374 while ((pending_copy_operations_.size() + issued_copy_operation_count_) >= | 356 context_provider->DetachFromThread(); |
375 kMaxCopyOperations) { | |
376 // Ignore limit when shutdown is set. | |
377 if (shutdown_) | |
378 break; | |
379 | |
380 ++failed_attempts; | |
381 | |
382 // Schedule a check that will also wait for operations to complete | |
383 // after too many failed attempts. | |
384 bool wait_if_needed = failed_attempts > kFailedAttemptsBeforeWaitIfNeeded; | |
385 | |
386 // Schedule a check for completed copy operations if too many operations | |
387 // are currently in-flight. | |
388 ScheduleCheckForCompletedCopyOperationsWithLockAcquired(wait_if_needed); | |
389 | |
390 { | |
391 TRACE_EVENT0("cc", "WaitingForCopyOperationsToComplete"); | |
392 | |
393 // Wait for in-flight copy operations to drop below limit. | |
394 copy_operation_count_cv_.Wait(); | |
395 } | |
396 } | |
397 | |
398 // There may be more work available, so wake up another worker thread. | |
399 copy_operation_count_cv_.Signal(); | |
400 | |
401 // Copy at most |chunk_size_in_rows|. | 357 // Copy at most |chunk_size_in_rows|. |
402 int rows_to_copy = std::min(chunk_size_in_rows, height - y); | 358 int rows_to_copy = std::min(chunk_size_in_rows, height - y); |
403 DCHECK_GT(rows_to_copy, 0); | 359 DCHECK_GT(rows_to_copy, 0); |
404 | 360 raster_resource_write_lock->BeginCopyTexture(); |
405 // |raster_resource_write_lock| is passed to the first copy operation as it | 361 gl->CopySubTextureCHROMIUM(GL_TEXTURE_2D, |
406 // needs to be released before we can issue a copy. | 362 raster_resource_write_lock->source_gl_id(), |
407 pending_copy_operations_.push_back(make_scoped_ptr(new CopyOperation( | 363 raster_resource_write_lock->dest_gl_id(), 0, y, |
408 raster_resource_write_lock.Pass(), raster_resource, output_resource, | 364 0, y, raster_resource_write_lock->size().width(), |
409 gfx::Rect(0, y, raster_resource->size().width(), rows_to_copy)))); | 365 rows_to_copy, false, false, false); |
366 raster_resource_write_lock->EndCopyTexture(); | |
410 y += rows_to_copy; | 367 y += rows_to_copy; |
411 | 368 // Sync/Deferred flush worker context to cc context. |
412 // Acquire a sequence number for this copy operation. | 369 gl->OrderingBarrierCHROMIUM(); |
413 sequence = next_copy_operation_sequence_++; | 370 context_provider->DetachFromThread(); |
414 | |
415 // Increment |bytes_scheduled_since_last_flush_| by the amount of memory | |
416 // used for this copy operation. | |
417 bytes_scheduled_since_last_flush_ += rows_to_copy * bytes_per_row; | |
418 | |
419 // Post task that will advance last flushed copy operation to |sequence| | |
420 // when |bytes_scheduled_since_last_flush_| has reached | |
421 // |max_bytes_per_copy_operation_|. | |
422 if (bytes_scheduled_since_last_flush_ >= max_bytes_per_copy_operation_) { | |
423 task_runner_->PostTask( | |
424 FROM_HERE, | |
425 base::Bind(&OneCopyTileTaskWorkerPool::AdvanceLastFlushedCopyTo, | |
426 weak_ptr_factory_.GetWeakPtr(), sequence)); | |
427 bytes_scheduled_since_last_flush_ = 0; | |
428 } | |
429 } | 371 } |
430 | |
431 return sequence; | |
432 } | |
433 | |
434 void OneCopyTileTaskWorkerPool::AdvanceLastIssuedCopyTo( | |
435 CopySequenceNumber sequence) { | |
436 if (last_issued_copy_operation_ >= sequence) | |
437 return; | |
438 | |
439 IssueCopyOperations(sequence - last_issued_copy_operation_); | |
440 last_issued_copy_operation_ = sequence; | |
441 } | |
442 | |
443 void OneCopyTileTaskWorkerPool::AdvanceLastFlushedCopyTo( | |
444 CopySequenceNumber sequence) { | |
445 if (last_flushed_copy_operation_ >= sequence) | |
446 return; | |
447 | |
448 AdvanceLastIssuedCopyTo(sequence); | |
449 | |
450 // Flush all issued copy operations. | |
451 context_provider_->ContextGL()->ShallowFlushCHROMIUM(); | |
452 last_flushed_copy_operation_ = last_issued_copy_operation_; | |
453 } | 372 } |
454 | 373 |
455 void OneCopyTileTaskWorkerPool::OnTaskSetFinished(TaskSet task_set) { | 374 void OneCopyTileTaskWorkerPool::OnTaskSetFinished(TaskSet task_set) { |
456 TRACE_EVENT1("cc", "OneCopyTileTaskWorkerPool::OnTaskSetFinished", "task_set", | 375 TRACE_EVENT1("cc", "OneCopyTileTaskWorkerPool::OnTaskSetFinished", "task_set", |
457 task_set); | 376 task_set); |
458 | 377 |
459 DCHECK(tasks_pending_[task_set]); | 378 DCHECK(tasks_pending_[task_set]); |
460 tasks_pending_[task_set] = false; | 379 tasks_pending_[task_set] = false; |
461 if (tasks_pending_.any()) { | 380 if (tasks_pending_.any()) { |
462 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", | 381 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", |
463 "state", StateAsValue()); | 382 "state", StateAsValue()); |
464 } else { | 383 } else { |
465 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); | 384 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); |
466 } | 385 } |
467 client_->DidFinishRunningTileTasks(task_set); | 386 client_->DidFinishRunningTileTasks(task_set); |
468 } | 387 } |
469 | 388 |
470 void OneCopyTileTaskWorkerPool::IssueCopyOperations(int64 count) { | |
471 TRACE_EVENT1("cc", "OneCopyTileTaskWorkerPool::IssueCopyOperations", "count", | |
472 count); | |
473 | |
474 CopyOperation::Deque copy_operations; | |
475 | |
476 { | |
477 base::AutoLock lock(lock_); | |
478 | |
479 for (int64 i = 0; i < count; ++i) { | |
480 DCHECK(!pending_copy_operations_.empty()); | |
481 copy_operations.push_back(pending_copy_operations_.take_front()); | |
482 } | |
483 | |
484 // Increment |issued_copy_operation_count_| to reflect the transition of | |
485 // copy operations from "pending" to "issued" state. | |
486 issued_copy_operation_count_ += copy_operations.size(); | |
487 } | |
488 | |
489 while (!copy_operations.empty()) { | |
490 scoped_ptr<CopyOperation> copy_operation = copy_operations.take_front(); | |
491 | |
492 // Remove the write lock. | |
493 copy_operation->src_write_lock.reset(); | |
494 | |
495 // Copy contents of source resource to destination resource. | |
496 resource_provider_->CopyResource(copy_operation->src->id(), | |
497 copy_operation->dst->id(), | |
498 copy_operation->rect); | |
499 } | |
500 } | |
501 | |
502 void OneCopyTileTaskWorkerPool:: | |
503 ScheduleCheckForCompletedCopyOperationsWithLockAcquired( | |
504 bool wait_if_needed) { | |
505 lock_.AssertAcquired(); | |
506 | |
507 if (check_for_completed_copy_operations_pending_) | |
508 return; | |
509 | |
510 base::TimeTicks now = base::TimeTicks::Now(); | |
511 | |
512 // Schedule a check for completed copy operations as soon as possible but | |
513 // don't allow two consecutive checks to be scheduled to run less than the | |
514 // tick rate apart. | |
515 base::TimeTicks next_check_for_completed_copy_operations_time = | |
516 std::max(last_check_for_completed_copy_operations_time_ + | |
517 base::TimeDelta::FromMilliseconds( | |
518 kCheckForCompletedCopyOperationsTickRateMs), | |
519 now); | |
520 | |
521 task_runner_->PostDelayedTask( | |
522 FROM_HERE, | |
523 base::Bind(&OneCopyTileTaskWorkerPool::CheckForCompletedCopyOperations, | |
524 weak_ptr_factory_.GetWeakPtr(), wait_if_needed), | |
525 next_check_for_completed_copy_operations_time - now); | |
526 | |
527 last_check_for_completed_copy_operations_time_ = | |
528 next_check_for_completed_copy_operations_time; | |
529 check_for_completed_copy_operations_pending_ = true; | |
530 } | |
531 | |
532 void OneCopyTileTaskWorkerPool::CheckForCompletedCopyOperations( | |
533 bool wait_if_needed) { | |
534 TRACE_EVENT1("cc", | |
535 "OneCopyTileTaskWorkerPool::CheckForCompletedCopyOperations", | |
536 "wait_if_needed", wait_if_needed); | |
537 | |
538 resource_pool_->CheckBusyResources(wait_if_needed); | |
539 | |
540 { | |
541 base::AutoLock lock(lock_); | |
542 | |
543 DCHECK(check_for_completed_copy_operations_pending_); | |
544 check_for_completed_copy_operations_pending_ = false; | |
545 | |
546 // The number of busy resources in the pool reflects the number of issued | |
547 // copy operations that have not yet completed. | |
548 issued_copy_operation_count_ = resource_pool_->busy_resource_count(); | |
549 | |
550 // There may be work blocked on too many in-flight copy operations, so wake | |
551 // up a worker thread. | |
552 copy_operation_count_cv_.Signal(); | |
553 } | |
554 } | |
555 | |
556 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 389 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
557 OneCopyTileTaskWorkerPool::StateAsValue() const { | 390 OneCopyTileTaskWorkerPool::StateAsValue() const { |
558 scoped_refptr<base::trace_event::TracedValue> state = | 391 scoped_refptr<base::trace_event::TracedValue> state = |
559 new base::trace_event::TracedValue(); | 392 new base::trace_event::TracedValue(); |
560 | 393 |
561 state->BeginArray("tasks_pending"); | 394 state->BeginArray("tasks_pending"); |
562 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) | 395 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) |
563 state->AppendBoolean(tasks_pending_[task_set]); | 396 state->AppendBoolean(tasks_pending_[task_set]); |
564 state->EndArray(); | 397 state->EndArray(); |
565 state->BeginDictionary("staging_state"); | 398 state->BeginDictionary("staging_state"); |
(...skipping 15 matching lines...) Expand all Loading... | |
581 "pending_copy_count", | 414 "pending_copy_count", |
582 static_cast<int>(resource_pool_->total_resource_count() - | 415 static_cast<int>(resource_pool_->total_resource_count() - |
583 resource_pool_->acquired_resource_count())); | 416 resource_pool_->acquired_resource_count())); |
584 staging_state->SetInteger( | 417 staging_state->SetInteger( |
585 "bytes_pending_copy", | 418 "bytes_pending_copy", |
586 static_cast<int>(resource_pool_->total_memory_usage_bytes() - | 419 static_cast<int>(resource_pool_->total_memory_usage_bytes() - |
587 resource_pool_->acquired_memory_usage_bytes())); | 420 resource_pool_->acquired_memory_usage_bytes())); |
588 } | 421 } |
589 | 422 |
590 } // namespace cc | 423 } // namespace cc |
OLD | NEW |