Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CC_RESOURCES_TILE_MANAGER_H_ |
| 6 | #define CC_RESOURCES_TILE_MANAGER_H_ |
| 7 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 8 | #include <queue> |
| 9 | #include <set> |
| 10 | #include <vector> |
| 11 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 12 | #include "base/containers/hash_tables.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 13 | #include "base/memory/scoped_ptr.h" |
| 14 | #include "base/values.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 15 | #include "cc/debug/rendering_stats_instrumentation.h" |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 16 | #include "cc/resources/managed_tile_state.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 17 | #include "cc/resources/memory_history.h" |
| 18 | #include "cc/resources/picture_pile_impl.h" |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 19 | #include "cc/resources/prioritized_tile_set.h" |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 20 | #include "cc/resources/raster_worker_pool.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 21 | #include "cc/resources/resource_pool.h" |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 22 | #include "cc/resources/tile.h" |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 23 | |
| 24 | namespace cc { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 25 | class ResourceProvider; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 26 | |
| 27 | class CC_EXPORT TileManagerClient { |
| 28 | public: |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 29 | virtual void NotifyReadyToActivate() = 0; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 30 | |
| 31 | protected: |
| 32 | virtual ~TileManagerClient() {} |
| 33 | }; |
| 34 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 35 | struct RasterTaskCompletionStats { |
| 36 | RasterTaskCompletionStats(); |
| 37 | |
| 38 | size_t completed_count; |
| 39 | size_t canceled_count; |
| 40 | }; |
| 41 | scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( |
| 42 | const RasterTaskCompletionStats& stats); |
| 43 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 44 | // This class manages tiles, deciding which should get rasterized and which |
| 45 | // should no longer have any memory assigned to them. Tile objects are "owned" |
| 46 | // by layers; they automatically register with the manager when they are |
| 47 | // created, and unregister from the manager when they are deleted. |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 48 | class CC_EXPORT TileManager : public RasterWorkerPoolClient { |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 49 | public: |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 50 | static scoped_ptr<TileManager> Create( |
| 51 | TileManagerClient* client, |
| 52 | ResourceProvider* resource_provider, |
| 53 | size_t num_raster_threads, |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 54 | RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| 55 | bool use_map_image); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 56 | virtual ~TileManager(); |
| 57 | |
| 58 | const GlobalStateThatImpactsTilePriority& GlobalState() const { |
| 59 | return global_state_; |
| 60 | } |
| 61 | void SetGlobalState(const GlobalStateThatImpactsTilePriority& state); |
| 62 | |
| 63 | void ManageTiles(); |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 64 | |
| 65 | // Returns true when visible tiles have been initialized. |
| 66 | bool UpdateVisibleTiles(); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 67 | |
| 68 | scoped_ptr<base::Value> BasicStateAsValue() const; |
| 69 | scoped_ptr<base::Value> AllTilesAsValue() const; |
| 70 | void GetMemoryStats(size_t* memory_required_bytes, |
| 71 | size_t* memory_nice_to_have_bytes, |
| 72 | size_t* memory_used_bytes) const; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 73 | |
| 74 | const MemoryHistory::Entry& memory_stats_from_last_assign() const { |
| 75 | return memory_stats_from_last_assign_; |
| 76 | } |
| 77 | |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 78 | bool AreTilesRequiredForActivationReady() const { |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 79 | return all_tiles_required_for_activation_have_been_initialized_; |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 80 | } |
| 81 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 82 | protected: |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 83 | TileManager(TileManagerClient* client, |
| 84 | ResourceProvider* resource_provider, |
| 85 | scoped_ptr<RasterWorkerPool> raster_worker_pool, |
| 86 | size_t num_raster_threads, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 87 | RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| 88 | GLenum texture_format); |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 89 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 90 | // Methods called by Tile |
| 91 | friend class Tile; |
| 92 | void RegisterTile(Tile* tile); |
| 93 | void UnregisterTile(Tile* tile); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 94 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 95 | // Overriden from RasterWorkerPoolClient: |
| 96 | virtual bool ShouldForceTasksRequiredForActivationToComplete() const |
| 97 | OVERRIDE; |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 98 | virtual void DidFinishRunningTasks() OVERRIDE; |
| 99 | virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; |
| 100 | |
| 101 | typedef std::vector<Tile*> TileVector; |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 102 | typedef std::set<Tile*> TileSet; |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 103 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 104 | // Virtual for test |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 105 | virtual void ScheduleTasks( |
| 106 | const TileVector& tiles_that_need_to_be_rasterized); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 107 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 108 | void AssignGpuMemoryToTiles( |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 109 | PrioritizedTileSet* tiles, |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 110 | TileVector* tiles_that_need_to_be_rasterized); |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 111 | void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); |
| 112 | void GetPrioritizedTileSet(PrioritizedTileSet* tiles); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 113 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 114 | private: |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 115 | void OnImageDecodeTaskCompleted( |
| 116 | int layer_id, |
| 117 | skia::LazyPixelRef* pixel_ref, |
| 118 | bool was_canceled); |
| 119 | void OnRasterTaskCompleted( |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 120 | Tile::Id tile, |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 121 | scoped_ptr<ResourcePool::Resource> resource, |
| 122 | RasterMode raster_mode, |
| 123 | const PicturePileImpl::Analysis& analysis, |
| 124 | bool was_canceled); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 125 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 126 | RasterMode DetermineRasterMode(const Tile* tile) const; |
| 127 | void CleanUpUnusedImageDecodeTasks(); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 128 | void FreeResourceForTile(Tile* tile, RasterMode mode); |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 129 | void FreeResourcesForTile(Tile* tile); |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 130 | void FreeUnusedResourcesForTile(Tile* tile); |
| 131 | RasterWorkerPool::Task CreateImageDecodeTask( |
| 132 | Tile* tile, skia::LazyPixelRef* pixel_ref); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 133 | RasterWorkerPool::RasterTask CreateRasterTask(Tile* tile); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 134 | scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 135 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 136 | TileManagerClient* client_; |
| 137 | scoped_ptr<ResourcePool> resource_pool_; |
| 138 | scoped_ptr<RasterWorkerPool> raster_worker_pool_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 139 | GlobalStateThatImpactsTilePriority global_state_; |
| 140 | |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 141 | typedef base::hash_map<Tile::Id, Tile*> TileMap; |
| 142 | TileMap tiles_; |
| 143 | |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 144 | PrioritizedTileSet prioritized_tiles_; |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 145 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 146 | bool all_tiles_that_need_to_be_rasterized_have_memory_; |
Ben Murdoch | 7dbb3d5 | 2013-07-17 14:55:54 +0100 | [diff] [blame] | 147 | bool all_tiles_required_for_activation_have_memory_; |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 148 | bool all_tiles_required_for_activation_have_been_initialized_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 149 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 150 | bool ever_exceeded_memory_budget_; |
| 151 | MemoryHistory::Entry memory_stats_from_last_assign_; |
| 152 | |
| 153 | RenderingStatsInstrumentation* rendering_stats_instrumentation_; |
| 154 | |
Torne (Richard Coles) | c2e0dbd | 2013-05-09 18:35:53 +0100 | [diff] [blame] | 155 | bool did_initialize_visible_tile_; |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 156 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 157 | GLenum texture_format_; |
| 158 | |
| 159 | typedef base::hash_map<uint32_t, RasterWorkerPool::Task> PixelRefTaskMap; |
| 160 | typedef base::hash_map<int, PixelRefTaskMap> LayerPixelRefTaskMap; |
| 161 | LayerPixelRefTaskMap image_decode_tasks_; |
| 162 | |
Ben Murdoch | ca12bfa | 2013-07-23 11:17:05 +0100 | [diff] [blame] | 163 | RasterTaskCompletionStats update_visible_tiles_stats_; |
| 164 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 165 | DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 166 | }; |
| 167 | |
| 168 | } // namespace cc |
| 169 | |
| 170 | #endif // CC_RESOURCES_TILE_MANAGER_H_ |