| 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, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 128 TileResolution tile_resolution; | 124 TileResolution tile_resolution; |
| 129 int layer_id; | 125 int layer_id; |
| 130 const void* tile_id; | 126 const void* tile_id; |
| 131 int source_frame_number; | 127 int source_frame_number; |
| 132 }; | 128 }; |
| 133 | 129 |
| 134 void AssignBinsToTiles(); | 130 void AssignBinsToTiles(); |
| 135 void SortTiles(); | 131 void SortTiles(); |
| 136 void AssignGpuMemoryToTiles(); | 132 void AssignGpuMemoryToTiles(); |
| 137 void FreeResourcesForTile(Tile* tile); | 133 void FreeResourcesForTile(Tile* tile); |
| 138 void ForceTileUploadToComplete(Tile* tile); | |
| 139 void ScheduleManageTiles() { | 134 void ScheduleManageTiles() { |
| 140 if (manage_tiles_pending_) | 135 if (manage_tiles_pending_) |
| 141 return; | 136 return; |
| 142 client_->ScheduleManageTiles(); | 137 client_->ScheduleManageTiles(); |
| 143 manage_tiles_pending_ = true; | 138 manage_tiles_pending_ = true; |
| 144 } | 139 } |
| 145 RasterWorkerPool::Task CreateImageDecodeTask( | 140 RasterWorkerPool::Task CreateImageDecodeTask( |
| 146 Tile* tile, skia::LazyPixelRef* pixel_ref); | 141 Tile* tile, skia::LazyPixelRef* pixel_ref); |
| 147 void OnImageDecodeTaskCompleted( | 142 void OnImageDecodeTaskCompleted( |
| 148 scoped_refptr<Tile> tile, | 143 scoped_refptr<Tile> tile, |
| 149 uint32_t pixel_ref_id, | 144 uint32_t pixel_ref_id); |
| 150 bool was_canceled); | |
| 151 RasterTaskMetadata GetRasterTaskMetadata(const Tile& tile) const; | 145 RasterTaskMetadata GetRasterTaskMetadata(const Tile& tile) const; |
| 152 RasterWorkerPool::Task CreateRasterTask(Tile* tile); | 146 RasterWorkerPool::RasterTask CreateRasterTask(Tile* tile); |
| 153 void OnRasterTaskCompleted( | 147 void OnRasterTaskCompleted( |
| 154 scoped_refptr<Tile> tile, | 148 scoped_refptr<Tile> tile, |
| 155 scoped_ptr<ResourcePool::Resource> resource, | 149 scoped_ptr<ResourcePool::Resource> resource, |
| 156 PicturePileImpl::Analysis* analysis, | 150 PicturePileImpl::Analysis* analysis, |
| 157 bool was_canceled); | 151 bool was_canceled); |
| 158 void DidFinishTileInitialization(Tile* tile); | 152 void DidFinishTileInitialization(Tile* tile); |
| 159 void DidTileTreeBinChange(Tile* tile, | 153 void DidTileTreeBinChange(Tile* tile, |
| 160 TileManagerBin new_tree_bin, | 154 TileManagerBin new_tree_bin, |
| 161 WhichTree tree); | 155 WhichTree tree); |
| 162 scoped_ptr<Value> GetMemoryRequirementsAsValue() const; | 156 scoped_ptr<Value> GetMemoryRequirementsAsValue() const; |
| 163 void AddRequiredTileForActivation(Tile* tile); | 157 void AddRequiredTileForActivation(Tile* tile); |
| 164 | 158 |
| 165 static void RunImageDecodeTask( | 159 static void RunImageDecodeTask( |
| 166 skia::LazyPixelRef* pixel_ref, | 160 skia::LazyPixelRef* pixel_ref, |
| 167 int layer_id, | 161 int layer_id, |
| 168 RenderingStatsInstrumentation* stats_instrumentation); | 162 RenderingStatsInstrumentation* stats_instrumentation); |
| 169 static void RunAnalyzeAndRasterTask( | 163 static bool RunAnalyzeAndRasterTask( |
| 170 const RasterWorkerPool::PictureTask::Callback& analyze_task, | 164 const base::Callback<void(PicturePileImpl*)>& analyze_task, |
| 171 const RasterWorkerPool::PictureTask::Callback& raster_task, | 165 const RasterWorkerPool::RasterTask::Callback& raster_task, |
| 166 uint8* buffer, |
| 172 PicturePileImpl* picture_pile); | 167 PicturePileImpl* picture_pile); |
| 173 static void RunAnalyzeTask( | 168 static void RunAnalyzeTask( |
| 174 PicturePileImpl::Analysis* analysis, | 169 PicturePileImpl::Analysis* analysis, |
| 175 gfx::Rect rect, | 170 gfx::Rect rect, |
| 176 float contents_scale, | 171 float contents_scale, |
| 177 bool use_color_estimator, | 172 bool use_color_estimator, |
| 178 const RasterTaskMetadata& metadata, | 173 const RasterTaskMetadata& metadata, |
| 179 RenderingStatsInstrumentation* stats_instrumentation, | 174 RenderingStatsInstrumentation* stats_instrumentation, |
| 180 PicturePileImpl* picture_pile); | 175 PicturePileImpl* picture_pile); |
| 181 static void RunRasterTask( | 176 static bool RunRasterTask( |
| 182 uint8* buffer, | |
| 183 PicturePileImpl::Analysis* analysis, | 177 PicturePileImpl::Analysis* analysis, |
| 184 gfx::Rect rect, | 178 gfx::Rect rect, |
| 185 float contents_scale, | 179 float contents_scale, |
| 186 const RasterTaskMetadata& metadata, | 180 const RasterTaskMetadata& metadata, |
| 187 RenderingStatsInstrumentation* stats_instrumentation, | 181 RenderingStatsInstrumentation* stats_instrumentation, |
| 182 uint8* buffer, |
| 188 PicturePileImpl* picture_pile); | 183 PicturePileImpl* picture_pile); |
| 189 | 184 |
| 190 TileManagerClient* client_; | 185 TileManagerClient* client_; |
| 191 scoped_ptr<ResourcePool> resource_pool_; | 186 scoped_ptr<ResourcePool> resource_pool_; |
| 192 scoped_ptr<RasterWorkerPool> raster_worker_pool_; | 187 scoped_ptr<RasterWorkerPool> raster_worker_pool_; |
| 193 bool manage_tiles_pending_; | 188 bool manage_tiles_pending_; |
| 194 | 189 |
| 195 GlobalStateThatImpactsTilePriority global_state_; | 190 GlobalStateThatImpactsTilePriority global_state_; |
| 196 | 191 |
| 197 typedef std::vector<Tile*> TileVector; | 192 typedef std::vector<Tile*> TileVector; |
| 198 TileVector tiles_; | 193 TileVector tiles_; |
| 199 TileVector tiles_that_need_to_be_rasterized_; | 194 TileVector tiles_that_need_to_be_rasterized_; |
| 200 typedef std::set<Tile*> TileSet; | 195 typedef std::set<Tile*> TileSet; |
| 201 TileSet tiles_that_need_to_be_initialized_for_activation_; | 196 TileSet tiles_that_need_to_be_initialized_for_activation_; |
| 202 | 197 |
| 203 typedef base::hash_map<uint32_t, RasterWorkerPool::Task> PixelRefMap; | 198 typedef base::hash_map<uint32_t, RasterWorkerPool::Task> PixelRefMap; |
| 204 PixelRefMap pending_decode_tasks_; | 199 PixelRefMap pending_decode_tasks_; |
| 205 | 200 |
| 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_; | 201 bool ever_exceeded_memory_budget_; |
| 211 MemoryHistory::Entry memory_stats_from_last_assign_; | 202 MemoryHistory::Entry memory_stats_from_last_assign_; |
| 212 | 203 |
| 213 RenderingStatsInstrumentation* rendering_stats_instrumentation_; | 204 RenderingStatsInstrumentation* rendering_stats_instrumentation_; |
| 214 | 205 |
| 215 bool use_color_estimator_; | 206 bool use_color_estimator_; |
| 216 bool did_initialize_visible_tile_; | 207 bool did_initialize_visible_tile_; |
| 217 | 208 |
| 218 size_t max_pending_tasks_; | |
| 219 | |
| 220 DISALLOW_COPY_AND_ASSIGN(TileManager); | 209 DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 221 }; | 210 }; |
| 222 | 211 |
| 223 } // namespace cc | 212 } // namespace cc |
| 224 | 213 |
| 225 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 214 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
| OLD | NEW |