Chromium Code Reviews| 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> | 
| 11 | 11 | 
| 12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" | 
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" | 
| 14 #include "base/values.h" | 14 #include "base/values.h" | 
| 15 #include "cc/base/ref_counted_managed.h" | 15 #include "cc/base/ref_counted_managed.h" | 
| 16 #include "cc/debug/rendering_stats_instrumentation.h" | 16 #include "cc/debug/rendering_stats_instrumentation.h" | 
| 17 #include "cc/resources/managed_tile_state.h" | 17 #include "cc/resources/managed_tile_state.h" | 
| 18 #include "cc/resources/memory_history.h" | 18 #include "cc/resources/memory_history.h" | 
| 19 #include "cc/resources/picture_pile_impl.h" | 19 #include "cc/resources/picture_pile_impl.h" | 
| 20 #include "cc/resources/prioritized_tile_set.h" | 20 #include "cc/resources/prioritized_tile_set.h" | 
| 21 #include "cc/resources/raster_worker_pool.h" | 21 #include "cc/resources/raster_worker_pool.h" | 
| 22 #include "cc/resources/resource_pool.h" | 22 #include "cc/resources/resource_pool.h" | 
| 23 #include "cc/resources/tile.h" | 23 #include "cc/resources/tile.h" | 
| 24 #include "cc/resources/tile_bundle.h" | |
| 24 | 25 | 
| 25 namespace cc { | 26 namespace cc { | 
| 26 class ResourceProvider; | 27 class ResourceProvider; | 
| 27 | 28 | 
| 28 class CC_EXPORT TileManagerClient { | 29 class CC_EXPORT TileManagerClient { | 
| 29 public: | 30 public: | 
| 30 virtual void NotifyReadyToActivate() = 0; | 31 virtual void NotifyReadyToActivate() = 0; | 
| 31 | 32 | 
| 32 protected: | 33 protected: | 
| 33 virtual ~TileManagerClient() {} | 34 virtual ~TileManagerClient() {} | 
| 34 }; | 35 }; | 
| 35 | 36 | 
| 36 struct RasterTaskCompletionStats { | 37 struct RasterTaskCompletionStats { | 
| 37 RasterTaskCompletionStats(); | 38 RasterTaskCompletionStats(); | 
| 38 | 39 | 
| 39 size_t completed_count; | 40 size_t completed_count; | 
| 40 size_t canceled_count; | 41 size_t canceled_count; | 
| 41 }; | 42 }; | 
| 42 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( | 43 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( | 
| 43 const RasterTaskCompletionStats& stats); | 44 const RasterTaskCompletionStats& stats); | 
| 44 | 45 | 
| 45 // This class manages tiles, deciding which should get rasterized and which | 46 // This class manages tiles, deciding which should get rasterized and which | 
| 46 // should no longer have any memory assigned to them. Tile objects are "owned" | 47 // should no longer have any memory assigned to them. Tile objects are "owned" | 
| 47 // by layers; they automatically register with the manager when they are | 48 // by layers; they automatically register with the manager when they are | 
| 48 // created, and unregister from the manager when they are deleted. | 49 // created, and unregister from the manager when they are deleted. | 
| 49 class CC_EXPORT TileManager : public RasterWorkerPoolClient, | 50 class CC_EXPORT TileManager : public RasterWorkerPoolClient, | 
| 50 public RefCountedManager<Tile> { | 51 public RefCountedManager<Tile>, | 
| 52 public RefCountedManager<TileBundle> { | |
| 51 public: | 53 public: | 
| 52 static scoped_ptr<TileManager> Create( | 54 static scoped_ptr<TileManager> Create( | 
| 53 TileManagerClient* client, | 55 TileManagerClient* client, | 
| 54 ResourceProvider* resource_provider, | 56 ResourceProvider* resource_provider, | 
| 55 size_t num_raster_threads, | 57 size_t num_raster_threads, | 
| 56 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 58 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 
| 57 bool use_map_image, | 59 bool use_map_image, | 
| 58 size_t max_transfer_buffer_usage_bytes, | 60 size_t max_transfer_buffer_usage_bytes, | 
| 59 size_t max_raster_usage_bytes); | 61 size_t max_raster_usage_bytes); | 
| 60 virtual ~TileManager(); | 62 virtual ~TileManager(); | 
| 61 | 63 | 
| 62 void ManageTiles(const GlobalStateThatImpactsTilePriority& state); | 64 void ManageTiles(const GlobalStateThatImpactsTilePriority& state); | 
| 63 | 65 | 
| 64 // Returns true when visible tiles have been initialized. | 66 // Returns true when visible tiles have been initialized. | 
| 65 bool UpdateVisibleTiles(); | 67 bool UpdateVisibleTiles(); | 
| 66 | 68 | 
| 67 scoped_refptr<Tile> CreateTile(PicturePileImpl* picture_pile, | 69 scoped_refptr<Tile> CreateTile(PicturePileImpl* picture_pile, | 
| 68 gfx::Size tile_size, | 70 gfx::Size tile_size, | 
| 69 gfx::Rect content_rect, | 71 gfx::Rect content_rect, | 
| 70 gfx::Rect opaque_rect, | 72 gfx::Rect opaque_rect, | 
| 71 float contents_scale, | 73 float contents_scale, | 
| 72 int layer_id, | 74 int layer_id, | 
| 73 int source_frame_number, | 75 int source_frame_number, | 
| 74 bool can_use_lcd_text); | 76 bool can_use_lcd_text); | 
| 75 | 77 | 
| 78 scoped_refptr<TileBundle> CreateTileBundle(int width, | |
| 79 int height, | |
| 80 int offset_x, | |
| 81 int offset_y); | |
| 82 | |
| 76 scoped_ptr<base::Value> BasicStateAsValue() const; | 83 scoped_ptr<base::Value> BasicStateAsValue() const; | 
| 77 scoped_ptr<base::Value> AllTilesAsValue() const; | 84 scoped_ptr<base::Value> AllTilesAsValue() const; | 
| 78 void GetMemoryStats(size_t* memory_required_bytes, | 85 void GetMemoryStats(size_t* memory_required_bytes, | 
| 79 size_t* memory_nice_to_have_bytes, | 86 size_t* memory_nice_to_have_bytes, | 
| 80 size_t* memory_allocated_bytes, | 87 size_t* memory_allocated_bytes, | 
| 81 size_t* memory_used_bytes) const; | 88 size_t* memory_used_bytes) const; | 
| 82 | 89 | 
| 83 const MemoryHistory::Entry& memory_stats_from_last_assign() const { | 90 const MemoryHistory::Entry& memory_stats_from_last_assign() const { | 
| 84 return memory_stats_from_last_assign_; | 91 return memory_stats_from_last_assign_; | 
| 85 } | 92 } | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 | 132 | 
| 126 // Methods called by Tile | 133 // Methods called by Tile | 
| 127 friend class Tile; | 134 friend class Tile; | 
| 128 void DidChangeTilePriority(Tile* tile); | 135 void DidChangeTilePriority(Tile* tile); | 
| 129 | 136 | 
| 130 void CleanUpReleasedTiles(); | 137 void CleanUpReleasedTiles(); | 
| 131 | 138 | 
| 132 // Overriden from RefCountedManager<Tile>: | 139 // Overriden from RefCountedManager<Tile>: | 
| 133 virtual void Release(Tile* tile) OVERRIDE; | 140 virtual void Release(Tile* tile) OVERRIDE; | 
| 134 | 141 | 
| 142 // Overridden from RefCountedManager<TileBundle>: | |
| 143 virtual void Release(TileBundle* tile) OVERRIDE; | |
| 144 | |
| 135 // Overriden from RasterWorkerPoolClient: | 145 // Overriden from RasterWorkerPoolClient: | 
| 136 virtual bool ShouldForceTasksRequiredForActivationToComplete() const | 146 virtual bool ShouldForceTasksRequiredForActivationToComplete() const | 
| 137 OVERRIDE; | 147 OVERRIDE; | 
| 138 virtual void DidFinishRunningTasks() OVERRIDE; | 148 virtual void DidFinishRunningTasks() OVERRIDE; | 
| 139 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; | 149 virtual void DidFinishRunningTasksRequiredForActivation() OVERRIDE; | 
| 140 | 150 | 
| 141 typedef std::vector<Tile*> TileVector; | 151 typedef std::vector<Tile*> TileVector; | 
| 142 typedef std::set<Tile*> TileSet; | 152 typedef std::set<Tile*> TileSet; | 
| 143 | 153 | 
| 144 // Virtual for test | 154 // Virtual for test | 
| 145 virtual void ScheduleTasks( | 155 virtual void ScheduleTasks( | 
| 146 const TileVector& tiles_that_need_to_be_rasterized); | 156 const TileVector& tiles_that_need_to_be_rasterized); | 
| 147 | 157 | 
| 148 void AssignGpuMemoryToTiles( | 158 void AssignGpuMemoryToTiles( | 
| 149 PrioritizedTileSet* tiles, | 159 PrioritizedTileSet* tiles, | 
| 150 TileVector* tiles_that_need_to_be_rasterized); | 160 TileVector* tiles_that_need_to_be_rasterized); | 
| 151 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); | 161 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); | 
| 152 | 162 | 
| 153 private: | 163 private: | 
| 164 typedef base::hash_map<TileBundle::Id, TileBundle*> TileBundleMap; | |
| 
 
reveman
2013/11/20 01:34:37
nit: make location of this typedef consistent with
 
 | |
| 165 | |
| 154 void OnImageDecodeTaskCompleted( | 166 void OnImageDecodeTaskCompleted( | 
| 155 int layer_id, | 167 int layer_id, | 
| 156 skia::LazyPixelRef* pixel_ref, | 168 skia::LazyPixelRef* pixel_ref, | 
| 157 bool was_canceled); | 169 bool was_canceled); | 
| 158 void OnRasterTaskCompleted( | 170 void OnRasterTaskCompleted( | 
| 159 Tile::Id tile, | 171 Tile::Id tile, | 
| 160 scoped_ptr<ResourcePool::Resource> resource, | 172 scoped_ptr<ResourcePool::Resource> resource, | 
| 161 RasterMode raster_mode, | 173 RasterMode raster_mode, | 
| 162 const PicturePileImpl::Analysis& analysis, | 174 const PicturePileImpl::Analysis& analysis, | 
| 163 bool was_canceled); | 175 bool was_canceled); | 
| (...skipping 14 matching lines...) Expand all Loading... | |
| 178 void UpdatePrioritizedTileSetIfNeeded(); | 190 void UpdatePrioritizedTileSetIfNeeded(); | 
| 179 | 191 | 
| 180 TileManagerClient* client_; | 192 TileManagerClient* client_; | 
| 181 scoped_ptr<ResourcePool> resource_pool_; | 193 scoped_ptr<ResourcePool> resource_pool_; | 
| 182 scoped_ptr<RasterWorkerPool> raster_worker_pool_; | 194 scoped_ptr<RasterWorkerPool> raster_worker_pool_; | 
| 183 GlobalStateThatImpactsTilePriority global_state_; | 195 GlobalStateThatImpactsTilePriority global_state_; | 
| 184 | 196 | 
| 185 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 197 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 
| 186 TileMap tiles_; | 198 TileMap tiles_; | 
| 187 | 199 | 
| 200 TileBundleMap bundles_; | |
| 201 | |
| 188 PrioritizedTileSet prioritized_tiles_; | 202 PrioritizedTileSet prioritized_tiles_; | 
| 189 bool prioritized_tiles_dirty_; | 203 bool prioritized_tiles_dirty_; | 
| 190 | 204 | 
| 191 bool all_tiles_that_need_to_be_rasterized_have_memory_; | 205 bool all_tiles_that_need_to_be_rasterized_have_memory_; | 
| 192 bool all_tiles_required_for_activation_have_memory_; | 206 bool all_tiles_required_for_activation_have_memory_; | 
| 193 | 207 | 
| 194 size_t memory_required_bytes_; | 208 size_t memory_required_bytes_; | 
| 195 size_t memory_nice_to_have_bytes_; | 209 size_t memory_nice_to_have_bytes_; | 
| 196 | 210 | 
| 197 size_t bytes_releasable_; | 211 size_t bytes_releasable_; | 
| (...skipping 11 matching lines...) Expand all Loading... | |
| 209 typedef base::hash_map<uint32_t, RasterWorkerPool::Task> PixelRefTaskMap; | 223 typedef base::hash_map<uint32_t, RasterWorkerPool::Task> PixelRefTaskMap; | 
| 210 typedef base::hash_map<int, PixelRefTaskMap> LayerPixelRefTaskMap; | 224 typedef base::hash_map<int, PixelRefTaskMap> LayerPixelRefTaskMap; | 
| 211 LayerPixelRefTaskMap image_decode_tasks_; | 225 LayerPixelRefTaskMap image_decode_tasks_; | 
| 212 | 226 | 
| 213 typedef base::hash_map<int, int> LayerCountMap; | 227 typedef base::hash_map<int, int> LayerCountMap; | 
| 214 LayerCountMap used_layer_counts_; | 228 LayerCountMap used_layer_counts_; | 
| 215 | 229 | 
| 216 RasterTaskCompletionStats update_visible_tiles_stats_; | 230 RasterTaskCompletionStats update_visible_tiles_stats_; | 
| 217 | 231 | 
| 218 std::vector<Tile*> released_tiles_; | 232 std::vector<Tile*> released_tiles_; | 
| 233 std::vector<TileBundle*> released_tile_bundles_; | |
| 219 | 234 | 
| 220 DISALLOW_COPY_AND_ASSIGN(TileManager); | 235 DISALLOW_COPY_AND_ASSIGN(TileManager); | 
| 221 }; | 236 }; | 
| 222 | 237 | 
| 223 } // namespace cc | 238 } // namespace cc | 
| 224 | 239 | 
| 225 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 240 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 
| OLD | NEW |