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

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

Issue 1229223003: Revert of Reland: cc: Make tile manager object persist for the length of LTHI. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « cc/tiles/tile_manager.h ('k') | cc/trees/layer_tree_host_impl.h » ('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 <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 10
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 base::saturated_cast<int>(stats.completed_count)); 221 base::saturated_cast<int>(stats.completed_count));
222 state->SetInteger("canceled_count", 222 state->SetInteger("canceled_count",
223 base::saturated_cast<int>(stats.canceled_count)); 223 base::saturated_cast<int>(stats.canceled_count));
224 return state; 224 return state;
225 } 225 }
226 226
227 // static 227 // static
228 scoped_ptr<TileManager> TileManager::Create( 228 scoped_ptr<TileManager> TileManager::Create(
229 TileManagerClient* client, 229 TileManagerClient* client,
230 base::SequencedTaskRunner* task_runner, 230 base::SequencedTaskRunner* task_runner,
231 ResourcePool* resource_pool,
232 TileTaskRunner* tile_task_runner,
231 size_t scheduled_raster_task_limit) { 233 size_t scheduled_raster_task_limit) {
232 return make_scoped_ptr( 234 return make_scoped_ptr(new TileManager(client, task_runner, resource_pool,
233 new TileManager(client, task_runner, scheduled_raster_task_limit)); 235 tile_task_runner,
236 scheduled_raster_task_limit));
234 } 237 }
235 238
236 TileManager::TileManager( 239 TileManager::TileManager(
237 TileManagerClient* client, 240 TileManagerClient* client,
238 const scoped_refptr<base::SequencedTaskRunner>& task_runner, 241 const scoped_refptr<base::SequencedTaskRunner>& task_runner,
242 ResourcePool* resource_pool,
243 TileTaskRunner* tile_task_runner,
239 size_t scheduled_raster_task_limit) 244 size_t scheduled_raster_task_limit)
240 : client_(client), 245 : client_(client),
241 task_runner_(task_runner), 246 task_runner_(task_runner),
242 resource_pool_(nullptr), 247 resource_pool_(resource_pool),
243 tile_task_runner_(nullptr), 248 tile_task_runner_(tile_task_runner),
244 scheduled_raster_task_limit_(scheduled_raster_task_limit), 249 scheduled_raster_task_limit_(scheduled_raster_task_limit),
245 all_tiles_that_need_to_be_rasterized_are_scheduled_(true), 250 all_tiles_that_need_to_be_rasterized_are_scheduled_(true),
246 did_check_for_completed_tasks_since_last_schedule_tasks_(true), 251 did_check_for_completed_tasks_since_last_schedule_tasks_(true),
247 did_oom_on_last_assign_(false), 252 did_oom_on_last_assign_(false),
248 more_tiles_need_prepare_check_notifier_( 253 more_tiles_need_prepare_check_notifier_(
249 task_runner_.get(), 254 task_runner_.get(),
250 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared, 255 base::Bind(&TileManager::CheckIfMoreTilesNeedToBePrepared,
251 base::Unretained(this))), 256 base::Unretained(this))),
252 signals_check_notifier_(task_runner_.get(), 257 signals_check_notifier_(task_runner_.get(),
253 base::Bind(&TileManager::CheckAndIssueSignals, 258 base::Bind(&TileManager::CheckAndIssueSignals,
254 base::Unretained(this))), 259 base::Unretained(this))),
255 has_scheduled_tile_tasks_(false), 260 has_scheduled_tile_tasks_(false),
256 prepare_tiles_count_(0u) { 261 prepare_tiles_count_(0u) {
262 tile_task_runner_->SetClient(this);
257 } 263 }
258 264
259 TileManager::~TileManager() { 265 TileManager::~TileManager() {
260 FinishTasksAndCleanUp(); 266 // Reset global state and manage. This should cause
261 } 267 // our memory usage to drop to zero.
262
263 void TileManager::FinishTasksAndCleanUp() {
264 if (!tile_task_runner_)
265 return;
266
267 global_state_ = GlobalStateThatImpactsTilePriority(); 268 global_state_ = GlobalStateThatImpactsTilePriority();
268 269
269 TileTaskQueue empty; 270 TileTaskQueue empty;
270 tile_task_runner_->ScheduleTasks(&empty); 271 tile_task_runner_->ScheduleTasks(&empty);
271 orphan_raster_tasks_.clear(); 272 orphan_raster_tasks_.clear();
272 273
273 // This should finish all pending tasks and release any uninitialized 274 // This should finish all pending tasks and release any uninitialized
274 // resources. 275 // resources.
275 tile_task_runner_->Shutdown(); 276 tile_task_runner_->Shutdown();
276 tile_task_runner_->CheckForCompletedTasks(); 277 tile_task_runner_->CheckForCompletedTasks();
277 278
278 FreeResourcesForReleasedTiles(); 279 FreeResourcesForReleasedTiles();
279 CleanUpReleasedTiles(); 280 CleanUpReleasedTiles();
280
281 tile_task_runner_ = nullptr;
282 resource_pool_ = nullptr;
283 more_tiles_need_prepare_check_notifier_.Cancel();
284 signals_check_notifier_.Cancel();
285 }
286
287 void TileManager::SetResources(ResourcePool* resource_pool,
288 TileTaskRunner* tile_task_runner,
289 size_t scheduled_raster_task_limit) {
290 DCHECK(!tile_task_runner_);
291 DCHECK(tile_task_runner);
292
293 scheduled_raster_task_limit_ = scheduled_raster_task_limit;
294 resource_pool_ = resource_pool;
295 tile_task_runner_ = tile_task_runner;
296 tile_task_runner_->SetClient(this);
297 } 281 }
298 282
299 void TileManager::Release(Tile* tile) { 283 void TileManager::Release(Tile* tile) {
300 released_tiles_.push_back(tile); 284 released_tiles_.push_back(tile);
301 } 285 }
302 286
303 TaskSetCollection TileManager::TasksThatShouldBeForcedToComplete() const { 287 TaskSetCollection TileManager::TasksThatShouldBeForcedToComplete() const {
304 TaskSetCollection tasks_that_should_be_forced_to_complete; 288 TaskSetCollection tasks_that_should_be_forced_to_complete;
305 if (global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY) 289 if (global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY)
306 tasks_that_should_be_forced_to_complete[REQUIRED_FOR_ACTIVATION] = true; 290 tasks_that_should_be_forced_to_complete[REQUIRED_FOR_ACTIVATION] = true;
(...skipping 26 matching lines...) Expand all
333 } 317 }
334 318
335 delete tile; 319 delete tile;
336 } 320 }
337 released_tiles_.swap(tiles_to_retain); 321 released_tiles_.swap(tiles_to_retain);
338 } 322 }
339 323
340 void TileManager::DidFinishRunningTileTasks(TaskSet task_set) { 324 void TileManager::DidFinishRunningTileTasks(TaskSet task_set) {
341 TRACE_EVENT1("cc", "TileManager::DidFinishRunningTileTasks", "task_set", 325 TRACE_EVENT1("cc", "TileManager::DidFinishRunningTileTasks", "task_set",
342 TaskSetName(task_set)); 326 TaskSetName(task_set));
343 DCHECK(resource_pool_);
344 DCHECK(tile_task_runner_);
345 327
346 switch (task_set) { 328 switch (task_set) {
347 case ALL: { 329 case ALL: {
348 has_scheduled_tile_tasks_ = false; 330 has_scheduled_tile_tasks_ = false;
349 331
350 bool memory_usage_above_limit = 332 bool memory_usage_above_limit =
351 resource_pool_->total_memory_usage_bytes() > 333 resource_pool_->total_memory_usage_bytes() >
352 global_state_.soft_memory_limit_in_bytes; 334 global_state_.soft_memory_limit_in_bytes;
353 335
354 if (all_tiles_that_need_to_be_rasterized_are_scheduled_ && 336 if (all_tiles_that_need_to_be_rasterized_are_scheduled_ &&
(...skipping 16 matching lines...) Expand all
371 353
372 case REQUIRED_FOR_DRAW: 354 case REQUIRED_FOR_DRAW:
373 signals_.ready_to_draw = true; 355 signals_.ready_to_draw = true;
374 signals_check_notifier_.Schedule(); 356 signals_check_notifier_.Schedule();
375 return; 357 return;
376 } 358 }
377 359
378 NOTREACHED(); 360 NOTREACHED();
379 } 361 }
380 362
381 bool TileManager::PrepareTiles( 363 void TileManager::PrepareTiles(
382 const GlobalStateThatImpactsTilePriority& state) { 364 const GlobalStateThatImpactsTilePriority& state) {
383 ++prepare_tiles_count_; 365 ++prepare_tiles_count_;
384 366
385 TRACE_EVENT1("cc", "TileManager::PrepareTiles", "prepare_tiles_id", 367 TRACE_EVENT1("cc", "TileManager::PrepareTiles", "prepare_tiles_id",
386 prepare_tiles_count_); 368 prepare_tiles_count_);
387 369
388 if (!tile_task_runner_) {
389 TRACE_EVENT_INSTANT0("cc", "PrepareTiles aborted",
390 TRACE_EVENT_SCOPE_THREAD);
391 return false;
392 }
393
394 signals_.reset(); 370 signals_.reset();
395 global_state_ = state; 371 global_state_ = state;
396 372
397 // We need to call CheckForCompletedTasks() once in-between each call 373 // We need to call CheckForCompletedTasks() once in-between each call
398 // to ScheduleTasks() to prevent canceled tasks from being scheduled. 374 // to ScheduleTasks() to prevent canceled tasks from being scheduled.
399 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) { 375 if (!did_check_for_completed_tasks_since_last_schedule_tasks_) {
400 tile_task_runner_->CheckForCompletedTasks(); 376 tile_task_runner_->CheckForCompletedTasks();
401 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; 377 did_check_for_completed_tasks_since_last_schedule_tasks_ = true;
402 } 378 }
403 379
(...skipping 16 matching lines...) Expand all
420 396
421 // Schedule tile tasks. 397 // Schedule tile tasks.
422 ScheduleTasks(tiles_that_need_to_be_rasterized); 398 ScheduleTasks(tiles_that_need_to_be_rasterized);
423 399
424 TRACE_EVENT_INSTANT1("cc", "DidPrepareTiles", TRACE_EVENT_SCOPE_THREAD, 400 TRACE_EVENT_INSTANT1("cc", "DidPrepareTiles", TRACE_EVENT_SCOPE_THREAD,
425 "state", BasicStateAsValue()); 401 "state", BasicStateAsValue());
426 402
427 TRACE_COUNTER_ID1("cc", "unused_memory_bytes", this, 403 TRACE_COUNTER_ID1("cc", "unused_memory_bytes", this,
428 resource_pool_->total_memory_usage_bytes() - 404 resource_pool_->total_memory_usage_bytes() -
429 resource_pool_->acquired_memory_usage_bytes()); 405 resource_pool_->acquired_memory_usage_bytes());
430 return true;
431 } 406 }
432 407
433 void TileManager::Flush() { 408 void TileManager::Flush() {
434 TRACE_EVENT0("cc", "TileManager::Flush"); 409 TRACE_EVENT0("cc", "TileManager::Flush");
435 410
436 if (!tile_task_runner_) {
437 TRACE_EVENT_INSTANT0("cc", "Flush aborted", TRACE_EVENT_SCOPE_THREAD);
438 return;
439 }
440
441 tile_task_runner_->CheckForCompletedTasks(); 411 tile_task_runner_->CheckForCompletedTasks();
442 412
443 did_check_for_completed_tasks_since_last_schedule_tasks_ = true; 413 did_check_for_completed_tasks_since_last_schedule_tasks_ = true;
444 414
445 TRACE_EVENT_INSTANT1("cc", "DidFlush", TRACE_EVENT_SCOPE_THREAD, "stats", 415 TRACE_EVENT_INSTANT1("cc", "DidFlush", TRACE_EVENT_SCOPE_THREAD, "stats",
446 RasterTaskCompletionStatsAsValue(flush_stats_)); 416 RasterTaskCompletionStatsAsValue(flush_stats_));
447 flush_stats_ = RasterTaskCompletionStats(); 417 flush_stats_ = RasterTaskCompletionStats();
448 } 418 }
449 419
450 scoped_refptr<base::trace_event::ConvertableToTraceFormat> 420 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 NOTREACHED(); 497 NOTREACHED();
528 return true; 498 return true;
529 } 499 }
530 500
531 void TileManager::AssignGpuMemoryToTiles( 501 void TileManager::AssignGpuMemoryToTiles(
532 RasterTilePriorityQueue* raster_priority_queue, 502 RasterTilePriorityQueue* raster_priority_queue,
533 size_t scheduled_raster_task_limit, 503 size_t scheduled_raster_task_limit,
534 PrioritizedTileVector* tiles_that_need_to_be_rasterized) { 504 PrioritizedTileVector* tiles_that_need_to_be_rasterized) {
535 TRACE_EVENT_BEGIN0("cc", "TileManager::AssignGpuMemoryToTiles"); 505 TRACE_EVENT_BEGIN0("cc", "TileManager::AssignGpuMemoryToTiles");
536 506
537 DCHECK(resource_pool_);
538 DCHECK(tile_task_runner_);
539
540 // Maintain the list of released resources that can potentially be re-used 507 // Maintain the list of released resources that can potentially be re-used
541 // or deleted. If this operation becomes expensive too, only do this after 508 // or deleted. If this operation becomes expensive too, only do this after
542 // some resource(s) was returned. Note that in that case, one also need to 509 // some resource(s) was returned. Note that in that case, one also need to
543 // invalidate when releasing some resource from the pool. 510 // invalidate when releasing some resource from the pool.
544 resource_pool_->CheckBusyResources(false); 511 resource_pool_->CheckBusyResources(false);
545 512
546 // Now give memory out to the tiles until we're out, and build 513 // Now give memory out to the tiles until we're out, and build
547 // the needs-to-be-rasterized queue. 514 // the needs-to-be-rasterized queue.
548 unsigned schedule_priority = 1u; 515 unsigned schedule_priority = 1u;
549 all_tiles_that_need_to_be_rasterized_are_scheduled_ = true; 516 all_tiles_that_need_to_be_rasterized_are_scheduled_ = true;
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 814
848 client_->NotifyTileStateChanged(tile); 815 client_->NotifyTileStateChanged(tile);
849 } 816 }
850 817
851 ScopedTilePtr TileManager::CreateTile(const gfx::Size& desired_texture_size, 818 ScopedTilePtr TileManager::CreateTile(const gfx::Size& desired_texture_size,
852 const gfx::Rect& content_rect, 819 const gfx::Rect& content_rect,
853 float contents_scale, 820 float contents_scale,
854 int layer_id, 821 int layer_id,
855 int source_frame_number, 822 int source_frame_number,
856 int flags) { 823 int flags) {
857 // We need to have a tile task worker pool to do anything meaningful with
858 // tiles.
859 DCHECK(tile_task_runner_);
860 ScopedTilePtr tile(new Tile(this, desired_texture_size, content_rect, 824 ScopedTilePtr tile(new Tile(this, desired_texture_size, content_rect,
861 contents_scale, layer_id, source_frame_number, 825 contents_scale, layer_id, source_frame_number,
862 flags)); 826 flags));
863 DCHECK(tiles_.find(tile->id()) == tiles_.end()); 827 DCHECK(tiles_.find(tile->id()) == tiles_.end());
864 828
865 tiles_[tile->id()] = tile.get(); 829 tiles_[tile->id()] = tile.get();
866 used_layer_counts_[tile->layer_id()]++; 830 used_layer_counts_[tile->layer_id()]++;
867 return tile; 831 return tile;
868 } 832 }
869 833
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 void TileManager::Signals::reset() { 1057 void TileManager::Signals::reset() {
1094 ready_to_activate = false; 1058 ready_to_activate = false;
1095 did_notify_ready_to_activate = false; 1059 did_notify_ready_to_activate = false;
1096 ready_to_draw = false; 1060 ready_to_draw = false;
1097 did_notify_ready_to_draw = false; 1061 did_notify_ready_to_draw = false;
1098 all_tile_tasks_completed = false; 1062 all_tile_tasks_completed = false;
1099 did_notify_all_tile_tasks_completed = false; 1063 did_notify_all_tile_tasks_completed = false;
1100 } 1064 }
1101 1065
1102 } // namespace cc 1066 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/tile_manager.h ('k') | cc/trees/layer_tree_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698