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

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

Issue 1139063002: cc: Partial tile update for one-copy raster. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: monocle: rebase Created 5 years, 6 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/resource_pool.h" 16 #include "cc/resources/resource_pool.h"
17 #include "cc/resources/scoped_resource.h" 17 #include "cc/resources/scoped_resource.h"
18 #include "gpu/command_buffer/client/gles2_interface.h" 18 #include "gpu/command_buffer/client/gles2_interface.h"
19 #include "ui/gfx/gpu_memory_buffer.h" 19 #include "ui/gfx/gpu_memory_buffer.h"
20 20
21 namespace cc { 21 namespace cc {
22 namespace { 22 namespace {
23 23
24 class RasterBufferImpl : public RasterBuffer { 24 class RasterBufferImpl : public RasterBuffer {
25 public: 25 public:
26 RasterBufferImpl(OneCopyTileTaskWorkerPool* worker_pool, 26 RasterBufferImpl(OneCopyTileTaskWorkerPool* worker_pool,
27 ResourceProvider* resource_provider, 27 ResourceProvider* resource_provider,
28 ResourcePool* resource_pool, 28 ResourcePool* resource_pool,
29 ResourceFormat resource_format, 29 ResourceFormat resource_format,
30 const Resource* resource) 30 const Resource* output_resource,
31 uint64_t new_content_id,
32 uint64_t previous_content_id)
31 : worker_pool_(worker_pool), 33 : worker_pool_(worker_pool),
32 resource_provider_(resource_provider), 34 resource_provider_(resource_provider),
33 resource_pool_(resource_pool), 35 resource_pool_(resource_pool),
34 resource_(resource), 36 output_resource_(output_resource),
35 raster_resource_( 37 new_content_id_(new_content_id),
36 resource_pool->AcquireResource(resource->size(), resource_format)), 38 previous_content_id_(previous_content_id),
37 lock_(new ResourceProvider::ScopedWriteLockGpuMemoryBuffer( 39 reusing_raster_resource_(true),
38 resource_provider_, 40 sequence_(0) {
39 raster_resource_->id())), 41 if (worker_pool->have_persistent_gpu_memory_buffers() &&
40 sequence_(0) {} 42 previous_content_id) {
43 raster_resource_ =
44 resource_pool->TryAcquireResourceWithContentId(previous_content_id);
45 }
46 if (raster_resource_) {
47 DCHECK_EQ(resource_format, raster_resource_->format());
48 DCHECK_EQ(output_resource->size().ToString(),
49 raster_resource_->size().ToString());
50 } else {
51 raster_resource_ = resource_pool->AcquireResource(output_resource->size(),
52 resource_format);
53 reusing_raster_resource_ = false;
54 }
55
56 lock_.reset(new ResourceProvider::ScopedWriteLockGpuMemoryBuffer(
57 resource_provider_, raster_resource_->id()));
58 }
41 59
42 ~RasterBufferImpl() override { 60 ~RasterBufferImpl() override {
43 // Release write lock in case a copy was never scheduled. 61 // Release write lock in case a copy was never scheduled.
44 lock_.reset(); 62 lock_.reset();
45 63
46 // Make sure any scheduled copy operations are issued before we release the 64 // Make sure any scheduled copy operations are issued before we release the
47 // raster resource. 65 // raster resource.
48 if (sequence_) 66 bool did_playback = sequence_ != 0;
67 if (did_playback)
49 worker_pool_->AdvanceLastIssuedCopyTo(sequence_); 68 worker_pool_->AdvanceLastIssuedCopyTo(sequence_);
50 69
51 // Return raster resource to pool so it can be used by another RasterBuffer 70 // Return resources to pool so they can be used by another RasterBuffer
52 // instance. 71 // instance.
53 if (raster_resource_) 72 uint64_t id(did_playback ? new_content_id_ : previous_content_id_);
54 resource_pool_->ReleaseResource(raster_resource_.Pass()); 73 resource_pool_->ReleaseResource(raster_resource_.Pass(), id);
55 } 74 }
56 75
57 // Overridden from RasterBuffer: 76 // Overridden from RasterBuffer:
58 void Playback(const RasterSource* raster_source, 77 void Playback(const RasterSource* raster_source,
59 const gfx::Rect& rect, 78 const gfx::Rect& raster_full_rect,
79 const gfx::Rect& raster_dirty_rect,
60 float scale) override { 80 float scale) override {
61 sequence_ = worker_pool_->PlaybackAndScheduleCopyOnWorkerThread( 81 sequence_ = worker_pool_->PlaybackAndScheduleCopyOnWorkerThread(
62 lock_.Pass(), raster_resource_.get(), resource_, raster_source, rect, 82 reusing_raster_resource_, lock_.Pass(), raster_resource_.get(),
83 output_resource_, raster_source, raster_full_rect, raster_dirty_rect,
63 scale); 84 scale);
64 } 85 }
65 86
66 private: 87 private:
67 OneCopyTileTaskWorkerPool* worker_pool_; 88 OneCopyTileTaskWorkerPool* worker_pool_;
68 ResourceProvider* resource_provider_; 89 ResourceProvider* resource_provider_;
69 ResourcePool* resource_pool_; 90 ResourcePool* resource_pool_;
70 const Resource* resource_; 91 const Resource* output_resource_;
92 uint64_t new_content_id_;
93 uint64_t previous_content_id_;
94 bool reusing_raster_resource_;
71 scoped_ptr<ScopedResource> raster_resource_; 95 scoped_ptr<ScopedResource> raster_resource_;
72 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> lock_; 96 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> lock_;
73 CopySequenceNumber sequence_; 97 CopySequenceNumber sequence_;
74 98
75 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); 99 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl);
76 }; 100 };
77 101
78 // Flush interval when performing copy operations. 102 // Flush interval when performing copy operations.
79 const int kCopyFlushPeriod = 4; 103 const int kCopyFlushPeriod = 4;
80 104
81 // Number of in-flight copy operations to allow. 105 // Number of in-flight copy operations to allow.
82 const int kMaxCopyOperations = 32; 106 const int kMaxCopyOperations = 32;
83 107
84 // Delay been checking for copy operations to complete. 108 // Delay been checking for copy operations to complete.
85 const int kCheckForCompletedCopyOperationsTickRateMs = 1; 109 const int kCheckForCompletedCopyOperationsTickRateMs = 1;
86 110
87 // Number of failed attempts to allow before we perform a check that will 111 // Number of failed attempts to allow before we perform a check that will
88 // wait for copy operations to complete if needed. 112 // wait for copy operations to complete if needed.
89 const int kFailedAttemptsBeforeWaitIfNeeded = 256; 113 const int kFailedAttemptsBeforeWaitIfNeeded = 256;
90 114
91 } // namespace 115 } // namespace
92 116
93 OneCopyTileTaskWorkerPool::CopyOperation::CopyOperation( 117 OneCopyTileTaskWorkerPool::CopyOperation::CopyOperation(
94 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock, 118 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> src_write_lock,
95 const Resource* src, 119 const Resource* src,
96 const Resource* dst, 120 const Resource* dst,
97 const gfx::Rect& rect) 121 const gfx::Rect& rect)
98 : write_lock(write_lock.Pass()), src(src), dst(dst), rect(rect) { 122 : src_write_lock(src_write_lock.Pass()), src(src), dst(dst), rect(rect) {
99 } 123 }
100 124
101 OneCopyTileTaskWorkerPool::CopyOperation::~CopyOperation() { 125 OneCopyTileTaskWorkerPool::CopyOperation::~CopyOperation() {
102 } 126 }
103 127
104 // static 128 // static
105 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( 129 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create(
106 base::SequencedTaskRunner* task_runner, 130 base::SequencedTaskRunner* task_runner,
107 TaskGraphRunner* task_graph_runner, 131 TaskGraphRunner* task_graph_runner,
108 ContextProvider* context_provider, 132 ContextProvider* context_provider,
109 ResourceProvider* resource_provider, 133 ResourceProvider* resource_provider,
110 ResourcePool* resource_pool, 134 ResourcePool* resource_pool,
111 size_t max_bytes_per_copy_operation) { 135 size_t max_bytes_per_copy_operation,
136 bool have_persistent_gpu_memory_buffers) {
112 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool( 137 return make_scoped_ptr<TileTaskWorkerPool>(new OneCopyTileTaskWorkerPool(
113 task_runner, task_graph_runner, context_provider, resource_provider, 138 task_runner, task_graph_runner, context_provider, resource_provider,
114 resource_pool, max_bytes_per_copy_operation)); 139 resource_pool, max_bytes_per_copy_operation,
140 have_persistent_gpu_memory_buffers));
115 } 141 }
116 142
117 OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool( 143 OneCopyTileTaskWorkerPool::OneCopyTileTaskWorkerPool(
118 base::SequencedTaskRunner* task_runner, 144 base::SequencedTaskRunner* task_runner,
119 TaskGraphRunner* task_graph_runner, 145 TaskGraphRunner* task_graph_runner,
120 ContextProvider* context_provider, 146 ContextProvider* context_provider,
121 ResourceProvider* resource_provider, 147 ResourceProvider* resource_provider,
122 ResourcePool* resource_pool, 148 ResourcePool* resource_pool,
123 size_t max_bytes_per_copy_operation) 149 size_t max_bytes_per_copy_operation,
150 bool have_persistent_gpu_memory_buffers)
124 : task_runner_(task_runner), 151 : task_runner_(task_runner),
125 task_graph_runner_(task_graph_runner), 152 task_graph_runner_(task_graph_runner),
126 namespace_token_(task_graph_runner->GetNamespaceToken()), 153 namespace_token_(task_graph_runner->GetNamespaceToken()),
127 context_provider_(context_provider), 154 context_provider_(context_provider),
128 resource_provider_(resource_provider), 155 resource_provider_(resource_provider),
129 resource_pool_(resource_pool), 156 resource_pool_(resource_pool),
130 max_bytes_per_copy_operation_(max_bytes_per_copy_operation), 157 max_bytes_per_copy_operation_(max_bytes_per_copy_operation),
158 have_persistent_gpu_memory_buffers_(have_persistent_gpu_memory_buffers),
131 last_issued_copy_operation_(0), 159 last_issued_copy_operation_(0),
132 last_flushed_copy_operation_(0), 160 last_flushed_copy_operation_(0),
133 lock_(), 161 lock_(),
134 copy_operation_count_cv_(&lock_), 162 copy_operation_count_cv_(&lock_),
135 issued_copy_operation_count_(0), 163 issued_copy_operation_count_(0),
136 next_copy_operation_sequence_(1), 164 next_copy_operation_sequence_(1),
137 check_for_completed_copy_operations_pending_(false), 165 check_for_completed_copy_operations_pending_(false),
138 shutdown_(false), 166 shutdown_(false),
139 weak_ptr_factory_(this), 167 weak_ptr_factory_(this),
140 task_set_finished_weak_ptr_factory_(this) { 168 task_set_finished_weak_ptr_factory_(this) {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 task->RunReplyOnOriginThread(); 287 task->RunReplyOnOriginThread();
260 } 288 }
261 completed_tasks_.clear(); 289 completed_tasks_.clear();
262 } 290 }
263 291
264 ResourceFormat OneCopyTileTaskWorkerPool::GetResourceFormat() { 292 ResourceFormat OneCopyTileTaskWorkerPool::GetResourceFormat() {
265 return resource_provider_->best_texture_format(); 293 return resource_provider_->best_texture_format();
266 } 294 }
267 295
268 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster( 296 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster(
269 const Resource* resource) { 297 const Resource* resource,
298 uint64_t new_content_id,
299 uint64_t previous_content_id) {
270 DCHECK_EQ(resource->format(), resource_provider_->best_texture_format()); 300 DCHECK_EQ(resource->format(), resource_provider_->best_texture_format());
271 return make_scoped_ptr<RasterBuffer>( 301 return make_scoped_ptr<RasterBuffer>(
272 new RasterBufferImpl(this, resource_provider_, resource_pool_, 302 new RasterBufferImpl(this, resource_provider_, resource_pool_,
273 resource_provider_->best_texture_format(), 303 resource_provider_->best_texture_format(), resource,
274 resource)); 304 new_content_id, previous_content_id));
275 } 305 }
276 306
277 void OneCopyTileTaskWorkerPool::ReleaseBufferForRaster( 307 void OneCopyTileTaskWorkerPool::ReleaseBufferForRaster(
278 scoped_ptr<RasterBuffer> buffer) { 308 scoped_ptr<RasterBuffer> buffer) {
279 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. 309 // Nothing to do here. RasterBufferImpl destructor cleans up after itself.
280 } 310 }
281 311
282 CopySequenceNumber 312 CopySequenceNumber
283 OneCopyTileTaskWorkerPool::PlaybackAndScheduleCopyOnWorkerThread( 313 OneCopyTileTaskWorkerPool::PlaybackAndScheduleCopyOnWorkerThread(
284 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock, 314 bool reusing_raster_resource,
285 const Resource* src, 315 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer>
286 const Resource* dst, 316 raster_resource_write_lock,
317 const Resource* raster_resource,
318 const Resource* output_resource,
287 const RasterSource* raster_source, 319 const RasterSource* raster_source,
288 const gfx::Rect& rect, 320 const gfx::Rect& raster_full_rect,
321 const gfx::Rect& raster_dirty_rect,
289 float scale) { 322 float scale) {
290 gfx::GpuMemoryBuffer* gpu_memory_buffer = write_lock->GetGpuMemoryBuffer(); 323 gfx::GpuMemoryBuffer* gpu_memory_buffer =
324 raster_resource_write_lock->GetGpuMemoryBuffer();
291 if (gpu_memory_buffer) { 325 if (gpu_memory_buffer) {
292 void* data = NULL; 326 void* data = NULL;
293 bool rv = gpu_memory_buffer->Map(&data); 327 bool rv = gpu_memory_buffer->Map(&data);
294 DCHECK(rv); 328 DCHECK(rv);
295 int stride; 329 int stride;
296 gpu_memory_buffer->GetStride(&stride); 330 gpu_memory_buffer->GetStride(&stride);
297 TileTaskWorkerPool::PlaybackToMemory(data, src->format(), src->size(), 331
298 stride, raster_source, rect, scale); 332 gfx::Rect playback_rect = raster_full_rect;
333 if (reusing_raster_resource) {
334 playback_rect.Intersect(raster_dirty_rect);
335 }
336 DCHECK(!playback_rect.IsEmpty())
337 << "Why are we rastering a tile that's not dirty?";
338 TileTaskWorkerPool::PlaybackToMemory(
339 data, raster_resource->format(), raster_resource->size(), stride,
340 raster_source, raster_full_rect, playback_rect, scale);
299 gpu_memory_buffer->Unmap(); 341 gpu_memory_buffer->Unmap();
300 } 342 }
301 343
302 base::AutoLock lock(lock_); 344 base::AutoLock lock(lock_);
303 345
304 CopySequenceNumber sequence = 0; 346 CopySequenceNumber sequence = 0;
305 size_t bytes_per_row = 347 size_t bytes_per_row = (BitsPerPixel(raster_resource->format()) *
306 (BitsPerPixel(src->format()) * src->size().width()) / 8; 348 raster_resource->size().width()) /
349 8;
307 size_t chunk_size_in_rows = std::max( 350 size_t chunk_size_in_rows = std::max(
308 static_cast<size_t>(1), max_bytes_per_copy_operation_ / bytes_per_row); 351 static_cast<size_t>(1), max_bytes_per_copy_operation_ / bytes_per_row);
309 // Align chunk size to 4. Required to support compressed texture formats. 352 // Align chunk size to 4. Required to support compressed texture formats.
310 chunk_size_in_rows = 353 chunk_size_in_rows =
311 MathUtil::RoundUp(chunk_size_in_rows, static_cast<size_t>(4)); 354 MathUtil::RoundUp(chunk_size_in_rows, static_cast<size_t>(4));
312 size_t y = 0; 355 size_t y = 0;
313 size_t height = src->size().height(); 356 size_t height = raster_resource->size().height();
314 while (y < height) { 357 while (y < height) {
315 int failed_attempts = 0; 358 int failed_attempts = 0;
316 while ((pending_copy_operations_.size() + issued_copy_operation_count_) >= 359 while ((pending_copy_operations_.size() + issued_copy_operation_count_) >=
317 kMaxCopyOperations) { 360 kMaxCopyOperations) {
318 // Ignore limit when shutdown is set. 361 // Ignore limit when shutdown is set.
319 if (shutdown_) 362 if (shutdown_)
320 break; 363 break;
321 364
322 ++failed_attempts; 365 ++failed_attempts;
323 366
(...skipping 12 matching lines...) Expand all
336 copy_operation_count_cv_.Wait(); 379 copy_operation_count_cv_.Wait();
337 } 380 }
338 } 381 }
339 382
340 // There may be more work available, so wake up another worker thread. 383 // There may be more work available, so wake up another worker thread.
341 copy_operation_count_cv_.Signal(); 384 copy_operation_count_cv_.Signal();
342 385
343 // Copy at most |chunk_size_in_rows|. 386 // Copy at most |chunk_size_in_rows|.
344 size_t rows_to_copy = std::min(chunk_size_in_rows, height - y); 387 size_t rows_to_copy = std::min(chunk_size_in_rows, height - y);
345 388
346 // |write_lock| is passed to the first copy operation as it needs to be 389 // |raster_resource_write_lock| is passed to the first copy operation as it
347 // released before we can issue a copy. 390 // needs to be released before we can issue a copy.
348 pending_copy_operations_.push_back(make_scoped_ptr( 391 pending_copy_operations_.push_back(make_scoped_ptr(new CopyOperation(
349 new CopyOperation(write_lock.Pass(), src, dst, 392 raster_resource_write_lock.Pass(), raster_resource, output_resource,
350 gfx::Rect(0, y, src->size().width(), rows_to_copy)))); 393 gfx::Rect(0, y, raster_resource->size().width(), rows_to_copy))));
351
352 y += rows_to_copy; 394 y += rows_to_copy;
353 395
354 // Acquire a sequence number for this copy operation. 396 // Acquire a sequence number for this copy operation.
355 sequence = next_copy_operation_sequence_++; 397 sequence = next_copy_operation_sequence_++;
356 398
357 // Post task that will advance last flushed copy operation to |sequence| 399 // Post task that will advance last flushed copy operation to |sequence|
358 // if we have reached the flush period. 400 // if we have reached the flush period.
359 if ((sequence % kCopyFlushPeriod) == 0) { 401 if ((sequence % kCopyFlushPeriod) == 0) {
360 task_runner_->PostTask( 402 task_runner_->PostTask(
361 FROM_HERE, 403 FROM_HERE,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 461
420 // Increment |issued_copy_operation_count_| to reflect the transition of 462 // Increment |issued_copy_operation_count_| to reflect the transition of
421 // copy operations from "pending" to "issued" state. 463 // copy operations from "pending" to "issued" state.
422 issued_copy_operation_count_ += copy_operations.size(); 464 issued_copy_operation_count_ += copy_operations.size();
423 } 465 }
424 466
425 while (!copy_operations.empty()) { 467 while (!copy_operations.empty()) {
426 scoped_ptr<CopyOperation> copy_operation = copy_operations.take_front(); 468 scoped_ptr<CopyOperation> copy_operation = copy_operations.take_front();
427 469
428 // Remove the write lock. 470 // Remove the write lock.
429 copy_operation->write_lock.reset(); 471 copy_operation->src_write_lock.reset();
430 472
431 // Copy contents of source resource to destination resource. 473 // Copy contents of source resource to destination resource.
432 resource_provider_->CopyResource(copy_operation->src->id(), 474 resource_provider_->CopyResource(copy_operation->src->id(),
433 copy_operation->dst->id(), 475 copy_operation->dst->id(),
434 copy_operation->rect); 476 copy_operation->rect);
435 } 477 }
436 } 478 }
437 479
438 void OneCopyTileTaskWorkerPool:: 480 void OneCopyTileTaskWorkerPool::
439 ScheduleCheckForCompletedCopyOperationsWithLockAcquired( 481 ScheduleCheckForCompletedCopyOperationsWithLockAcquired(
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 resource_pool_->total_memory_usage_bytes()); 555 resource_pool_->total_memory_usage_bytes());
514 staging_state->SetInteger("pending_copy_count", 556 staging_state->SetInteger("pending_copy_count",
515 resource_pool_->total_resource_count() - 557 resource_pool_->total_resource_count() -
516 resource_pool_->acquired_resource_count()); 558 resource_pool_->acquired_resource_count());
517 staging_state->SetInteger("bytes_pending_copy", 559 staging_state->SetInteger("bytes_pending_copy",
518 resource_pool_->total_memory_usage_bytes() - 560 resource_pool_->total_memory_usage_bytes() -
519 resource_pool_->acquired_memory_usage_bytes()); 561 resource_pool_->acquired_memory_usage_bytes());
520 } 562 }
521 563
522 } // namespace cc 564 } // namespace cc
OLDNEW
« no previous file with comments | « cc/raster/one_copy_tile_task_worker_pool.h ('k') | cc/raster/pixel_buffer_tile_task_worker_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698