| 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_TILE_MANAGER_H_ | 5 #ifndef CC_TILE_MANAGER_H_ |
| 6 #define CC_TILE_MANAGER_H_ | 6 #define CC_TILE_MANAGER_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/hash_tables.h" | 13 #include "base/hash_tables.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "cc/memory_history.h" | 16 #include "cc/memory_history.h" |
| 17 #include "cc/rendering_stats.h" | 17 #include "cc/rendering_stats.h" |
| 18 #include "cc/resource_pool.h" | 18 #include "cc/resource_pool.h" |
| 19 #include "cc/tile_priority.h" | 19 #include "cc/tile_priority.h" |
| 20 #include "cc/worker_pool.h" |
| 20 | 21 |
| 21 namespace cc { | 22 namespace cc { |
| 22 class RasterWorkerPool; | 23 class RasterWorkerPool; |
| 23 class ResourceProvider; | 24 class ResourceProvider; |
| 24 class Tile; | 25 class Tile; |
| 25 class TileVersion; | 26 class TileVersion; |
| 26 | 27 |
| 27 class CC_EXPORT TileManagerClient { | 28 class CC_EXPORT TileManagerClient { |
| 28 public: | 29 public: |
| 29 virtual void ScheduleManageTiles() = 0; | 30 virtual void ScheduleManageTiles() = 0; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // send to the GPU memory manager to determine policy. | 96 // send to the GPU memory manager to determine policy. |
| 96 TileManagerBin gpu_memmgr_stats_bin; | 97 TileManagerBin gpu_memmgr_stats_bin; |
| 97 TileResolution resolution; | 98 TileResolution resolution; |
| 98 float time_to_needed_in_seconds; | 99 float time_to_needed_in_seconds; |
| 99 }; | 100 }; |
| 100 | 101 |
| 101 // This class manages tiles, deciding which should get rasterized and which | 102 // This class manages tiles, deciding which should get rasterized and which |
| 102 // should no longer have any memory assigned to them. Tile objects are "owned" | 103 // should no longer have any memory assigned to them. Tile objects are "owned" |
| 103 // by layers; they automatically register with the manager when they are | 104 // by layers; they automatically register with the manager when they are |
| 104 // created, and unregister from the manager when they are deleted. | 105 // created, and unregister from the manager when they are deleted. |
| 105 class CC_EXPORT TileManager { | 106 class CC_EXPORT TileManager : public WorkerPoolClient { |
| 106 public: | 107 public: |
| 107 TileManager(TileManagerClient* client, | 108 TileManager(TileManagerClient* client, |
| 108 ResourceProvider *resource_provider, | 109 ResourceProvider *resource_provider, |
| 109 size_t num_raster_threads, | 110 size_t num_raster_threads, |
| 110 bool use_cheapess_estimator); | 111 bool use_cheapess_estimator); |
| 111 virtual ~TileManager(); | 112 virtual ~TileManager(); |
| 112 | 113 |
| 113 const GlobalStateThatImpactsTilePriority& GlobalState() const { | 114 const GlobalStateThatImpactsTilePriority& GlobalState() const { |
| 114 return global_state_; | 115 return global_state_; |
| 115 } | 116 } |
| 116 void SetGlobalState(const GlobalStateThatImpactsTilePriority& state); | 117 void SetGlobalState(const GlobalStateThatImpactsTilePriority& state); |
| 117 | 118 |
| 118 void ManageTiles(); | 119 void ManageTiles(); |
| 119 void CheckForCompletedTileUploads(); | 120 void CheckForCompletedTileUploads(); |
| 120 void AbortPendingTileUploads(); | 121 void AbortPendingTileUploads(); |
| 121 | 122 |
| 122 scoped_ptr<base::Value> BasicStateAsValue() const; | 123 scoped_ptr<base::Value> BasicStateAsValue() const; |
| 123 scoped_ptr<base::Value> AllTilesAsValue() const; | 124 scoped_ptr<base::Value> AllTilesAsValue() const; |
| 124 void GetMemoryStats(size_t* memoryRequiredBytes, | 125 void GetMemoryStats(size_t* memoryRequiredBytes, |
| 125 size_t* memoryNiceToHaveBytes, | 126 size_t* memoryNiceToHaveBytes, |
| 126 size_t* memoryUsedBytes) const; | 127 size_t* memoryUsedBytes) const; |
| 127 void SetRecordRenderingStats(bool record_rendering_stats); | 128 void SetRecordRenderingStats(bool record_rendering_stats); |
| 128 void GetRenderingStats(RenderingStats* stats); | 129 void GetRenderingStats(RenderingStats* stats); |
| 129 bool HasPendingWorkScheduled(WhichTree tree) const; | 130 bool HasPendingWorkScheduled(WhichTree tree) const; |
| 130 | 131 |
| 131 const MemoryHistory::Entry& memory_stats_from_last_assign() const { return mem
ory_stats_from_last_assign_; } | 132 const MemoryHistory::Entry& memory_stats_from_last_assign() const { |
| 133 return memory_stats_from_last_assign_; |
| 134 } |
| 135 |
| 136 // Overridden from WorkerPoolClient: |
| 137 virtual void DidFinishDispatchingWorkerPoolCompletionCallbacks() OVERRIDE; |
| 132 | 138 |
| 133 protected: | 139 protected: |
| 134 // Methods called by Tile | 140 // Methods called by Tile |
| 135 friend class Tile; | 141 friend class Tile; |
| 136 void RegisterTile(Tile* tile); | 142 void RegisterTile(Tile* tile); |
| 137 void UnregisterTile(Tile* tile); | 143 void UnregisterTile(Tile* tile); |
| 138 void WillModifyTilePriority( | 144 void WillModifyTilePriority( |
| 139 Tile* tile, WhichTree tree, const TilePriority& new_priority) { | 145 Tile* tile, WhichTree tree, const TilePriority& new_priority) { |
| 140 // TODO(nduca): Do something smarter if reprioritization turns out to be | 146 // TODO(nduca): Do something smarter if reprioritization turns out to be |
| 141 // costly. | 147 // costly. |
| 142 ScheduleManageTiles(); | 148 ScheduleManageTiles(); |
| 143 } | 149 } |
| 144 | 150 |
| 145 private: | 151 private: |
| 146 void SortTiles(); | 152 void SortTiles(); |
| 147 void AssignGpuMemoryToTiles(); | 153 void AssignGpuMemoryToTiles(); |
| 148 void FreeResourcesForTile(Tile* tile); | 154 void FreeResourcesForTile(Tile* tile); |
| 149 void ScheduleManageTiles() { | 155 void ScheduleManageTiles() { |
| 150 if (manage_tiles_pending_) | 156 if (manage_tiles_pending_) |
| 151 return; | 157 return; |
| 152 client_->ScheduleManageTiles(); | 158 client_->ScheduleManageTiles(); |
| 153 manage_tiles_pending_ = true; | 159 manage_tiles_pending_ = true; |
| 154 } | 160 } |
| 155 void DispatchMoreTasks(); | 161 void DispatchMoreTasks(); |
| 156 void GatherPixelRefsForTile(Tile* tile); | 162 void GatherPixelRefsForTile(Tile* tile); |
| 157 void DispatchImageDecodeTasksForTile(Tile* tile); | 163 void DispatchImageDecodeTasksForTile(Tile* tile); |
| 158 void DispatchOneImageDecodeTask( | 164 void DispatchOneImageDecodeTask( |
| 159 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref); | 165 scoped_refptr<Tile> tile, skia::LazyPixelRef* pixel_ref); |
| 160 void OnImageDecodeTaskCompleted( | 166 void OnImageDecodeTaskCompleted( |
| 161 scoped_refptr<Tile> tile, uint32_t pixel_ref_id); | 167 scoped_refptr<Tile> tile, |
| 168 uint32_t pixel_ref_id); |
| 162 bool CanDispatchRasterTask(Tile* tile); | 169 bool CanDispatchRasterTask(Tile* tile); |
| 163 scoped_ptr<ResourcePool::Resource> PrepareTileForRaster(Tile* tile); | 170 scoped_ptr<ResourcePool::Resource> PrepareTileForRaster(Tile* tile); |
| 164 void DispatchOneRasterTask(scoped_refptr<Tile> tile); | 171 void DispatchOneRasterTask(scoped_refptr<Tile> tile); |
| 165 void PerformOneRaster(Tile* tile); | 172 void PerformOneRaster(Tile* tile); |
| 166 void OnRasterCompleted( | 173 void OnRasterCompleted( |
| 167 scoped_refptr<Tile> tile, | 174 scoped_refptr<Tile> tile, |
| 168 scoped_ptr<ResourcePool::Resource> resource, | 175 scoped_ptr<ResourcePool::Resource> resource, |
| 169 int manage_tiles_call_count_when_dispatched); | 176 int manage_tiles_call_count_when_dispatched); |
| 170 void OnRasterTaskCompleted( | 177 void OnRasterTaskCompleted( |
| 171 scoped_refptr<Tile> tile, | 178 scoped_refptr<Tile> tile, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // Tiles with image decoding tasks. These tiles need to be rasterized | 216 // Tiles with image decoding tasks. These tiles need to be rasterized |
| 210 // when all the image decoding tasks finish. | 217 // when all the image decoding tasks finish. |
| 211 TileList tiles_with_image_decoding_tasks_; | 218 TileList tiles_with_image_decoding_tasks_; |
| 212 | 219 |
| 213 typedef base::hash_map<uint32_t, skia::LazyPixelRef*> PixelRefMap; | 220 typedef base::hash_map<uint32_t, skia::LazyPixelRef*> PixelRefMap; |
| 214 PixelRefMap pending_decode_tasks_; | 221 PixelRefMap pending_decode_tasks_; |
| 215 | 222 |
| 216 typedef std::queue<scoped_refptr<Tile> > TileQueue; | 223 typedef std::queue<scoped_refptr<Tile> > TileQueue; |
| 217 TileQueue tiles_with_pending_set_pixels_; | 224 TileQueue tiles_with_pending_set_pixels_; |
| 218 size_t bytes_pending_set_pixels_; | 225 size_t bytes_pending_set_pixels_; |
| 226 bool has_performed_uploads_since_last_flush_; |
| 219 bool ever_exceeded_memory_budget_; | 227 bool ever_exceeded_memory_budget_; |
| 220 MemoryHistory::Entry memory_stats_from_last_assign_; | 228 MemoryHistory::Entry memory_stats_from_last_assign_; |
| 221 | 229 |
| 222 bool record_rendering_stats_; | 230 bool record_rendering_stats_; |
| 223 RenderingStats rendering_stats_; | 231 RenderingStats rendering_stats_; |
| 224 | 232 |
| 225 bool use_cheapness_estimator_; | 233 bool use_cheapness_estimator_; |
| 226 int raster_state_count_[NUM_STATES][NUM_TREES][NUM_BINS]; | 234 int raster_state_count_[NUM_STATES][NUM_TREES][NUM_BINS]; |
| 227 | 235 |
| 228 DISALLOW_COPY_AND_ASSIGN(TileManager); | 236 DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 229 }; | 237 }; |
| 230 | 238 |
| 231 } // namespace cc | 239 } // namespace cc |
| 232 | 240 |
| 233 #endif // CC_TILE_MANAGER_H_ | 241 #endif // CC_TILE_MANAGER_H_ |
| OLD | NEW |