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

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

Issue 1951193002: cc: Add mailbox support to ResourceProvider write locks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@worker_context_stream
Patch Set: rebase Created 4 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 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 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 void TileManager::FinishTasksAndCleanUp() { 337 void TileManager::FinishTasksAndCleanUp() {
338 if (!tile_task_manager_) 338 if (!tile_task_manager_)
339 return; 339 return;
340 340
341 global_state_ = GlobalStateThatImpactsTilePriority(); 341 global_state_ = GlobalStateThatImpactsTilePriority();
342 342
343 // This cancels tasks if possible, finishes pending tasks, and release any 343 // This cancels tasks if possible, finishes pending tasks, and release any
344 // uninitialized resources. 344 // uninitialized resources.
345 tile_task_manager_->Shutdown(); 345 tile_task_manager_->Shutdown();
346 346
347 // Now that all tasks have been finished, we can clear any 347 raster_buffer_provider_->Shutdown();
348 // |orphan_tasks_|. 348
349 // Now that all tasks have been finished, we can clear any |orphan_tasks_|.
349 orphan_tasks_.clear(); 350 orphan_tasks_.clear();
350 351
351 tile_task_manager_->CheckForCompletedTasks(); 352 tile_task_manager_->CheckForCompletedTasks();
352 353
353 FreeResourcesForReleasedTiles(); 354 FreeResourcesForReleasedTiles();
354 CleanUpReleasedTiles(); 355 CleanUpReleasedTiles();
355 356
356 tile_task_manager_ = nullptr; 357 tile_task_manager_ = nullptr;
357 resource_pool_ = nullptr; 358 resource_pool_ = nullptr;
358 more_tiles_need_prepare_check_notifier_.Cancel(); 359 more_tiles_need_prepare_check_notifier_.Cancel();
359 signals_check_notifier_.Cancel(); 360 signals_check_notifier_.Cancel();
360 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs(); 361 task_set_finished_weak_ptr_factory_.InvalidateWeakPtrs();
361 } 362 }
362 363
363 void TileManager::SetResources(ResourcePool* resource_pool, 364 void TileManager::SetResources(ResourcePool* resource_pool,
364 ImageDecodeController* image_decode_controller, 365 ImageDecodeController* image_decode_controller,
365 TileTaskManager* tile_task_manager, 366 TileTaskManager* tile_task_manager,
367 RasterBufferProvider* raster_buffer_provider,
366 size_t scheduled_raster_task_limit, 368 size_t scheduled_raster_task_limit,
367 bool use_gpu_rasterization) { 369 bool use_gpu_rasterization) {
368 DCHECK(!tile_task_manager_); 370 DCHECK(!tile_task_manager_);
369 DCHECK(tile_task_manager); 371 DCHECK(tile_task_manager);
370 372
371 use_gpu_rasterization_ = use_gpu_rasterization; 373 use_gpu_rasterization_ = use_gpu_rasterization;
372 scheduled_raster_task_limit_ = scheduled_raster_task_limit; 374 scheduled_raster_task_limit_ = scheduled_raster_task_limit;
373 resource_pool_ = resource_pool; 375 resource_pool_ = resource_pool;
374 image_decode_controller_ = image_decode_controller; 376 image_decode_controller_ = image_decode_controller;
375 tile_task_manager_ = tile_task_manager; 377 tile_task_manager_ = tile_task_manager;
378 raster_buffer_provider_ = raster_buffer_provider;
376 } 379 }
377 380
378 void TileManager::Release(Tile* tile) { 381 void TileManager::Release(Tile* tile) {
379 released_tiles_.push_back(tile); 382 released_tiles_.push_back(tile);
380 } 383 }
381 384
382 void TileManager::FreeResourcesForReleasedTiles() { 385 void TileManager::FreeResourcesForReleasedTiles() {
383 for (auto* tile : released_tiles_) 386 for (auto* tile : released_tiles_)
384 FreeResourcesForTile(tile); 387 FreeResourcesForTile(tile);
385 } 388 }
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 kRequiredForDrawDoneTaskPriority, required_for_draw_count); 831 kRequiredForDrawDoneTaskPriority, required_for_draw_count);
829 InsertNodeForTask(&graph_, all_done_task.get(), 832 InsertNodeForTask(&graph_, all_done_task.get(),
830 TASK_CATEGORY_NONCONCURRENT_FOREGROUND, 833 TASK_CATEGORY_NONCONCURRENT_FOREGROUND,
831 kAllDoneTaskPriority, all_count); 834 kAllDoneTaskPriority, all_count);
832 835
833 // We must reduce the amount of unused resoruces before calling 836 // We must reduce the amount of unused resoruces before calling
834 // ScheduleTasks to prevent usage from rising above limits. 837 // ScheduleTasks to prevent usage from rising above limits.
835 resource_pool_->ReduceResourceUsage(); 838 resource_pool_->ReduceResourceUsage();
836 image_decode_controller_->ReduceCacheUsage(); 839 image_decode_controller_->ReduceCacheUsage();
837 840
841 // Synchronize worker with compositor.
842 raster_buffer_provider_->OrderingBarrier();
843
838 // Schedule running of |raster_queue_|. This replaces any previously 844 // Schedule running of |raster_queue_|. This replaces any previously
839 // scheduled tasks and effectively cancels all tasks not present 845 // scheduled tasks and effectively cancels all tasks not present
840 // in |raster_queue_|. 846 // in |raster_queue_|.
841 tile_task_manager_->ScheduleTasks(&graph_); 847 tile_task_manager_->ScheduleTasks(&graph_);
842 848
843 // It's now safe to clean up orphan tasks as raster worker pool is not 849 // It's now safe to clean up orphan tasks as raster worker pool is not
844 // allowed to keep around unreferenced raster tasks after ScheduleTasks() has 850 // allowed to keep around unreferenced raster tasks after ScheduleTasks() has
845 // been called. 851 // been called.
846 orphan_tasks_.clear(); 852 orphan_tasks_.clear();
847 853
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 decode_tasks.push_back(task); 911 decode_tasks.push_back(task);
906 912
907 if (need_to_unref_when_finished) 913 if (need_to_unref_when_finished)
908 ++it; 914 ++it;
909 else 915 else
910 it = images.erase(it); 916 it = images.erase(it);
911 } 917 }
912 918
913 bool supports_concurrent_execution = !use_gpu_rasterization_; 919 bool supports_concurrent_execution = !use_gpu_rasterization_;
914 std::unique_ptr<RasterBuffer> raster_buffer = 920 std::unique_ptr<RasterBuffer> raster_buffer =
915 tile_task_manager_->GetRasterBufferProvider()->AcquireBufferForRaster( 921 raster_buffer_provider_->AcquireBufferForRaster(
916 resource, resource_content_id, tile->invalidated_id()); 922 resource, resource_content_id, tile->invalidated_id());
917 return make_scoped_refptr(new RasterTaskImpl( 923 return make_scoped_refptr(new RasterTaskImpl(
918 this, tile, resource, prioritized_tile.raster_source(), playback_settings, 924 this, tile, resource, prioritized_tile.raster_source(), playback_settings,
919 prioritized_tile.priority().resolution, prepare_tiles_count_, 925 prioritized_tile.priority().resolution, prepare_tiles_count_,
920 std::move(raster_buffer), &decode_tasks, supports_concurrent_execution)); 926 std::move(raster_buffer), &decode_tasks, supports_concurrent_execution));
921 } 927 }
922 928
923 void TileManager::OnRasterTaskCompleted( 929 void TileManager::OnRasterTaskCompleted(
924 std::unique_ptr<RasterBuffer> raster_buffer, 930 std::unique_ptr<RasterBuffer> raster_buffer,
925 Tile* tile, 931 Tile* tile,
926 Resource* resource, 932 Resource* resource,
927 bool was_canceled) { 933 bool was_canceled) {
928 DCHECK(tile); 934 DCHECK(tile);
929 DCHECK(tiles_.find(tile->id()) != tiles_.end()); 935 DCHECK(tiles_.find(tile->id()) != tiles_.end());
930 tile_task_manager_->GetRasterBufferProvider()->ReleaseBufferForRaster( 936 raster_buffer_provider_->ReleaseBufferForRaster(std::move(raster_buffer));
931 std::move(raster_buffer));
932 937
933 TileDrawInfo& draw_info = tile->draw_info(); 938 TileDrawInfo& draw_info = tile->draw_info();
934 DCHECK(tile->raster_task_.get()); 939 DCHECK(tile->raster_task_.get());
935 orphan_tasks_.push_back(tile->raster_task_); 940 orphan_tasks_.push_back(tile->raster_task_);
936 tile->raster_task_ = nullptr; 941 tile->raster_task_ = nullptr;
937 942
938 // Unref all the images. 943 // Unref all the images.
939 auto images_it = scheduled_draw_images_.find(tile->id()); 944 auto images_it = scheduled_draw_images_.find(tile->id());
940 const std::vector<DrawImage>& images = images_it->second; 945 const std::vector<DrawImage>& images = images_it->second;
941 for (const auto& image : images) 946 for (const auto& image : images)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
977 982
978 tiles_[tile->id()] = tile.get(); 983 tiles_[tile->id()] = tile.get();
979 return tile; 984 return tile;
980 } 985 }
981 986
982 void TileManager::SetTileTaskManagerForTesting( 987 void TileManager::SetTileTaskManagerForTesting(
983 TileTaskManager* tile_task_manager) { 988 TileTaskManager* tile_task_manager) {
984 tile_task_manager_ = tile_task_manager; 989 tile_task_manager_ = tile_task_manager;
985 } 990 }
986 991
992 void TileManager::SetRasterBufferProviderForTesting(
993 RasterBufferProvider* raster_buffer_provider) {
994 raster_buffer_provider_ = raster_buffer_provider;
995 }
996
987 bool TileManager::AreRequiredTilesReadyToDraw( 997 bool TileManager::AreRequiredTilesReadyToDraw(
988 RasterTilePriorityQueue::Type type) const { 998 RasterTilePriorityQueue::Type type) const {
989 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue( 999 std::unique_ptr<RasterTilePriorityQueue> raster_priority_queue(
990 client_->BuildRasterQueue(global_state_.tree_priority, type)); 1000 client_->BuildRasterQueue(global_state_.tree_priority, type));
991 // It is insufficient to check whether the raster queue we constructed is 1001 // It is insufficient to check whether the raster queue we constructed is
992 // empty. The reason for this is that there are situations (rasterize on 1002 // empty. The reason for this is that there are situations (rasterize on
993 // demand) when the tile both needs raster and it's ready to draw. Hence, we 1003 // demand) when the tile both needs raster and it's ready to draw. Hence, we
994 // have to iterate the queue to check whether the required tiles are ready to 1004 // have to iterate the queue to check whether the required tiles are ready to
995 // draw. 1005 // draw.
996 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) { 1006 for (; !raster_priority_queue->IsEmpty(); raster_priority_queue->Pop()) {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 Tile* tile = queue->Top().tile(); 1149 Tile* tile = queue->Top().tile();
1140 if (tile->draw_info().IsReadyToDraw()) 1150 if (tile->draw_info().IsReadyToDraw())
1141 continue; 1151 continue;
1142 tile->draw_info().set_oom(); 1152 tile->draw_info().set_oom();
1143 client_->NotifyTileStateChanged(tile); 1153 client_->NotifyTileStateChanged(tile);
1144 } 1154 }
1145 return true; 1155 return true;
1146 } 1156 }
1147 1157
1148 ResourceFormat TileManager::DetermineResourceFormat(const Tile* tile) const { 1158 ResourceFormat TileManager::DetermineResourceFormat(const Tile* tile) const {
1149 return tile_task_manager_->GetRasterBufferProvider()->GetResourceFormat( 1159 return raster_buffer_provider_->GetResourceFormat(!tile->is_opaque());
1160 }
1161
1162 bool TileManager::DetermineResourceRequiresSwizzle(const Tile* tile) const {
1163 return raster_buffer_provider_->GetResourceRequiresSwizzle(
1150 !tile->is_opaque()); 1164 !tile->is_opaque());
1151 } 1165 }
1152 1166
1153 bool TileManager::DetermineResourceRequiresSwizzle(const Tile* tile) const {
1154 return tile_task_manager_->GetRasterBufferProvider()
1155 ->GetResourceRequiresSwizzle(!tile->is_opaque());
1156 }
1157
1158 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> 1167 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
1159 TileManager::ScheduledTasksStateAsValue() const { 1168 TileManager::ScheduledTasksStateAsValue() const {
1160 std::unique_ptr<base::trace_event::TracedValue> state( 1169 std::unique_ptr<base::trace_event::TracedValue> state(
1161 new base::trace_event::TracedValue()); 1170 new base::trace_event::TracedValue());
1162 state->BeginDictionary("tasks_pending"); 1171 state->BeginDictionary("tasks_pending");
1163 state->SetBoolean("ready_to_activate", signals_.ready_to_activate); 1172 state->SetBoolean("ready_to_activate", signals_.ready_to_activate);
1164 state->SetBoolean("ready_to_draw", signals_.ready_to_draw); 1173 state->SetBoolean("ready_to_draw", signals_.ready_to_draw);
1165 state->SetBoolean("all_tile_tasks_completed", 1174 state->SetBoolean("all_tile_tasks_completed",
1166 signals_.all_tile_tasks_completed); 1175 signals_.all_tile_tasks_completed);
1167 state->EndDictionary(); 1176 state->EndDictionary();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 void TileManager::Signals::reset() { 1256 void TileManager::Signals::reset() {
1248 ready_to_activate = false; 1257 ready_to_activate = false;
1249 did_notify_ready_to_activate = false; 1258 did_notify_ready_to_activate = false;
1250 ready_to_draw = false; 1259 ready_to_draw = false;
1251 did_notify_ready_to_draw = false; 1260 did_notify_ready_to_draw = false;
1252 all_tile_tasks_completed = false; 1261 all_tile_tasks_completed = false;
1253 did_notify_all_tile_tasks_completed = false; 1262 did_notify_all_tile_tasks_completed = false;
1254 } 1263 }
1255 1264
1256 } // namespace cc 1265 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698