| OLD | NEW |
| 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 #ifndef CC_TILES_TILE_MANAGER_H_ | 5 #ifndef CC_TILES_TILE_MANAGER_H_ |
| 6 #define CC_TILES_TILE_MANAGER_H_ | 6 #define CC_TILES_TILE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 }; | 88 }; |
| 89 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | 89 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
| 90 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats); | 90 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats); |
| 91 | 91 |
| 92 // This class manages tiles, deciding which should get rasterized and which | 92 // This class manages tiles, deciding which should get rasterized and which |
| 93 // should no longer have any memory assigned to them. Tile objects are "owned" | 93 // should no longer have any memory assigned to them. Tile objects are "owned" |
| 94 // by layers; they automatically register with the manager when they are | 94 // by layers; they automatically register with the manager when they are |
| 95 // created, and unregister from the manager when they are deleted. | 95 // created, and unregister from the manager when they are deleted. |
| 96 class CC_EXPORT TileManager { | 96 class CC_EXPORT TileManager { |
| 97 public: | 97 public: |
| 98 static std::unique_ptr<TileManager> Create( | 98 TileManager(TileManagerClient* client, |
| 99 TileManagerClient* client, | 99 scoped_refptr<base::SequencedTaskRunner> task_runner, |
| 100 base::SequencedTaskRunner* task_runner, | 100 size_t scheduled_raster_task_limit, |
| 101 size_t scheduled_raster_task_limit, | 101 bool use_partial_raster); |
| 102 bool use_partial_raster); | |
| 103 virtual ~TileManager(); | 102 virtual ~TileManager(); |
| 104 | 103 |
| 105 // Assigns tile memory and schedules work to prepare tiles for drawing. | 104 // Assigns tile memory and schedules work to prepare tiles for drawing. |
| 106 // - Runs client_->NotifyReadyToActivate() when all tiles required for | 105 // - Runs client_->NotifyReadyToActivate() when all tiles required for |
| 107 // activation are prepared, or failed to prepare due to OOM. | 106 // activation are prepared, or failed to prepare due to OOM. |
| 108 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are | 107 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are |
| 109 // prepared, or failed to prepare due to OOM. | 108 // prepared, or failed to prepare due to OOM. |
| 110 bool PrepareTiles(const GlobalStateThatImpactsTilePriority& state); | 109 bool PrepareTiles(const GlobalStateThatImpactsTilePriority& state); |
| 111 | 110 |
| 112 // Synchronously finish any in progress work, cancel the rest, and clean up as | 111 // Synchronously finish any in progress work, cancel the rest, and clean up as |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 166 |
| 168 void SetTileTaskManagerForTesting(TileTaskManager* tile_task_manager); | 167 void SetTileTaskManagerForTesting(TileTaskManager* tile_task_manager); |
| 169 | 168 |
| 170 void FreeResourcesAndCleanUpReleasedTilesForTesting() { | 169 void FreeResourcesAndCleanUpReleasedTilesForTesting() { |
| 171 FreeResourcesForReleasedTiles(); | 170 FreeResourcesForReleasedTiles(); |
| 172 CleanUpReleasedTiles(); | 171 CleanUpReleasedTiles(); |
| 173 } | 172 } |
| 174 | 173 |
| 175 std::vector<Tile*> AllTilesForTesting() const { | 174 std::vector<Tile*> AllTilesForTesting() const { |
| 176 std::vector<Tile*> tiles; | 175 std::vector<Tile*> tiles; |
| 177 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); | 176 for (auto& tile_pair : tiles_) |
| 178 ++it) { | 177 tiles.push_back(tile_pair.second); |
| 179 tiles.push_back(it->second); | |
| 180 } | |
| 181 return tiles; | 178 return tiles; |
| 182 } | 179 } |
| 183 | 180 |
| 184 void SetScheduledRasterTaskLimitForTesting(size_t limit) { | 181 void SetScheduledRasterTaskLimitForTesting(size_t limit) { |
| 185 scheduled_raster_task_limit_ = limit; | 182 scheduled_raster_task_limit_ = limit; |
| 186 } | 183 } |
| 187 | 184 |
| 188 void CheckIfMoreTilesNeedToBePreparedForTesting() { | 185 void CheckIfMoreTilesNeedToBePreparedForTesting() { |
| 189 CheckIfMoreTilesNeedToBePrepared(); | 186 CheckIfMoreTilesNeedToBePrepared(); |
| 190 } | 187 } |
| 191 | 188 |
| 192 void SetMoreTilesNeedToBeRasterizedForTesting() { | 189 void SetMoreTilesNeedToBeRasterizedForTesting() { |
| 193 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; | 190 all_tiles_that_need_to_be_rasterized_are_scheduled_ = false; |
| 194 } | 191 } |
| 195 | 192 |
| 196 bool HasScheduledTileTasksForTesting() const { | 193 bool HasScheduledTileTasksForTesting() const { |
| 197 return has_scheduled_tile_tasks_; | 194 return has_scheduled_tile_tasks_; |
| 198 } | 195 } |
| 199 | 196 |
| 200 void OnRasterTaskCompleted(std::unique_ptr<RasterBuffer> raster_buffer, | 197 void OnRasterTaskCompleted(std::unique_ptr<RasterBuffer> raster_buffer, |
| 201 Tile* tile, | 198 Tile* tile, |
| 202 Resource* resource, | 199 Resource* resource, |
| 203 bool was_canceled); | 200 bool was_canceled); |
| 204 | 201 |
| 205 protected: | 202 protected: |
| 206 TileManager(TileManagerClient* client, | |
| 207 scoped_refptr<base::SequencedTaskRunner> task_runner, | |
| 208 size_t scheduled_raster_task_limit, | |
| 209 bool use_partial_raster); | |
| 210 | |
| 211 void FreeResourcesForReleasedTiles(); | 203 void FreeResourcesForReleasedTiles(); |
| 212 void CleanUpReleasedTiles(); | 204 void CleanUpReleasedTiles(); |
| 213 | 205 |
| 214 friend class Tile; | 206 friend class Tile; |
| 215 // Virtual for testing. | 207 // Virtual for testing. |
| 216 virtual void Release(Tile* tile); | 208 virtual void Release(Tile* tile); |
| 217 Tile::Id GetUniqueTileId() { return ++next_tile_id_; } | 209 Tile::Id GetUniqueTileId() { return ++next_tile_id_; } |
| 218 | 210 |
| 219 typedef std::vector<PrioritizedTile> PrioritizedTileVector; | |
| 220 typedef std::set<Tile*> TileSet; | |
| 221 | |
| 222 // Virtual for test | 211 // Virtual for test |
| 223 virtual void ScheduleTasks( | 212 virtual void ScheduleTasks( |
| 224 const PrioritizedTileVector& tiles_that_need_to_be_rasterized); | 213 const std::vector<PrioritizedTile>& tiles_that_need_to_be_rasterized); |
| 225 | |
| 226 void AssignGpuMemoryToTiles( | |
| 227 RasterTilePriorityQueue* raster_priority_queue, | |
| 228 size_t scheduled_raser_task_limit, | |
| 229 PrioritizedTileVector* tiles_that_need_to_be_rasterized); | |
| 230 | 214 |
| 231 private: | 215 private: |
| 232 class MemoryUsage { | 216 class MemoryUsage { |
| 233 public: | 217 public: |
| 234 MemoryUsage(); | 218 MemoryUsage(); |
| 235 MemoryUsage(size_t memory_bytes, size_t resource_count); | 219 MemoryUsage(size_t memory_bytes, size_t resource_count); |
| 236 | 220 |
| 237 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); | 221 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); |
| 238 static MemoryUsage FromTile(const Tile* tile); | 222 static MemoryUsage FromTile(const Tile* tile); |
| 239 | 223 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 258 |
| 275 ResourceFormat DetermineResourceFormat(const Tile* tile) const; | 259 ResourceFormat DetermineResourceFormat(const Tile* tile) const; |
| 276 bool DetermineResourceRequiresSwizzle(const Tile* tile) const; | 260 bool DetermineResourceRequiresSwizzle(const Tile* tile) const; |
| 277 | 261 |
| 278 void DidFinishRunningTileTasksRequiredForActivation(); | 262 void DidFinishRunningTileTasksRequiredForActivation(); |
| 279 void DidFinishRunningTileTasksRequiredForDraw(); | 263 void DidFinishRunningTileTasksRequiredForDraw(); |
| 280 void DidFinishRunningAllTileTasks(); | 264 void DidFinishRunningAllTileTasks(); |
| 281 | 265 |
| 282 scoped_refptr<TileTask> CreateTaskSetFinishedTask( | 266 scoped_refptr<TileTask> CreateTaskSetFinishedTask( |
| 283 void (TileManager::*callback)()); | 267 void (TileManager::*callback)()); |
| 268 std::vector<PrioritizedTile> AssignGpuMemoryToTiles(); |
| 284 | 269 |
| 285 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | 270 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
| 286 ScheduledTasksStateAsValue() const; | 271 ScheduledTasksStateAsValue() const; |
| 287 | 272 |
| 288 TileManagerClient* client_; | 273 TileManagerClient* client_; |
| 289 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 274 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 290 ResourcePool* resource_pool_; | 275 ResourcePool* resource_pool_; |
| 291 TileTaskManager* tile_task_manager_; | 276 TileTaskManager* tile_task_manager_; |
| 292 GlobalStateThatImpactsTilePriority global_state_; | 277 GlobalStateThatImpactsTilePriority global_state_; |
| 293 size_t scheduled_raster_task_limit_; | 278 size_t scheduled_raster_task_limit_; |
| 294 const bool use_partial_raster_; | 279 const bool use_partial_raster_; |
| 295 bool use_gpu_rasterization_; | 280 bool use_gpu_rasterization_; |
| 296 | 281 |
| 297 using TileMap = std::unordered_map<Tile::Id, Tile*>; | 282 std::unordered_map<Tile::Id, Tile*> tiles_; |
| 298 TileMap tiles_; | |
| 299 | 283 |
| 300 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; | 284 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; |
| 301 MemoryHistory::Entry memory_stats_from_last_assign_; | 285 MemoryHistory::Entry memory_stats_from_last_assign_; |
| 302 | 286 |
| 303 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 287 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
| 304 bool did_oom_on_last_assign_; | 288 bool did_oom_on_last_assign_; |
| 305 | 289 |
| 306 ImageDecodeController* image_decode_controller_; | 290 ImageDecodeController* image_decode_controller_; |
| 307 | 291 |
| 308 RasterTaskCompletionStats flush_stats_; | 292 RasterTaskCompletionStats flush_stats_; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 std::unordered_map<Tile::Id, std::vector<DrawImage>> scheduled_draw_images_; | 325 std::unordered_map<Tile::Id, std::vector<DrawImage>> scheduled_draw_images_; |
| 342 | 326 |
| 343 base::WeakPtrFactory<TileManager> task_set_finished_weak_ptr_factory_; | 327 base::WeakPtrFactory<TileManager> task_set_finished_weak_ptr_factory_; |
| 344 | 328 |
| 345 DISALLOW_COPY_AND_ASSIGN(TileManager); | 329 DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 346 }; | 330 }; |
| 347 | 331 |
| 348 } // namespace cc | 332 } // namespace cc |
| 349 | 333 |
| 350 #endif // CC_TILES_TILE_MANAGER_H_ | 334 #endif // CC_TILES_TILE_MANAGER_H_ |
| OLD | NEW |