| 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 <queue> | 8 #include <queue> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 }; | 55 }; |
| 56 scoped_ptr<base::Value> TileManagerBinPriorityAsValue( | 56 scoped_ptr<base::Value> TileManagerBinPriorityAsValue( |
| 57 TileManagerBinPriority bin); | 57 TileManagerBinPriority bin); |
| 58 | 58 |
| 59 // This class manages tiles, deciding which should get rasterized and which | 59 // This class manages tiles, deciding which should get rasterized and which |
| 60 // should no longer have any memory assigned to them. Tile objects are "owned" | 60 // should no longer have any memory assigned to them. Tile objects are "owned" |
| 61 // by layers; they automatically register with the manager when they are | 61 // by layers; they automatically register with the manager when they are |
| 62 // created, and unregister from the manager when they are deleted. | 62 // created, and unregister from the manager when they are deleted. |
| 63 class CC_EXPORT TileManager : public WorkerPoolClient { | 63 class CC_EXPORT TileManager : public WorkerPoolClient { |
| 64 public: | 64 public: |
| 65 typedef base::hash_set<uint32_t> PixelRefSet; | |
| 66 | |
| 67 static scoped_ptr<TileManager> Create( | 65 static scoped_ptr<TileManager> Create( |
| 68 TileManagerClient* client, | 66 TileManagerClient* client, |
| 69 ResourceProvider* resource_provider, | 67 ResourceProvider* resource_provider, |
| 70 size_t num_raster_threads, | 68 size_t num_raster_threads, |
| 71 bool use_color_estimator, | 69 bool use_color_estimator, |
| 72 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 70 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| 73 bool use_map_image); | 71 bool use_map_image); |
| 74 virtual ~TileManager(); | 72 virtual ~TileManager(); |
| 75 | 73 |
| 76 const GlobalStateThatImpactsTilePriority& GlobalState() const { | 74 const GlobalStateThatImpactsTilePriority& GlobalState() const { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 bool use_color_estimator, | 109 bool use_color_estimator, |
| 112 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 110 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| 113 bool use_map_image); | 111 bool use_map_image); |
| 114 | 112 |
| 115 // Methods called by Tile | 113 // Methods called by Tile |
| 116 friend class Tile; | 114 friend class Tile; |
| 117 void RegisterTile(Tile* tile); | 115 void RegisterTile(Tile* tile); |
| 118 void UnregisterTile(Tile* tile); | 116 void UnregisterTile(Tile* tile); |
| 119 | 117 |
| 120 // Virtual for test | 118 // Virtual for test |
| 121 virtual void ScheduleTasks(); | 119 virtual void DispatchMoreTasks(); |
| 122 | 120 |
| 123 private: | 121 private: |
| 124 // Data that is passed to raster tasks. | 122 // Data that is passed to raster tasks. |
| 125 struct RasterTaskMetadata { | 123 struct RasterTaskMetadata { |
| 126 scoped_ptr<base::Value> AsValue() const; | 124 scoped_ptr<base::Value> AsValue() const; |
| 127 bool is_tile_in_pending_tree_now_bin; | 125 bool is_tile_in_pending_tree_now_bin; |
| 128 TileResolution tile_resolution; | 126 TileResolution tile_resolution; |
| 129 int layer_id; | 127 int layer_id; |
| 130 const void* tile_id; | 128 const void* tile_id; |
| 131 int source_frame_number; | 129 int source_frame_number; |
| 132 }; | 130 }; |
| 133 | 131 |
| 132 RasterTaskMetadata GetRasterTaskMetadata(const Tile& tile) const; |
| 133 |
| 134 void AssignBinsToTiles(); | 134 void AssignBinsToTiles(); |
| 135 void SortTiles(); | 135 void SortTiles(); |
| 136 void AssignGpuMemoryToTiles(); | 136 void AssignGpuMemoryToTiles(); |
| 137 void FreeResourcesForTile(Tile* tile); | 137 void FreeResourcesForTile(Tile* tile); |
| 138 void ForceTileUploadToComplete(Tile* tile); | 138 void ForceTileUploadToComplete(Tile* tile); |
| 139 void ScheduleManageTiles() { | 139 void ScheduleManageTiles() { |
| 140 if (manage_tiles_pending_) | 140 if (manage_tiles_pending_) |
| 141 return; | 141 return; |
| 142 client_->ScheduleManageTiles(); | 142 client_->ScheduleManageTiles(); |
| 143 manage_tiles_pending_ = true; | 143 manage_tiles_pending_ = true; |
| 144 } | 144 } |
| 145 RasterWorkerPool::Task CreateImageDecodeTask( | 145 bool DispatchImageDecodeTasksForTile(Tile* tile); |
| 146 Tile* tile, skia::LazyPixelRef* pixel_ref); | 146 void DispatchOneImageDecodeTask( |
| 147 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref); |
| 147 void OnImageDecodeTaskCompleted( | 148 void OnImageDecodeTaskCompleted( |
| 148 scoped_refptr<Tile> tile, | 149 scoped_refptr<Tile> tile, |
| 149 uint32_t pixel_ref_id, | 150 uint32_t pixel_ref_id); |
| 150 bool was_canceled); | 151 bool CanDispatchRasterTask(Tile* tile) const; |
| 151 RasterTaskMetadata GetRasterTaskMetadata(const Tile& tile) const; | 152 scoped_ptr<ResourcePool::Resource> PrepareTileForRaster(Tile* tile); |
| 152 RasterWorkerPool::Task CreateRasterTask(Tile* tile); | 153 void DispatchOneRasterTask(scoped_refptr<Tile> tile); |
| 153 void OnRasterTaskCompleted( | 154 void OnRasterTaskCompleted( |
| 154 scoped_refptr<Tile> tile, | 155 scoped_refptr<Tile> tile, |
| 155 scoped_ptr<ResourcePool::Resource> resource, | 156 scoped_ptr<ResourcePool::Resource> resource, |
| 156 PicturePileImpl::Analysis* analysis, | 157 PicturePileImpl::Analysis* analysis, |
| 157 bool was_canceled); | 158 int manage_tiles_call_count_when_dispatched); |
| 158 void DidFinishTileInitialization(Tile* tile); | 159 void DidFinishTileInitialization(Tile* tile); |
| 159 void DidTileTreeBinChange(Tile* tile, | 160 void DidTileTreeBinChange(Tile* tile, |
| 160 TileManagerBin new_tree_bin, | 161 TileManagerBin new_tree_bin, |
| 161 WhichTree tree); | 162 WhichTree tree); |
| 162 scoped_ptr<Value> GetMemoryRequirementsAsValue() const; | 163 scoped_ptr<Value> GetMemoryRequirementsAsValue() const; |
| 163 void AddRequiredTileForActivation(Tile* tile); | 164 void AddRequiredTileForActivation(Tile* tile); |
| 164 | 165 |
| 165 static void RunImageDecodeTask( | |
| 166 skia::LazyPixelRef* pixel_ref, | |
| 167 int layer_id, | |
| 168 RenderingStatsInstrumentation* stats_instrumentation); | |
| 169 static void RunAnalyzeAndRasterTask( | 166 static void RunAnalyzeAndRasterTask( |
| 170 const RasterWorkerPool::PictureTask::Callback& analyze_task, | 167 const RasterWorkerPool::RasterCallback& analyze_task, |
| 171 const RasterWorkerPool::PictureTask::Callback& raster_task, | 168 const RasterWorkerPool::RasterCallback& raster_task, |
| 172 PicturePileImpl* picture_pile); | 169 PicturePileImpl* picture_pile); |
| 173 static void RunAnalyzeTask( | 170 static void RunAnalyzeTask( |
| 174 PicturePileImpl::Analysis* analysis, | 171 PicturePileImpl::Analysis* analysis, |
| 175 gfx::Rect rect, | 172 gfx::Rect rect, |
| 176 float contents_scale, | 173 float contents_scale, |
| 177 bool use_color_estimator, | 174 bool use_color_estimator, |
| 178 const RasterTaskMetadata& metadata, | 175 const RasterTaskMetadata& metadata, |
| 179 RenderingStatsInstrumentation* stats_instrumentation, | 176 RenderingStatsInstrumentation* stats_instrumentation, |
| 180 PicturePileImpl* picture_pile); | 177 PicturePileImpl* picture_pile); |
| 181 static void RunRasterTask( | 178 static void RunRasterTask( |
| 182 uint8* buffer, | 179 uint8* buffer, |
| 183 PicturePileImpl::Analysis* analysis, | 180 PicturePileImpl::Analysis* analysis, |
| 184 gfx::Rect rect, | 181 gfx::Rect rect, |
| 185 float contents_scale, | 182 float contents_scale, |
| 186 const RasterTaskMetadata& metadata, | 183 const RasterTaskMetadata& metadata, |
| 187 RenderingStatsInstrumentation* stats_instrumentation, | 184 RenderingStatsInstrumentation* stats_instrumentation, |
| 188 PicturePileImpl* picture_pile); | 185 PicturePileImpl* picture_pile); |
| 186 static void RunImageDecodeTask( |
| 187 skia::LazyPixelRef* pixel_ref, |
| 188 int layer_id, |
| 189 RenderingStatsInstrumentation* stats_instrumentation); |
| 189 | 190 |
| 190 TileManagerClient* client_; | 191 TileManagerClient* client_; |
| 191 scoped_ptr<ResourcePool> resource_pool_; | 192 scoped_ptr<ResourcePool> resource_pool_; |
| 192 scoped_ptr<RasterWorkerPool> raster_worker_pool_; | 193 scoped_ptr<RasterWorkerPool> raster_worker_pool_; |
| 193 bool manage_tiles_pending_; | 194 bool manage_tiles_pending_; |
| 195 int manage_tiles_call_count_; |
| 194 | 196 |
| 195 GlobalStateThatImpactsTilePriority global_state_; | 197 GlobalStateThatImpactsTilePriority global_state_; |
| 196 | 198 |
| 197 typedef std::vector<Tile*> TileVector; | 199 typedef std::vector<Tile*> TileVector; |
| 198 TileVector tiles_; | 200 TileVector tiles_; |
| 199 TileVector tiles_that_need_to_be_rasterized_; | 201 TileVector tiles_that_need_to_be_rasterized_; |
| 200 typedef std::set<Tile*> TileSet; | 202 typedef std::set<Tile*> TileSet; |
| 201 TileSet tiles_that_need_to_be_initialized_for_activation_; | 203 TileSet tiles_that_need_to_be_initialized_for_activation_; |
| 202 | 204 |
| 203 typedef base::hash_map<uint32_t, RasterWorkerPool::Task> PixelRefMap; | 205 typedef base::hash_set<uint32_t> PixelRefSet; |
| 204 PixelRefMap pending_decode_tasks_; | 206 PixelRefSet pending_decode_tasks_; |
| 205 | 207 |
| 206 typedef std::queue<scoped_refptr<Tile> > TileQueue; | 208 typedef std::queue<scoped_refptr<Tile> > TileQueue; |
| 207 TileQueue tiles_with_pending_upload_; | 209 TileQueue tiles_with_pending_upload_; |
| 208 size_t bytes_pending_upload_; | 210 size_t bytes_pending_upload_; |
| 209 bool has_performed_uploads_since_last_flush_; | 211 bool has_performed_uploads_since_last_flush_; |
| 210 bool ever_exceeded_memory_budget_; | 212 bool ever_exceeded_memory_budget_; |
| 211 MemoryHistory::Entry memory_stats_from_last_assign_; | 213 MemoryHistory::Entry memory_stats_from_last_assign_; |
| 212 | 214 |
| 213 RenderingStatsInstrumentation* rendering_stats_instrumentation_; | 215 RenderingStatsInstrumentation* rendering_stats_instrumentation_; |
| 214 | 216 |
| 215 bool use_color_estimator_; | 217 bool use_color_estimator_; |
| 216 bool did_initialize_visible_tile_; | 218 bool did_initialize_visible_tile_; |
| 217 | 219 |
| 220 size_t pending_tasks_; |
| 218 size_t max_pending_tasks_; | 221 size_t max_pending_tasks_; |
| 219 | 222 |
| 220 DISALLOW_COPY_AND_ASSIGN(TileManager); | 223 DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 221 }; | 224 }; |
| 222 | 225 |
| 223 } // namespace cc | 226 } // namespace cc |
| 224 | 227 |
| 225 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 228 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
| OLD | NEW |