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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 LOW_PRIORITY_BIN = 1, | 53 LOW_PRIORITY_BIN = 1, |
54 NUM_BIN_PRIORITIES = 2 | 54 NUM_BIN_PRIORITIES = 2 |
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 { |
64 public: | 64 public: |
65 typedef base::hash_set<uint32_t> PixelRefSet; | 65 typedef base::hash_set<uint32_t> PixelRefSet; |
66 | 66 |
67 static scoped_ptr<TileManager> Create( | 67 static scoped_ptr<TileManager> Create( |
68 TileManagerClient* client, | 68 TileManagerClient* client, |
69 ResourceProvider* resource_provider, | 69 ResourceProvider* resource_provider, |
70 size_t num_raster_threads, | 70 size_t num_raster_threads, |
71 bool use_color_estimator, | 71 bool use_color_estimator, |
72 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 72 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
73 bool use_map_image); | 73 bool use_map_image); |
74 virtual ~TileManager(); | 74 virtual ~TileManager(); |
75 | 75 |
76 const GlobalStateThatImpactsTilePriority& GlobalState() const { | 76 const GlobalStateThatImpactsTilePriority& GlobalState() const { |
77 return global_state_; | 77 return global_state_; |
78 } | 78 } |
79 void SetGlobalState(const GlobalStateThatImpactsTilePriority& state); | 79 void SetGlobalState(const GlobalStateThatImpactsTilePriority& state); |
80 | 80 |
81 void ManageTiles(); | 81 void ManageTiles(); |
82 void CheckForCompletedTileUploads(); | 82 void CheckForCompletedTileUploads(); |
83 void AbortPendingTileUploads(); | |
84 | 83 |
85 scoped_ptr<base::Value> BasicStateAsValue() const; | 84 scoped_ptr<base::Value> BasicStateAsValue() const; |
86 scoped_ptr<base::Value> AllTilesAsValue() const; | 85 scoped_ptr<base::Value> AllTilesAsValue() const; |
87 void GetMemoryStats(size_t* memory_required_bytes, | 86 void GetMemoryStats(size_t* memory_required_bytes, |
88 size_t* memory_nice_to_have_bytes, | 87 size_t* memory_nice_to_have_bytes, |
89 size_t* memory_used_bytes) const; | 88 size_t* memory_used_bytes) const; |
90 | 89 |
91 const MemoryHistory::Entry& memory_stats_from_last_assign() const { | 90 const MemoryHistory::Entry& memory_stats_from_last_assign() const { |
92 return memory_stats_from_last_assign_; | 91 return memory_stats_from_last_assign_; |
93 } | 92 } |
94 | 93 |
95 // Overridden from WorkerPoolClient: | |
96 virtual void DidFinishDispatchingWorkerPoolCompletionCallbacks() OVERRIDE; | |
97 | |
98 void WillModifyTilePriorities() { | 94 void WillModifyTilePriorities() { |
99 ScheduleManageTiles(); | 95 ScheduleManageTiles(); |
100 } | 96 } |
101 | 97 |
102 bool AreTilesRequiredForActivationReady() const { | 98 bool AreTilesRequiredForActivationReady() const { |
103 return tiles_that_need_to_be_initialized_for_activation_.empty(); | 99 return tiles_that_need_to_be_initialized_for_activation_.empty(); |
104 } | 100 } |
105 | 101 |
106 protected: | 102 protected: |
107 TileManager(TileManagerClient* client, | 103 TileManager(TileManagerClient* client, |
108 ResourceProvider* resource_provider, | 104 ResourceProvider* resource_provider, |
109 scoped_ptr<RasterWorkerPool> raster_worker_pool, | 105 scoped_ptr<RasterWorkerPool> raster_worker_pool, |
110 size_t num_raster_threads, | 106 size_t num_raster_threads, |
111 bool use_color_estimator, | 107 bool use_color_estimator, |
112 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 108 RenderingStatsInstrumentation* rendering_stats_instrumentation); |
113 bool use_map_image); | |
114 | 109 |
115 // Methods called by Tile | 110 // Methods called by Tile |
116 friend class Tile; | 111 friend class Tile; |
117 void RegisterTile(Tile* tile); | 112 void RegisterTile(Tile* tile); |
118 void UnregisterTile(Tile* tile); | 113 void UnregisterTile(Tile* tile); |
119 | 114 |
120 // Virtual for test | 115 // Virtual for test |
121 virtual void ScheduleTasks(); | 116 virtual void ScheduleTasks(); |
122 | 117 |
123 private: | 118 private: |
124 // Data that is passed to raster tasks. | 119 // Data that is passed to raster tasks. |
125 struct RasterTaskMetadata { | 120 struct RasterTaskMetadata { |
126 scoped_ptr<base::Value> AsValue() const; | 121 scoped_ptr<base::Value> AsValue() const; |
127 bool is_tile_in_pending_tree_now_bin; | 122 bool is_tile_in_pending_tree_now_bin; |
128 TileResolution tile_resolution; | 123 TileResolution tile_resolution; |
129 int layer_id; | 124 int layer_id; |
130 const void* tile_id; | 125 const void* tile_id; |
131 int source_frame_number; | 126 int source_frame_number; |
132 }; | 127 }; |
133 | 128 |
134 void AssignBinsToTiles(); | 129 void AssignBinsToTiles(); |
135 void SortTiles(); | 130 void SortTiles(); |
136 void AssignGpuMemoryToTiles(); | 131 void AssignGpuMemoryToTiles(); |
137 void FreeResourcesForTile(Tile* tile); | 132 void FreeResourcesForTile(Tile* tile); |
138 void ForceTileUploadToComplete(Tile* tile); | |
139 void ScheduleManageTiles() { | 133 void ScheduleManageTiles() { |
140 if (manage_tiles_pending_) | 134 if (manage_tiles_pending_) |
141 return; | 135 return; |
142 client_->ScheduleManageTiles(); | 136 client_->ScheduleManageTiles(); |
143 manage_tiles_pending_ = true; | 137 manage_tiles_pending_ = true; |
144 } | 138 } |
145 RasterWorkerPool::Task CreateImageDecodeTask( | 139 RasterWorkerPool::Task CreateImageDecodeTask( |
146 Tile* tile, skia::LazyPixelRef* pixel_ref); | 140 Tile* tile, skia::LazyPixelRef* pixel_ref); |
147 void OnImageDecodeTaskCompleted( | 141 void OnImageDecodeTaskCompleted( |
148 scoped_refptr<Tile> tile, | 142 scoped_refptr<Tile> tile, |
149 uint32_t pixel_ref_id, | 143 uint32_t pixel_ref_id); |
150 bool was_canceled); | |
151 RasterTaskMetadata GetRasterTaskMetadata(const Tile& tile) const; | 144 RasterTaskMetadata GetRasterTaskMetadata(const Tile& tile) const; |
152 RasterWorkerPool::Task CreateRasterTask(Tile* tile); | 145 RasterWorkerPool::RasterTask CreateRasterTask(Tile* tile); |
153 void OnRasterTaskCompleted( | 146 void OnRasterTaskCompleted( |
154 scoped_refptr<Tile> tile, | 147 scoped_refptr<Tile> tile, |
155 scoped_ptr<ResourcePool::Resource> resource, | 148 scoped_ptr<ResourcePool::Resource> resource, |
156 PicturePileImpl::Analysis* analysis, | 149 PicturePileImpl::Analysis* analysis, |
157 bool was_canceled); | 150 bool was_canceled); |
158 void DidFinishTileInitialization(Tile* tile); | 151 void DidFinishTileInitialization(Tile* tile); |
159 void DidTileTreeBinChange(Tile* tile, | 152 void DidTileTreeBinChange(Tile* tile, |
160 TileManagerBin new_tree_bin, | 153 TileManagerBin new_tree_bin, |
161 WhichTree tree); | 154 WhichTree tree); |
162 scoped_ptr<Value> GetMemoryRequirementsAsValue() const; | 155 scoped_ptr<Value> GetMemoryRequirementsAsValue() const; |
163 void AddRequiredTileForActivation(Tile* tile); | 156 void AddRequiredTileForActivation(Tile* tile); |
164 | 157 |
165 static void RunImageDecodeTask( | 158 static void RunImageDecodeTask( |
166 skia::LazyPixelRef* pixel_ref, | 159 skia::LazyPixelRef* pixel_ref, |
167 int layer_id, | 160 int layer_id, |
168 RenderingStatsInstrumentation* stats_instrumentation); | 161 RenderingStatsInstrumentation* stats_instrumentation); |
169 static void RunAnalyzeAndRasterTask( | 162 static bool RunAnalyzeAndRasterTask( |
170 const RasterWorkerPool::PictureTask::Callback& analyze_task, | 163 const base::Callback<void(PicturePileImpl* picture_pile)>& analyze_task, |
171 const RasterWorkerPool::PictureTask::Callback& raster_task, | 164 const RasterWorkerPool::RasterTask::Callback& raster_task, |
| 165 SkDevice* device, |
172 PicturePileImpl* picture_pile); | 166 PicturePileImpl* picture_pile); |
173 static void RunAnalyzeTask( | 167 static void RunAnalyzeTask( |
174 PicturePileImpl::Analysis* analysis, | 168 PicturePileImpl::Analysis* analysis, |
175 gfx::Rect rect, | 169 gfx::Rect rect, |
176 float contents_scale, | 170 float contents_scale, |
177 bool use_color_estimator, | 171 bool use_color_estimator, |
178 const RasterTaskMetadata& metadata, | 172 const RasterTaskMetadata& metadata, |
179 RenderingStatsInstrumentation* stats_instrumentation, | 173 RenderingStatsInstrumentation* stats_instrumentation, |
180 PicturePileImpl* picture_pile); | 174 PicturePileImpl* picture_pile); |
181 static void RunRasterTask( | 175 static bool RunRasterTask( |
182 uint8* buffer, | |
183 PicturePileImpl::Analysis* analysis, | 176 PicturePileImpl::Analysis* analysis, |
184 gfx::Rect rect, | 177 gfx::Rect rect, |
185 float contents_scale, | 178 float contents_scale, |
186 const RasterTaskMetadata& metadata, | 179 const RasterTaskMetadata& metadata, |
187 RenderingStatsInstrumentation* stats_instrumentation, | 180 RenderingStatsInstrumentation* stats_instrumentation, |
| 181 SkDevice* device, |
188 PicturePileImpl* picture_pile); | 182 PicturePileImpl* picture_pile); |
189 | 183 |
190 TileManagerClient* client_; | 184 TileManagerClient* client_; |
191 scoped_ptr<ResourcePool> resource_pool_; | 185 scoped_ptr<ResourcePool> resource_pool_; |
192 scoped_ptr<RasterWorkerPool> raster_worker_pool_; | 186 scoped_ptr<RasterWorkerPool> raster_worker_pool_; |
193 bool manage_tiles_pending_; | 187 bool manage_tiles_pending_; |
194 | 188 |
195 GlobalStateThatImpactsTilePriority global_state_; | 189 GlobalStateThatImpactsTilePriority global_state_; |
196 | 190 |
197 typedef std::vector<Tile*> TileVector; | 191 typedef std::vector<Tile*> TileVector; |
198 TileVector tiles_; | 192 TileVector tiles_; |
199 TileVector tiles_that_need_to_be_rasterized_; | 193 TileVector tiles_that_need_to_be_rasterized_; |
200 typedef std::set<Tile*> TileSet; | 194 typedef std::set<Tile*> TileSet; |
201 TileSet tiles_that_need_to_be_initialized_for_activation_; | 195 TileSet tiles_that_need_to_be_initialized_for_activation_; |
202 | 196 |
203 typedef base::hash_map<uint32_t, RasterWorkerPool::Task> PixelRefMap; | 197 typedef base::hash_map<uint32_t, RasterWorkerPool::Task> PixelRefMap; |
204 PixelRefMap pending_decode_tasks_; | 198 PixelRefMap pending_decode_tasks_; |
205 | 199 |
206 typedef std::queue<scoped_refptr<Tile> > TileQueue; | |
207 TileQueue tiles_with_pending_upload_; | |
208 size_t bytes_pending_upload_; | |
209 bool has_performed_uploads_since_last_flush_; | |
210 bool ever_exceeded_memory_budget_; | 200 bool ever_exceeded_memory_budget_; |
211 MemoryHistory::Entry memory_stats_from_last_assign_; | 201 MemoryHistory::Entry memory_stats_from_last_assign_; |
212 | 202 |
213 RenderingStatsInstrumentation* rendering_stats_instrumentation_; | 203 RenderingStatsInstrumentation* rendering_stats_instrumentation_; |
214 | 204 |
215 bool use_color_estimator_; | 205 bool use_color_estimator_; |
216 bool did_initialize_visible_tile_; | 206 bool did_initialize_visible_tile_; |
217 | 207 |
218 size_t max_pending_tasks_; | |
219 | |
220 DISALLOW_COPY_AND_ASSIGN(TileManager); | 208 DISALLOW_COPY_AND_ASSIGN(TileManager); |
221 }; | 209 }; |
222 | 210 |
223 } // namespace cc | 211 } // namespace cc |
224 | 212 |
225 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 213 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
OLD | NEW |