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

Side by Side Diff: cc/tiles/tile_manager.cc

Issue 1866043006: cc: Remove ScheduleOnOriginThread() and CompleteOnOriginThread(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nits Created 4 years, 8 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
« no previous file with comments | « cc/tiles/tile_manager.h ('k') | cc/tiles/tile_manager_perftest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/tiles/tile_manager.h" 5 #include "cc/tiles/tile_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 26 matching lines...) Expand all
37 // a tile is of solid color. 37 // a tile is of solid color.
38 const bool kUseColorEstimator = true; 38 const bool kUseColorEstimator = true;
39 39
40 DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER( 40 DEFINE_SCOPED_UMA_HISTOGRAM_AREA_TIMER(
41 ScopedRasterTaskTimer, 41 ScopedRasterTaskTimer,
42 "Compositing.%s.RasterTask.RasterUs", 42 "Compositing.%s.RasterTask.RasterUs",
43 "Compositing.%s.RasterTask.RasterPixelsPerMs"); 43 "Compositing.%s.RasterTask.RasterPixelsPerMs");
44 44
45 class RasterTaskImpl : public RasterTask { 45 class RasterTaskImpl : public RasterTask {
46 public: 46 public:
47 RasterTaskImpl(const Resource* resource, 47 RasterTaskImpl(Resource* resource,
48 scoped_refptr<RasterSource> raster_source, 48 scoped_refptr<RasterSource> raster_source,
49 const gfx::Rect& content_rect, 49 const gfx::Rect& content_rect,
50 const gfx::Rect& invalid_content_rect, 50 const gfx::Rect& invalid_content_rect,
51 float contents_scale, 51 float contents_scale,
52 const RasterSource::PlaybackSettings& playback_settings, 52 const RasterSource::PlaybackSettings& playback_settings,
53 TileResolution tile_resolution, 53 TileResolution tile_resolution,
54 int layer_id, 54 int layer_id,
55 uint64_t source_prepare_tiles_id, 55 uint64_t source_prepare_tiles_id,
56 const void* tile, 56 Tile* tile,
57 uint64_t new_content_id, 57 uint64_t new_content_id,
58 uint64_t previous_content_id, 58 uint64_t previous_content_id,
59 uint64_t resource_content_id, 59 uint64_t resource_content_id,
60 int source_frame_number, 60 int source_frame_number,
61 const base::Callback<void(bool)>& reply, 61 std::unique_ptr<RasterBuffer> raster_buffer,
62 ImageDecodeTask::Vector* dependencies) 62 ImageDecodeTask::Vector* dependencies)
63 : RasterTask(dependencies), 63 : RasterTask(dependencies),
64 resource_(resource), 64 resource_(resource),
65 raster_source_(std::move(raster_source)), 65 raster_source_(std::move(raster_source)),
66 content_rect_(content_rect), 66 content_rect_(content_rect),
67 invalid_content_rect_(invalid_content_rect), 67 invalid_content_rect_(invalid_content_rect),
68 contents_scale_(contents_scale), 68 contents_scale_(contents_scale),
69 playback_settings_(playback_settings), 69 playback_settings_(playback_settings),
70 tile_resolution_(tile_resolution), 70 tile_resolution_(tile_resolution),
71 layer_id_(layer_id), 71 layer_id_(layer_id),
72 source_prepare_tiles_id_(source_prepare_tiles_id), 72 source_prepare_tiles_id_(source_prepare_tiles_id),
73 tile_(tile), 73 tile_(tile),
74 new_content_id_(new_content_id), 74 new_content_id_(new_content_id),
75 previous_content_id_(previous_content_id), 75 previous_content_id_(previous_content_id),
76 resource_content_id_(resource_content_id), 76 resource_content_id_(resource_content_id),
77 source_frame_number_(source_frame_number), 77 source_frame_number_(source_frame_number),
78 reply_(reply) {} 78 raster_buffer_(std::move(raster_buffer)) {
79 SetTaskTypeId(TASK_TYPE_RASTER);
80 }
79 81
80 // Overridden from Task: 82 // Overridden from Task:
81 void RunOnWorkerThread() override { 83 void RunOnWorkerThread() override {
82 TRACE_EVENT1("cc", "RasterizerTaskImpl::RunOnWorkerThread", 84 TRACE_EVENT1("cc", "RasterizerTaskImpl::RunOnWorkerThread",
83 "source_prepare_tiles_id", source_prepare_tiles_id_); 85 "source_prepare_tiles_id", source_prepare_tiles_id_);
84 86
85 DCHECK(raster_source_.get()); 87 DCHECK(raster_source_.get());
86 DCHECK(raster_buffer_); 88 DCHECK(raster_buffer_);
87 89
88 frame_viewer_instrumentation::ScopedRasterTask raster_task( 90 frame_viewer_instrumentation::ScopedRasterTask raster_task(
89 tile_, tile_resolution_, source_frame_number_, layer_id_); 91 tile_, tile_resolution_, source_frame_number_, layer_id_);
90 ScopedRasterTaskTimer timer; 92 ScopedRasterTaskTimer timer;
91 timer.SetArea(content_rect_.size().GetArea()); 93 timer.SetArea(content_rect_.size().GetArea());
92 94
93 DCHECK(raster_source_); 95 DCHECK(raster_source_);
94 96
95 raster_buffer_->Playback(raster_source_.get(), content_rect_, 97 raster_buffer_->Playback(raster_source_.get(), content_rect_,
96 invalid_content_rect_, new_content_id_, 98 invalid_content_rect_, new_content_id_,
97 contents_scale_, playback_settings_); 99 contents_scale_, playback_settings_);
98 } 100 }
99 101
100 // Overridden from TileTask: 102 protected:
101 void ScheduleOnOriginThread(TileTaskClient* client) override { 103 ~RasterTaskImpl() override {}
102 DCHECK(!raster_buffer_);
103 raster_buffer_ = client->AcquireBufferForRaster(
104 resource_, resource_content_id_, previous_content_id_);
105 }
106 void CompleteOnOriginThread(TileTaskClient* client) override {
107 client->ReleaseBufferForRaster(std::move(raster_buffer_));
108 reply_.Run(!HasFinishedRunning());
109 }
110 104
111 protected: 105 public:
112 ~RasterTaskImpl() override { DCHECK(!raster_buffer_); } 106 Resource* resource_;
113
114 private:
115 const Resource* resource_;
116 scoped_refptr<RasterSource> raster_source_; 107 scoped_refptr<RasterSource> raster_source_;
117 gfx::Rect content_rect_; 108 gfx::Rect content_rect_;
118 gfx::Rect invalid_content_rect_; 109 gfx::Rect invalid_content_rect_;
119 float contents_scale_; 110 float contents_scale_;
120 RasterSource::PlaybackSettings playback_settings_; 111 RasterSource::PlaybackSettings playback_settings_;
121 TileResolution tile_resolution_; 112 TileResolution tile_resolution_;
122 int layer_id_; 113 int layer_id_;
123 uint64_t source_prepare_tiles_id_; 114 uint64_t source_prepare_tiles_id_;
124 const void* tile_; 115 Tile* tile_;
125 uint64_t new_content_id_; 116 uint64_t new_content_id_;
126 uint64_t previous_content_id_; 117 uint64_t previous_content_id_;
127 uint64_t resource_content_id_; 118 uint64_t resource_content_id_;
128 int source_frame_number_; 119 int source_frame_number_;
129 const base::Callback<void(bool)> reply_;
130 std::unique_ptr<RasterBuffer> raster_buffer_; 120 std::unique_ptr<RasterBuffer> raster_buffer_;
131 121
122 private:
132 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl); 123 DISALLOW_COPY_AND_ASSIGN(RasterTaskImpl);
133 }; 124 };
134 125
135 // Task priorities that make sure that the task set done tasks run before any 126 // Task priorities that make sure that the task set done tasks run before any
136 // other remaining tasks. 127 // other remaining tasks.
137 const size_t kRequiredForActivationDoneTaskPriority = 1u; 128 const size_t kRequiredForActivationDoneTaskPriority = 1u;
138 const size_t kRequiredForDrawDoneTaskPriority = 2u; 129 const size_t kRequiredForDrawDoneTaskPriority = 2u;
139 const size_t kAllDoneTaskPriority = 3u; 130 const size_t kAllDoneTaskPriority = 3u;
140 131
141 // For correctness, |kTileTaskPriorityBase| must be greater than 132 // For correctness, |kTileTaskPriorityBase| must be greater than
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 const base::Closure& on_task_set_finished_callback) 235 const base::Closure& on_task_set_finished_callback)
245 : task_runner_(task_runner), 236 : task_runner_(task_runner),
246 on_task_set_finished_callback_(on_task_set_finished_callback) {} 237 on_task_set_finished_callback_(on_task_set_finished_callback) {}
247 238
248 // Overridden from Task: 239 // Overridden from Task:
249 void RunOnWorkerThread() override { 240 void RunOnWorkerThread() override {
250 TRACE_EVENT0("cc", "TaskSetFinishedTaskImpl::RunOnWorkerThread"); 241 TRACE_EVENT0("cc", "TaskSetFinishedTaskImpl::RunOnWorkerThread");
251 TaskSetFinished(); 242 TaskSetFinished();
252 } 243 }
253 244
254 // Overridden from TileTask:
255 void ScheduleOnOriginThread(TileTaskClient* client) override {}
256 void CompleteOnOriginThread(TileTaskClient* client) override {}
257
258 protected: 245 protected:
259 ~TaskSetFinishedTaskImpl() override {} 246 ~TaskSetFinishedTaskImpl() override {}
260 247
261 void TaskSetFinished() { 248 void TaskSetFinished() {
262 task_runner_->PostTask(FROM_HERE, on_task_set_finished_callback_); 249 task_runner_->PostTask(FROM_HERE, on_task_set_finished_callback_);
263 } 250 }
264 251
265 private: 252 private:
266 scoped_refptr<base::SequencedTaskRunner> task_runner_; 253 scoped_refptr<base::SequencedTaskRunner> task_runner_;
267 const base::Closure on_task_set_finished_callback_; 254 const base::Closure on_task_set_finished_callback_;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 size_t scheduled_raster_task_limit, 290 size_t scheduled_raster_task_limit,
304 bool use_partial_raster) 291 bool use_partial_raster)
305 : client_(client), 292 : client_(client),
306 task_runner_(std::move(task_runner)), 293 task_runner_(std::move(task_runner)),
307 resource_pool_(nullptr), 294 resource_pool_(nullptr),
308 tile_task_runner_(nullptr), 295 tile_task_runner_(nullptr),
309 scheduled_raster_task_limit_(scheduled_raster_task_limit), 296 scheduled_raster_task_limit_(scheduled_raster_task_limit),
310 use_partial_raster_(use_partial_raster), 297 use_partial_raster_(use_partial_raster),
311 use_gpu_rasterization_(false), 298 use_gpu_rasterization_(false),
312 all_tiles_that_need_to_be_rasterized_are_scheduled_(true), 299 all_tiles_that_need_to_be_rasterized_are_scheduled_(true),
313 did_check_for_completed_tasks_since_last_schedule_tasks_(true), 300 did_check_and_process_completed_tasks_since_last_schedule_tasks_(true),
314 did_oom_on_last_assign_(false), 301 did_oom_on_last_assign_(false),
315 more_tiles_need_prepare_check_notifier_( 302 more_tiles_need_prepare_check_notifier_(
316 task_runner_.get(), 303 task_runner_.get(),
317 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared, 304 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared,
318 base::Unretained(this))), 305 base::Unretained(this))),
319 signals_check_notifier_(task_runner_.get(), 306 signals_check_notifier_(task_runner_.get(),
320 base::Bind(&TileManager::CheckAndIssueSignals, 307 base::Bind(&TileManager::CheckAndIssueSignals,
321 base::Unretained(this))), 308 base::Unretained(this))),
322 has_scheduled_tile_tasks_(false), 309 has_scheduled_tile_tasks_(false),
323 prepare_tiles_count_(0u), 310 prepare_tiles_count_(0u),
(...skipping 11 matching lines...) Expand all
335 global_state_ = GlobalStateThatImpactsTilePriority(); 322 global_state_ = GlobalStateThatImpactsTilePriority();
336 323
337 // This cancels tasks if possible, finishes pending tasks, and release any 324 // This cancels tasks if possible, finishes pending tasks, and release any
338 // uninitialized resources. 325 // uninitialized resources.
339 tile_task_runner_->Shutdown(); 326 tile_task_runner_->Shutdown();
340 327
341 // Now that all tasks have been finished, we can clear any 328 // Now that all tasks have been finished, we can clear any
342 // |orphan_tasks_|. 329 // |orphan_tasks_|.
343 orphan_tasks_.clear(); 330 orphan_tasks_.clear();
344 331
345 tile_task_runner_->CheckForCompletedTasks(); 332 CheckAndProcessCompletedTasks();
346 333
347 FreeResourcesForReleasedTiles(); 334 FreeResourcesForReleasedTiles();
348 CleanUpReleasedTiles(); 335 CleanUpReleasedTiles();
349 336
350 tile_task_runner_ = nullptr; 337 tile_task_runner_ = nullptr;
351 resource_pool_ = nullptr; 338 resource_pool_ = nullptr;
352 more_tiles_need_prepare_check_notifier_.Cancel(); 339 more_tiles_need_prepare_check_notifier_.Cancel();
353 signals_check_notifier_.Cancel(); 340 signals_check_notifier_.Cancel();
354 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); 341 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs();
355 } 342 }
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 432
446 if (!tile_task_runner_) { 433 if (!tile_task_runner_) {
447 TRACE_EVENT_INSTANT0("cc", "PrepareTiles aborted", 434 TRACE_EVENT_INSTANT0("cc", "PrepareTiles aborted",
448 TRACE_EVENT_SCOPE_THREAD); 435 TRACE_EVENT_SCOPE_THREAD);
449 return false; 436 return false;
450 } 437 }
451 438
452 signals_.reset(); 439 signals_.reset();
453 global_state_ = state; 440 global_state_ = state;
454 441
455 // We need to call CheckForCompletedTasks() once in-between each call 442 // We need to call CheckAndProcessCompletedTasks() once in-between each call
456 // to ScheduleTasks() to prevent canceled tasks from being scheduled. 443 // to ScheduleTasks() to prevent canceled tasks from being scheduled.
457 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { 444 if (!did_check_and_process_completed_tasks_since_last_schedule_tasks_)
458 tile_task_runner_->CheckForCompletedTasks(); 445 CheckAndProcessCompletedTasks();
459 did_check_for_completed_tasks_since_last_schedule_tasks_ = true;
460 }
461 446
462 FreeResourcesForReleasedTiles(); 447 FreeResourcesForReleasedTiles();
463 CleanUpReleasedTiles(); 448 CleanUpReleasedTiles();
464 449
465 PrioritizedTileVector tiles_that_need_to_be_rasterized; 450 PrioritizedTileVector tiles_that_need_to_be_rasterized;
466 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue( 451 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue(
467 client_->BuildRasterQueue(global_state_.tree_priority, 452 client_->BuildRasterQueue(global_state_.tree_priority,
468 RasterTilePriorityQueue::Type::ALL)); 453 RasterTilePriorityQueue::Type::ALL));
469 AssignGpuMemoryToTiles(raster_priority_queue.get(), 454 AssignGpuMemoryToTiles(raster_priority_queue.get(),
470 scheduled_raster_task_limit_, 455 scheduled_raster_task_limit_,
(...skipping 14 matching lines...) Expand all
485 } 470 }
486 471
487 void TileManager::Flush() { 472 void TileManager::Flush() {
488 TRACE_EVENT0("cc", "TileManager::Flush"); 473 TRACE_EVENT0("cc", "TileManager::Flush");
489 474
490 if (!tile_task_runner_) { 475 if (!tile_task_runner_) {
491 TRACE_EVENT_INSTANT0("cc", "Flush aborted", TRACE_EVENT_SCOPE_THREAD); 476 TRACE_EVENT_INSTANT0("cc", "Flush aborted", TRACE_EVENT_SCOPE_THREAD);
492 return; 477 return;
493 } 478 }
494 479
495 tile_task_runner_->CheckForCompletedTasks(); 480 CheckAndProcessCompletedTasks();
496
497 did_check_for_completed_tasks_since_last_schedule_tasks_ = true;
498 481
499 TRACE_EVENT_INSTANT1("cc", "DidFlush", TRACE_EVENT_SCOPE_THREAD, "stats", 482 TRACE_EVENT_INSTANT1("cc", "DidFlush", TRACE_EVENT_SCOPE_THREAD, "stats",
500 RasterTaskCompletionStatsAsValue(flush_stats_)); 483 RasterTaskCompletionStatsAsValue(flush_stats_));
501 flush_stats_ = RasterTaskCompletionStats(); 484 flush_stats_ = RasterTaskCompletionStats();
502 } 485 }
503 486
504 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> 487 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
505 TileManager::BasicStateAsValue() const { 488 TileManager::BasicStateAsValue() const {
506 std::unique_ptr<base::trace_event::TracedValue> value( 489 std::unique_ptr<base::trace_event::TracedValue> value(
507 new base::trace_event::TracedValue()); 490 new base::trace_event::TracedValue());
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 FreeResourcesForTile(tile); 712 FreeResourcesForTile(tile);
730 if (was_ready_to_draw) 713 if (was_ready_to_draw)
731 client_->NotifyTileStateChanged(tile); 714 client_->NotifyTileStateChanged(tile);
732 } 715 }
733 716
734 void TileManager::ScheduleTasks( 717 void TileManager::ScheduleTasks(
735 const PrioritizedTileVector& tiles_that_need_to_be_rasterized) { 718 const PrioritizedTileVector& tiles_that_need_to_be_rasterized) {
736 TRACE_EVENT1("cc", "TileManager::ScheduleTasks", "count", 719 TRACE_EVENT1("cc", "TileManager::ScheduleTasks", "count",
737 tiles_that_need_to_be_rasterized.size()); 720 tiles_that_need_to_be_rasterized.size());
738 721
739 DCHECK(did_check_for_completed_tasks_since_last_schedule_tasks_); 722 DCHECK(did_check_and_process_completed_tasks_since_last_schedule_tasks_);
740 723
741 if (!has_scheduled_tile_tasks_) { 724 if (!has_scheduled_tile_tasks_) {
742 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this); 725 TRACE_EVENT_ASYNC_BEGIN0("cc", "ScheduledTasks", this);
743 } 726 }
744 727
745 // Cancel existing OnTaskSetFinished callbacks. 728 // Cancel existing OnTaskSetFinished callbacks.
746 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); 729 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs();
747 730
748 // Even when scheduling an empty set of tiles, the TTWP does some work, and 731 // Even when scheduling an empty set of tiles, the TTWP does some work, and
749 // will always trigger a DidFinishRunningTileTasks notification. Because of 732 // will always trigger a DidFinishRunningTileTasks notification. Because of
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 // allowed to keep around unreferenced raster tasks after ScheduleTasks() has 815 // allowed to keep around unreferenced raster tasks after ScheduleTasks() has
833 // been called. 816 // been called.
834 orphan_tasks_.clear(); 817 orphan_tasks_.clear();
835 818
836 // It's also now safe to replace our *_done_task_ tasks. 819 // It's also now safe to replace our *_done_task_ tasks.
837 required_for_activation_done_task_ = 820 required_for_activation_done_task_ =
838 std::move(required_for_activation_done_task); 821 std::move(required_for_activation_done_task);
839 required_for_draw_done_task_ = std::move(required_for_draw_done_task); 822 required_for_draw_done_task_ = std::move(required_for_draw_done_task);
840 all_done_task_ = std::move(all_done_task); 823 all_done_task_ = std::move(all_done_task);
841 824
842 did_check_for_completed_tasks_since_last_schedule_tasks_ = false; 825 did_check_and_process_completed_tasks_since_last_schedule_tasks_ = false;
843 826
844 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state", 827 TRACE_EVENT_ASYNC_STEP_INTO1("cc", "ScheduledTasks", this, "running", "state",
845 ScheduledTasksStateAsValue()); 828 ScheduledTasksStateAsValue());
846 } 829 }
847 830
848 scoped_refptr<RasterTask> TileManager::CreateRasterTask( 831 scoped_refptr<RasterTask> TileManager::CreateRasterTask(
849 const PrioritizedTile& prioritized_tile) { 832 const PrioritizedTile& prioritized_tile) {
850 Tile* tile = prioritized_tile.tile(); 833 Tile* tile = prioritized_tile.tile();
851 834
852 // Get the resource. 835 // Get the resource.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 *it, prepare_tiles_count_, &task); 873 *it, prepare_tiles_count_, &task);
891 if (task) 874 if (task)
892 decode_tasks.push_back(task); 875 decode_tasks.push_back(task);
893 876
894 if (need_to_unref_when_finished) 877 if (need_to_unref_when_finished)
895 ++it; 878 ++it;
896 else 879 else
897 it = images.erase(it); 880 it = images.erase(it);
898 } 881 }
899 882
883 std::unique_ptr<RasterBuffer> raster_buffer =
884 tile_task_runner_->AsTileTaskClient()->AcquireBufferForRaster(
885 resource, resource_content_id, tile->invalidated_id());
900 return make_scoped_refptr(new RasterTaskImpl( 886 return make_scoped_refptr(new RasterTaskImpl(
901 resource, prioritized_tile.raster_source(), tile->content_rect(), 887 resource, prioritized_tile.raster_source(), tile->content_rect(),
902 tile->invalidated_content_rect(), tile->contents_scale(), 888 tile->invalidated_content_rect(), tile->contents_scale(),
903 playback_settings, prioritized_tile.priority().resolution, 889 playback_settings, prioritized_tile.priority().resolution,
904 tile->layer_id(), prepare_tiles_count_, static_cast<const void*>(tile), 890 tile->layer_id(), prepare_tiles_count_, tile, tile->id(),
905 tile->id(), tile->invalidated_id(), resource_content_id, 891 tile->invalidated_id(), resource_content_id, tile->source_frame_number(),
906 tile->source_frame_number(), 892 std::move(raster_buffer), &decode_tasks));
907 base::Bind(&TileManager::OnRasterTaskCompleted, base::Unretained(this),
908 tile->id(), resource),
909 &decode_tasks));
910 } 893 }
911 894
912 void TileManager::OnRasterTaskCompleted( 895 void TileManager::CheckAndProcessCompletedTasks() {
913 Tile::Id tile_id, 896 Task::Vector completed_tasks;
914 Resource* resource, 897 tile_task_runner_->CollectCompletedTasks(&completed_tasks);
915 bool was_canceled) {
916 DCHECK(tiles_.find(tile_id) != tiles_.end());
917 898
918 Tile* tile = tiles_[tile_id]; 899 for (auto task : completed_tasks) {
919 TileDrawInfo& draw_info = tile->draw_info(); 900 switch (task->GetTaskTypeId()) {
920 DCHECK(tile->raster_task_.get()); 901 case TASK_TYPE_IMAGE_DECODE:
921 orphan_tasks_.push_back(tile->raster_task_); 902 image_decode_controller_->ImageDecodeTaskCompleted(task.get());
922 tile->raster_task_ = nullptr; 903 break;
904 case TASK_TYPE_IMAGE_UPLOAD:
905 image_decode_controller_->ImageUploadTaskCompleted(task.get());
906 break;
907 case TASK_TYPE_RASTER:
908 RasterTaskCompleted(task.get());
909 break;
910 }
911
912 static_cast<TileTask*>(task.get())->DidComplete();
913 }
914
915 completed_tasks.clear();
916
917 did_check_and_process_completed_tasks_since_last_schedule_tasks_ = true;
918 }
919
920 void TileManager::RasterTaskCompleted(Task* task) {
921 DCHECK(task);
922 RasterTaskImpl* raster_task = static_cast<RasterTaskImpl*>(task);
923 tile_task_runner_->AsTileTaskClient()->ReleaseBufferForRaster(
924 std::move(raster_task->raster_buffer_));
925
926 DCHECK(tiles_.find(raster_task->tile_->id()) == tiles_.end());
prashant.n 2016/04/13 12:04:51 The check should be !=
927 TileDrawInfo& draw_info = raster_task->tile_->draw_info();
928 DCHECK(raster_task->tile_->raster_task_.get());
929 orphan_tasks_.push_back(raster_task->tile_->raster_task_);
930 raster_task->tile_->raster_task_ = nullptr;
923 931
924 // Unref all the images. 932 // Unref all the images.
925 auto images_it = scheduled_draw_images_.find(tile->id()); 933 auto images_it = scheduled_draw_images_.find(raster_task->tile_->id());
926 const std::vector<DrawImage>& images = images_it->second; 934 const std::vector<DrawImage>& images = images_it->second;
927 for (const auto& image : images) 935 for (const auto& image : images)
928 image_decode_controller_->UnrefImage(image); 936 image_decode_controller_->UnrefImage(image);
929 scheduled_draw_images_.erase(images_it); 937 scheduled_draw_images_.erase(images_it);
930 938
931 if (was_canceled) { 939 // Task was cancelled.
940 if (!raster_task->HasFinishedRunning()) {
932 ++flush_stats_.canceled_count; 941 ++flush_stats_.canceled_count;
933 // TODO(ericrk): If more partial raster work is done in the future, it may 942 // TODO(ericrk): If more partial raster work is done in the future, it may
934 // be worth returning the resource to the pool with its previous ID (not 943 // be worth returning the resource to the pool with its previous ID (not
935 // currently tracked). crrev.com/1370333002/#ps40001 has a possible method 944 // currently tracked). crrev.com/1370333002/#ps40001 has a possible method
936 // of achieving this. 945 // of achieving this.
937 resource_pool_->ReleaseResource(resource, 0 /* content_id */); 946 resource_pool_->ReleaseResource(raster_task->resource_, 0 /* content_id */);
938 return; 947 return;
939 } 948 }
940 949
941 ++flush_stats_.completed_count; 950 ++flush_stats_.completed_count;
942 951
943 draw_info.set_use_resource(); 952 draw_info.set_use_resource();
944 draw_info.resource_ = resource; 953 draw_info.resource_ = raster_task->resource_;
945 draw_info.contents_swizzled_ = DetermineResourceRequiresSwizzle(tile); 954 draw_info.contents_swizzled_ =
955 DetermineResourceRequiresSwizzle(raster_task->tile_);
946 956
947 DCHECK(draw_info.IsReadyToDraw()); 957 DCHECK(draw_info.IsReadyToDraw());
948 draw_info.set_was_ever_ready_to_draw(); 958 draw_info.set_was_ever_ready_to_draw();
949 959
950 client_->NotifyTileStateChanged(tile); 960 client_->NotifyTileStateChanged(raster_task->tile_);
951 } 961 }
952 962
953 ScopedTilePtr TileManager::CreateTile(const Tile::CreateInfo& info, 963 ScopedTilePtr TileManager::CreateTile(const Tile::CreateInfo& info,
954 int layer_id, 964 int layer_id,
955 int source_frame_number, 965 int source_frame_number,
956 int flags) { 966 int flags) {
957 // We need to have a tile task worker pool to do anything meaningful with 967 // We need to have a tile task worker pool to do anything meaningful with
958 // tiles. 968 // tiles.
959 DCHECK(tile_task_runner_); 969 DCHECK(tile_task_runner_);
960 ScopedTilePtr tile( 970 ScopedTilePtr tile(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1003 } 1013 }
1004 1014
1005 bool TileManager::IsReadyToDraw() const { 1015 bool TileManager::IsReadyToDraw() const {
1006 TRACE_EVENT0("cc", "TileManager::IsReadyToDraw"); 1016 TRACE_EVENT0("cc", "TileManager::IsReadyToDraw");
1007 return AreRequiredTilesReadyToDraw( 1017 return AreRequiredTilesReadyToDraw(
1008 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW); 1018 RasterTilePriorityQueue::Type::REQUIRED_FOR_DRAW);
1009 } 1019 }
1010 1020
1011 void TileManager::CheckAndIssueSignals() { 1021 void TileManager::CheckAndIssueSignals() {
1012 TRACE_EVENT0("cc", "TileManager::CheckAndIssueSignals"); 1022 TRACE_EVENT0("cc", "TileManager::CheckAndIssueSignals");
1013 tile_task_runner_->CheckForCompletedTasks(); 1023 CheckAndProcessCompletedTasks();
1014 did_check_for_completed_tasks_since_last_schedule_tasks_ = true;
1015 1024
1016 // Ready to activate. 1025 // Ready to activate.
1017 if (signals_.ready_to_activate && !signals_.did_notify_ready_to_activate) { 1026 if (signals_.ready_to_activate && !signals_.did_notify_ready_to_activate) {
1018 signals_.ready_to_activate = false; 1027 signals_.ready_to_activate = false;
1019 if (IsReadyToActivate()) { 1028 if (IsReadyToActivate()) {
1020 TRACE_EVENT0("disabled-by-default-cc.debug", 1029 TRACE_EVENT0("disabled-by-default-cc.debug",
1021 "TileManager::CheckAndIssueSignals - ready to activate"); 1030 "TileManager::CheckAndIssueSignals - ready to activate");
1022 signals_.did_notify_ready_to_activate = true; 1031 signals_.did_notify_ready_to_activate = true;
1023 client_->NotifyReadyToActivate(); 1032 client_->NotifyReadyToActivate();
1024 } 1033 }
(...skipping 18 matching lines...) Expand all
1043 TRACE_EVENT0( 1052 TRACE_EVENT0(
1044 "disabled-by-default-cc.debug", 1053 "disabled-by-default-cc.debug",
1045 "TileManager::CheckAndIssueSignals - all tile tasks completed"); 1054 "TileManager::CheckAndIssueSignals - all tile tasks completed");
1046 signals_.did_notify_all_tile_tasks_completed = true; 1055 signals_.did_notify_all_tile_tasks_completed = true;
1047 client_->NotifyAllTileTasksCompleted(); 1056 client_->NotifyAllTileTasksCompleted();
1048 } 1057 }
1049 } 1058 }
1050 } 1059 }
1051 1060
1052 void TileManager::CheckIfMoreTilesNeedToBePrepared() { 1061 void TileManager::CheckIfMoreTilesNeedToBePrepared() {
1053 tile_task_runner_->CheckForCompletedTasks(); 1062 CheckAndProcessCompletedTasks();
1054 did_check_for_completed_tasks_since_last_schedule_tasks_ = true;
1055 1063
1056 // When OOM, keep re-assigning memory until we reach a steady state 1064 // When OOM, keep re-assigning memory until we reach a steady state
1057 // where top-priority tiles are initialized. 1065 // where top-priority tiles are initialized.
1058 PrioritizedTileVector tiles_that_need_to_be_rasterized; 1066 PrioritizedTileVector tiles_that_need_to_be_rasterized;
1059 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue( 1067 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue(
1060 client_->BuildRasterQueue(global_state_.tree_priority, 1068 client_->BuildRasterQueue(global_state_.tree_priority,
1061 RasterTilePriorityQueue::Type::ALL)); 1069 RasterTilePriorityQueue::Type::ALL));
1062 AssignGpuMemoryToTiles(raster_priority_queue.get(), 1070 AssignGpuMemoryToTiles(raster_priority_queue.get(),
1063 scheduled_raster_task_limit_, 1071 scheduled_raster_task_limit_,
1064 &tiles_that_need_to_be_rasterized); 1072 &tiles_that_need_to_be_rasterized);
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 void TileManager::Signals::reset() { 1244 void TileManager::Signals::reset() {
1237 ready_to_activate = false; 1245 ready_to_activate = false;
1238 did_notify_ready_to_activate = false; 1246 did_notify_ready_to_activate = false;
1239 ready_to_draw = false; 1247 ready_to_draw = false;
1240 did_notify_ready_to_draw = false; 1248 did_notify_ready_to_draw = false;
1241 all_tile_tasks_completed = false; 1249 all_tile_tasks_completed = false;
1242 did_notify_all_tile_tasks_completed = false; 1250 did_notify_all_tile_tasks_completed = false;
1243 } 1251 }
1244 1252
1245 } // namespace cc 1253 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/tile_manager.h ('k') | cc/tiles/tile_manager_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698