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

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

Issue 98113005: Revert "cc: Added tile bundles" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « cc/resources/tile_manager.h ('k') | cc/resources/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/resources/tile_manager.h" 5 #include "cc/resources/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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 did_check_for_completed_tasks_since_last_schedule_tasks_(true) { 217 did_check_for_completed_tasks_since_last_schedule_tasks_(true) {
218 raster_worker_pool_->SetClient(this); 218 raster_worker_pool_->SetClient(this);
219 } 219 }
220 220
221 TileManager::~TileManager() { 221 TileManager::~TileManager() {
222 // Reset global state and manage. This should cause 222 // Reset global state and manage. This should cause
223 // our memory usage to drop to zero. 223 // our memory usage to drop to zero.
224 global_state_ = GlobalStateThatImpactsTilePriority(); 224 global_state_ = GlobalStateThatImpactsTilePriority();
225 225
226 CleanUpReleasedTiles(); 226 CleanUpReleasedTiles();
227 DCHECK_EQ(0u, bundles_.size());
228 DCHECK_EQ(0u, tiles_.size()); 227 DCHECK_EQ(0u, tiles_.size());
229 228
230 RasterWorkerPool::RasterTask::Queue empty; 229 RasterWorkerPool::RasterTask::Queue empty;
231 raster_worker_pool_->ScheduleTasks(&empty); 230 raster_worker_pool_->ScheduleTasks(&empty);
232 231
233 // This should finish all pending tasks and release any uninitialized 232 // This should finish all pending tasks and release any uninitialized
234 // resources. 233 // resources.
235 raster_worker_pool_->Shutdown(); 234 raster_worker_pool_->Shutdown();
236 raster_worker_pool_->CheckForCompletedTasks(); 235 raster_worker_pool_->CheckForCompletedTasks();
237 236
238 DCHECK_EQ(0u, bytes_releasable_); 237 DCHECK_EQ(0u, bytes_releasable_);
239 DCHECK_EQ(0u, resources_releasable_); 238 DCHECK_EQ(0u, resources_releasable_);
240 } 239 }
241 240
242 void TileManager::Release(Tile* tile) { 241 void TileManager::Release(Tile* tile) {
243 prioritized_tiles_dirty_ = true; 242 prioritized_tiles_dirty_ = true;
244 released_tiles_.push_back(tile); 243 released_tiles_.push_back(tile);
245 } 244 }
246 245
247 void TileManager::Release(TileBundle* bundle) {
248 released_tile_bundles_.push_back(bundle);
249 }
250
251 void TileManager::DidChangeTilePriority(Tile* tile) { 246 void TileManager::DidChangeTilePriority(Tile* tile) {
252 prioritized_tiles_dirty_ = true; 247 prioritized_tiles_dirty_ = true;
253 } 248 }
254 249
255 void TileManager::DidChangeTileBundlePriority(TileBundle* bundle) {
256 prioritized_tiles_dirty_ = true;
257 }
258
259 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const { 250 bool TileManager::ShouldForceTasksRequiredForActivationToComplete() const {
260 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY; 251 return global_state_.tree_priority != SMOOTHNESS_TAKES_PRIORITY;
261 } 252 }
262 253
263 void TileManager::CleanUpReleasedTiles() { 254 void TileManager::CleanUpReleasedTiles() {
264 // Clean up bundles first, since they might have tiles that will become
265 // released as well.
266 for (std::vector<TileBundle*>::iterator it = released_tile_bundles_.begin();
267 it != released_tile_bundles_.end();
268 ++it) {
269 TileBundle* bundle = *it;
270 DCHECK(bundles_.find(bundle->id()) != bundles_.end());
271 bundles_.erase(bundle->id());
272 delete bundle;
273 }
274 released_tile_bundles_.clear();
275
276 for (std::vector<Tile*>::iterator it = released_tiles_.begin(); 255 for (std::vector<Tile*>::iterator it = released_tiles_.begin();
277 it != released_tiles_.end(); 256 it != released_tiles_.end();
278 ++it) { 257 ++it) {
279 Tile* tile = *it; 258 Tile* tile = *it;
280 259
281 FreeResourcesForTile(tile); 260 FreeResourcesForTile(tile);
282 261
283 DCHECK(tiles_.find(tile->id()) != tiles_.end()); 262 DCHECK(tiles_.find(tile->id()) != tiles_.end());
284 tiles_.erase(tile->id()); 263 tiles_.erase(tile->id());
285 264
286 LayerCountMap::iterator layer_it = 265 LayerCountMap::iterator layer_it =
287 used_layer_counts_.find(tile->layer_id()); 266 used_layer_counts_.find(tile->layer_id());
288 DCHECK_GT(layer_it->second, 0); 267 DCHECK_GT(layer_it->second, 0);
289 if (--layer_it->second == 0) { 268 if (--layer_it->second == 0) {
290 used_layer_counts_.erase(layer_it); 269 used_layer_counts_.erase(layer_it);
291 image_decode_tasks_.erase(tile->layer_id()); 270 image_decode_tasks_.erase(tile->layer_id());
292 } 271 }
293 272
294 delete tile; 273 delete tile;
295 } 274 }
275
296 released_tiles_.clear(); 276 released_tiles_.clear();
297 } 277 }
298 278
299 void TileManager::UpdatePrioritizedTileSetIfNeeded() { 279 void TileManager::UpdatePrioritizedTileSetIfNeeded() {
300 if (!prioritized_tiles_dirty_) 280 if (!prioritized_tiles_dirty_)
301 return; 281 return;
302 282
303 CleanUpReleasedTiles(); 283 CleanUpReleasedTiles();
304 284
305 prioritized_tiles_.Clear(); 285 prioritized_tiles_.Clear();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins"); 351 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins");
372 352
373 // Compute new stats to be return by GetMemoryStats(). 353 // Compute new stats to be return by GetMemoryStats().
374 memory_required_bytes_ = 0; 354 memory_required_bytes_ = 0;
375 memory_nice_to_have_bytes_ = 0; 355 memory_nice_to_have_bytes_ = 0;
376 356
377 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy; 357 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy;
378 const TreePriority tree_priority = global_state_.tree_priority; 358 const TreePriority tree_priority = global_state_.tree_priority;
379 359
380 // For each tree, bin into different categories of tiles. 360 // For each tree, bin into different categories of tiles.
381 for (TileBundleMap::iterator bundle_it = bundles_.begin(); 361 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
382 bundle_it != bundles_.end(); 362 Tile* tile = it->second;
383 ++bundle_it) { 363 ManagedTileState& mts = tile->managed_state();
384 for (TileBundle::Iterator it(bundle_it->second); it; ++it) {
385 Tile* tile = *it;
386 ManagedTileState& mts = tile->managed_state();
387 364
388 const ManagedTileState::TileVersion& tile_version = 365 const ManagedTileState::TileVersion& tile_version =
389 tile->GetTileVersionForDrawing(); 366 tile->GetTileVersionForDrawing();
390 bool tile_is_ready_to_draw = tile_version.IsReadyToDraw(); 367 bool tile_is_ready_to_draw = tile_version.IsReadyToDraw();
391 bool tile_is_active = 368 bool tile_is_active =
392 tile_is_ready_to_draw || 369 tile_is_ready_to_draw ||
393 !mts.tile_versions[mts.raster_mode].raster_task_.is_null(); 370 !mts.tile_versions[mts.raster_mode].raster_task_.is_null();
394 371
395 // Get the active priority and bin. 372 // Get the active priority and bin.
396 TilePriority active_priority = it.priority(ACTIVE_TREE); 373 TilePriority active_priority = tile->priority(ACTIVE_TREE);
397 ManagedTileBin active_bin = BinFromTilePriority(active_priority); 374 ManagedTileBin active_bin = BinFromTilePriority(active_priority);
398 375
399 // Get the pending priority and bin. 376 // Get the pending priority and bin.
400 TilePriority pending_priority = it.priority(PENDING_TREE); 377 TilePriority pending_priority = tile->priority(PENDING_TREE);
401 ManagedTileBin pending_bin = BinFromTilePriority(pending_priority); 378 ManagedTileBin pending_bin = BinFromTilePriority(pending_priority);
402 379
403 bool pending_is_low_res = 380 bool pending_is_low_res =
404 pending_priority.resolution == LOW_RESOLUTION; 381 pending_priority.resolution == LOW_RESOLUTION;
405 bool pending_is_non_ideal = 382 bool pending_is_non_ideal =
406 pending_priority.resolution == NON_IDEAL_RESOLUTION; 383 pending_priority.resolution == NON_IDEAL_RESOLUTION;
407 bool active_is_non_ideal = 384 bool active_is_non_ideal =
408 active_priority.resolution == NON_IDEAL_RESOLUTION; 385 active_priority.resolution == NON_IDEAL_RESOLUTION;
409 386
410 // Adjust pending bin state for low res tiles. This prevents 387 // Adjust pending bin state for low res tiles. This prevents
411 // pending tree low-res tiles from being initialized before 388 // pending tree low-res tiles from being initialized before
412 // high-res tiles. 389 // high-res tiles.
413 if (pending_is_low_res) 390 if (pending_is_low_res)
414 pending_bin = std::max(pending_bin, EVENTUALLY_BIN); 391 pending_bin = std::max(pending_bin, EVENTUALLY_BIN);
415 392
416 // Adjust bin state based on if ready to draw. 393 // Adjust bin state based on if ready to draw.
417 active_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][active_bin]; 394 active_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][active_bin];
418 pending_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][pending_bin]; 395 pending_bin = kBinReadyToDrawMap[tile_is_ready_to_draw][pending_bin];
419 396
420 // Adjust bin state based on if active. 397 // Adjust bin state based on if active.
421 active_bin = kBinIsActiveMap[tile_is_active][active_bin]; 398 active_bin = kBinIsActiveMap[tile_is_active][active_bin];
422 pending_bin = kBinIsActiveMap[tile_is_active][pending_bin]; 399 pending_bin = kBinIsActiveMap[tile_is_active][pending_bin];
423 400
424 // We never want to paint new non-ideal tiles, as we always have 401 // We never want to paint new non-ideal tiles, as we always have
425 // a high-res tile covering that content (paint that instead). 402 // a high-res tile covering that content (paint that instead).
426 if (!tile_is_ready_to_draw && active_is_non_ideal) 403 if (!tile_is_ready_to_draw && active_is_non_ideal)
427 active_bin = NEVER_BIN; 404 active_bin = NEVER_BIN;
428 if (!tile_is_ready_to_draw && pending_is_non_ideal) 405 if (!tile_is_ready_to_draw && pending_is_non_ideal)
429 pending_bin = NEVER_BIN; 406 pending_bin = NEVER_BIN;
430 407
431 // Compute combined bin. 408 // Compute combined bin.
432 ManagedTileBin combined_bin = std::min(active_bin, pending_bin); 409 ManagedTileBin combined_bin = std::min(active_bin, pending_bin);
433 410
434 ManagedTileBin tree_bin[NUM_TREES]; 411 ManagedTileBin tree_bin[NUM_TREES];
435 tree_bin[ACTIVE_TREE] = kBinPolicyMap[memory_policy][active_bin]; 412 tree_bin[ACTIVE_TREE] = kBinPolicyMap[memory_policy][active_bin];
436 tree_bin[PENDING_TREE] = kBinPolicyMap[memory_policy][pending_bin]; 413 tree_bin[PENDING_TREE] = kBinPolicyMap[memory_policy][pending_bin];
437 414
438 // The bin that the tile would have if the GPU memory manager had 415 // The bin that the tile would have if the GPU memory manager had
439 // a maximally permissive policy, send to the GPU memory manager 416 // a maximally permissive policy, send to the GPU memory manager
440 // to determine policy. 417 // to determine policy.
441 ManagedTileBin gpu_memmgr_stats_bin = NEVER_BIN; 418 ManagedTileBin gpu_memmgr_stats_bin = NEVER_BIN;
442 TilePriority tile_priority; 419 TilePriority tile_priority;
443 420
444 switch (tree_priority) { 421 switch (tree_priority) {
445 case SAME_PRIORITY_FOR_BOTH_TREES: 422 case SAME_PRIORITY_FOR_BOTH_TREES:
446 mts.bin = kBinPolicyMap[memory_policy][combined_bin]; 423 mts.bin = kBinPolicyMap[memory_policy][combined_bin];
447 gpu_memmgr_stats_bin = combined_bin; 424 gpu_memmgr_stats_bin = combined_bin;
448 tile_priority = TilePriority(active_priority, pending_priority); 425 tile_priority = tile->combined_priority();
449 break; 426 break;
450 case SMOOTHNESS_TAKES_PRIORITY: 427 case SMOOTHNESS_TAKES_PRIORITY:
451 mts.bin = tree_bin[ACTIVE_TREE]; 428 mts.bin = tree_bin[ACTIVE_TREE];
452 gpu_memmgr_stats_bin = active_bin; 429 gpu_memmgr_stats_bin = active_bin;
453 tile_priority = active_priority; 430 tile_priority = active_priority;
454 break; 431 break;
455 case NEW_CONTENT_TAKES_PRIORITY: 432 case NEW_CONTENT_TAKES_PRIORITY:
456 mts.bin = tree_bin[PENDING_TREE]; 433 mts.bin = tree_bin[PENDING_TREE];
457 gpu_memmgr_stats_bin = pending_bin; 434 gpu_memmgr_stats_bin = pending_bin;
458 tile_priority = pending_priority; 435 tile_priority = pending_priority;
459 break; 436 break;
460 } 437 }
461 438
462 if (!tile_is_ready_to_draw || tile_version.requires_resource()) { 439 if (!tile_is_ready_to_draw || tile_version.requires_resource()) {
463 if ((gpu_memmgr_stats_bin == NOW_BIN) || 440 if ((gpu_memmgr_stats_bin == NOW_BIN) ||
464 (gpu_memmgr_stats_bin == NOW_AND_READY_TO_DRAW_BIN)) 441 (gpu_memmgr_stats_bin == NOW_AND_READY_TO_DRAW_BIN))
465 memory_required_bytes_ += BytesConsumedIfAllocated(tile); 442 memory_required_bytes_ += BytesConsumedIfAllocated(tile);
466 if (gpu_memmgr_stats_bin != NEVER_BIN) 443 if (gpu_memmgr_stats_bin != NEVER_BIN)
467 memory_nice_to_have_bytes_ += BytesConsumedIfAllocated(tile); 444 memory_nice_to_have_bytes_ += BytesConsumedIfAllocated(tile);
468 } 445 }
469 446
470 // Bump up the priority if we determined it's NEVER_BIN on one tree, 447 // Bump up the priority if we determined it's NEVER_BIN on one tree,
471 // but is still required on the other tree. 448 // but is still required on the other tree.
472 bool is_in_never_bin_on_both_trees = 449 bool is_in_never_bin_on_both_trees =
473 tree_bin[ACTIVE_TREE] == NEVER_BIN && 450 tree_bin[ACTIVE_TREE] == NEVER_BIN &&
474 tree_bin[PENDING_TREE] == NEVER_BIN; 451 tree_bin[PENDING_TREE] == NEVER_BIN;
475 452
476 if (mts.bin == NEVER_BIN && !is_in_never_bin_on_both_trees) 453 if (mts.bin == NEVER_BIN && !is_in_never_bin_on_both_trees)
477 mts.bin = tile_is_active ? AT_LAST_AND_ACTIVE_BIN : AT_LAST_BIN; 454 mts.bin = tile_is_active ? AT_LAST_AND_ACTIVE_BIN : AT_LAST_BIN;
478 455
479 mts.resolution = tile_priority.resolution; 456 mts.resolution = tile_priority.resolution;
480 mts.time_to_needed_in_seconds = tile_priority.time_to_visible_in_seconds; 457 mts.time_to_needed_in_seconds = tile_priority.time_to_visible_in_seconds;
481 mts.distance_to_visible_in_pixels = 458 mts.distance_to_visible_in_pixels =
482 tile_priority.distance_to_visible_in_pixels; 459 tile_priority.distance_to_visible_in_pixels;
483 mts.required_for_activation = tile_priority.required_for_activation; 460 mts.required_for_activation = tile_priority.required_for_activation;
484 461
485 mts.visible_and_ready_to_draw = 462 mts.visible_and_ready_to_draw =
486 tree_bin[ACTIVE_TREE] == NOW_AND_READY_TO_DRAW_BIN; 463 tree_bin[ACTIVE_TREE] == NOW_AND_READY_TO_DRAW_BIN;
487 464
488 if (mts.bin == NEVER_BIN) { 465 if (mts.bin == NEVER_BIN) {
489 FreeResourcesForTile(tile); 466 FreeResourcesForTile(tile);
490 continue; 467 continue;
491 } 468 }
492 469
493 // Note that if the tile is visible_and_ready_to_draw, then we always want 470 // Note that if the tile is visible_and_ready_to_draw, then we always want
494 // the priority to be NOW_AND_READY_TO_DRAW_BIN, even if HIGH_PRIORITY_BIN 471 // the priority to be NOW_AND_READY_TO_DRAW_BIN, even if HIGH_PRIORITY_BIN
495 // is something different. The reason for this is that if we're 472 // is something different. The reason for this is that if we're prioritizing
496 // prioritizing the pending tree, we still want visible tiles to take the 473 // the pending tree, we still want visible tiles to take the highest
497 // highest priority. 474 // priority.
498 ManagedTileBin priority_bin = mts.visible_and_ready_to_draw 475 ManagedTileBin priority_bin = mts.visible_and_ready_to_draw
499 ? NOW_AND_READY_TO_DRAW_BIN 476 ? NOW_AND_READY_TO_DRAW_BIN
500 : mts.bin; 477 : mts.bin;
501 478
502 // Insert the tile into a priority set. 479 // Insert the tile into a priority set.
503 tiles->InsertTile(tile, priority_bin); 480 tiles->InsertTile(tile, priority_bin);
504 }
505 } 481 }
506 } 482 }
507 483
508 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) { 484 void TileManager::ManageTiles(const GlobalStateThatImpactsTilePriority& state) {
509 TRACE_EVENT0("cc", "TileManager::ManageTiles"); 485 TRACE_EVENT0("cc", "TileManager::ManageTiles");
510 486
511 // Update internal state. 487 // Update internal state.
512 if (state != global_state_) { 488 if (state != global_state_) {
513 global_state_ = state; 489 global_state_ = state;
514 prioritized_tiles_dirty_ = true; 490 prioritized_tiles_dirty_ = true;
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
976 resource_pool_->ReleaseResource(resource.Pass()); 952 resource_pool_->ReleaseResource(resource.Pass());
977 } else { 953 } else {
978 tile_version.set_use_resource(); 954 tile_version.set_use_resource();
979 tile_version.resource_ = resource.Pass(); 955 tile_version.resource_ = resource.Pass();
980 956
981 bytes_releasable_ += BytesConsumedIfAllocated(tile); 957 bytes_releasable_ += BytesConsumedIfAllocated(tile);
982 ++resources_releasable_; 958 ++resources_releasable_;
983 } 959 }
984 960
985 FreeUnusedResourcesForTile(tile); 961 FreeUnusedResourcesForTile(tile);
986 if (tile->is_visible()) 962 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0)
987 did_initialize_visible_tile_ = true; 963 did_initialize_visible_tile_ = true;
988 } 964 }
989 965
990 scoped_refptr<Tile> TileManager::CreateTile(PicturePileImpl* picture_pile, 966 scoped_refptr<Tile> TileManager::CreateTile(PicturePileImpl* picture_pile,
991 gfx::Size tile_size, 967 gfx::Size tile_size,
992 gfx::Rect content_rect, 968 gfx::Rect content_rect,
993 gfx::Rect opaque_rect, 969 gfx::Rect opaque_rect,
994 float contents_scale, 970 float contents_scale,
995 int layer_id, 971 int layer_id,
996 int source_frame_number, 972 int source_frame_number,
997 int flags) { 973 int flags) {
998 scoped_refptr<Tile> tile = make_scoped_refptr(new Tile(this, 974 scoped_refptr<Tile> tile = make_scoped_refptr(new Tile(this,
999 picture_pile, 975 picture_pile,
1000 tile_size, 976 tile_size,
1001 content_rect, 977 content_rect,
1002 opaque_rect, 978 opaque_rect,
1003 contents_scale, 979 contents_scale,
1004 layer_id, 980 layer_id,
1005 source_frame_number, 981 source_frame_number,
1006 flags)); 982 flags));
1007 DCHECK(tiles_.find(tile->id()) == tiles_.end()); 983 DCHECK(tiles_.find(tile->id()) == tiles_.end());
1008 984
1009 tiles_[tile->id()] = tile; 985 tiles_[tile->id()] = tile;
1010 used_layer_counts_[tile->layer_id()]++; 986 used_layer_counts_[tile->layer_id()]++;
1011 prioritized_tiles_dirty_ = true; 987 prioritized_tiles_dirty_ = true;
1012 return tile; 988 return tile;
1013 } 989 }
1014 990
1015 scoped_refptr<TileBundle> TileManager::CreateTileBundle(int offset_x,
1016 int offset_y,
1017 int width,
1018 int height) {
1019 scoped_refptr<TileBundle> bundle = make_scoped_refptr(
1020 new TileBundle(this, offset_x, offset_y, width, height));
1021 bundles_[bundle->id()] = bundle;
1022 return bundle;
1023 }
1024
1025 } // namespace cc 991 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/tile_manager.h ('k') | cc/resources/tile_manager_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698