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 |
11 #include <memory> | 11 #include <memory> |
12 #include <set> | 12 #include <set> |
13 #include <unordered_map> | 13 #include <unordered_map> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "cc/base/unique_notifier.h" | 19 #include "cc/base/unique_notifier.h" |
20 #include "cc/playback/raster_source.h" | 20 #include "cc/playback/raster_source.h" |
21 #include "cc/raster/raster_buffer_provider.h" | 21 #include "cc/raster/raster_buffer_provider.h" |
22 #include "cc/resources/memory_history.h" | 22 #include "cc/resources/memory_history.h" |
23 #include "cc/resources/resource_pool.h" | 23 #include "cc/resources/resource_pool.h" |
| 24 #include "cc/tiles/checker_image_tracker.h" |
24 #include "cc/tiles/decoded_image_tracker.h" | 25 #include "cc/tiles/decoded_image_tracker.h" |
25 #include "cc/tiles/eviction_tile_priority_queue.h" | 26 #include "cc/tiles/eviction_tile_priority_queue.h" |
26 #include "cc/tiles/image_controller.h" | 27 #include "cc/tiles/image_controller.h" |
27 #include "cc/tiles/raster_tile_priority_queue.h" | 28 #include "cc/tiles/raster_tile_priority_queue.h" |
28 #include "cc/tiles/tile.h" | 29 #include "cc/tiles/tile.h" |
29 #include "cc/tiles/tile_draw_info.h" | 30 #include "cc/tiles/tile_draw_info.h" |
| 31 #include "cc/tiles/tile_manager_settings.h" |
30 #include "cc/tiles/tile_task_manager.h" | 32 #include "cc/tiles/tile_task_manager.h" |
31 | 33 |
32 namespace base { | 34 namespace base { |
33 namespace trace_event { | 35 namespace trace_event { |
34 class ConvertableToTraceFormat; | 36 class ConvertableToTraceFormat; |
35 class TracedValue; | 37 class TracedValue; |
36 } | 38 } |
37 } | 39 } |
38 | 40 |
39 namespace cc { | 41 namespace cc { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 TreePriority tree_priority) = 0; | 74 TreePriority tree_priority) = 0; |
73 | 75 |
74 // Informs the client that due to the currently rasterizing (or scheduled to | 76 // Informs the client that due to the currently rasterizing (or scheduled to |
75 // be rasterized) tiles, we will be in a position that will likely require a | 77 // be rasterized) tiles, we will be in a position that will likely require a |
76 // draw. This can be used to preemptively start a frame. | 78 // draw. This can be used to preemptively start a frame. |
77 virtual void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw) = 0; | 79 virtual void SetIsLikelyToRequireADraw(bool is_likely_to_require_a_draw) = 0; |
78 | 80 |
79 // Requests the color space into which tiles should be rasterized. | 81 // Requests the color space into which tiles should be rasterized. |
80 virtual gfx::ColorSpace GetTileColorSpace() const = 0; | 82 virtual gfx::ColorSpace GetTileColorSpace() const = 0; |
81 | 83 |
| 84 // Requests that a pending tree be scheduled to invalidate content on the |
| 85 // pending on active tree. This is currently used when tiles that are |
| 86 // rasterized with missing images need to be invalidated. |
| 87 virtual void RequestImplSideInvalidation() = 0; |
| 88 |
82 protected: | 89 protected: |
83 virtual ~TileManagerClient() {} | 90 virtual ~TileManagerClient() {} |
84 }; | 91 }; |
85 | 92 |
86 struct RasterTaskCompletionStats { | 93 struct RasterTaskCompletionStats { |
87 RasterTaskCompletionStats(); | 94 RasterTaskCompletionStats(); |
88 | 95 |
89 size_t completed_count; | 96 size_t completed_count; |
90 size_t canceled_count; | 97 size_t canceled_count; |
91 }; | 98 }; |
92 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | 99 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
93 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats); | 100 RasterTaskCompletionStatsAsValue(const RasterTaskCompletionStats& stats); |
94 | 101 |
95 // This class manages tiles, deciding which should get rasterized and which | 102 // This class manages tiles, deciding which should get rasterized and which |
96 // should no longer have any memory assigned to them. Tile objects are "owned" | 103 // should no longer have any memory assigned to them. Tile objects are "owned" |
97 // by layers; they automatically register with the manager when they are | 104 // by layers; they automatically register with the manager when they are |
98 // created, and unregister from the manager when they are deleted. | 105 // created, and unregister from the manager when they are deleted. |
99 class CC_EXPORT TileManager { | 106 class CC_EXPORT TileManager : CheckerImageTrackerClient { |
100 public: | 107 public: |
101 TileManager(TileManagerClient* client, | 108 TileManager(TileManagerClient* client, |
102 base::SequencedTaskRunner* origin_task_runner, | 109 base::SequencedTaskRunner* origin_task_runner, |
103 scoped_refptr<base::SequencedTaskRunner> image_worker_task_runner, | 110 scoped_refptr<base::SequencedTaskRunner> image_worker_task_runner, |
104 size_t scheduled_raster_task_limit, | 111 size_t scheduled_raster_task_limit, |
105 bool use_partial_raster, | 112 const TileManagerSettings& tile_manager_settings); |
106 bool check_tile_priority_inversion); | 113 ~TileManager() override; |
107 virtual ~TileManager(); | |
108 | 114 |
109 // Assigns tile memory and schedules work to prepare tiles for drawing. | 115 // Assigns tile memory and schedules work to prepare tiles for drawing. |
110 // - Runs client_->NotifyReadyToActivate() when all tiles required for | 116 // - Runs client_->NotifyReadyToActivate() when all tiles required for |
111 // activation are prepared, or failed to prepare due to OOM. | 117 // activation are prepared, or failed to prepare due to OOM. |
112 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are | 118 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are |
113 // prepared, or failed to prepare due to OOM. | 119 // prepared, or failed to prepare due to OOM. |
114 bool PrepareTiles(const GlobalStateThatImpactsTilePriority& state); | 120 bool PrepareTiles(const GlobalStateThatImpactsTilePriority& state); |
115 | 121 |
116 // Synchronously finish any in progress work, cancel the rest, and clean up as | 122 // Synchronously finish any in progress work, cancel the rest, and clean up as |
117 // much resources as possible. Also, prevents any future work until a | 123 // much resources as possible. Also, prevents any future work until a |
(...skipping 19 matching lines...) Expand all Loading... |
137 void DidModifyTilePriorities(); | 143 void DidModifyTilePriorities(); |
138 | 144 |
139 std::unique_ptr<Tile> CreateTile(const Tile::CreateInfo& info, | 145 std::unique_ptr<Tile> CreateTile(const Tile::CreateInfo& info, |
140 int layer_id, | 146 int layer_id, |
141 int source_frame_number, | 147 int source_frame_number, |
142 int flags); | 148 int flags); |
143 | 149 |
144 bool IsReadyToActivate() const; | 150 bool IsReadyToActivate() const; |
145 bool IsReadyToDraw() const; | 151 bool IsReadyToDraw() const; |
146 | 152 |
| 153 const std::unordered_set<ImageId>& TakeImagesToInvalidateOnSyncTree(); |
| 154 void DidActivateSyncTree(); |
| 155 |
147 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> | 156 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> |
148 BasicStateAsValue() const; | 157 BasicStateAsValue() const; |
149 void BasicStateAsValueInto(base::trace_event::TracedValue* dict) const; | 158 void BasicStateAsValueInto(base::trace_event::TracedValue* dict) const; |
150 const MemoryHistory::Entry& memory_stats_from_last_assign() const { | 159 const MemoryHistory::Entry& memory_stats_from_last_assign() const { |
151 return memory_stats_from_last_assign_; | 160 return memory_stats_from_last_assign_; |
152 } | 161 } |
153 | 162 |
154 // Public methods for testing. | 163 // Public methods for testing. |
155 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { | 164 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { |
156 for (size_t i = 0; i < tiles.size(); ++i) { | 165 for (size_t i = 0; i < tiles.size(); ++i) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 return has_scheduled_tile_tasks_; | 219 return has_scheduled_tile_tasks_; |
211 } | 220 } |
212 | 221 |
213 void OnRasterTaskCompleted(std::unique_ptr<RasterBuffer> raster_buffer, | 222 void OnRasterTaskCompleted(std::unique_ptr<RasterBuffer> raster_buffer, |
214 Tile::Id tile_id, | 223 Tile::Id tile_id, |
215 Resource* resource, | 224 Resource* resource, |
216 bool was_canceled); | 225 bool was_canceled); |
217 | 226 |
218 void SetDecodedImageTracker(DecodedImageTracker* decoded_image_tracker); | 227 void SetDecodedImageTracker(DecodedImageTracker* decoded_image_tracker); |
219 | 228 |
| 229 // CheckerImageTrackerClient implementation. |
| 230 void NeedsInvalidationForCheckerImagedTiles() override; |
| 231 |
220 protected: | 232 protected: |
221 friend class Tile; | 233 friend class Tile; |
222 // Must be called by tile during destruction. | 234 // Must be called by tile during destruction. |
223 void Release(Tile* tile); | 235 void Release(Tile* tile); |
224 Tile::Id GetUniqueTileId() { return ++next_tile_id_; } | 236 Tile::Id GetUniqueTileId() { return ++next_tile_id_; } |
225 | 237 |
226 private: | 238 private: |
227 class MemoryUsage { | 239 class MemoryUsage { |
228 public: | 240 public: |
229 MemoryUsage(); | 241 MemoryUsage(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 | 321 |
310 void CheckPendingGpuWorkTiles(bool issue_signals); | 322 void CheckPendingGpuWorkTiles(bool issue_signals); |
311 | 323 |
312 TileManagerClient* client_; | 324 TileManagerClient* client_; |
313 base::SequencedTaskRunner* task_runner_; | 325 base::SequencedTaskRunner* task_runner_; |
314 ResourcePool* resource_pool_; | 326 ResourcePool* resource_pool_; |
315 std::unique_ptr<TileTaskManager> tile_task_manager_; | 327 std::unique_ptr<TileTaskManager> tile_task_manager_; |
316 RasterBufferProvider* raster_buffer_provider_; | 328 RasterBufferProvider* raster_buffer_provider_; |
317 GlobalStateThatImpactsTilePriority global_state_; | 329 GlobalStateThatImpactsTilePriority global_state_; |
318 size_t scheduled_raster_task_limit_; | 330 size_t scheduled_raster_task_limit_; |
319 const bool use_partial_raster_; | 331 |
| 332 const TileManagerSettings tile_manager_settings_; |
320 bool use_gpu_rasterization_; | 333 bool use_gpu_rasterization_; |
321 | 334 |
322 std::unordered_map<Tile::Id, Tile*> tiles_; | 335 std::unordered_map<Tile::Id, Tile*> tiles_; |
323 | 336 |
324 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; | 337 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; |
325 MemoryHistory::Entry memory_stats_from_last_assign_; | 338 MemoryHistory::Entry memory_stats_from_last_assign_; |
326 | 339 |
327 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 340 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
328 bool did_oom_on_last_assign_; | 341 bool did_oom_on_last_assign_; |
329 | 342 |
330 ImageController image_controller_; | 343 ImageController image_controller_; |
| 344 CheckerImageTracker checker_image_tracker_; |
331 | 345 |
332 RasterTaskCompletionStats flush_stats_; | 346 RasterTaskCompletionStats flush_stats_; |
333 | 347 |
334 TaskGraph graph_; | 348 TaskGraph graph_; |
335 | 349 |
336 UniqueNotifier more_tiles_need_prepare_check_notifier_; | 350 UniqueNotifier more_tiles_need_prepare_check_notifier_; |
337 | 351 |
338 Signals signals_; | 352 Signals signals_; |
339 | 353 |
340 UniqueNotifier signals_check_notifier_; | 354 UniqueNotifier signals_check_notifier_; |
341 | 355 |
342 bool has_scheduled_tile_tasks_; | 356 bool has_scheduled_tile_tasks_; |
343 | 357 |
344 uint64_t prepare_tiles_count_; | 358 uint64_t prepare_tiles_count_; |
345 uint64_t next_tile_id_; | 359 uint64_t next_tile_id_; |
346 | 360 |
347 std::unordered_set<Tile*> pending_gpu_work_tiles_; | 361 std::unordered_set<Tile*> pending_gpu_work_tiles_; |
348 uint64_t pending_required_for_activation_callback_id_ = 0; | 362 uint64_t pending_required_for_activation_callback_id_ = 0; |
349 uint64_t pending_required_for_draw_callback_id_ = 0; | 363 uint64_t pending_required_for_draw_callback_id_ = 0; |
350 // If true, we should re-compute tile requirements in | 364 // If true, we should re-compute tile requirements in |
351 // CheckPendingGpuWorkTiles. | 365 // CheckPendingGpuWorkTiles. |
352 bool pending_tile_requirements_dirty_ = false; | 366 bool pending_tile_requirements_dirty_ = false; |
353 | 367 |
354 std::unordered_map<Tile::Id, std::vector<DrawImage>> scheduled_draw_images_; | 368 std::unordered_map<Tile::Id, std::vector<DrawImage>> scheduled_draw_images_; |
355 std::vector<scoped_refptr<TileTask>> locked_image_tasks_; | 369 std::vector<scoped_refptr<TileTask>> locked_image_tasks_; |
356 const bool check_tile_priority_inversion_; | |
357 | 370 |
358 // We need two WeakPtrFactory objects as the invalidation pattern of each is | 371 // We need two WeakPtrFactory objects as the invalidation pattern of each is |
359 // different. The |task_set_finished_weak_ptr_factory_| is invalidated any | 372 // different. The |task_set_finished_weak_ptr_factory_| is invalidated any |
360 // time new tasks are scheduled, preventing a race when the callback has | 373 // time new tasks are scheduled, preventing a race when the callback has |
361 // been scheduled but not yet executed. | 374 // been scheduled but not yet executed. |
362 base::WeakPtrFactory<TileManager> task_set_finished_weak_ptr_factory_; | 375 base::WeakPtrFactory<TileManager> task_set_finished_weak_ptr_factory_; |
363 // The |ready_to_draw_callback_weak_ptr_factory_| is never invalidated. | 376 // The |ready_to_draw_callback_weak_ptr_factory_| is never invalidated. |
364 base::WeakPtrFactory<TileManager> ready_to_draw_callback_weak_ptr_factory_; | 377 base::WeakPtrFactory<TileManager> ready_to_draw_callback_weak_ptr_factory_; |
365 | 378 |
366 DISALLOW_COPY_AND_ASSIGN(TileManager); | 379 DISALLOW_COPY_AND_ASSIGN(TileManager); |
367 }; | 380 }; |
368 | 381 |
369 } // namespace cc | 382 } // namespace cc |
370 | 383 |
371 #endif // CC_TILES_TILE_MANAGER_H_ | 384 #endif // CC_TILES_TILE_MANAGER_H_ |
OLD | NEW |