Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Side by Side Diff: cc/raster/one_copy_tile_task_worker_pool.cc

Issue 1157943004: cc: [WIP] Use worker context and OrderingBarrierCHROMIUM for one-copy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: piman's comments Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 gl_lock_.reset(new ResourceProvider::ScopedWriteLockGL(
56 resource_provider_, output_resource_->id()));
57
58 lock_.reset(new ResourceProvider::ScopedWriteLockGpuMemoryBufferForThread(
55 resource_provider_, raster_resource_->id())); 59 resource_provider_, raster_resource_->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 66 gl_lock_.reset();
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 67 // Return resources to pool so they can be used by another RasterBuffer
68 // instance. 68 // instance.
69 resource_pool_->ReleaseResource(raster_resource_.Pass(), 69 resource_pool_->ReleaseResource(raster_resource_.Pass(),
70 raster_content_id_); 70 raster_content_id_);
71 } 71 }
72 72
73 // Overridden from RasterBuffer: 73 // Overridden from RasterBuffer:
74 void Playback(const RasterSource* raster_source, 74 void Playback(const RasterSource* raster_source,
75 const gfx::Rect& raster_full_rect, 75 const gfx::Rect& raster_full_rect,
76 const gfx::Rect& raster_dirty_rect, 76 const gfx::Rect& raster_dirty_rect,
77 uint64_t new_content_id, 77 uint64_t new_content_id,
78 float scale) override { 78 float scale) override {
79 // If there's a raster_content_id_, we are reusing a resource with that 79 // If there's a raster_content_id_, we are reusing a resource with that
80 // content id. 80 // content id.
81 bool reusing_raster_resource = raster_content_id_ != 0; 81 bool reusing_raster_resource = raster_content_id_ != 0;
82 sequence_ = worker_pool_->PlaybackAndScheduleCopyOnWorkerThread( 82 worker_pool_->PlaybackAndCopyOnWorkerThread(
83 reusing_raster_resource, lock_.Pass(), raster_resource_.get(), 83 reusing_raster_resource, lock_.Pass(), gl_lock_.Pass(),
piman 2015/07/10 02:25:09 Oh, actually, something I missed in previous revie
sohanjg 2015/07/10 13:34:31 Done.
84 output_resource_, raster_source, raster_full_rect, raster_dirty_rect, 84 raster_resource_.get(), output_resource_, raster_source,
85 scale); 85 raster_full_rect, raster_dirty_rect, scale);
86 // Store the content id of the resource to return to the pool. 86 // Store the content id of the resource to return to the pool.
87 raster_content_id_ = new_content_id; 87 raster_content_id_ = new_content_id;
88 } 88 }
89 89
90 private: 90 private:
91 OneCopyTileTaskWorkerPool* worker_pool_; 91 OneCopyTileTaskWorkerPool* worker_pool_;
92 ResourceProvider* resource_provider_; 92 ResourceProvider* resource_provider_;
93 ResourcePool* resource_pool_; 93 ResourcePool* resource_pool_;
94 const Resource* output_resource_; 94 const Resource* output_resource_;
95 uint64_t raster_content_id_; 95 uint64_t raster_content_id_;
96 scoped_ptr<ScopedResource> raster_resource_; 96 scoped_ptr<ScopedResource> raster_resource_;
97 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> lock_; 97 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBufferForThread> lock_;
98 CopySequenceNumber sequence_; 98 scoped_ptr<ResourceProvider::ScopedWriteLockGL> gl_lock_;
99 99
100 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); 100 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl);
101 }; 101 };
102 102
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 103 // 4MiB is the size of 4 512x512 tiles, which has proven to be a good
114 // default batch size for copy operations. 104 // default batch size for copy operations.
115 const int kMaxBytesPerCopyOperation = 1024 * 1024 * 4; 105 const int kMaxBytesPerCopyOperation = 1024 * 1024 * 4;
116 106
117 } // namespace 107 } // namespace
118 108
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 109 // static
131 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( 110 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create(
132 base::SequencedTaskRunner* task_runner, 111 base::SequencedTaskRunner* task_runner,
133 TaskGraphRunner* task_graph_runner, 112 TaskGraphRunner* task_graph_runner,
134 ContextProvider* context_provider, 113 ContextProvider* context_provider,
135 ResourceProvider* resource_provider, 114 ResourceProvider* resource_provider,
136 ResourcePool* resource_pool, 115 ResourcePool* resource_pool,
137 int max_copy_texture_chromium_size, 116 int max_copy_texture_chromium_size,
138 bool have_persistent_gpu_memory_buffers) { 117 bool have_persistent_gpu_memory_buffers) {
139 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool( 118 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool(
(...skipping 15 matching lines...) Expand all
155 namespace_token_(task_graph_runner->GetNamespaceToken()), 134 namespace_token_(task_graph_runner->GetNamespaceToken()),
156 context_provider_(context_provider), 135 context_provider_(context_provider),
157 resource_provider_(resource_provider), 136 resource_provider_(resource_provider),
158 resource_pool_(resource_pool), 137 resource_pool_(resource_pool),
159 max_bytes_per_copy_operation_( 138 max_bytes_per_copy_operation_(
160 max_copy_texture_chromium_size 139 max_copy_texture_chromium_size
161 ? std::min(kMaxBytesPerCopyOperation, 140 ? std::min(kMaxBytesPerCopyOperation,
162 max_copy_texture_chromium_size) 141 max_copy_texture_chromium_size)
163 : kMaxBytesPerCopyOperation), 142 : kMaxBytesPerCopyOperation),
164 have_persistent_gpu_memory_buffers_(have_persistent_gpu_memory_buffers), 143 have_persistent_gpu_memory_buffers_(have_persistent_gpu_memory_buffers),
165 last_issued_copy_operation_(0),
166 last_flushed_copy_operation_(0),
167 lock_(), 144 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), 145 shutdown_(false),
174 weak_ptr_factory_(this), 146 weak_ptr_factory_(this),
175 task_set_finished_weak_ptr_factory_(this) { 147 task_set_finished_weak_ptr_factory_(this) {
176 DCHECK(context_provider_); 148 DCHECK(context_provider_);
177 } 149 }
178 150
179 OneCopyTileTaskWorkerPool::~OneCopyTileTaskWorkerPool() { 151 OneCopyTileTaskWorkerPool::~OneCopyTileTaskWorkerPool() {
180 DCHECK_EQ(pending_copy_operations_.size(), 0u);
181 } 152 }
182 153
183 TileTaskRunner* OneCopyTileTaskWorkerPool::AsTileTaskRunner() { 154 TileTaskRunner* OneCopyTileTaskWorkerPool::AsTileTaskRunner() {
184 return this; 155 return this;
185 } 156 }
186 157
187 void OneCopyTileTaskWorkerPool::SetClient(TileTaskRunnerClient* client) { 158 void OneCopyTileTaskWorkerPool::SetClient(TileTaskRunnerClient* client) {
188 client_ = client; 159 client_ = client;
189 } 160 }
190 161
191 void OneCopyTileTaskWorkerPool::Shutdown() { 162 void OneCopyTileTaskWorkerPool::Shutdown() {
192 TRACE_EVENT0("cc", "OneCopyTileTaskWorkerPool::Shutdown"); 163 TRACE_EVENT0("cc", "OneCopyTileTaskWorkerPool::Shutdown");
193 164
194 { 165 {
195 base::AutoLock lock(lock_); 166 base::AutoLock lock(lock_);
196 167
197 shutdown_ = true; 168 shutdown_ = true;
198 copy_operation_count_cv_.Signal();
199 } 169 }
200 170
201 TaskGraph empty; 171 TaskGraph empty;
202 task_graph_runner_->ScheduleTasks(namespace_token_, &empty); 172 task_graph_runner_->ScheduleTasks(namespace_token_, &empty);
203 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_); 173 task_graph_runner_->WaitForTasksToFinishRunning(namespace_token_);
204 } 174 }
205 175
206 void OneCopyTileTaskWorkerPool::ScheduleTasks(TileTaskQueue* queue) { 176 void OneCopyTileTaskWorkerPool::ScheduleTasks(TileTaskQueue* queue) {
207 TRACE_EVENT0("cc", "OneCopyTileTaskWorkerPool::ScheduleTasks"); 177 TRACE_EVENT0("cc", "OneCopyTileTaskWorkerPool::ScheduleTasks");
208 178
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++); 228 InsertNodesForRasterTask(&graph_, task, task->dependencies(), priority++);
259 } 229 }
260 230
261 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) { 231 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) {
262 InsertNodeForTask(&graph_, new_task_set_finished_tasks[task_set].get(), 232 InsertNodeForTask(&graph_, new_task_set_finished_tasks[task_set].get(),
263 kTaskSetFinishedTaskPriorityBase + task_set, 233 kTaskSetFinishedTaskPriorityBase + task_set,
264 task_count[task_set]); 234 task_count[task_set]);
265 } 235 }
266 236
267 ScheduleTasksOnOriginThread(this, &graph_); 237 ScheduleTasksOnOriginThread(this, &graph_);
238
239 // Barrier to sync any new resources to the worker context.
240 resource_provider_->output_surface()
241 ->context_provider()
242 ->ContextGL()
243 ->OrderingBarrierCHROMIUM();
244
268 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_); 245 task_graph_runner_->ScheduleTasks(namespace_token_, &graph_);
269 246
270 std::copy(new_task_set_finished_tasks, 247 std::copy(new_task_set_finished_tasks,
271 new_task_set_finished_tasks + kNumberOfTaskSets, 248 new_task_set_finished_tasks + kNumberOfTaskSets,
272 task_set_finished_tasks_); 249 task_set_finished_tasks_);
273 250
274 resource_pool_->ReduceResourceUsage(); 251 resource_pool_->ReduceResourceUsage();
275 252
276 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", 253 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state",
277 StateAsValue()); 254 StateAsValue());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 new RasterBufferImpl(this, resource_provider_, resource_pool_, 292 new RasterBufferImpl(this, resource_provider_, resource_pool_,
316 resource_provider_->best_texture_format(), resource, 293 resource_provider_->best_texture_format(), resource,
317 previous_content_id)); 294 previous_content_id));
318 } 295 }
319 296
320 void OneCopyTileTaskWorkerPool::ReleaseBufferForRaster( 297 void OneCopyTileTaskWorkerPool::ReleaseBufferForRaster(
321 scoped_ptr<RasterBuffer> buffer) { 298 scoped_ptr<RasterBuffer> buffer) {
322 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. 299 // Nothing to do here. RasterBufferImpl destructor cleans up after itself.
323 } 300 }
324 301
325 CopySequenceNumber 302 void OneCopyTileTaskWorkerPool::PlaybackAndCopyOnWorkerThread(
326 OneCopyTileTaskWorkerPool::PlaybackAndScheduleCopyOnWorkerThread(
327 bool reusing_raster_resource, 303 bool reusing_raster_resource,
328 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> 304 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBufferForThread>
329 raster_resource_write_lock, 305 raster_resource_write_lock,
306 scoped_ptr<ResourceProvider::ScopedWriteLockGL> output_resource_write_lock,
330 const Resource* raster_resource, 307 const Resource* raster_resource,
331 const Resource* output_resource, 308 const Resource* output_resource,
332 const RasterSource* raster_source, 309 const RasterSource* raster_source,
333 const gfx::Rect& raster_full_rect, 310 const gfx::Rect& raster_full_rect,
334 const gfx::Rect& raster_dirty_rect, 311 const gfx::Rect& raster_dirty_rect,
335 float scale) { 312 float scale) {
313 TRACE_EVENT0("cc",
314 "OneCopyTileTaskWorkerPool::PlaybackAndCopyOnWorkerThread");
315 ContextProvider* context_provider =
316 raster_resource_write_lock->worker_context();
317 if (!context_provider) {
318 return;
319 }
320 GLES2Interface* gl = context_provider->ContextGL();
336 gfx::GpuMemoryBuffer* gpu_memory_buffer = 321 gfx::GpuMemoryBuffer* gpu_memory_buffer =
337 raster_resource_write_lock->GetGpuMemoryBuffer(); 322 raster_resource_write_lock->GetGpuMemoryBuffer();
323
338 if (gpu_memory_buffer) { 324 if (gpu_memory_buffer) {
339 void* data = NULL; 325 void* data = NULL;
340 bool rv = gpu_memory_buffer->Map(&data); 326 bool rv = gpu_memory_buffer->Map(&data);
341 DCHECK(rv); 327 DCHECK(rv);
342 int stride; 328 int stride;
343 gpu_memory_buffer->GetStride(&stride); 329 gpu_memory_buffer->GetStride(&stride);
344 // TileTaskWorkerPool::PlaybackToMemory only supports unsigned strides. 330 // TileTaskWorkerPool::PlaybackToMemory only supports unsigned strides.
345 DCHECK_GE(stride, 0); 331 DCHECK_GE(stride, 0);
346 332
347 gfx::Rect playback_rect = raster_full_rect; 333 gfx::Rect playback_rect = raster_full_rect;
348 if (reusing_raster_resource) { 334 if (reusing_raster_resource) {
349 playback_rect.Intersect(raster_dirty_rect); 335 playback_rect.Intersect(raster_dirty_rect);
350 } 336 }
351 DCHECK(!playback_rect.IsEmpty()) 337 DCHECK(!playback_rect.IsEmpty())
352 << "Why are we rastering a tile that's not dirty?"; 338 << "Why are we rastering a tile that's not dirty?";
353 TileTaskWorkerPool::PlaybackToMemory( 339 TileTaskWorkerPool::PlaybackToMemory(
354 data, raster_resource->format(), raster_resource->size(), 340 data, raster_resource_write_lock->format(),
355 static_cast<size_t>(stride), raster_source, raster_full_rect, 341 raster_resource_write_lock->size(), static_cast<size_t>(stride),
356 playback_rect, scale); 342 raster_source, raster_full_rect, playback_rect, scale);
357 gpu_memory_buffer->Unmap(); 343 gpu_memory_buffer->Unmap();
358 } 344 }
359 345
360 base::AutoLock lock(lock_); 346 raster_resource_write_lock->CreateAndBindImage();
361 347
362 CopySequenceNumber sequence = 0; 348 int bytes_per_row = (BitsPerPixel(raster_resource_write_lock->format()) *
363 int bytes_per_row = (BitsPerPixel(raster_resource->format()) * 349 raster_resource_write_lock->size().width()) /
364 raster_resource->size().width()) /
365 8; 350 8;
366 int chunk_size_in_rows = 351 int chunk_size_in_rows =
367 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row); 352 std::max(1, max_bytes_per_copy_operation_ / bytes_per_row);
368 // Align chunk size to 4. Required to support compressed texture formats. 353 // Align chunk size to 4. Required to support compressed texture formats.
369 chunk_size_in_rows = MathUtil::RoundUp(chunk_size_in_rows, 4); 354 chunk_size_in_rows = MathUtil::RoundUp(chunk_size_in_rows, 4);
370 int y = 0; 355 int y = 0;
371 int height = raster_resource->size().height(); 356 int height = raster_resource_write_lock->size().height();
372 while (y < height) { 357 while (y < height) {
373 int failed_attempts = 0; 358 base::AutoLock context_lock(*context_provider->GetLock());
374 while ((pending_copy_operations_.size() + issued_copy_operation_count_) >= 359 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|. 360 // Copy at most |chunk_size_in_rows|.
402 int rows_to_copy = std::min(chunk_size_in_rows, height - y); 361 int rows_to_copy = std::min(chunk_size_in_rows, height - y);
403 DCHECK_GT(rows_to_copy, 0); 362 DCHECK_GT(rows_to_copy, 0);
404 363 raster_resource_write_lock->BeginCopyTexture();
405 // |raster_resource_write_lock| is passed to the first copy operation as it 364 gl->CopySubTextureCHROMIUM(GL_TEXTURE_2D,
406 // needs to be released before we can issue a copy. 365 raster_resource_write_lock->source_gl_id(),
407 pending_copy_operations_.push_back(make_scoped_ptr(new CopyOperation( 366 output_resource_write_lock->texture_id(), 0, y,
408 raster_resource_write_lock.Pass(), raster_resource, output_resource, 367 0, y, raster_resource_write_lock->size().width(),
409 gfx::Rect(0, y, raster_resource->size().width(), rows_to_copy)))); 368 rows_to_copy, false, false, false);
369 raster_resource_write_lock->EndCopyTexture();
410 y += rows_to_copy; 370 y += rows_to_copy;
411 371 // Sync/Deferred flush worker context to cc context.
412 // Acquire a sequence number for this copy operation. 372 gl->OrderingBarrierCHROMIUM();
413 sequence = next_copy_operation_sequence_++; 373 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 } 374 }
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 } 375 }
454 376
455 void OneCopyTileTaskWorkerPool::OnTaskSetFinished(TaskSet task_set) { 377 void OneCopyTileTaskWorkerPool::OnTaskSetFinished(TaskSet task_set) {
456 TRACE_EVENT1("cc", "OneCopyTileTaskWorkerPool::OnTaskSetFinished", "task_set", 378 TRACE_EVENT1("cc", "OneCopyTileTaskWorkerPool::OnTaskSetFinished", "task_set",
457 task_set); 379 task_set);
458 380
459 DCHECK(tasks_pending_[task_set]); 381 DCHECK(tasks_pending_[task_set]);
460 tasks_pending_[task_set] = false; 382 tasks_pending_[task_set] = false;
461 if (tasks_pending_.any()) { 383 if (tasks_pending_.any()) {
462 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", 384 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running",
463 "state", StateAsValue()); 385 "state", StateAsValue());
464 } else { 386 } else {
465 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this); 387 TRACE_EVENT_ASYNC_END0("cc", "ScheduledTasks", this);
466 } 388 }
467 client_->DidFinishRunningTileTasks(task_set); 389 client_->DidFinishRunningTileTasks(task_set);
468 } 390 }
469 391
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> 392 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
557 OneCopyTileTaskWorkerPool::StateAsValue() const { 393 OneCopyTileTaskWorkerPool::StateAsValue() const {
558 scoped_refptr<base::trace_event::TracedValue> state = 394 scoped_refptr<base::trace_event::TracedValue> state =
559 new base::trace_event::TracedValue(); 395 new base::trace_event::TracedValue();
560 396
561 state->BeginArray("tasks_pending"); 397 state->BeginArray("tasks_pending");
562 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set) 398 for (TaskSet task_set = 0; task_set < kNumberOfTaskSets; ++task_set)
563 state->AppendBoolean(tasks_pending_[task_set]); 399 state->AppendBoolean(tasks_pending_[task_set]);
564 state->EndArray(); 400 state->EndArray();
565 state->BeginDictionary("staging_state"); 401 state->BeginDictionary("staging_state");
(...skipping 15 matching lines...) Expand all
581 "pending_copy_count", 417 "pending_copy_count",
582 static_cast<int>(resource_pool_->total_resource_count() - 418 static_cast<int>(resource_pool_->total_resource_count() -
583 resource_pool_->acquired_resource_count())); 419 resource_pool_->acquired_resource_count()));
584 staging_state->SetInteger( 420 staging_state->SetInteger(
585 "bytes_pending_copy", 421 "bytes_pending_copy",
586 static_cast<int>(resource_pool_->total_memory_usage_bytes() - 422 static_cast<int>(resource_pool_->total_memory_usage_bytes() -
587 resource_pool_->acquired_memory_usage_bytes())); 423 resource_pool_->acquired_memory_usage_bytes()));
588 } 424 }
589 425
590 } // namespace cc 426 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698