| 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/debug/rendering_stats_instrumentation.h" | 15 #include "cc/debug/rendering_stats_instrumentation.h" |
| 16 #include "cc/resources/managed_tile_state.h" | 16 #include "cc/resources/managed_tile_state.h" |
| 17 #include "cc/resources/memory_history.h" | 17 #include "cc/resources/memory_history.h" |
| 18 #include "cc/resources/picture_pile_impl.h" | 18 #include "cc/resources/picture_pile_impl.h" |
| 19 #include "cc/resources/raster_worker_pool.h" | 19 #include "cc/resources/raster_worker_pool.h" |
| 20 #include "cc/resources/resource_pool.h" | 20 #include "cc/resources/resource_pool.h" |
| 21 #include "cc/resources/tile.h" |
| 21 | 22 |
| 22 namespace cc { | 23 namespace cc { |
| 23 class ResourceProvider; | 24 class ResourceProvider; |
| 24 class Tile; | |
| 25 class TileVersion; | |
| 26 | 25 |
| 27 class CC_EXPORT TileManagerClient { | 26 class CC_EXPORT TileManagerClient { |
| 28 public: | 27 public: |
| 29 virtual void DidInitializeVisibleTile() = 0; | 28 virtual void DidInitializeVisibleTile() = 0; |
| 30 virtual void NotifyReadyToActivate() = 0; | 29 virtual void NotifyReadyToActivate() = 0; |
| 31 | 30 |
| 32 protected: | 31 protected: |
| 33 virtual ~TileManagerClient() {} | 32 virtual ~TileManagerClient() {} |
| 34 }; | 33 }; |
| 35 | 34 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 59 scoped_ptr<base::Value> AllTilesAsValue() const; | 58 scoped_ptr<base::Value> AllTilesAsValue() const; |
| 60 void GetMemoryStats(size_t* memory_required_bytes, | 59 void GetMemoryStats(size_t* memory_required_bytes, |
| 61 size_t* memory_nice_to_have_bytes, | 60 size_t* memory_nice_to_have_bytes, |
| 62 size_t* memory_used_bytes) const; | 61 size_t* memory_used_bytes) const; |
| 63 | 62 |
| 64 const MemoryHistory::Entry& memory_stats_from_last_assign() const { | 63 const MemoryHistory::Entry& memory_stats_from_last_assign() const { |
| 65 return memory_stats_from_last_assign_; | 64 return memory_stats_from_last_assign_; |
| 66 } | 65 } |
| 67 | 66 |
| 68 bool AreTilesRequiredForActivationReady() const { | 67 bool AreTilesRequiredForActivationReady() const { |
| 69 return tiles_that_need_to_be_initialized_for_activation_.empty() && | 68 return all_tiles_required_for_activation_have_been_initialized_ && |
| 70 oom_tiles_that_need_to_be_initialized_for_activation_.empty(); | 69 all_tiles_required_for_activation_have_memory_; |
| 71 } | 70 } |
| 72 | 71 |
| 73 protected: | 72 protected: |
| 74 TileManager(TileManagerClient* client, | 73 TileManager(TileManagerClient* client, |
| 75 ResourceProvider* resource_provider, | 74 ResourceProvider* resource_provider, |
| 76 scoped_ptr<RasterWorkerPool> raster_worker_pool, | 75 scoped_ptr<RasterWorkerPool> raster_worker_pool, |
| 77 size_t num_raster_threads, | 76 size_t num_raster_threads, |
| 78 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 77 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| 79 GLenum texture_format); | 78 GLenum texture_format); |
| 80 | 79 |
| 81 // Methods called by Tile | 80 // Methods called by Tile |
| 82 friend class Tile; | 81 friend class Tile; |
| 83 void RegisterTile(Tile* tile); | 82 void RegisterTile(Tile* tile); |
| 84 void UnregisterTile(Tile* tile); | 83 void UnregisterTile(Tile* tile); |
| 85 | 84 |
| 86 // Overriden from RasterWorkerPoolClient: | 85 // Overriden from RasterWorkerPoolClient: |
| 87 virtual bool ShouldForceTasksRequiredForActivationToComplete() const | 86 virtual bool ShouldForceTasksRequiredForActivationToComplete() const |
| 88 OVERRIDE; | 87 OVERRIDE; |
| 89 virtual void DidFinishedRunningTasks() OVERRIDE; | 88 virtual void DidFinishedRunningTasks() OVERRIDE; |
| 90 virtual void DidFinishedRunningTasksRequiredForActivation() OVERRIDE; | 89 virtual void DidFinishedRunningTasksRequiredForActivation() OVERRIDE; |
| 91 | 90 |
| 91 typedef std::vector<Tile*> TileVector; |
| 92 typedef std::vector<scoped_refptr<Tile> > TileRefVector; |
| 93 typedef std::set<Tile*> TileSet; |
| 94 |
| 92 // Virtual for test | 95 // Virtual for test |
| 93 virtual void ScheduleTasks(); | 96 virtual void ScheduleTasks( |
| 97 const TileVector& tiles_that_need_to_be_rasterized); |
| 94 | 98 |
| 95 const std::vector<Tile*>& tiles_that_need_to_be_rasterized() const { | 99 void ReassignGpuMemoryToOOMTilesRequiredForActivation( |
| 96 return tiles_that_need_to_be_rasterized_; | 100 const TileRefVector& sorted_tiles, |
| 97 } | 101 TileVector* tiles_that_need_to_be_rasterized, |
| 98 | 102 TileSet* oom_tiles_required_for_activation); |
| 99 void ReassignGpuMemoryToOOMTilesRequiredForActivation(); | 103 void AssignGpuMemoryToTiles( |
| 104 const TileRefVector& sorted_tiles, |
| 105 TileVector* tiles_that_need_to_be_rasterized, |
| 106 TileSet* oom_tiles_required_for_activation); |
| 107 void AssignBinsToTiles(TileRefVector* tiles); |
| 108 void SortTiles(TileRefVector* tiles); |
| 109 void GetSortedTiles(TileRefVector* tiles); |
| 100 | 110 |
| 101 private: | 111 private: |
| 102 void OnImageDecodeTaskCompleted( | 112 void OnImageDecodeTaskCompleted( |
| 103 int layer_id, | 113 int layer_id, |
| 104 skia::LazyPixelRef* pixel_ref, | 114 skia::LazyPixelRef* pixel_ref, |
| 105 bool was_canceled); | 115 bool was_canceled); |
| 106 void OnRasterTaskCompleted( | 116 void OnRasterTaskCompleted( |
| 107 scoped_refptr<Tile> tile, | 117 Tile::Id tile, |
| 108 scoped_ptr<ResourcePool::Resource> resource, | 118 scoped_ptr<ResourcePool::Resource> resource, |
| 109 RasterMode raster_mode, | 119 RasterMode raster_mode, |
| 110 const PicturePileImpl::Analysis& analysis, | 120 const PicturePileImpl::Analysis& analysis, |
| 111 bool was_canceled); | 121 bool was_canceled); |
| 112 | 122 |
| 113 void AssignBinsToTiles(); | |
| 114 void SortTiles(); | |
| 115 RasterMode DetermineRasterMode(const Tile* tile) const; | 123 RasterMode DetermineRasterMode(const Tile* tile) const; |
| 116 void CleanUpUnusedImageDecodeTasks(); | 124 void CleanUpUnusedImageDecodeTasks(); |
| 117 void AssignGpuMemoryToTiles(); | |
| 118 void FreeResourceForTile(Tile* tile, RasterMode mode); | 125 void FreeResourceForTile(Tile* tile, RasterMode mode); |
| 119 void FreeResourcesForTile(Tile* tile); | 126 void FreeResourcesForTile(Tile* tile); |
| 120 void FreeUnusedResourcesForTile(Tile* tile); | 127 void FreeUnusedResourcesForTile(Tile* tile); |
| 121 RasterWorkerPool::Task CreateImageDecodeTask( | 128 RasterWorkerPool::Task CreateImageDecodeTask( |
| 122 Tile* tile, skia::LazyPixelRef* pixel_ref); | 129 Tile* tile, skia::LazyPixelRef* pixel_ref); |
| 123 RasterWorkerPool::RasterTask CreateRasterTask(Tile* tile); | 130 RasterWorkerPool::RasterTask CreateRasterTask(Tile* tile); |
| 124 void DidFinishTileInitialization(Tile* tile); | |
| 125 void DidTileTreeBinChange(Tile* tile, | |
| 126 ManagedTileBin new_tree_bin, | |
| 127 WhichTree tree); | |
| 128 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; | 131 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; |
| 129 void AddRequiredTileForActivation(Tile* tile); | |
| 130 | 132 |
| 131 TileManagerClient* client_; | 133 TileManagerClient* client_; |
| 132 scoped_ptr<ResourcePool> resource_pool_; | 134 scoped_ptr<ResourcePool> resource_pool_; |
| 133 scoped_ptr<RasterWorkerPool> raster_worker_pool_; | 135 scoped_ptr<RasterWorkerPool> raster_worker_pool_; |
| 134 GlobalStateThatImpactsTilePriority global_state_; | 136 GlobalStateThatImpactsTilePriority global_state_; |
| 135 | 137 |
| 136 typedef std::vector<Tile*> TileVector; | 138 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
| 137 TileVector tiles_; | 139 TileMap tiles_; |
| 138 TileVector tiles_that_need_to_be_rasterized_; | 140 |
| 139 typedef std::set<Tile*> TileSet; | 141 TileRefVector sorted_tiles_; |
| 140 TileSet tiles_that_need_to_be_initialized_for_activation_; | 142 |
| 141 TileSet oom_tiles_that_need_to_be_initialized_for_activation_; | 143 bool all_tiles_required_for_activation_have_been_initialized_; |
| 144 bool all_tiles_required_for_activation_have_memory_; |
| 142 | 145 |
| 143 bool ever_exceeded_memory_budget_; | 146 bool ever_exceeded_memory_budget_; |
| 144 MemoryHistory::Entry memory_stats_from_last_assign_; | 147 MemoryHistory::Entry memory_stats_from_last_assign_; |
| 145 | 148 |
| 146 RenderingStatsInstrumentation* rendering_stats_instrumentation_; | 149 RenderingStatsInstrumentation* rendering_stats_instrumentation_; |
| 147 | 150 |
| 148 bool did_initialize_visible_tile_; | 151 bool did_initialize_visible_tile_; |
| 149 | 152 |
| 150 GLenum texture_format_; | 153 GLenum texture_format_; |
| 151 | 154 |
| 152 typedef base::hash_map<uint32_t, RasterWorkerPool::Task> PixelRefTaskMap; | 155 typedef base::hash_map<uint32_t, RasterWorkerPool::Task> PixelRefTaskMap; |
| 153 typedef base::hash_map<int, PixelRefTaskMap> LayerPixelRefTaskMap; | 156 typedef base::hash_map<int, PixelRefTaskMap> LayerPixelRefTaskMap; |
| 154 LayerPixelRefTaskMap image_decode_tasks_; | 157 LayerPixelRefTaskMap image_decode_tasks_; |
| 155 | 158 |
| 156 DISALLOW_COPY_AND_ASSIGN(TileManager); | 159 DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 157 }; | 160 }; |
| 158 | 161 |
| 159 } // namespace cc | 162 } // namespace cc |
| 160 | 163 |
| 161 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 164 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
| OLD | NEW |