Index: cc/tile_manager.cc |
diff --git a/cc/tile_manager.cc b/cc/tile_manager.cc |
index f3921df7903764ed3ce93d7f4e3c0aa379dc8554..4641a459f8b0f50c02842e12e9d793db0a794316 100644 |
--- a/cc/tile_manager.cc |
+++ b/cc/tile_manager.cc |
@@ -31,6 +31,30 @@ const int kDefaultNumberOfRasterThreads = 1; |
// low while making sure raster threads aren't unnecessarily idle. |
const int kNumPendingRasterTasksPerThread = 2; |
+// Determine bin based on three categories of tiles: things we need now, |
+// things we need soon, and eventually. |
+cc::TileManagerBin BinFromTilePriority(const cc::TilePriority& prio) { |
enne (OOO)
2012/12/16 01:26:44
This is a nice refactoring.
|
+ |
+ // The amount of time for which we want to have prepainting coverage. |
+ const double prepainting_window_time_seconds = 1.0; |
+ const double backfling_guard_distance_pixels = 314.0; |
+ |
+ if (prio.time_to_needed_in_seconds() == std::numeric_limits<float>::max()) |
+ return cc::NEVER_BIN; |
+ |
+ if (prio.resolution == cc::NON_IDEAL_RESOLUTION) |
+ return cc::EVENTUALLY_BIN; |
+ |
+ if (prio.time_to_needed_in_seconds() == 0 || |
+ prio.distance_to_visible_in_pixels < backfling_guard_distance_pixels) |
+ return cc::NOW_BIN; |
+ |
+ if (prio.time_to_needed_in_seconds() < prepainting_window_time_seconds) |
+ return cc::SOON_BIN; |
+ |
+ return cc::EVENTUALLY_BIN; |
+} |
+ |
} // namespace |
namespace cc { |
@@ -144,6 +168,8 @@ TileManager::TileManager( |
StringPrintf("Worker%d", thread_number).c_str())); |
raster_threads_.append(thread.Pass()); |
} |
+ |
+ ResetBinCounts(); |
} |
TileManager::~TileManager() { |
@@ -219,8 +245,8 @@ public: |
bool operator() (const Tile* a, const Tile* b) const { |
const ManagedTileState& ams = a->managed_state(); |
const ManagedTileState& bms = b->managed_state(); |
- if (ams.bin != bms.bin) |
- return ams.bin < bms.bin; |
+ if (ams.raster_bin != bms.raster_bin) |
+ return ams.raster_bin < bms.raster_bin; |
if (ams.resolution != bms.resolution) |
return ams.resolution < ams.resolution; |
@@ -235,16 +261,16 @@ void TileManager::ManageTiles() { |
TRACE_EVENT0("cc", "TileManager::ManageTiles"); |
manage_tiles_pending_ = false; |
- // The amount of time for which we want to have prepainting coverage. |
- const double prepainting_window_time_seconds = 1.0; |
- const double backfling_guard_distance_pixels = 314.0; |
- |
- const bool smoothness_takes_priority = global_state_.smoothness_takes_priority; |
+ const bool smoothness_takes_priority = |
+ global_state_.smoothness_takes_priority; |
- // Bin into three categories of tiles: things we need now, things we need soon, and eventually |
+ // For each tree, bin into different categories of tiles. |
for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
Tile* tile = *it; |
ManagedTileState& mts = tile->managed_state(); |
+ mts.bin[ACTIVE_TREE] = BinFromTilePriority(tile->priority(ACTIVE_TREE)); |
+ mts.bin[PENDING_TREE] = BinFromTilePriority(tile->priority(PENDING_TREE)); |
+ |
TilePriority prio; |
if (smoothness_takes_priority) |
prio = tile->priority(ACTIVE_TREE); |
@@ -253,30 +279,7 @@ void TileManager::ManageTiles() { |
mts.resolution = prio.resolution; |
mts.time_to_needed_in_seconds = prio.time_to_needed_in_seconds(); |
- |
- if (mts.time_to_needed_in_seconds == |
- std::numeric_limits<float>::max()) { |
- mts.bin = NEVER_BIN; |
- continue; |
- } |
- |
- if (mts.resolution == NON_IDEAL_RESOLUTION) { |
- mts.bin = EVENTUALLY_BIN; |
- continue; |
- } |
- |
- if (mts.time_to_needed_in_seconds == 0 || |
- prio.distance_to_visible_in_pixels < backfling_guard_distance_pixels) { |
- mts.bin = NOW_BIN; |
- continue; |
- } |
- |
- if (prio.time_to_needed_in_seconds() < prepainting_window_time_seconds) { |
- mts.bin = SOON_BIN; |
- continue; |
- } |
- |
- mts.bin = EVENTUALLY_BIN; |
+ mts.raster_bin = BinFromTilePriority(prio); |
} |
// Memory limit policy works by mapping some bin states to the NEVER bin. |
@@ -304,8 +307,25 @@ void TileManager::ManageTiles() { |
} |
for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
Tile* tile = *it; |
- TileManagerBin bin = bin_map[tile->managed_state().bin]; |
- tile->managed_state().bin = bin; |
+ ManagedTileState& mts = tile->managed_state(); |
+ mts.bin[ACTIVE_TREE] = bin_map[mts.bin[ACTIVE_TREE]]; |
+ mts.bin[PENDING_TREE] = bin_map[mts.bin[PENDING_TREE]]; |
+ mts.raster_bin = bin_map[mts.raster_bin]; |
+ } |
+ |
+ // Update bin counts. |
+ ResetBinCounts(); |
+ for (TileVector::iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
+ Tile* tile = *it; |
+ ManagedTileState& mts = tile->managed_state(); |
+ for (int i = 0; i < NUM_TREES; ++i) |
+ tiles_in_bin_count_[mts.bin[i]][i]++; |
+ |
+ // Increment drawable count if GetResourceId() doesn't return 0. |
+ if (tile->GetResourceId()) { |
+ for (int i = 0; i < NUM_TREES; ++i) |
+ drawable_tiles_in_bin_count_[mts.bin[i]][i]++; |
+ } |
} |
// Sort by bin. |
@@ -341,12 +361,35 @@ void TileManager::CheckForCompletedSetPixels() { |
} |
} |
-void TileManager::renderingStats(RenderingStats* stats) { |
+void TileManager::GetRenderingStats(RenderingStats* stats) { |
stats->totalRasterizeTimeInSeconds = |
rendering_stats_.totalRasterizeTimeInSeconds; |
stats->totalPixelsRasterized = rendering_stats_.totalPixelsRasterized; |
} |
+int TileManager::GetTilesInBinCount(TileManagerBin bin, WhichTree tree) { |
+ DCHECK(bin >= 0); |
+ DCHECK(bin < NUM_BINS); |
+ DCHECK(tree >= 0); |
+ DCHECK(tree < NUM_TREES); |
+ return tiles_in_bin_count_[bin][tree]; |
+} |
+ |
+int TileManager::GetDrawableTilesInBinCount( |
+ TileManagerBin bin, WhichTree tree) { |
+ DCHECK(bin >= 0); |
+ DCHECK(bin < NUM_BINS); |
+ DCHECK(tree >= 0); |
+ DCHECK(tree < NUM_TREES); |
+ return drawable_tiles_in_bin_count_[bin][tree]; |
+} |
+ |
+void TileManager::ResetBinCounts() { |
+ for (int i = 0; i < NUM_BINS; ++i) |
+ for (int j = 0; j < NUM_TREES; ++j) |
+ tiles_in_bin_count_[i][j] = drawable_tiles_in_bin_count_[i][j] = 0; |
+} |
+ |
void TileManager::AssignGpuMemoryToTiles() { |
TRACE_EVENT0("cc", "TileManager::AssignGpuMemoryToTiles"); |
// Some memory cannot be released. Figure out which. |
@@ -379,7 +422,7 @@ void TileManager::AssignGpuMemoryToTiles() { |
ManagedTileState& managed_tile_state = tile->managed_state(); |
if (!managed_tile_state.can_be_freed) |
continue; |
- if (managed_tile_state.bin == NEVER_BIN) { |
+ if (managed_tile_state.raster_bin == NEVER_BIN) { |
managed_tile_state.can_use_gpu_memory = false; |
FreeResourcesForTile(tile); |
continue; |
@@ -619,6 +662,8 @@ void TileManager::DidFinishTileInitialization(Tile* tile) { |
DCHECK(managed_tile_state.resource); |
managed_tile_state.resource_is_being_initialized = false; |
managed_tile_state.can_be_freed = true; |
+ for (int i = 0; i < NUM_TREES; ++i) |
+ drawable_tiles_in_bin_count_[managed_tile_state.bin[i]][i]++; |
} |
} |