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