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> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "cc/base/ref_counted_managed.h" | 17 #include "cc/base/ref_counted_managed.h" |
18 #include "cc/base/unique_notifier.h" | 18 #include "cc/base/unique_notifier.h" |
19 #include "cc/resources/eviction_tile_priority_queue.h" | 19 #include "cc/resources/eviction_tile_priority_queue.h" |
| 20 #include "cc/resources/gpu_rasterizer.h" |
20 #include "cc/resources/managed_tile_state.h" | 21 #include "cc/resources/managed_tile_state.h" |
21 #include "cc/resources/memory_history.h" | 22 #include "cc/resources/memory_history.h" |
22 #include "cc/resources/raster_source.h" | 23 #include "cc/resources/raster_source.h" |
23 #include "cc/resources/raster_tile_priority_queue.h" | 24 #include "cc/resources/raster_tile_priority_queue.h" |
24 #include "cc/resources/resource_pool.h" | 25 #include "cc/resources/resource_pool.h" |
25 #include "cc/resources/tile.h" | 26 #include "cc/resources/tile.h" |
26 #include "cc/resources/tile_task_runner.h" | 27 #include "cc/resources/tile_task_runner.h" |
27 | 28 |
28 namespace base { | 29 namespace base { |
29 namespace debug { | 30 namespace debug { |
(...skipping 59 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 |
| 108 void PrepareTilesBeforeDraw(const GlobalStateThatImpactsTilePriority& state); |
| 109 |
107 // Assigns tile memory and schedules work to prepare tiles for drawing. | 110 // Assigns tile memory and schedules work to prepare tiles for drawing. |
108 // - Runs client_->NotifyReadyToActivate() when all tiles required for | 111 // - Runs client_->NotifyReadyToActivate() when all tiles required for |
109 // activation are prepared, or failed to prepare due to OOM. | 112 // activation are prepared, or failed to prepare due to OOM. |
110 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are | 113 // - Runs client_->NotifyReadyToDraw() when all tiles required draw are |
111 // prepared, or failed to prepare due to OOM. | 114 // prepared, or failed to prepare due to OOM. |
112 void PrepareTiles(const GlobalStateThatImpactsTilePriority& state); | 115 void PrepareTiles(const GlobalStateThatImpactsTilePriority& state); |
113 | 116 |
114 void UpdateVisibleTiles(); | 117 void UpdateVisibleTiles(); |
115 | 118 |
116 scoped_refptr<Tile> CreateTile(RasterSource* raster_source, | 119 scoped_refptr<Tile> CreateTile(RasterSource* raster_source, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 ++it) { | 165 ++it) { |
163 tiles.push_back(it->second); | 166 tiles.push_back(it->second); |
164 } | 167 } |
165 return tiles; | 168 return tiles; |
166 } | 169 } |
167 | 170 |
168 void SetScheduledRasterTaskLimitForTesting(size_t limit) { | 171 void SetScheduledRasterTaskLimitForTesting(size_t limit) { |
169 scheduled_raster_task_limit_ = limit; | 172 scheduled_raster_task_limit_ = limit; |
170 } | 173 } |
171 | 174 |
| 175 void CompleteRasterTask(Tile::Id tile, |
| 176 scoped_ptr<ScopedResource> resource, |
| 177 const RasterSource::SolidColorAnalysis& analysis); |
| 178 |
172 protected: | 179 protected: |
173 TileManager(TileManagerClient* client, | 180 TileManager(TileManagerClient* client, |
174 const scoped_refptr<base::SequencedTaskRunner>& task_runner, | 181 const scoped_refptr<base::SequencedTaskRunner>& task_runner, |
175 ResourcePool* resource_pool, | 182 ResourcePool* resource_pool, |
176 TileTaskRunner* tile_task_runner, | 183 TileTaskRunner* tile_task_runner, |
| 184 Rasterizer* rasterizer, |
177 size_t scheduled_raster_task_limit); | 185 size_t scheduled_raster_task_limit); |
178 | 186 |
179 void FreeResourcesForReleasedTiles(); | 187 void FreeResourcesForReleasedTiles(); |
180 void CleanUpReleasedTiles(); | 188 void CleanUpReleasedTiles(); |
181 | 189 |
182 // Overriden from RefCountedManager<Tile>: | 190 // Overriden from RefCountedManager<Tile>: |
183 friend class Tile; | 191 friend class Tile; |
184 void Release(Tile* tile) override; | 192 void Release(Tile* tile) override; |
185 | 193 |
186 // Overriden from TileTaskRunnerClient: | 194 // Overriden from TileTaskRunnerClient: |
187 void DidFinishRunningTileTasks(TaskSet task_set) override; | 195 void DidFinishRunningTileTasks(TaskSet task_set) override; |
188 TaskSetCollection TasksThatShouldBeForcedToComplete() const override; | 196 TaskSetCollection TasksThatShouldBeForcedToComplete() const override; |
189 | 197 |
190 typedef std::vector<Tile*> TileVector; | 198 typedef std::vector<Tile*> TileVector; |
191 typedef std::set<Tile*> TileSet; | 199 typedef std::set<Tile*> TileSet; |
192 | 200 |
193 // Virtual for test | 201 // Virtual for test |
194 virtual void ScheduleTasks( | 202 virtual void ScheduleTasks( |
195 const TileVector& tiles_that_need_to_be_rasterized); | 203 const TileVector& tiles_that_need_to_be_rasterized); |
196 | 204 |
197 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized); | 205 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized, |
| 206 size_t scheduled_raser_task_limit, |
| 207 bool required_for_draw_only); |
198 | 208 |
199 private: | 209 private: |
200 class MemoryUsage { | 210 class MemoryUsage { |
201 public: | 211 public: |
202 MemoryUsage(); | 212 MemoryUsage(); |
203 MemoryUsage(int64 memory_bytes, int resource_count); | 213 MemoryUsage(int64 memory_bytes, int resource_count); |
204 | 214 |
205 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); | 215 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); |
206 static MemoryUsage FromTile(const Tile* tile); | 216 static MemoryUsage FromTile(const Tile* tile); |
207 | 217 |
(...skipping 26 matching lines...) Expand all Loading... |
234 void RebuildEvictionQueueIfNeeded(); | 244 void RebuildEvictionQueueIfNeeded(); |
235 bool FreeTileResourcesUntilUsageIsWithinLimit(const MemoryUsage& limit, | 245 bool FreeTileResourcesUntilUsageIsWithinLimit(const MemoryUsage& limit, |
236 MemoryUsage* usage); | 246 MemoryUsage* usage); |
237 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( | 247 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( |
238 const MemoryUsage& limit, | 248 const MemoryUsage& limit, |
239 const TilePriority& oother_priority, | 249 const TilePriority& oother_priority, |
240 MemoryUsage* usage); | 250 MemoryUsage* usage); |
241 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); | 251 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); |
242 bool IsReadyToActivate() const; | 252 bool IsReadyToActivate() const; |
243 bool IsReadyToDraw() const; | 253 bool IsReadyToDraw() const; |
| 254 void NotifyReadyToActivate(); |
| 255 void NotifyReadyToDraw(); |
244 void CheckIfReadyToActivate(); | 256 void CheckIfReadyToActivate(); |
245 void CheckIfReadyToDraw(); | 257 void CheckIfReadyToDraw(); |
246 | 258 |
247 TileManagerClient* client_; | 259 TileManagerClient* client_; |
248 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 260 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
249 ResourcePool* resource_pool_; | 261 ResourcePool* resource_pool_; |
250 TileTaskRunner* tile_task_runner_; | 262 TileTaskRunner* tile_task_runner_; |
| 263 Rasterizer* rasterizer_; |
251 GlobalStateThatImpactsTilePriority global_state_; | 264 GlobalStateThatImpactsTilePriority global_state_; |
252 size_t scheduled_raster_task_limit_; | 265 size_t scheduled_raster_task_limit_; |
253 | 266 |
254 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 267 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
255 TileMap tiles_; | 268 TileMap tiles_; |
256 | 269 |
257 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; | 270 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; |
258 MemoryHistory::Entry memory_stats_from_last_assign_; | 271 MemoryHistory::Entry memory_stats_from_last_assign_; |
259 | 272 |
260 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 273 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
(...skipping 11 matching lines...) Expand all Loading... |
272 | 285 |
273 std::vector<Tile*> released_tiles_; | 286 std::vector<Tile*> released_tiles_; |
274 | 287 |
275 ResourceFormat resource_format_; | 288 ResourceFormat resource_format_; |
276 | 289 |
277 // Queue used when scheduling raster tasks. | 290 // Queue used when scheduling raster tasks. |
278 TileTaskQueue raster_queue_; | 291 TileTaskQueue raster_queue_; |
279 | 292 |
280 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; | 293 std::vector<scoped_refptr<RasterTask>> orphan_raster_tasks_; |
281 | 294 |
| 295 UniqueNotifier ready_to_activate_notifier_; |
| 296 UniqueNotifier ready_to_draw_notifier_; |
282 UniqueNotifier ready_to_activate_check_notifier_; | 297 UniqueNotifier ready_to_activate_check_notifier_; |
283 UniqueNotifier ready_to_draw_check_notifier_; | 298 UniqueNotifier ready_to_draw_check_notifier_; |
284 | 299 |
285 RasterTilePriorityQueue raster_priority_queue_; | 300 RasterTilePriorityQueue raster_priority_queue_; |
286 EvictionTilePriorityQueue eviction_priority_queue_; | 301 EvictionTilePriorityQueue eviction_priority_queue_; |
287 bool eviction_priority_queue_is_up_to_date_; | 302 bool eviction_priority_queue_is_up_to_date_; |
288 | 303 |
289 bool did_notify_ready_to_activate_; | 304 bool did_notify_ready_to_activate_; |
290 bool did_notify_ready_to_draw_; | 305 bool did_notify_ready_to_draw_; |
291 | 306 |
292 DISALLOW_COPY_AND_ASSIGN(TileManager); | 307 DISALLOW_COPY_AND_ASSIGN(TileManager); |
293 }; | 308 }; |
294 | 309 |
295 } // namespace cc | 310 } // namespace cc |
296 | 311 |
297 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 312 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
OLD | NEW |