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

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

Issue 22875045: cc: Remove unnecessary "default" cases from switch statements. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 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 | Annotate | Revision Log
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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/json/json_writer.h" 12 #include "base/json/json_writer.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
15 #include "cc/debug/devtools_instrumentation.h" 15 #include "cc/debug/devtools_instrumentation.h"
16 #include "cc/debug/traced_value.h" 16 #include "cc/debug/traced_value.h"
17 #include "cc/resources/image_raster_worker_pool.h" 17 #include "cc/resources/image_raster_worker_pool.h"
18 #include "cc/resources/pixel_buffer_raster_worker_pool.h" 18 #include "cc/resources/pixel_buffer_raster_worker_pool.h"
19 #include "cc/resources/tile.h" 19 #include "cc/resources/tile.h"
20 #include "third_party/skia/include/core/SkCanvas.h" 20 #include "third_party/skia/include/core/SkCanvas.h"
21 #include "ui/gfx/rect_conversions.h" 21 #include "ui/gfx/rect_conversions.h"
22 22
23 namespace cc { 23 namespace cc {
24 24
25 namespace { 25 namespace {
26 26
27 // Memory limit policy works by mapping some bin states to the NEVER bin. 27 // Memory limit policy works by mapping some bin states to the NEVER bin.
28 const ManagedTileBin kBinPolicyMap[NUM_TILE_MEMORY_LIMIT_POLICIES][NUM_BINS] = { 28 const ManagedTileBin
29 kBinPolicyMap[MAX_TILE_MEMORY_LIMIT_POLICY + 1][MAX_BIN + 1] = {
enne (OOO) 2013/08/23 00:44:38 Ugh. I really don't like how awkward this makes e
29 { // [ALLOW_NOTHING] 30 { // [ALLOW_NOTHING]
30 NEVER_BIN, // [NOW_AND_READY_TO_DRAW_BIN] 31 NEVER_BIN, // [NOW_AND_READY_TO_DRAW_BIN]
31 NEVER_BIN, // [NOW_BIN] 32 NEVER_BIN, // [NOW_BIN]
32 NEVER_BIN, // [SOON_BIN] 33 NEVER_BIN, // [SOON_BIN]
33 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN] 34 NEVER_BIN, // [EVENTUALLY_AND_ACTIVE_BIN]
34 NEVER_BIN, // [EVENTUALLY_BIN] 35 NEVER_BIN, // [EVENTUALLY_BIN]
35 NEVER_BIN, // [NEVER_AND_ACTIVE_BIN] 36 NEVER_BIN, // [NEVER_AND_ACTIVE_BIN]
36 NEVER_BIN // [NEVER_BIN] 37 NEVER_BIN // [NEVER_BIN]
37 }, { // [ALLOW_ABSOLUTE_MINIMUM] 38 }, { // [ALLOW_ABSOLUTE_MINIMUM]
38 NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN] 39 NOW_AND_READY_TO_DRAW_BIN, // [NOW_AND_READY_TO_DRAW_BIN]
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins"); 255 TRACE_EVENT0("cc", "TileManager::GetTilesWithAssignedBins");
255 256
256 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy; 257 const TileMemoryLimitPolicy memory_policy = global_state_.memory_limit_policy;
257 const TreePriority tree_priority = global_state_.tree_priority; 258 const TreePriority tree_priority = global_state_.tree_priority;
258 259
259 // For each tree, bin into different categories of tiles. 260 // For each tree, bin into different categories of tiles.
260 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { 261 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) {
261 Tile* tile = it->second; 262 Tile* tile = it->second;
262 ManagedTileState& mts = tile->managed_state(); 263 ManagedTileState& mts = tile->managed_state();
263 264
264 TilePriority prio[NUM_BIN_PRIORITIES]; 265 TilePriority prio[MAX_BIN_PRIORITY + 1];
265 switch (tree_priority) { 266 switch (tree_priority) {
266 case SAME_PRIORITY_FOR_BOTH_TREES: 267 case SAME_PRIORITY_FOR_BOTH_TREES:
267 prio[HIGH_PRIORITY_BIN] = prio[LOW_PRIORITY_BIN] = 268 prio[HIGH_PRIORITY_BIN] = prio[LOW_PRIORITY_BIN] =
268 tile->combined_priority(); 269 tile->combined_priority();
269 break; 270 break;
270 case SMOOTHNESS_TAKES_PRIORITY: 271 case SMOOTHNESS_TAKES_PRIORITY:
271 prio[HIGH_PRIORITY_BIN] = tile->priority(ACTIVE_TREE); 272 prio[HIGH_PRIORITY_BIN] = tile->priority(ACTIVE_TREE);
272 prio[LOW_PRIORITY_BIN] = tile->priority(PENDING_TREE); 273 prio[LOW_PRIORITY_BIN] = tile->priority(PENDING_TREE);
273 break; 274 break;
274 case NEW_CONTENT_TAKES_PRIORITY: 275 case NEW_CONTENT_TAKES_PRIORITY:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 tile_is_active); 314 tile_is_active);
314 mts.tree_bin[ACTIVE_TREE] = kBinPolicyMap[memory_policy][active_bin]; 315 mts.tree_bin[ACTIVE_TREE] = kBinPolicyMap[memory_policy][active_bin];
315 316
316 ManagedTileBin pending_bin = 317 ManagedTileBin pending_bin =
317 BinFromTilePriority(tile->priority(PENDING_TREE), 318 BinFromTilePriority(tile->priority(PENDING_TREE),
318 tree_priority, 319 tree_priority,
319 tile_is_ready_to_draw, 320 tile_is_ready_to_draw,
320 tile_is_active); 321 tile_is_active);
321 mts.tree_bin[PENDING_TREE] = kBinPolicyMap[memory_policy][pending_bin]; 322 mts.tree_bin[PENDING_TREE] = kBinPolicyMap[memory_policy][pending_bin];
322 323
323 for (int i = 0; i < NUM_BIN_PRIORITIES; ++i) 324 for (int i = 0; i <= MAX_BIN_PRIORITY; ++i)
324 mts.bin[i] = kBinPolicyMap[memory_policy][mts.bin[i]]; 325 mts.bin[i] = kBinPolicyMap[memory_policy][mts.bin[i]];
325 326
326 mts.visible_and_ready_to_draw = 327 mts.visible_and_ready_to_draw =
327 mts.tree_bin[ACTIVE_TREE] == NOW_AND_READY_TO_DRAW_BIN; 328 mts.tree_bin[ACTIVE_TREE] == NOW_AND_READY_TO_DRAW_BIN;
328 329
329 if (mts.is_in_never_bin_on_both_trees()) { 330 if (mts.is_in_never_bin_on_both_trees()) {
330 FreeResourcesForTile(tile); 331 FreeResourcesForTile(tile);
331 continue; 332 continue;
332 } 333 }
333 334
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 // If the tile is not needed, free it up. 532 // If the tile is not needed, free it up.
532 if (mts.is_in_never_bin_on_both_trees()) { 533 if (mts.is_in_never_bin_on_both_trees()) {
533 FreeResourcesForTile(tile); 534 FreeResourcesForTile(tile);
534 continue; 535 continue;
535 } 536 }
536 537
537 size_t tile_bytes = 0; 538 size_t tile_bytes = 0;
538 size_t tile_resources = 0; 539 size_t tile_resources = 0;
539 540
540 // It costs to maintain a resource. 541 // It costs to maintain a resource.
541 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { 542 for (int mode = 0; mode <= MAX_RASTER_MODE; ++mode) {
542 if (mts.tile_versions[mode].resource_) { 543 if (mts.tile_versions[mode].resource_) {
543 tile_bytes += tile->bytes_consumed_if_allocated(); 544 tile_bytes += tile->bytes_consumed_if_allocated();
544 tile_resources++; 545 tile_resources++;
545 } 546 }
546 } 547 }
547 548
548 // Allow lower priority tiles with initialized resources to keep 549 // Allow lower priority tiles with initialized resources to keep
549 // their memory by only assigning memory to new raster tasks if 550 // their memory by only assigning memory to new raster tasks if
550 // they can be scheduled. 551 // they can be scheduled.
551 if (tiles_that_need_to_be_rasterized->size() < kMaxRasterTasks) { 552 if (tiles_that_need_to_be_rasterized->size() < kMaxRasterTasks) {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 650
650 DCHECK_GE(bytes_releasable_, tile->bytes_consumed_if_allocated()); 651 DCHECK_GE(bytes_releasable_, tile->bytes_consumed_if_allocated());
651 DCHECK_GE(resources_releasable_, 1u); 652 DCHECK_GE(resources_releasable_, 1u);
652 653
653 bytes_releasable_ -= tile->bytes_consumed_if_allocated(); 654 bytes_releasable_ -= tile->bytes_consumed_if_allocated();
654 --resources_releasable_; 655 --resources_releasable_;
655 } 656 }
656 } 657 }
657 658
658 void TileManager::FreeResourcesForTile(Tile* tile) { 659 void TileManager::FreeResourcesForTile(Tile* tile) {
659 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { 660 for (int mode = 0; mode <= MAX_RASTER_MODE; ++mode) {
660 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); 661 FreeResourceForTile(tile, static_cast<RasterMode>(mode));
661 } 662 }
662 } 663 }
663 664
664 void TileManager::FreeUnusedResourcesForTile(Tile* tile) { 665 void TileManager::FreeUnusedResourcesForTile(Tile* tile) {
665 DCHECK(tile->IsReadyToDraw()); 666 DCHECK(tile->IsReadyToDraw());
666 ManagedTileState& mts = tile->managed_state(); 667 ManagedTileState& mts = tile->managed_state();
667 RasterMode used_mode = HIGH_QUALITY_NO_LCD_RASTER_MODE; 668 RasterMode used_mode = HIGH_QUALITY_NO_LCD_RASTER_MODE;
668 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { 669 for (int mode = 0; mode < MAX_RASTER_MODE; ++mode) {
669 if (mts.tile_versions[mode].IsReadyToDraw()) { 670 if (mts.tile_versions[mode].IsReadyToDraw()) {
670 used_mode = static_cast<RasterMode>(mode); 671 used_mode = static_cast<RasterMode>(mode);
671 break; 672 break;
672 } 673 }
673 } 674 }
674 675
675 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { 676 for (int mode = 0; mode < MAX_RASTER_MODE; ++mode) {
676 if (mode != used_mode) 677 if (mode != used_mode)
677 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); 678 FreeResourceForTile(tile, static_cast<RasterMode>(mode));
678 } 679 }
679 } 680 }
680 681
681 void TileManager::ScheduleTasks( 682 void TileManager::ScheduleTasks(
682 const TileVector& tiles_that_need_to_be_rasterized) { 683 const TileVector& tiles_that_need_to_be_rasterized) {
683 TRACE_EVENT1("cc", "TileManager::ScheduleTasks", 684 TRACE_EVENT1("cc", "TileManager::ScheduleTasks",
684 "count", tiles_that_need_to_be_rasterized.size()); 685 "count", tiles_that_need_to_be_rasterized.size());
685 RasterWorkerPool::RasterTask::Queue tasks; 686 RasterWorkerPool::RasterTask::Queue tasks;
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 bytes_releasable_ += tile->bytes_consumed_if_allocated(); 841 bytes_releasable_ += tile->bytes_consumed_if_allocated();
841 ++resources_releasable_; 842 ++resources_releasable_;
842 } 843 }
843 844
844 FreeUnusedResourcesForTile(tile); 845 FreeUnusedResourcesForTile(tile);
845 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0) 846 if (tile->priority(ACTIVE_TREE).distance_to_visible_in_pixels == 0)
846 did_initialize_visible_tile_ = true; 847 did_initialize_visible_tile_ = true;
847 } 848 }
848 849
849 } // namespace cc 850 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698