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