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

Side by Side Diff: cc/resources/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: bademacs Created 5 years, 7 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/resources/one_copy_tile_task_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/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/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(OneCopyTileTaskWorkerPool* worker_pool, 25 RasterBufferImpl(OneCopyTileTaskWorkerPool* worker_pool,
26 ResourceProvider* resource_provider, 26 ResourceProvider* resource_provider,
27 ResourcePool* resource_pool, 27 ResourcePool* resource_pool,
28 ResourceFormat resource_format, 28 ResourceFormat resource_format,
29 const Resource* resource) 29 const TileTaskData& data)
30 : worker_pool_(worker_pool), 30 : worker_pool_(worker_pool),
31 resource_provider_(resource_provider), 31 resource_provider_(resource_provider),
32 resource_pool_(resource_pool), 32 resource_pool_(resource_pool),
33 resource_(resource), 33 tile_task_data_(data),
34 raster_resource_( 34 reusing_raster_resource_(true),
35 resource_pool->AcquireResource(resource->size(), resource_format)), 35 sequence_(0) {
36 lock_(new ResourceProvider::ScopedWriteLockGpuMemoryBuffer( 36 raster_resource_ = resource_pool->TryAcquireOldResource(
37 resource_provider_, 37 data.resource->size(), resource_format, data.previous_tile_id);
38 raster_resource_->id())), 38 if (!raster_resource_) {
39 sequence_(0) {} 39 raster_resource_ = resource_pool->AcquireResource(data.resource->size(),
40 resource_format);
41 reusing_raster_resource_ = false;
42
43 previous_frame_raster_resource_ =
44 // XXX Readable.
45 resource_pool->TryAcquireOldBusyResource(
46 data.resource->size(), resource_format, data.previous_tile_id);
47 }
48
49 lock_.reset(new ResourceProvider::ScopedWriteLockGpuMemoryBuffer(
50 resource_provider_, raster_resource_->id()));
51 if (previous_frame_raster_resource_) {
52 previous_frame_lock_.reset(
reveman 2015/05/14 23:52:20 We need to somehow explicitly allocated a GpuMemor
danakj 2015/05/15 00:09:58 What's the plan to extend it to the renderer then?
reveman 2015/05/15 00:33:20 I'd like to have more data on performance and usag
53 new ResourceProvider::ScopedReadLockGpuMemoryBuffer(
54 resource_provider_, previous_frame_raster_resource_->id()));
55 }
56 }
40 57
41 ~RasterBufferImpl() override { 58 ~RasterBufferImpl() override {
42 // Release write lock in case a copy was never scheduled. 59 // Release write/read lock in case a copy was never scheduled.
43 lock_.reset(); 60 lock_.reset();
61 previous_frame_lock_.reset();
44 62
45 // Make sure any scheduled copy operations are issued before we release the 63 // Make sure any scheduled copy operations are issued before we release the
46 // raster resource. 64 // raster resource.
47 if (sequence_) 65 if (sequence_)
48 worker_pool_->AdvanceLastIssuedCopyTo(sequence_); 66 worker_pool_->AdvanceLastIssuedCopyTo(sequence_);
49 67
50 // Return raster resource to pool so it can be used by another RasterBuffer 68 // Return resources to pool so they can be used by another RasterBuffer
51 // instance. 69 // instance.
52 if (raster_resource_) 70 if (raster_resource_) {
53 resource_pool_->ReleaseResource(raster_resource_.Pass()); 71 resource_pool_->ReleaseResource(raster_resource_.Pass(),
72 tile_task_data_.new_tile_id);
73 }
74 if (previous_frame_raster_resource_) {
75 resource_pool_->ReleaseResource(raster_resource_.Pass(),
76 tile_task_data_.previous_tile_id);
77 }
54 } 78 }
55 79
56 // Overridden from RasterBuffer: 80 // Overridden from RasterBuffer:
57 void Playback(const RasterSource* raster_source, 81 void Playback(const RasterSource* raster_source,
58 const gfx::Rect& rect, 82 const gfx::Rect& rect,
59 float scale) override { 83 float scale) override {
60 sequence_ = worker_pool_->PlaybackAndScheduleCopyOnWorkerThread( 84 sequence_ = worker_pool_->PlaybackAndScheduleCopyOnWorkerThread(
61 lock_.Pass(), raster_resource_.Pass(), resource_, raster_source, rect, 85 reusing_raster_resource_, lock_.Pass(), raster_resource_.Pass(),
62 scale); 86 previous_frame_lock_.Pass(), previous_frame_raster_resource_.Pass(),
87 tile_task_data_, raster_source, rect, scale);
63 } 88 }
64 89
65 private: 90 private:
66 OneCopyTileTaskWorkerPool* worker_pool_; 91 OneCopyTileTaskWorkerPool* worker_pool_;
67 ResourceProvider* resource_provider_; 92 ResourceProvider* resource_provider_;
68 ResourcePool* resource_pool_; 93 ResourcePool* resource_pool_;
69 const Resource* resource_; 94 TileTaskData tile_task_data_;
95 bool reusing_raster_resource_;
70 scoped_ptr<ScopedResource> raster_resource_; 96 scoped_ptr<ScopedResource> raster_resource_;
97 scoped_ptr<ScopedResource> previous_frame_raster_resource_;
reveman 2015/05/14 23:52:20 nit: previous_raster_resource_ instead as I think
danakj 2015/05/15 00:09:58 Done.
71 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> lock_; 98 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> lock_;
99 scoped_ptr<ResourceProvider::ScopedReadLockGpuMemoryBuffer>
100 previous_frame_lock_;
reveman 2015/05/14 23:52:20 nit: previous_lock_
danakj 2015/05/15 00:09:58 Done.
72 CopySequenceNumber sequence_; 101 CopySequenceNumber sequence_;
73 102
74 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl); 103 DISALLOW_COPY_AND_ASSIGN(RasterBufferImpl);
75 }; 104 };
76 105
77 // Flush interval when performing copy operations. 106 // Flush interval when performing copy operations.
78 const int kCopyFlushPeriod = 4; 107 const int kCopyFlushPeriod = 4;
79 108
80 // Number of in-flight copy operations to allow. 109 // Number of in-flight copy operations to allow.
81 const int kMaxCopyOperations = 32; 110 const int kMaxCopyOperations = 32;
82 111
83 // Delay been checking for copy operations to complete. 112 // Delay been checking for copy operations to complete.
84 const int kCheckForCompletedCopyOperationsTickRateMs = 1; 113 const int kCheckForCompletedCopyOperationsTickRateMs = 1;
85 114
86 // Number of failed attempts to allow before we perform a check that will 115 // Number of failed attempts to allow before we perform a check that will
87 // wait for copy operations to complete if needed. 116 // wait for copy operations to complete if needed.
88 const int kFailedAttemptsBeforeWaitIfNeeded = 256; 117 const int kFailedAttemptsBeforeWaitIfNeeded = 256;
89 118
90 } // namespace 119 } // namespace
91 120
92 OneCopyTileTaskWorkerPool::CopyOperation::CopyOperation( 121 OneCopyTileTaskWorkerPool::CopyOperation::CopyOperation(
93 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock, 122 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock,
94 scoped_ptr<ScopedResource> src, 123 scoped_ptr<ScopedResource> src,
95 const Resource* dst) 124 scoped_ptr<ResourceProvider::ScopedReadLockGpuMemoryBuffer>
96 : write_lock(write_lock.Pass()), src(src.Pass()), dst(dst) { 125 previous_frame_read_lock,
126 scoped_ptr<ScopedResource> previous_frame_src,
127 const TileTaskData& data)
128 : write_lock(write_lock.Pass()),
129 src(src.Pass()),
130 previous_frame_read_lock(previous_frame_read_lock.Pass()),
131 previous_frame_src(previous_frame_src.Pass()),
132 tile_task_data(data) {
97 } 133 }
98 134
99 OneCopyTileTaskWorkerPool::CopyOperation::~CopyOperation() { 135 OneCopyTileTaskWorkerPool::CopyOperation::~CopyOperation() {
100 } 136 }
101 137
102 // static 138 // static
103 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create( 139 scoped_ptr<TileTaskWorkerPool> OneCopyTileTaskWorkerPool::Create(
104 base::SequencedTaskRunner* task_runner, 140 base::SequencedTaskRunner* task_runner,
105 TaskGraphRunner* task_graph_runner, 141 TaskGraphRunner* task_graph_runner,
106 ContextProvider* context_provider, 142 ContextProvider* context_provider,
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 task->RunReplyOnOriginThread(); 291 task->RunReplyOnOriginThread();
256 } 292 }
257 completed_tasks_.clear(); 293 completed_tasks_.clear();
258 } 294 }
259 295
260 ResourceFormat OneCopyTileTaskWorkerPool::GetResourceFormat() { 296 ResourceFormat OneCopyTileTaskWorkerPool::GetResourceFormat() {
261 return resource_provider_->best_texture_format(); 297 return resource_provider_->best_texture_format();
262 } 298 }
263 299
264 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster( 300 scoped_ptr<RasterBuffer> OneCopyTileTaskWorkerPool::AcquireBufferForRaster(
265 const Resource* resource) { 301 const TileTaskData& data) {
266 DCHECK_EQ(resource->format(), resource_provider_->best_texture_format()); 302 DCHECK_EQ(data.resource->format(), resource_provider_->best_texture_format());
267 return make_scoped_ptr<RasterBuffer>( 303 return make_scoped_ptr<RasterBuffer>(
268 new RasterBufferImpl(this, resource_provider_, resource_pool_, 304 new RasterBufferImpl(this, resource_provider_, resource_pool_,
269 resource_provider_->best_texture_format(), 305 resource_provider_->best_texture_format(), data));
270 resource));
271 } 306 }
272 307
273 void OneCopyTileTaskWorkerPool::ReleaseBufferForRaster( 308 void OneCopyTileTaskWorkerPool::ReleaseBufferForRaster(
274 scoped_ptr<RasterBuffer> buffer) { 309 scoped_ptr<RasterBuffer> buffer) {
275 // Nothing to do here. RasterBufferImpl destructor cleans up after itself. 310 // Nothing to do here. RasterBufferImpl destructor cleans up after itself.
276 } 311 }
277 312
278 CopySequenceNumber 313 CopySequenceNumber
279 OneCopyTileTaskWorkerPool::PlaybackAndScheduleCopyOnWorkerThread( 314 OneCopyTileTaskWorkerPool::PlaybackAndScheduleCopyOnWorkerThread(
315 bool reusing_raster_resource,
280 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock, 316 scoped_ptr<ResourceProvider::ScopedWriteLockGpuMemoryBuffer> write_lock,
281 scoped_ptr<ScopedResource> src, 317 scoped_ptr<ScopedResource> src,
282 const Resource* dst, 318 scoped_ptr<ResourceProvider::ScopedReadLockGpuMemoryBuffer>
319 previous_frame_read_lock,
320 scoped_ptr<ScopedResource> previous_frame_src,
321 const TileTaskData& tile_task_data,
283 const RasterSource* raster_source, 322 const RasterSource* raster_source,
284 const gfx::Rect& rect, 323 const gfx::Rect& rect,
285 float scale) { 324 float scale) {
325 DCHECK_IMPLIES(reusing_raster_resource, !previous_frame_read_lock);
286 base::AutoLock lock(lock_); 326 base::AutoLock lock(lock_);
287 327
288 int failed_attempts = 0; 328 int failed_attempts = 0;
289 while ((scheduled_copy_operation_count_ + issued_copy_operation_count_) >= 329 while ((scheduled_copy_operation_count_ + issued_copy_operation_count_) >=
290 kMaxCopyOperations) { 330 kMaxCopyOperations) {
291 // Ignore limit when shutdown is set. 331 // Ignore limit when shutdown is set.
292 if (shutdown_) 332 if (shutdown_)
293 break; 333 break;
294 334
295 ++failed_attempts; 335 ++failed_attempts;
(...skipping 23 matching lines...) Expand all
319 { 359 {
320 base::AutoUnlock unlock(lock_); 360 base::AutoUnlock unlock(lock_);
321 361
322 gfx::GpuMemoryBuffer* gpu_memory_buffer = write_lock->GetGpuMemoryBuffer(); 362 gfx::GpuMemoryBuffer* gpu_memory_buffer = write_lock->GetGpuMemoryBuffer();
323 if (gpu_memory_buffer) { 363 if (gpu_memory_buffer) {
324 void* data = NULL; 364 void* data = NULL;
325 bool rv = gpu_memory_buffer->Map(&data); 365 bool rv = gpu_memory_buffer->Map(&data);
326 DCHECK(rv); 366 DCHECK(rv);
327 int stride; 367 int stride;
328 gpu_memory_buffer->GetStride(&stride); 368 gpu_memory_buffer->GetStride(&stride);
369
370 // If the |src| is already from the previous frame then there's nothing
371 // we need to copy. But otherwise we try copy from the previous_frame_src
372 // to |src| to reuse raster work if possible.
373 bool do_partial_update = reusing_raster_resource;
374 if (previous_frame_src) {
375 gfx::GpuMemoryBuffer* previous_gpu_memory_buffer =
376 previous_frame_read_lock->GetGpuMemoryBuffer();
377 if (previous_gpu_memory_buffer) {
378 void* previous_data = NULL;
379 bool prv = previous_gpu_memory_buffer->Map(&previous_data);
380 DCHECK(prv);
381 int previous_stride;
382 previous_gpu_memory_buffer->GetStride(&previous_stride);
383
384 if (previous_stride == stride) {
reveman 2015/05/14 23:52:20 what if this is false?
danakj 2015/05/14 23:56:34 We just don't use the old resource, and we re-rast
385 size_t bytes = static_cast<size_t>(stride) * src->size().height();
reveman 2015/05/14 23:52:20 Two problems here: 1. gfx::GpuMemoryBuffer::GetSt
danakj 2015/05/14 23:56:34 What does a negative stride mean? https://code.goo
reveman 2015/05/15 00:15:48 No special meaning. If stride=-10 then start of ro
danakj 2015/05/15 00:40:09 Ah okay, thanks. Fixed it.
386 memcpy(data, previous_data, bytes);
387 do_partial_update = true;
388 }
389 previous_gpu_memory_buffer->Unmap();
390 }
391 }
392
393 gfx::Rect playback_rect = rect;
394 if (do_partial_update)
395 playback_rect.Intersect(tile_task_data.raster_dirty_rect);
396 DCHECK(!playback_rect.IsEmpty())
397 << "Why are we rastering a tile that's not dirty?";
329 TileTaskWorkerPool::PlaybackToMemory(data, src->format(), src->size(), 398 TileTaskWorkerPool::PlaybackToMemory(data, src->format(), src->size(),
330 stride, raster_source, rect, scale); 399 stride, raster_source, rect,
400 playback_rect, scale);
331 gpu_memory_buffer->Unmap(); 401 gpu_memory_buffer->Unmap();
332 } 402 }
333 } 403 }
334 404
335 pending_copy_operations_.push_back( 405 pending_copy_operations_.push_back(make_scoped_ptr(new CopyOperation(
336 make_scoped_ptr(new CopyOperation(write_lock.Pass(), src.Pass(), dst))); 406 write_lock.Pass(), src.Pass(), previous_frame_read_lock.Pass(),
407 previous_frame_src.Pass(), tile_task_data)));
337 408
338 // Acquire a sequence number for this copy operation. 409 // Acquire a sequence number for this copy operation.
339 CopySequenceNumber sequence = next_copy_operation_sequence_++; 410 CopySequenceNumber sequence = next_copy_operation_sequence_++;
340 411
341 // Post task that will advance last flushed copy operation to |sequence| 412 // Post task that will advance last flushed copy operation to |sequence|
342 // if we have reached the flush period. 413 // if we have reached the flush period.
343 if ((sequence % kCopyFlushPeriod) == 0) { 414 if ((sequence % kCopyFlushPeriod) == 0) {
344 task_runner_->PostTask( 415 task_runner_->PostTask(
345 FROM_HERE, 416 FROM_HERE,
346 base::Bind(&OneCopyTileTaskWorkerPool::AdvanceLastFlushedCopyTo, 417 base::Bind(&OneCopyTileTaskWorkerPool::AdvanceLastFlushedCopyTo,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 issued_copy_operation_count_ += copy_operations.size(); 479 issued_copy_operation_count_ += copy_operations.size();
409 } 480 }
410 481
411 while (!copy_operations.empty()) { 482 while (!copy_operations.empty()) {
412 scoped_ptr<CopyOperation> copy_operation = copy_operations.take_front(); 483 scoped_ptr<CopyOperation> copy_operation = copy_operations.take_front();
413 484
414 // Remove the write lock. 485 // Remove the write lock.
415 copy_operation->write_lock.reset(); 486 copy_operation->write_lock.reset();
416 487
417 // Copy contents of source resource to destination resource. 488 // Copy contents of source resource to destination resource.
418 resource_provider_->CopyResource(copy_operation->src->id(), 489 resource_provider_->CopyResource(
419 copy_operation->dst->id()); 490 copy_operation->src->id(),
491 copy_operation->tile_task_data.resource->id());
420 492
421 // Return source resource to pool where it can be reused once copy 493 // Return source resource to pool where it can be reused once copy
422 // operation has completed and resource is no longer busy. 494 // operation has completed and resource is no longer busy.
423 resource_pool_->ReleaseResource(copy_operation->src.Pass()); 495 resource_pool_->ReleaseResource(copy_operation->src.Pass(),
496 copy_operation->tile_task_data.new_tile_id);
497 if (copy_operation->previous_frame_src) {
498 resource_pool_->ReleaseResource(
499 copy_operation->previous_frame_src.Pass(),
500 copy_operation->tile_task_data.previous_tile_id);
501 }
424 } 502 }
425 } 503 }
426 504
427 void OneCopyTileTaskWorkerPool:: 505 void OneCopyTileTaskWorkerPool::
428 ScheduleCheckForCompletedCopyOperationsWithLockAcquired( 506 ScheduleCheckForCompletedCopyOperationsWithLockAcquired(
429 bool wait_if_needed) { 507 bool wait_if_needed) {
430 lock_.AssertAcquired(); 508 lock_.AssertAcquired();
431 509
432 if (check_for_completed_copy_operations_pending_) 510 if (check_for_completed_copy_operations_pending_)
433 return; 511 return;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 resource_pool_->total_memory_usage_bytes()); 580 resource_pool_->total_memory_usage_bytes());
503 staging_state->SetInteger("pending_copy_count", 581 staging_state->SetInteger("pending_copy_count",
504 resource_pool_->total_resource_count() - 582 resource_pool_->total_resource_count() -
505 resource_pool_->acquired_resource_count()); 583 resource_pool_->acquired_resource_count());
506 staging_state->SetInteger("bytes_pending_copy", 584 staging_state->SetInteger("bytes_pending_copy",
507 resource_pool_->total_memory_usage_bytes() - 585 resource_pool_->total_memory_usage_bytes() -
508 resource_pool_->acquired_memory_usage_bytes()); 586 resource_pool_->acquired_memory_usage_bytes());
509 } 587 }
510 588
511 } // namespace cc 589 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698