Chromium Code Reviews| Index: cc/tiles/tile_manager.cc |
| diff --git a/cc/tiles/tile_manager.cc b/cc/tiles/tile_manager.cc |
| index 477025f3f80f9da5f0eb9304eafe787d7c398c64..235813dabe0d3f5a714051ec8a4f601e584a4edb 100644 |
| --- a/cc/tiles/tile_manager.cc |
| +++ b/cc/tiles/tile_manager.cc |
| @@ -248,7 +248,8 @@ void TileManager::FinishTasksAndCleanUp() { |
| void TileManager::SetResources(ResourcePool* resource_pool, |
| TileTaskRunner* tile_task_runner, |
| - size_t scheduled_raster_task_limit) { |
| + size_t scheduled_raster_task_limit, |
| + bool is_using_gpu_rasterization) { |
| DCHECK(!tile_task_runner_); |
| DCHECK(tile_task_runner); |
| @@ -256,6 +257,8 @@ void TileManager::SetResources(ResourcePool* resource_pool, |
| resource_pool_ = resource_pool; |
| tile_task_runner_ = tile_task_runner; |
| tile_task_runner_->SetClient(this); |
| + image_decode_controller_.SetIsUsingGpuRasterization( |
| + is_using_gpu_rasterization); |
| } |
| void TileManager::Release(Tile* tile) { |
| @@ -279,7 +282,6 @@ void TileManager::CleanUpReleasedTiles() { |
| DCHECK(tiles_.find(tile->id()) != tiles_.end()); |
| tiles_.erase(tile->id()); |
| - image_decode_controller_.SubtractLayerUsedCount(tile->layer_id()); |
| delete tile; |
| } |
| released_tiles_.swap(tiles_to_retain); |
| @@ -627,7 +629,7 @@ void TileManager::ScheduleTasks( |
| DCHECK(tile->draw_info().requires_resource()); |
| DCHECK(!tile->draw_info().resource_); |
| - if (!tile->raster_task_.get()) |
| + if (!tile->raster_task_) |
| tile->raster_task_ = CreateRasterTask(prioritized_tile); |
| TaskSetCollection task_sets; |
| @@ -643,6 +645,7 @@ void TileManager::ScheduleTasks( |
| // We must reduce the amount of unused resoruces before calling |
| // ScheduleTasks to prevent usage from rising above limits. |
| resource_pool_->ReduceResourceUsage(); |
| + image_decode_controller_.ReduceCacheUsage(); |
|
ericrk
2015/12/04 00:50:46
should we also ReduceCacheUsage in CheckIfMoreTile
|
| // Schedule running of |raster_queue_|. This replaces any previously |
| // scheduled tasks and effectively cancels all tasks not present |
| @@ -660,6 +663,8 @@ void TileManager::ScheduleTasks( |
| scoped_refptr<RasterTask> TileManager::CreateRasterTask( |
| const PrioritizedTile& prioritized_tile) { |
| Tile* tile = prioritized_tile.tile(); |
| + |
| + // Get the resource. |
| uint64_t resource_content_id = 0; |
| Resource* resource = nullptr; |
| if (use_partial_raster_ && tile->invalidated_id()) { |
| @@ -680,12 +685,22 @@ scoped_refptr<RasterTask> TileManager::CreateRasterTask( |
| // Create and queue all image decode tasks that this tile depends on. |
| ImageDecodeTask::Vector decode_tasks; |
| - std::vector<DrawImage> images; |
| + std::vector<DrawImage>& images = scheduled_draw_images_[tile->id()]; |
| + images.clear(); |
| prioritized_tile.raster_source()->GetDiscardableImagesInRect( |
| tile->enclosing_layer_rect(), tile->contents_scale(), &images); |
| - for (const auto& image : images) { |
| - decode_tasks.push_back(image_decode_controller_.GetTaskForImage( |
| - image, tile->layer_id(), prepare_tiles_count_)); |
| + for (auto it = images.begin(); it != images.end();) { |
| + scoped_refptr<ImageDecodeTask> task; |
| + bool need_to_unref_when_finished = |
| + image_decode_controller_.GetTaskForImageAndRef( |
| + *it, prepare_tiles_count_, &task); |
| + if (task) |
| + decode_tasks.push_back(task); |
| + |
| + if (need_to_unref_when_finished) |
| + ++it; |
| + else |
| + it = images.erase(it); |
| } |
| return make_scoped_refptr(new RasterTaskImpl( |
| @@ -712,6 +727,13 @@ void TileManager::OnRasterTaskCompleted( |
| orphan_raster_tasks_.push_back(tile->raster_task_); |
| tile->raster_task_ = nullptr; |
| + // Unref all the images. |
| + auto images_it = scheduled_draw_images_.find(tile->id()); |
| + const std::vector<DrawImage>& images = images_it->second; |
| + for (const auto& image : images) |
| + image_decode_controller_.UnrefImage(image); |
| + scheduled_draw_images_.erase(images_it); |
| + |
| if (was_canceled) { |
| ++flush_stats_.canceled_count; |
| // TODO(ericrk): If more partial raster work is done in the future, it may |
| @@ -766,7 +788,6 @@ ScopedTilePtr TileManager::CreateTile(const Tile::CreateInfo& info, |
| DCHECK(tiles_.find(tile->id()) == tiles_.end()); |
| tiles_[tile->id()] = tile.get(); |
| - image_decode_controller_.AddLayerUsedCount(tile->layer_id()); |
| return tile; |
| } |