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> | |
9 #include <queue> | |
10 #include <set> | 8 #include <set> |
11 #include <utility> | 9 #include <utility> |
12 #include <vector> | 10 #include <vector> |
13 | 11 |
14 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
15 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
16 #include "base/values.h" | 14 #include "base/values.h" |
17 #include "cc/base/unique_notifier.h" | 15 #include "cc/base/unique_notifier.h" |
18 #include "cc/playback/display_list_raster_source.h" | 16 #include "cc/playback/display_list_raster_source.h" |
19 #include "cc/raster/tile_task_runner.h" | 17 #include "cc/raster/tile_task_runner.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 size_t completed_count; | 81 size_t completed_count; |
84 size_t canceled_count; | 82 size_t canceled_count; |
85 }; | 83 }; |
86 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 84 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
87 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats); | 85 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats); |
88 | 86 |
89 // This class manages tiles, deciding which should get rasterized and which | 87 // 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" | 88 // 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 | 89 // by layers; they automatically register with the manager when they are |
92 // created, and unregister from the manager when they are deleted. | 90 // created, and unregister from the manager when they are deleted. |
93 class CC_EXPORT TileManager : public TileTaskRunnerClient { | 91 class CC_EXPORT TileManager { |
94 public: | 92 public: |
95 enum NamedTaskSet { | |
96 REQUIRED_FOR_ACTIVATION, | |
97 REQUIRED_FOR_DRAW, | |
98 // PixelBufferTileTaskWorkerPool depends on ALL being last. | |
99 ALL | |
100 // Adding additional values requires increasing kNumberOfTaskSets in | |
101 // tile_task_runner.h | |
102 }; | |
103 | |
104 static_assert(NamedTaskSet::ALL == (kNumberOfTaskSets - 1), | |
105 "NamedTaskSet::ALL should be equal to kNumberOfTaskSets" | |
106 "minus 1"); | |
107 | |
108 static scoped_ptr<TileManager> Create(TileManagerClient* client, | 93 static scoped_ptr<TileManager> Create(TileManagerClient* client, |
109 base::SequencedTaskRunner* task_runner, | 94 base::SequencedTaskRunner* task_runner, |
110 size_t scheduled_raster_task_limit, | 95 size_t scheduled_raster_task_limit, |
111 bool use_partial_raster); | 96 bool use_partial_raster); |
112 ~TileManager() override; | 97 virtual ~TileManager(); |
113 | 98 |
114 // Assigns tile memory and schedules work to prepare tiles for drawing. | 99 // Assigns tile memory and schedules work to prepare tiles for drawing. |
115 // - Runs client_->NotifyReadyToActivate() when all tiles required for | 100 // - Runs client_->NotifyReadyToActivate() when all tiles required for |
116 // activation are prepared, or failed to prepare due to OOM. | 101 // activation are prepared, or failed to prepare due to OOM. |
117 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are | 102 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are |
118 // prepared, or failed to prepare due to OOM. | 103 // prepared, or failed to prepare due to OOM. |
119 bool PrepareTiles(const GlobalStateThatImpactsTilePriority& state); | 104 bool PrepareTiles(const GlobalStateThatImpactsTilePriority& state); |
120 | 105 |
121 // Synchronously finish any in progress work, cancel the rest, and clean up as | 106 // 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 | 107 // 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); | 195 bool use_partial_raster); |
211 | 196 |
212 void FreeResourcesForReleasedTiles(); | 197 void FreeResourcesForReleasedTiles(); |
213 void CleanUpReleasedTiles(); | 198 void CleanUpReleasedTiles(); |
214 | 199 |
215 friend class Tile; | 200 friend class Tile; |
216 // Virtual for testing. | 201 // Virtual for testing. |
217 virtual void Release(Tile* tile); | 202 virtual void Release(Tile* tile); |
218 Tile::Id GetUniqueTileId() { return ++next_tile_id_; } | 203 Tile::Id GetUniqueTileId() { return ++next_tile_id_; } |
219 | 204 |
220 // Overriden from TileTaskRunnerClient: | |
221 void DidFinishRunningTileTasks(TaskSet task_set) override; | |
222 | |
223 typedef std::vector<PrioritizedTile> PrioritizedTileVector; | 205 typedef std::vector<PrioritizedTile> PrioritizedTileVector; |
224 typedef std::set<Tile*> TileSet; | 206 typedef std::set<Tile*> TileSet; |
225 | 207 |
226 // Virtual for test | 208 // Virtual for test |
227 virtual void ScheduleTasks( | 209 virtual void ScheduleTasks( |
228 const PrioritizedTileVector& tiles_that_need_to_be_rasterized); | 210 const PrioritizedTileVector& tiles_that_need_to_be_rasterized); |
229 | 211 |
230 void AssignGpuMemoryToTiles( | 212 void AssignGpuMemoryToTiles( |
231 RasterTilePriorityQueue* raster_priority_queue, | 213 RasterTilePriorityQueue* raster_priority_queue, |
232 size_t scheduled_raser_task_limit, | 214 size_t scheduled_raser_task_limit, |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 MemoryUsage* usage); | 263 MemoryUsage* usage); |
282 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); | 264 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); |
283 bool AreRequiredTilesReadyToDraw(RasterTilePriorityQueue::Type type) const; | 265 bool AreRequiredTilesReadyToDraw(RasterTilePriorityQueue::Type type) const; |
284 void CheckIfMoreTilesNeedToBePrepared(); | 266 void CheckIfMoreTilesNeedToBePrepared(); |
285 void CheckAndIssueSignals(); | 267 void CheckAndIssueSignals(); |
286 bool MarkTilesOutOfMemory(scoped_ptr<RasterTilePriorityQueue> queue) const; | 268 bool MarkTilesOutOfMemory(scoped_ptr<RasterTilePriorityQueue> queue) const; |
287 | 269 |
288 ResourceFormat DetermineResourceFormat(const Tile* tile) const; | 270 ResourceFormat DetermineResourceFormat(const Tile* tile) const; |
289 bool DetermineResourceRequiresSwizzle(const Tile* tile) const; | 271 bool DetermineResourceRequiresSwizzle(const Tile* tile) const; |
290 | 272 |
| 273 void DidFinishRunningTileTasksRequiredForActivation(); |
| 274 void DidFinishRunningTileTasksRequiredForDraw(); |
| 275 void DidFinishRunningAllTileTasks(); |
| 276 |
| 277 scoped_refptr<TileTask> CreateTaskSetFinishedTask( |
| 278 void (TileManager::*callback)()); |
| 279 |
| 280 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
| 281 ScheduledTasksStateAsValue() const; |
| 282 |
291 TileManagerClient* client_; | 283 TileManagerClient* client_; |
292 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 284 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
293 ResourcePool* resource_pool_; | 285 ResourcePool* resource_pool_; |
294 TileTaskRunner* tile_task_runner_; | 286 TileTaskRunner* tile_task_runner_; |
295 GlobalStateThatImpactsTilePriority global_state_; | 287 GlobalStateThatImpactsTilePriority global_state_; |
296 size_t scheduled_raster_task_limit_; | 288 size_t scheduled_raster_task_limit_; |
297 const bool use_partial_raster_; | 289 const bool use_partial_raster_; |
298 | 290 |
299 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 291 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
300 TileMap tiles_; | 292 TileMap tiles_; |
301 | 293 |
302 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; | 294 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; |
303 MemoryHistory::Entry memory_stats_from_last_assign_; | 295 MemoryHistory::Entry memory_stats_from_last_assign_; |
304 | 296 |
305 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 297 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
306 bool did_oom_on_last_assign_; | 298 bool did_oom_on_last_assign_; |
307 | 299 |
308 ImageDecodeController image_decode_controller_; | 300 ImageDecodeController image_decode_controller_; |
309 | 301 |
310 RasterTaskCompletionStats flush_stats_; | 302 RasterTaskCompletionStats flush_stats_; |
311 | 303 |
312 std::vector<Tile*> released_tiles_; | 304 std::vector<Tile*> released_tiles_; |
313 | 305 |
314 // Queue used when scheduling raster tasks. | 306 std::vector<scoped_refptr<TileTask>> orphan_tasks_; |
315 TileTaskQueue raster_queue_; | |
316 | 307 |
317 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; | 308 TaskGraph graph_; |
| 309 scoped_refptr<TileTask> required_for_activation_done_task_; |
| 310 scoped_refptr<TileTask> required_for_draw_done_task_; |
| 311 scoped_refptr<TileTask> all_done_task_; |
318 | 312 |
319 UniqueNotifier more_tiles_need_prepare_check_notifier_; | 313 UniqueNotifier more_tiles_need_prepare_check_notifier_; |
320 | 314 |
321 struct Signals { | 315 struct Signals { |
322 Signals(); | 316 Signals(); |
323 | 317 |
324 void reset(); | 318 void reset(); |
325 | 319 |
326 bool ready_to_activate; | 320 bool ready_to_activate; |
327 bool did_notify_ready_to_activate; | 321 bool did_notify_ready_to_activate; |
328 bool ready_to_draw; | 322 bool ready_to_draw; |
329 bool did_notify_ready_to_draw; | 323 bool did_notify_ready_to_draw; |
330 bool all_tile_tasks_completed; | 324 bool all_tile_tasks_completed; |
331 bool did_notify_all_tile_tasks_completed; | 325 bool did_notify_all_tile_tasks_completed; |
332 } signals_; | 326 } signals_; |
333 | 327 |
334 UniqueNotifier signals_check_notifier_; | 328 UniqueNotifier signals_check_notifier_; |
335 | 329 |
336 bool has_scheduled_tile_tasks_; | 330 bool has_scheduled_tile_tasks_; |
337 | 331 |
338 uint64_t prepare_tiles_count_; | 332 uint64_t prepare_tiles_count_; |
339 uint64_t next_tile_id_; | 333 uint64_t next_tile_id_; |
340 | 334 |
| 335 base::WeakPtrFactory<TileManager> task_set_finished_weak_ptr_factory_; |
| 336 |
341 DISALLOW_COPY_AND_ASSIGN(TileManager); | 337 DISALLOW_COPY_AND_ASSIGN(TileManager); |
342 }; | 338 }; |
343 | 339 |
344 } // namespace cc | 340 } // namespace cc |
345 | 341 |
346 #endif // CC_TILES_TILE_MANAGER_H_ | 342 #endif // CC_TILES_TILE_MANAGER_H_ |
OLD | NEW |