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/debug/rendering_stats_instrumentation.h" | 18 #include "cc/debug/rendering_stats_instrumentation.h" |
19 #include "cc/layers/picture_layer_impl.h" | 19 #include "cc/layers/picture_layer_impl.h" |
20 #include "cc/resources/managed_tile_state.h" | 20 #include "cc/resources/managed_tile_state.h" |
21 #include "cc/resources/memory_history.h" | 21 #include "cc/resources/memory_history.h" |
22 #include "cc/resources/picture_pile_impl.h" | 22 #include "cc/resources/picture_pile_impl.h" |
23 #include "cc/resources/prioritized_tile_set.h" | |
24 #include "cc/resources/rasterizer.h" | 23 #include "cc/resources/rasterizer.h" |
25 #include "cc/resources/resource_pool.h" | 24 #include "cc/resources/resource_pool.h" |
26 #include "cc/resources/tile.h" | 25 #include "cc/resources/tile.h" |
27 | 26 |
28 namespace cc { | 27 namespace cc { |
29 class ResourceProvider; | 28 class ResourceProvider; |
30 | 29 |
31 class CC_EXPORT TileManagerClient { | 30 class CC_EXPORT TileManagerClient { |
32 public: | 31 public: |
33 // Called when all tiles marked as required for activation are ready to draw. | 32 // Called when all tiles marked as required for activation are ready to draw. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 DISALLOW_COPY_AND_ASSIGN(RasterTileIterator); | 112 DISALLOW_COPY_AND_ASSIGN(RasterTileIterator); |
114 }; | 113 }; |
115 | 114 |
116 struct CC_EXPORT EvictionTileIterator { | 115 struct CC_EXPORT EvictionTileIterator { |
117 public: | 116 public: |
118 EvictionTileIterator(); | 117 EvictionTileIterator(); |
119 EvictionTileIterator(TileManager* tile_manager, TreePriority tree_priority); | 118 EvictionTileIterator(TileManager* tile_manager, TreePriority tree_priority); |
120 ~EvictionTileIterator(); | 119 ~EvictionTileIterator(); |
121 | 120 |
122 EvictionTileIterator& operator++(); | 121 EvictionTileIterator& operator++(); |
123 operator bool() const; | 122 operator bool(); |
124 Tile* operator*(); | 123 Tile* operator*(); |
125 | 124 |
126 private: | 125 private: |
127 struct PairedPictureLayerIterator { | 126 struct PairedPictureLayerIterator { |
128 PairedPictureLayerIterator(); | 127 PairedPictureLayerIterator(); |
129 ~PairedPictureLayerIterator(); | 128 ~PairedPictureLayerIterator(); |
130 | 129 |
131 Tile* PeekTile(TreePriority tree_priority); | 130 Tile* PeekTile(TreePriority tree_priority); |
132 void PopTile(TreePriority tree_priority); | 131 void PopTile(TreePriority tree_priority); |
133 | 132 |
(...skipping 10 matching lines...) Expand all Loading... |
144 public: | 143 public: |
145 explicit EvictionOrderComparator(TreePriority tree_priority); | 144 explicit EvictionOrderComparator(TreePriority tree_priority); |
146 | 145 |
147 bool operator()(PairedPictureLayerIterator* a, | 146 bool operator()(PairedPictureLayerIterator* a, |
148 PairedPictureLayerIterator* b) const; | 147 PairedPictureLayerIterator* b) const; |
149 | 148 |
150 private: | 149 private: |
151 TreePriority tree_priority_; | 150 TreePriority tree_priority_; |
152 }; | 151 }; |
153 | 152 |
| 153 void Initialize(); |
| 154 |
| 155 bool initialized_; |
| 156 TileManager* tile_manager_; |
154 std::vector<PairedPictureLayerIterator> paired_iterators_; | 157 std::vector<PairedPictureLayerIterator> paired_iterators_; |
155 std::vector<PairedPictureLayerIterator*> iterator_heap_; | 158 std::vector<PairedPictureLayerIterator*> iterator_heap_; |
156 TreePriority tree_priority_; | 159 TreePriority tree_priority_; |
157 EvictionOrderComparator comparator_; | 160 EvictionOrderComparator comparator_; |
158 | 161 |
159 DISALLOW_COPY_AND_ASSIGN(EvictionTileIterator); | 162 DISALLOW_COPY_AND_ASSIGN(EvictionTileIterator); |
160 }; | 163 }; |
161 | 164 |
162 static scoped_ptr<TileManager> Create( | 165 static scoped_ptr<TileManager> Create( |
163 TileManagerClient* client, | 166 TileManagerClient* client, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 219 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
217 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); | 220 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); |
218 } | 221 } |
219 } | 222 } |
220 } | 223 } |
221 | 224 |
222 void SetGlobalStateForTesting( | 225 void SetGlobalStateForTesting( |
223 const GlobalStateThatImpactsTilePriority& state) { | 226 const GlobalStateThatImpactsTilePriority& state) { |
224 // Soft limit is used for resource pool such that | 227 // Soft limit is used for resource pool such that |
225 // memory returns to soft limit after going over. | 228 // memory returns to soft limit after going over. |
226 if (state != global_state_) { | 229 global_state_ = state; |
227 global_state_ = state; | |
228 prioritized_tiles_dirty_ = true; | |
229 } | |
230 } | 230 } |
231 | 231 |
232 void SetRasterizerForTesting(Rasterizer* rasterizer); | 232 void SetRasterizerForTesting(Rasterizer* rasterizer); |
233 | 233 |
234 void CleanUpReleasedTilesForTesting() { CleanUpReleasedTiles(); } | 234 void CleanUpReleasedTilesForTesting() { CleanUpReleasedTiles(); } |
235 | 235 |
236 protected: | 236 protected: |
237 TileManager(TileManagerClient* client, | 237 TileManager(TileManagerClient* client, |
238 base::SequencedTaskRunner* task_runner, | 238 base::SequencedTaskRunner* task_runner, |
239 ResourcePool* resource_pool, | 239 ResourcePool* resource_pool, |
240 Rasterizer* rasterizer, | 240 Rasterizer* rasterizer, |
241 RenderingStatsInstrumentation* rendering_stats_instrumentation); | 241 RenderingStatsInstrumentation* rendering_stats_instrumentation); |
242 | 242 |
243 // Methods called by Tile | |
244 friend class Tile; | |
245 void DidChangeTilePriority(Tile* tile); | |
246 | |
247 void CleanUpReleasedTiles(); | 243 void CleanUpReleasedTiles(); |
248 | 244 |
249 // Overriden from RefCountedManager<Tile>: | 245 // Overriden from RefCountedManager<Tile>: |
| 246 friend class Tile; |
250 virtual void Release(Tile* tile) OVERRIDE; | 247 virtual void Release(Tile* tile) OVERRIDE; |
251 | 248 |
252 // Overriden from RasterizerClient: | 249 // Overriden from RasterizerClient: |
253 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE; | 250 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE; |
254 virtual void DidFinishRunningTasks() OVERRIDE; | 251 virtual void DidFinishRunningTasks() OVERRIDE; |
255 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; | 252 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; |
256 | 253 |
257 typedef std::vector<Tile*> TileVector; | 254 typedef std::vector<Tile*> TileVector; |
258 typedef std::set<Tile*> TileSet; | 255 typedef std::set<Tile*> TileSet; |
259 | 256 |
260 // Virtual for test | 257 // Virtual for test |
261 virtual void ScheduleTasks( | 258 virtual void ScheduleTasks( |
262 const TileVector& tiles_that_need_to_be_rasterized); | 259 const TileVector& tiles_that_need_to_be_rasterized); |
263 | 260 |
264 void AssignGpuMemoryToTiles(PrioritizedTileSet* tiles, | 261 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized); |
265 TileVector* tiles_that_need_to_be_rasterized); | |
266 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); | |
267 | 262 |
268 private: | 263 private: |
| 264 struct MemoryBudget { |
| 265 int64 soft_memory_bytes; |
| 266 int64 hard_memory_bytes; |
| 267 int resource_count; |
| 268 |
| 269 bool Exceeds(const MemoryBudget& other) const { |
| 270 return soft_memory_bytes > other.soft_memory_bytes || |
| 271 hard_memory_bytes > other.hard_memory_bytes || |
| 272 resource_count > other.resource_count; |
| 273 } |
| 274 }; |
| 275 |
269 void OnImageDecodeTaskCompleted(int layer_id, | 276 void OnImageDecodeTaskCompleted(int layer_id, |
270 SkPixelRef* pixel_ref, | 277 SkPixelRef* pixel_ref, |
271 bool was_canceled); | 278 bool was_canceled); |
272 void OnRasterTaskCompleted(Tile::Id tile, | 279 void OnRasterTaskCompleted(Tile::Id tile, |
273 scoped_ptr<ScopedResource> resource, | 280 scoped_ptr<ScopedResource> resource, |
274 RasterMode raster_mode, | 281 RasterMode raster_mode, |
275 const PicturePileImpl::Analysis& analysis, | 282 const PicturePileImpl::Analysis& analysis, |
276 bool was_canceled); | 283 bool was_canceled); |
277 | 284 |
278 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { | 285 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { |
279 return Resource::MemorySizeBytes(tile->size(), | 286 return Resource::MemorySizeBytes(tile->size(), |
280 resource_pool_->resource_format()); | 287 resource_pool_->resource_format()); |
281 } | 288 } |
282 | 289 |
283 void FreeResourceForTile(Tile* tile, RasterMode mode); | 290 void FreeResourceForTile(Tile* tile, RasterMode mode); |
284 void FreeResourcesForTile(Tile* tile); | 291 void FreeResourcesForTile(Tile* tile); |
285 void FreeUnusedResourcesForTile(Tile* tile); | 292 void FreeUnusedResourcesForTile(Tile* tile); |
286 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); | 293 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); |
287 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, | 294 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, |
288 SkPixelRef* pixel_ref); | 295 SkPixelRef* pixel_ref); |
289 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); | 296 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); |
290 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; | 297 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; |
291 void UpdatePrioritizedTileSetIfNeeded(); | 298 bool FreeTileResourcesUntilUsageIsWithinBudget( |
| 299 EvictionTileIterator* eviction_iterator, |
| 300 const MemoryBudget& required_budget, |
| 301 MemoryBudget* current_budget, |
| 302 const TilePriority& max_priority, |
| 303 bool evict_unconditionally); |
292 void CleanUpLayers(); | 304 void CleanUpLayers(); |
| 305 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); |
293 | 306 |
294 bool IsReadyToActivate() const; | 307 bool IsReadyToActivate() const; |
295 void ScheduleCheckIfReadyToActivate(); | 308 void ScheduleCheckIfReadyToActivate(); |
296 void CheckIfReadyToActivate(); | 309 void CheckIfReadyToActivate(); |
297 | 310 |
298 TileManagerClient* client_; | 311 TileManagerClient* client_; |
299 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 312 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
300 ResourcePool* resource_pool_; | 313 ResourcePool* resource_pool_; |
301 Rasterizer* rasterizer_; | 314 Rasterizer* rasterizer_; |
302 GlobalStateThatImpactsTilePriority global_state_; | 315 GlobalStateThatImpactsTilePriority global_state_; |
303 | 316 |
304 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 317 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
305 TileMap tiles_; | 318 TileMap tiles_; |
306 | 319 |
307 PrioritizedTileSet prioritized_tiles_; | |
308 bool prioritized_tiles_dirty_; | |
309 | |
310 bool all_tiles_that_need_to_be_rasterized_have_memory_; | 320 bool all_tiles_that_need_to_be_rasterized_have_memory_; |
311 bool all_tiles_required_for_activation_have_memory_; | 321 bool all_tiles_required_for_activation_have_memory_; |
312 | 322 |
313 size_t memory_required_bytes_; | |
314 size_t memory_nice_to_have_bytes_; | |
315 | |
316 size_t bytes_releasable_; | 323 size_t bytes_releasable_; |
317 size_t resources_releasable_; | 324 size_t resources_releasable_; |
| 325 size_t bytes_required_but_not_allocated_; |
318 | 326 |
319 bool ever_exceeded_memory_budget_; | 327 bool ever_exceeded_memory_budget_; |
320 MemoryHistory::Entry memory_stats_from_last_assign_; | 328 MemoryHistory::Entry memory_stats_from_last_assign_; |
321 | 329 |
322 RenderingStatsInstrumentation* rendering_stats_instrumentation_; | 330 RenderingStatsInstrumentation* rendering_stats_instrumentation_; |
323 | 331 |
324 bool did_initialize_visible_tile_; | 332 bool did_initialize_visible_tile_; |
325 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 333 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
326 | 334 |
327 typedef base::hash_map<uint32_t, scoped_refptr<ImageDecodeTask> > | 335 typedef base::hash_map<uint32_t, scoped_refptr<ImageDecodeTask> > |
(...skipping 20 matching lines...) Expand all Loading... |
348 bool check_if_ready_to_activate_pending_; | 356 bool check_if_ready_to_activate_pending_; |
349 | 357 |
350 base::WeakPtrFactory<TileManager> weak_ptr_factory_; | 358 base::WeakPtrFactory<TileManager> weak_ptr_factory_; |
351 | 359 |
352 DISALLOW_COPY_AND_ASSIGN(TileManager); | 360 DISALLOW_COPY_AND_ASSIGN(TileManager); |
353 }; | 361 }; |
354 | 362 |
355 } // namespace cc | 363 } // namespace cc |
356 | 364 |
357 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 365 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
OLD | NEW |