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_RESOURCES_TILE_MANAGER_H_ | 5 #ifndef CC_RESOURCES_TILE_MANAGER_H_ |
6 #define CC_RESOURCES_TILE_MANAGER_H_ | 6 #define CC_RESOURCES_TILE_MANAGER_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <queue> | 9 #include <queue> |
10 #include <set> | 10 #include <set> |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 namespace base { | 28 namespace base { |
29 namespace debug { | 29 namespace debug { |
30 class ConvertableToTraceFormat; | 30 class ConvertableToTraceFormat; |
31 class TracedValue; | 31 class TracedValue; |
32 } | 32 } |
33 } | 33 } |
34 | 34 |
35 namespace cc { | 35 namespace cc { |
36 class PictureLayerImpl; | 36 class PictureLayerImpl; |
| 37 class Rasterizer; |
37 class ResourceProvider; | 38 class ResourceProvider; |
38 | 39 |
39 class CC_EXPORT TileManagerClient { | 40 class CC_EXPORT TileManagerClient { |
40 public: | 41 public: |
41 // Returns the set of layers that the tile manager should consider for raster. | 42 // Returns the set of layers that the tile manager should consider for raster. |
42 // TODO(vmpstr): Change the way we determine if we are ready to activate, so | 43 // TODO(vmpstr): Change the way we determine if we are ready to activate, so |
43 // that this can be removed. | 44 // that this can be removed. |
44 virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() const = 0; | 45 virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() const = 0; |
45 | 46 |
46 // Called when all tiles marked as required for activation are ready to draw. | 47 // Called when all tiles marked as required for activation are ready to draw. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 public RefCountedManager<Tile> { | 90 public RefCountedManager<Tile> { |
90 public: | 91 public: |
91 enum NamedTaskSet { | 92 enum NamedTaskSet { |
92 ALL, | 93 ALL, |
93 REQUIRED_FOR_ACTIVATION, | 94 REQUIRED_FOR_ACTIVATION, |
94 REQUIRED_FOR_DRAW | 95 REQUIRED_FOR_DRAW |
95 // Adding additional values requires increasing kNumberOfTaskSets in | 96 // Adding additional values requires increasing kNumberOfTaskSets in |
96 // rasterizer.h | 97 // rasterizer.h |
97 }; | 98 }; |
98 | 99 |
99 static scoped_ptr<TileManager> Create( | 100 static scoped_ptr<TileManager> Create(TileManagerClient* client, |
100 TileManagerClient* client, | 101 base::SequencedTaskRunner* task_runner, |
101 base::SequencedTaskRunner* task_runner, | 102 ResourcePool* resource_pool, |
102 ResourcePool* resource_pool, | 103 TileTaskRunner* tile_task_runner, |
103 TileTaskRunner* tile_task_runner, | 104 Rasterizer* rasterizer, |
104 size_t scheduled_raster_task_limit); | 105 size_t scheduled_raster_task_limit); |
105 ~TileManager() override; | 106 ~TileManager() override; |
106 | 107 |
107 // Assigns tile memory and schedules work to prepare tiles for drawing. | 108 // Assigns tile memory and schedules work to prepare tiles for drawing. |
108 // - Runs client_->NotifyReadyToActivate() when all tiles required for | 109 // - Runs client_->NotifyReadyToActivate() when all tiles required for |
109 // activation are prepared, or failed to prepare due to OOM. | 110 // activation are prepared, or failed to prepare due to OOM. |
110 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are | 111 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are |
111 // prepared, or failed to prepare due to OOM. | 112 // prepared, or failed to prepare due to OOM. |
112 void PrepareTiles(const GlobalStateThatImpactsTilePriority& state); | 113 void PrepareTiles(const GlobalStateThatImpactsTilePriority& state); |
113 | 114 |
114 void UpdateVisibleTiles(); | 115 void UpdateVisibleTiles(const GlobalStateThatImpactsTilePriority& state); |
115 | 116 |
116 scoped_refptr<Tile> CreateTile(RasterSource* raster_source, | 117 scoped_refptr<Tile> CreateTile(RasterSource* raster_source, |
117 const gfx::Size& tile_size, | 118 const gfx::Size& tile_size, |
118 const gfx::Rect& content_rect, | 119 const gfx::Rect& content_rect, |
119 float contents_scale, | 120 float contents_scale, |
120 int layer_id, | 121 int layer_id, |
121 int source_frame_number, | 122 int source_frame_number, |
122 int flags); | 123 int flags); |
123 | 124 |
124 scoped_refptr<base::debug::ConvertableToTraceFormat> BasicStateAsValue() | 125 scoped_refptr<base::debug::ConvertableToTraceFormat> BasicStateAsValue() |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 ++it) { | 161 ++it) { |
161 tiles.push_back(it->second); | 162 tiles.push_back(it->second); |
162 } | 163 } |
163 return tiles; | 164 return tiles; |
164 } | 165 } |
165 | 166 |
166 void SetScheduledRasterTaskLimitForTesting(size_t limit) { | 167 void SetScheduledRasterTaskLimitForTesting(size_t limit) { |
167 scheduled_raster_task_limit_ = limit; | 168 scheduled_raster_task_limit_ = limit; |
168 } | 169 } |
169 | 170 |
| 171 void CompleteRasterTask(Tile::Id tile, |
| 172 scoped_ptr<ScopedResource> resource, |
| 173 const RasterSource::SolidColorAnalysis& analysis); |
| 174 |
170 protected: | 175 protected: |
171 TileManager(TileManagerClient* client, | 176 TileManager(TileManagerClient* client, |
172 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 177 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
173 ResourcePool* resource_pool, | 178 ResourcePool* resource_pool, |
174 TileTaskRunner* tile_task_runner, | 179 TileTaskRunner* tile_task_runner, |
| 180 Rasterizer* rasterizer, |
175 size_t scheduled_raster_task_limit); | 181 size_t scheduled_raster_task_limit); |
176 | 182 |
177 void FreeResourcesForReleasedTiles(); | 183 void FreeResourcesForReleasedTiles(); |
178 void CleanUpReleasedTiles(); | 184 void CleanUpReleasedTiles(); |
179 | 185 |
180 // Overriden from RefCountedManager<Tile>: | 186 // Overriden from RefCountedManager<Tile>: |
181 friend class Tile; | 187 friend class Tile; |
182 void Release(Tile* tile) override; | 188 void Release(Tile* tile) override; |
183 | 189 |
184 // Overriden from TileTaskRunnerClient: | 190 // Overriden from TileTaskRunnerClient: |
185 void DidFinishRunningTileTasks(TaskSet task_set) override; | 191 void DidFinishRunningTileTasks(TaskSet task_set) override; |
186 TaskSetCollection TasksThatShouldBeForcedToComplete() const override; | 192 TaskSetCollection TasksThatShouldBeForcedToComplete() const override; |
187 | 193 |
188 typedef std::vector<Tile*> TileVector; | 194 typedef std::vector<Tile*> TileVector; |
189 typedef std::set<Tile*> TileSet; | 195 typedef std::set<Tile*> TileSet; |
190 | 196 |
191 // Virtual for test | 197 // Virtual for test |
192 virtual void ScheduleTasks( | 198 virtual void ScheduleTasks( |
193 const TileVector& tiles_that_need_to_be_rasterized); | 199 const TileVector& tiles_that_need_to_be_rasterized); |
194 | 200 |
195 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized); | 201 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized, |
| 202 size_t scheduled_raser_task_limit, |
| 203 bool required_for_draw_only); |
| 204 |
| 205 void SynchronouslyRasterizeTiles( |
| 206 const GlobalStateThatImpactsTilePriority& state); |
196 | 207 |
197 private: | 208 private: |
198 class MemoryUsage { | 209 class MemoryUsage { |
199 public: | 210 public: |
200 MemoryUsage(); | 211 MemoryUsage(); |
201 MemoryUsage(int64 memory_bytes, int resource_count); | 212 MemoryUsage(int64 memory_bytes, int resource_count); |
202 | 213 |
203 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); | 214 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); |
204 static MemoryUsage FromTile(const Tile* tile); | 215 static MemoryUsage FromTile(const Tile* tile); |
205 | 216 |
(...skipping 26 matching lines...) Expand all Loading... |
232 void RebuildEvictionQueueIfNeeded(); | 243 void RebuildEvictionQueueIfNeeded(); |
233 bool FreeTileResourcesUntilUsageIsWithinLimit(const MemoryUsage& limit, | 244 bool FreeTileResourcesUntilUsageIsWithinLimit(const MemoryUsage& limit, |
234 MemoryUsage* usage); | 245 MemoryUsage* usage); |
235 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( | 246 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( |
236 const MemoryUsage& limit, | 247 const MemoryUsage& limit, |
237 const TilePriority& oother_priority, | 248 const TilePriority& oother_priority, |
238 MemoryUsage* usage); | 249 MemoryUsage* usage); |
239 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); | 250 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); |
240 bool IsReadyToActivate() const; | 251 bool IsReadyToActivate() const; |
241 bool IsReadyToDraw() const; | 252 bool IsReadyToDraw() const; |
| 253 void NotifyReadyToActivate(); |
| 254 void NotifyReadyToDraw(); |
242 void CheckIfReadyToActivate(); | 255 void CheckIfReadyToActivate(); |
243 void CheckIfReadyToDraw(); | 256 void CheckIfReadyToDraw(); |
244 | 257 |
245 TileManagerClient* client_; | 258 TileManagerClient* client_; |
246 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 259 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
247 ResourcePool* resource_pool_; | 260 ResourcePool* resource_pool_; |
248 TileTaskRunner* tile_task_runner_; | 261 TileTaskRunner* tile_task_runner_; |
| 262 Rasterizer* rasterizer_; |
249 GlobalStateThatImpactsTilePriority global_state_; | 263 GlobalStateThatImpactsTilePriority global_state_; |
250 size_t scheduled_raster_task_limit_; | 264 size_t scheduled_raster_task_limit_; |
251 | 265 |
252 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 266 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
253 TileMap tiles_; | 267 TileMap tiles_; |
254 | 268 |
255 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; | 269 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; |
256 MemoryHistory::Entry memory_stats_from_last_assign_; | 270 MemoryHistory::Entry memory_stats_from_last_assign_; |
257 | 271 |
258 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 272 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
(...skipping 11 matching lines...) Expand all Loading... |
270 | 284 |
271 std::vector<Tile*> released_tiles_; | 285 std::vector<Tile*> released_tiles_; |
272 | 286 |
273 ResourceFormat resource_format_; | 287 ResourceFormat resource_format_; |
274 | 288 |
275 // Queue used when scheduling raster tasks. | 289 // Queue used when scheduling raster tasks. |
276 TileTaskQueue raster_queue_; | 290 TileTaskQueue raster_queue_; |
277 | 291 |
278 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; | 292 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; |
279 | 293 |
| 294 UniqueNotifier ready_to_activate_notifier_; |
| 295 UniqueNotifier ready_to_draw_notifier_; |
280 UniqueNotifier ready_to_activate_check_notifier_; | 296 UniqueNotifier ready_to_activate_check_notifier_; |
281 UniqueNotifier ready_to_draw_check_notifier_; | 297 UniqueNotifier ready_to_draw_check_notifier_; |
282 | 298 |
283 RasterTilePriorityQueue raster_priority_queue_; | 299 RasterTilePriorityQueue raster_priority_queue_; |
284 EvictionTilePriorityQueue eviction_priority_queue_; | 300 EvictionTilePriorityQueue eviction_priority_queue_; |
285 bool eviction_priority_queue_is_up_to_date_; | 301 bool eviction_priority_queue_is_up_to_date_; |
286 | 302 |
287 bool did_notify_ready_to_activate_; | 303 bool did_notify_ready_to_activate_; |
288 bool did_notify_ready_to_draw_; | 304 bool did_notify_ready_to_draw_; |
289 | 305 |
290 DISALLOW_COPY_AND_ASSIGN(TileManager); | 306 DISALLOW_COPY_AND_ASSIGN(TileManager); |
291 }; | 307 }; |
292 | 308 |
293 } // namespace cc | 309 } // namespace cc |
294 | 310 |
295 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 311 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
OLD | NEW |