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/debug/rendering_stats_instrumentation.h" | 19 #include "cc/debug/rendering_stats_instrumentation.h" |
20 #include "cc/layers/picture_layer_impl.h" | 20 #include "cc/layers/picture_layer_impl.h" |
21 #include "cc/resources/managed_tile_state.h" | 21 #include "cc/resources/managed_tile_state.h" |
22 #include "cc/resources/memory_history.h" | 22 #include "cc/resources/memory_history.h" |
23 #include "cc/resources/picture_pile_impl.h" | 23 #include "cc/resources/picture_pile_impl.h" |
24 #include "cc/resources/prioritized_tile_set.h" | |
25 #include "cc/resources/rasterizer.h" | 24 #include "cc/resources/rasterizer.h" |
26 #include "cc/resources/resource_pool.h" | 25 #include "cc/resources/resource_pool.h" |
27 #include "cc/resources/tile.h" | 26 #include "cc/resources/tile.h" |
28 | 27 |
29 namespace cc { | 28 namespace cc { |
30 class ResourceProvider; | 29 class ResourceProvider; |
31 | 30 |
32 class CC_EXPORT TileManagerClient { | 31 class CC_EXPORT TileManagerClient { |
33 public: | 32 public: |
34 // Returns the set of layers that the tile manager should consider for raster. | 33 // Returns the set of layers that the tile manager should consider for raster. |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 191 } |
193 | 192 |
194 void GetPairedPictureLayers(std::vector<PairedPictureLayer>* layers) const; | 193 void GetPairedPictureLayers(std::vector<PairedPictureLayer>* layers) const; |
195 | 194 |
196 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { | 195 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { |
197 for (size_t i = 0; i < tiles.size(); ++i) { | 196 for (size_t i = 0; i < tiles.size(); ++i) { |
198 ManagedTileState& mts = tiles[i]->managed_state(); | 197 ManagedTileState& mts = tiles[i]->managed_state(); |
199 ManagedTileState::TileVersion& tile_version = | 198 ManagedTileState::TileVersion& tile_version = |
200 mts.tile_versions[HIGH_QUALITY_RASTER_MODE]; | 199 mts.tile_versions[HIGH_QUALITY_RASTER_MODE]; |
201 | 200 |
202 tile_version.resource_ = resource_pool_->AcquireResource(gfx::Size(1, 1)); | 201 tile_version.resource_ = |
203 | 202 resource_pool_->AcquireResource(tiles[i]->size()); |
204 bytes_releasable_ += BytesConsumedIfAllocated(tiles[i]); | |
205 ++resources_releasable_; | |
206 } | 203 } |
207 } | 204 } |
208 | 205 |
209 void ReleaseTileResourcesForTesting(const std::vector<Tile*>& tiles) { | 206 void ReleaseTileResourcesForTesting(const std::vector<Tile*>& tiles) { |
210 for (size_t i = 0; i < tiles.size(); ++i) { | 207 for (size_t i = 0; i < tiles.size(); ++i) { |
211 Tile* tile = tiles[i]; | 208 Tile* tile = tiles[i]; |
212 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { | 209 for (int mode = 0; mode < NUM_RASTER_MODES; ++mode) { |
213 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); | 210 FreeResourceForTile(tile, static_cast<RasterMode>(mode)); |
214 } | 211 } |
215 } | 212 } |
216 } | 213 } |
217 | 214 |
218 void SetGlobalStateForTesting( | 215 void SetGlobalStateForTesting( |
219 const GlobalStateThatImpactsTilePriority& state) { | 216 const GlobalStateThatImpactsTilePriority& state) { |
220 // Soft limit is used for resource pool such that | 217 global_state_ = state; |
221 // memory returns to soft limit after going over. | |
222 if (state != global_state_) { | |
223 global_state_ = state; | |
224 prioritized_tiles_dirty_ = true; | |
225 } | |
226 } | 218 } |
227 | 219 |
228 void SetRasterizerForTesting(Rasterizer* rasterizer); | 220 void SetRasterizerForTesting(Rasterizer* rasterizer); |
229 | 221 |
230 void CleanUpReleasedTilesForTesting() { CleanUpReleasedTiles(); } | 222 void CleanUpReleasedTilesForTesting() { CleanUpReleasedTiles(); } |
231 | 223 |
232 protected: | 224 protected: |
233 TileManager(TileManagerClient* client, | 225 TileManager(TileManagerClient* client, |
234 base::SequencedTaskRunner* task_runner, | 226 base::SequencedTaskRunner* task_runner, |
235 ResourcePool* resource_pool, | 227 ResourcePool* resource_pool, |
236 Rasterizer* rasterizer, | 228 Rasterizer* rasterizer, |
237 RenderingStatsInstrumentation* rendering_stats_instrumentation); | 229 RenderingStatsInstrumentation* rendering_stats_instrumentation); |
238 | 230 |
239 // Methods called by Tile | |
240 friend class Tile; | |
241 void DidChangeTilePriority(Tile* tile); | |
242 | |
243 void CleanUpReleasedTiles(); | 231 void CleanUpReleasedTiles(); |
244 | 232 |
245 // Overriden from RefCountedManager<Tile>: | 233 // Overriden from RefCountedManager<Tile>: |
| 234 friend class Tile; |
246 virtual void Release(Tile* tile) OVERRIDE; | 235 virtual void Release(Tile* tile) OVERRIDE; |
247 | 236 |
248 // Overriden from RasterizerClient: | 237 // Overriden from RasterizerClient: |
249 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE; | 238 virtual bool ShouldForceTasksRequiredForActivationToComplete() const OVERRIDE; |
250 virtual void DidFinishRunningTasks() OVERRIDE; | 239 virtual void DidFinishRunningTasks() OVERRIDE; |
251 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; | 240 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; |
252 | 241 |
253 typedef std::vector<Tile*> TileVector; | 242 typedef std::vector<Tile*> TileVector; |
254 typedef std::set<Tile*> TileSet; | 243 typedef std::set<Tile*> TileSet; |
255 | 244 |
256 // Virtual for test | 245 // Virtual for test |
257 virtual void ScheduleTasks( | 246 virtual void ScheduleTasks( |
258 const TileVector& tiles_that_need_to_be_rasterized); | 247 const TileVector& tiles_that_need_to_be_rasterized); |
259 | 248 |
260 void AssignGpuMemoryToTiles(PrioritizedTileSet* tiles, | 249 void AssignGpuMemoryToTiles(TileVector* tiles_that_need_to_be_rasterized); |
261 TileVector* tiles_that_need_to_be_rasterized); | |
262 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); | |
263 | 250 |
264 private: | 251 private: |
| 252 class MemoryUsage { |
| 253 public: |
| 254 MemoryUsage(); |
| 255 MemoryUsage(int64 memory_bytes, int resource_count); |
| 256 |
| 257 static MemoryUsage FromConfig(const gfx::Size& size, ResourceFormat format); |
| 258 static MemoryUsage FromTile(const Tile* tile); |
| 259 |
| 260 MemoryUsage& operator+=(const MemoryUsage& other); |
| 261 MemoryUsage& operator-=(const MemoryUsage& other); |
| 262 MemoryUsage operator-(const MemoryUsage& other); |
| 263 |
| 264 bool Exceeds(const MemoryUsage& limit) const; |
| 265 |
| 266 int64 memory_bytes() const { return memory_bytes_; } |
| 267 |
| 268 private: |
| 269 int64 memory_bytes_; |
| 270 int resource_count_; |
| 271 }; |
| 272 |
265 void OnImageDecodeTaskCompleted(int layer_id, | 273 void OnImageDecodeTaskCompleted(int layer_id, |
266 SkPixelRef* pixel_ref, | 274 SkPixelRef* pixel_ref, |
267 bool was_canceled); | 275 bool was_canceled); |
268 void OnRasterTaskCompleted(Tile::Id tile, | 276 void OnRasterTaskCompleted(Tile::Id tile, |
269 scoped_ptr<ScopedResource> resource, | 277 scoped_ptr<ScopedResource> resource, |
270 RasterMode raster_mode, | 278 RasterMode raster_mode, |
271 const PicturePileImpl::Analysis& analysis, | 279 const PicturePileImpl::Analysis& analysis, |
272 bool was_canceled); | 280 bool was_canceled); |
273 | 281 |
274 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { | |
275 return Resource::MemorySizeBytes(tile->size(), | |
276 resource_pool_->resource_format()); | |
277 } | |
278 | |
279 void FreeResourceForTile(Tile* tile, RasterMode mode); | 282 void FreeResourceForTile(Tile* tile, RasterMode mode); |
280 void FreeResourcesForTile(Tile* tile); | 283 void FreeResourcesForTile(Tile* tile); |
281 void FreeUnusedResourcesForTile(Tile* tile); | 284 void FreeUnusedResourcesForTile(Tile* tile); |
282 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); | 285 void FreeResourcesForTileAndNotifyClientIfTileWasReadyToDraw(Tile* tile); |
283 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, | 286 scoped_refptr<ImageDecodeTask> CreateImageDecodeTask(Tile* tile, |
284 SkPixelRef* pixel_ref); | 287 SkPixelRef* pixel_ref); |
285 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); | 288 scoped_refptr<RasterTask> CreateRasterTask(Tile* tile); |
286 void UpdatePrioritizedTileSetIfNeeded(); | |
287 | 289 |
| 290 bool FreeTileResourcesUntilUsageIsWithinLimit(EvictionTileIterator* iterator, |
| 291 const MemoryUsage& limit, |
| 292 MemoryUsage* usage); |
| 293 bool FreeTileResourcesWithLowerPriorityUntilUsageIsWithinLimit( |
| 294 EvictionTileIterator* iterator, |
| 295 const MemoryUsage& limit, |
| 296 const TilePriority& other_priority, |
| 297 MemoryUsage* usage); |
| 298 bool TilePriorityViolatesMemoryPolicy(const TilePriority& priority); |
288 bool IsReadyToActivate() const; | 299 bool IsReadyToActivate() const; |
289 void CheckIfReadyToActivate(); | 300 void CheckIfReadyToActivate(); |
290 | 301 |
291 TileManagerClient* client_; | 302 TileManagerClient* client_; |
292 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 303 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
293 ResourcePool* resource_pool_; | 304 ResourcePool* resource_pool_; |
294 Rasterizer* rasterizer_; | 305 Rasterizer* rasterizer_; |
295 GlobalStateThatImpactsTilePriority global_state_; | 306 GlobalStateThatImpactsTilePriority global_state_; |
296 | 307 |
297 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 308 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
298 TileMap tiles_; | 309 TileMap tiles_; |
299 | 310 |
300 PrioritizedTileSet prioritized_tiles_; | 311 bool all_tiles_that_need_to_be_rasterized_are_scheduled_; |
301 bool prioritized_tiles_dirty_; | |
302 | 312 |
303 bool all_tiles_that_need_to_be_rasterized_have_memory_; | |
304 bool all_tiles_required_for_activation_have_memory_; | |
305 | |
306 size_t bytes_releasable_; | |
307 size_t resources_releasable_; | |
308 | |
309 bool ever_exceeded_memory_budget_; | |
310 MemoryHistory::Entry memory_stats_from_last_assign_; | 313 MemoryHistory::Entry memory_stats_from_last_assign_; |
311 | 314 |
312 RenderingStatsInstrumentation* rendering_stats_instrumentation_; | 315 RenderingStatsInstrumentation* rendering_stats_instrumentation_; |
313 | 316 |
314 bool did_initialize_visible_tile_; | 317 bool did_initialize_visible_tile_; |
315 bool did_check_for_completed_tasks_since_last_schedule_tasks_; | 318 bool did_check_for_completed_tasks_since_last_schedule_tasks_; |
316 | 319 |
317 typedef base::hash_map<uint32_t, scoped_refptr<ImageDecodeTask> > | 320 typedef base::hash_map<uint32_t, scoped_refptr<ImageDecodeTask> > |
318 PixelRefTaskMap; | 321 PixelRefTaskMap; |
319 typedef base::hash_map<int, PixelRefTaskMap> LayerPixelRefTaskMap; | 322 typedef base::hash_map<int, PixelRefTaskMap> LayerPixelRefTaskMap; |
(...skipping 14 matching lines...) Expand all Loading... |
334 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; | 337 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; |
335 | 338 |
336 UniqueNotifier ready_to_activate_check_notifier_; | 339 UniqueNotifier ready_to_activate_check_notifier_; |
337 | 340 |
338 DISALLOW_COPY_AND_ASSIGN(TileManager); | 341 DISALLOW_COPY_AND_ASSIGN(TileManager); |
339 }; | 342 }; |
340 | 343 |
341 } // namespace cc | 344 } // namespace cc |
342 | 345 |
343 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 346 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
OLD | NEW |