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 <deque> | 8 #include <deque> |
9 #include <queue> | 9 #include <queue> |
10 #include <set> | 10 #include <set> |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 | 79 |
80 struct RasterTaskCompletionStats { | 80 struct RasterTaskCompletionStats { |
81 RasterTaskCompletionStats(); | 81 RasterTaskCompletionStats(); |
82 | 82 |
83 size_t completed_count; | 83 size_t completed_count; |
84 size_t canceled_count; | 84 size_t canceled_count; |
85 }; | 85 }; |
86 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 86 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
87 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats); | 87 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats); |
88 | 88 |
89 // kNumberOfTaskSets must be greater or equal to the number of values in | |
90 // TileManager::NamedTaskSet. | |
91 // TODO(reveman): Use template specialization to make it easy for client code to | |
92 // check at compile time that the number of supported task sets is correct. | |
93 static const size_t kNumberOfTaskSets = 3; | |
94 using TaskSet = size_t; | |
95 using TaskSetCollection = std::bitset<kNumberOfTaskSets>; | |
reveman
2015/11/26 00:18:30
Can we get rid of all this and just build the corr
ericrk
2015/11/30 23:52:16
this is more used for tracking which task sets are
reveman
2015/12/02 05:22:54
I'm thinking that we just get rid of all this task
| |
96 | |
89 // This class manages tiles, deciding which should get rasterized and which | 97 // This class manages tiles, deciding which should get rasterized and which |
90 // should no longer have any memory assigned to them. Tile objects are "owned" | 98 // should no longer have any memory assigned to them. Tile objects are "owned" |
91 // by layers; they automatically register with the manager when they are | 99 // by layers; they automatically register with the manager when they are |
92 // created, and unregister from the manager when they are deleted. | 100 // created, and unregister from the manager when they are deleted. |
93 class CC_EXPORT TileManager : public TileTaskRunnerClient { | 101 class CC_EXPORT TileManager { |
94 public: | 102 public: |
95 enum NamedTaskSet { | 103 enum NamedTaskSet { |
96 REQUIRED_FOR_ACTIVATION, | 104 REQUIRED_FOR_ACTIVATION, |
97 REQUIRED_FOR_DRAW, | 105 REQUIRED_FOR_DRAW, |
98 // PixelBufferTileTaskWorkerPool depends on ALL being last. | 106 // PixelBufferTileTaskWorkerPool depends on ALL being last. |
99 ALL | 107 ALL |
100 // Adding additional values requires increasing kNumberOfTaskSets in | 108 // Adding additional values requires increasing kNumberOfTaskSets in |
101 // tile_task_runner.h | 109 // tile_task_runner.h |
102 }; | 110 }; |
103 | 111 |
104 static_assert(NamedTaskSet::ALL == (kNumberOfTaskSets - 1), | 112 static_assert(NamedTaskSet::ALL == (kNumberOfTaskSets - 1), |
105 "NamedTaskSet::ALL should be equal to kNumberOfTaskSets" | 113 "NamedTaskSet::ALL should be equal to kNumberOfTaskSets" |
106 "minus 1"); | 114 "minus 1"); |
107 | 115 |
108 static scoped_ptr<TileManager> Create(TileManagerClient* client, | 116 static scoped_ptr<TileManager> Create(TileManagerClient* client, |
109 base::SequencedTaskRunner* task_runner, | 117 base::SequencedTaskRunner* task_runner, |
110 size_t scheduled_raster_task_limit, | 118 size_t scheduled_raster_task_limit, |
111 bool use_partial_raster); | 119 bool use_partial_raster); |
112 ~TileManager() override; | 120 virtual ~TileManager(); |
113 | 121 |
114 // Assigns tile memory and schedules work to prepare tiles for drawing. | 122 // Assigns tile memory and schedules work to prepare tiles for drawing. |
115 // - Runs client_->NotifyReadyToActivate() when all tiles required for | 123 // - Runs client_->NotifyReadyToActivate() when all tiles required for |
116 // activation are prepared, or failed to prepare due to OOM. | 124 // activation are prepared, or failed to prepare due to OOM. |
117 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are | 125 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are |
118 // prepared, or failed to prepare due to OOM. | 126 // prepared, or failed to prepare due to OOM. |
119 bool PrepareTiles(const GlobalStateThatImpactsTilePriority& state); | 127 bool PrepareTiles(const GlobalStateThatImpactsTilePriority& state); |
120 | 128 |
121 // Synchronously finish any in progress work, cancel the rest, and clean up as | 129 // Synchronously finish any in progress work, cancel the rest, and clean up as |
122 // much resources as possible. Also, prevents any future work until a | 130 // much resources as possible. Also, prevents any future work until a |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 bool use_partial_raster); | 218 bool use_partial_raster); |
211 | 219 |
212 void FreeResourcesForReleasedTiles(); | 220 void FreeResourcesForReleasedTiles(); |
213 void CleanUpReleasedTiles(); | 221 void CleanUpReleasedTiles(); |
214 | 222 |
215 friend class Tile; | 223 friend class Tile; |
216 // Virtual for testing. | 224 // Virtual for testing. |
217 virtual void Release(Tile* tile); | 225 virtual void Release(Tile* tile); |
218 Tile::Id GetUniqueTileId() { return ++next_tile_id_; } | 226 Tile::Id GetUniqueTileId() { return ++next_tile_id_; } |
219 | 227 |
220 // Overriden from TileTaskRunnerClient: | |
221 void DidFinishRunningTileTasks(TaskSet task_set) override; | |
222 | |
223 typedef std::vector<PrioritizedTile> PrioritizedTileVector; | 228 typedef std::vector<PrioritizedTile> PrioritizedTileVector; |
224 typedef std::set<Tile*> TileSet; | 229 typedef std::set<Tile*> TileSet; |
225 | 230 |
226 // Virtual for test | 231 // Virtual for test |
227 virtual void ScheduleTasks( | 232 virtual void ScheduleTasks( |
228 const PrioritizedTileVector& tiles_that_need_to_be_rasterized); | 233 const PrioritizedTileVector& tiles_that_need_to_be_rasterized); |
229 | 234 |
230 void AssignGpuMemoryToTiles( | 235 void AssignGpuMemoryToTiles( |
231 RasterTilePriorityQueue* raster_priority_queue, | 236 RasterTilePriorityQueue* raster_priority_queue, |
232 size_t scheduled_raser_task_limit, | 237 size_t scheduled_raser_task_limit, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 MemoryUsage* usage); | 286 MemoryUsage* usage); |
282 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); | 287 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); |
283 bool AreRequiredTilesReadyToDraw(RasterTilePriorityQueue::Type type) const; | 288 bool AreRequiredTilesReadyToDraw(RasterTilePriorityQueue::Type type) const; |
284 void CheckIfMoreTilesNeedToBePrepared(); | 289 void CheckIfMoreTilesNeedToBePrepared(); |
285 void CheckAndIssueSignals(); | 290 void CheckAndIssueSignals(); |
286 bool MarkTilesOutOfMemory(scoped_ptr<RasterTilePriorityQueue> queue) const; | 291 bool MarkTilesOutOfMemory(scoped_ptr<RasterTilePriorityQueue> queue) const; |
287 | 292 |
288 ResourceFormat DetermineResourceFormat(const Tile* tile) const; | 293 ResourceFormat DetermineResourceFormat(const Tile* tile) const; |
289 bool DetermineResourceRequiresSwizzle(const Tile* tile) const; | 294 bool DetermineResourceRequiresSwizzle(const Tile* tile) const; |
290 | 295 |
296 void DidFinishRunningTileTasks(TaskSet task_set); | |
297 | |
298 void BuildTaskGraph( | |
299 const PrioritizedTileVector& tiles_that_need_to_be_rasterized, | |
300 TaskGraph* graph, | |
301 scoped_refptr<TileTask>(&new_task_set_finished_tasks)[kNumberOfTaskSets]); | |
302 | |
303 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | |
304 ScheduledTasksStateAsValue() const; | |
305 | |
291 TileManagerClient* client_; | 306 TileManagerClient* client_; |
292 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 307 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
293 ResourcePool* resource_pool_; | 308 ResourcePool* resource_pool_; |
294 TileTaskRunner* tile_task_runner_; | 309 TileTaskRunner* tile_task_runner_; |
295 GlobalStateThatImpactsTilePriority global_state_; | 310 GlobalStateThatImpactsTilePriority global_state_; |
296 size_t scheduled_raster_task_limit_; | 311 size_t scheduled_raster_task_limit_; |
297 const bool use_partial_raster_; | 312 const bool use_partial_raster_; |
298 | 313 |
299 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 314 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
300 TileMap tiles_; | 315 TileMap tiles_; |
301 | 316 |
302 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; | 317 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; |
303 MemoryHistory::Entry memory_stats_from_last_assign_; | 318 MemoryHistory::Entry memory_stats_from_last_assign_; |
304 | 319 |
305 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 320 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
306 bool did_oom_on_last_assign_; | 321 bool did_oom_on_last_assign_; |
307 | 322 |
308 ImageDecodeController image_decode_controller_; | 323 ImageDecodeController image_decode_controller_; |
309 | 324 |
310 RasterTaskCompletionStats flush_stats_; | 325 RasterTaskCompletionStats flush_stats_; |
311 | 326 |
312 std::vector<Tile*> released_tiles_; | 327 std::vector<Tile*> released_tiles_; |
313 | 328 |
314 // Queue used when scheduling raster tasks. | 329 std::vector<scoped_refptr<TileTask>> orphan_tasks_; |
315 TileTaskQueue raster_queue_; | 330 TaskSetCollection tasks_pending_; |
316 | |
317 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; | |
318 | 331 |
319 UniqueNotifier more_tiles_need_prepare_check_notifier_; | 332 UniqueNotifier more_tiles_need_prepare_check_notifier_; |
320 | 333 |
321 struct Signals { | 334 struct Signals { |
322 Signals(); | 335 Signals(); |
323 | 336 |
324 void reset(); | 337 void reset(); |
325 | 338 |
326 bool ready_to_activate; | 339 bool ready_to_activate; |
327 bool did_notify_ready_to_activate; | 340 bool did_notify_ready_to_activate; |
328 bool ready_to_draw; | 341 bool ready_to_draw; |
329 bool did_notify_ready_to_draw; | 342 bool did_notify_ready_to_draw; |
330 bool all_tile_tasks_completed; | 343 bool all_tile_tasks_completed; |
331 bool did_notify_all_tile_tasks_completed; | 344 bool did_notify_all_tile_tasks_completed; |
332 } signals_; | 345 } signals_; |
333 | 346 |
334 UniqueNotifier signals_check_notifier_; | 347 UniqueNotifier signals_check_notifier_; |
335 | 348 |
336 bool has_scheduled_tile_tasks_; | 349 bool has_scheduled_tile_tasks_; |
337 | 350 |
338 uint64_t prepare_tiles_count_; | 351 uint64_t prepare_tiles_count_; |
339 uint64_t next_tile_id_; | 352 uint64_t next_tile_id_; |
340 | 353 |
354 base::WeakPtrFactory<TileManager> task_set_finished_weak_ptr_factory_; | |
355 | |
341 DISALLOW_COPY_AND_ASSIGN(TileManager); | 356 DISALLOW_COPY_AND_ASSIGN(TileManager); |
342 }; | 357 }; |
343 | 358 |
344 } // namespace cc | 359 } // namespace cc |
345 | 360 |
346 #endif // CC_TILES_TILE_MANAGER_H_ | 361 #endif // CC_TILES_TILE_MANAGER_H_ |
OLD | NEW |