| 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/gpu_rasterizer.h" |
| 17 #include "cc/resources/managed_tile_state.h" | 18 #include "cc/resources/managed_tile_state.h" |
| 18 #include "cc/resources/memory_history.h" | 19 #include "cc/resources/memory_history.h" |
| 19 #include "cc/resources/picture_pile_impl.h" | 20 #include "cc/resources/picture_pile_impl.h" |
| 20 #include "cc/resources/prioritized_tile_set.h" | 21 #include "cc/resources/prioritized_tile_set.h" |
| 21 #include "cc/resources/raster_worker_pool.h" | 22 #include "cc/resources/raster_worker_pool.h" |
| 22 #include "cc/resources/resource_pool.h" | 23 #include "cc/resources/resource_pool.h" |
| 23 #include "cc/resources/tile.h" | 24 #include "cc/resources/tile.h" |
| 24 #include "cc/resources/tile_bundle.h" | 25 #include "cc/resources/tile_bundle.h" |
| 25 | 26 |
| 26 namespace cc { | 27 namespace cc { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 41 size_t canceled_count; | 42 size_t canceled_count; |
| 42 }; | 43 }; |
| 43 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( | 44 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( |
| 44 const RasterTaskCompletionStats& stats); | 45 const RasterTaskCompletionStats& stats); |
| 45 | 46 |
| 46 // This class manages tiles, deciding which should get rasterized and which | 47 // This class manages tiles, deciding which should get rasterized and which |
| 47 // should no longer have any memory assigned to them. Tile objects are "owned" | 48 // should no longer have any memory assigned to them. Tile objects are "owned" |
| 48 // by layers; they automatically register with the manager when they are | 49 // by layers; they automatically register with the manager when they are |
| 49 // created, and unregister from the manager when they are deleted. | 50 // created, and unregister from the manager when they are deleted. |
| 50 class CC_EXPORT TileManager : public RasterWorkerPoolClient, | 51 class CC_EXPORT TileManager : public RasterWorkerPoolClient, |
| 52 public GpuRasterizerClient, |
| 51 public RefCountedManager<Tile>, | 53 public RefCountedManager<Tile>, |
| 52 public RefCountedManager<TileBundle> { | 54 public RefCountedManager<TileBundle> { |
| 53 public: | 55 public: |
| 54 static scoped_ptr<TileManager> Create( | 56 static scoped_ptr<TileManager> Create( |
| 55 TileManagerClient* client, | 57 TileManagerClient* client, |
| 56 ResourceProvider* resource_provider, | 58 ResourceProvider* resource_provider, |
| 59 ContextProvider* context_provider, |
| 57 size_t num_raster_threads, | 60 size_t num_raster_threads, |
| 58 RenderingStatsInstrumentation* rendering_stats_instrumentation, | 61 RenderingStatsInstrumentation* rendering_stats_instrumentation, |
| 59 bool use_map_image, | 62 bool use_map_image, |
| 60 size_t max_transfer_buffer_usage_bytes, | 63 size_t max_transfer_buffer_usage_bytes, |
| 61 size_t max_raster_usage_bytes, | 64 size_t max_raster_usage_bytes, |
| 62 GLenum map_image_texture_target); | 65 GLenum map_image_texture_target); |
| 63 virtual ~TileManager(); | 66 virtual ~TileManager(); |
| 64 | 67 |
| 65 void ManageTiles(const GlobalStateThatImpactsTilePriority& state); | 68 void ManageTiles(const GlobalStateThatImpactsTilePriority& state); |
| 66 | 69 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 if (state != global_state_) { | 119 if (state != global_state_) { |
| 117 global_state_ = state; | 120 global_state_ = state; |
| 118 prioritized_tiles_dirty_ = true; | 121 prioritized_tiles_dirty_ = true; |
| 119 resource_pool_->SetResourceUsageLimits( | 122 resource_pool_->SetResourceUsageLimits( |
| 120 global_state_.memory_limit_in_bytes, | 123 global_state_.memory_limit_in_bytes, |
| 121 global_state_.unused_memory_limit_in_bytes, | 124 global_state_.unused_memory_limit_in_bytes, |
| 122 global_state_.num_resources_limit); | 125 global_state_.num_resources_limit); |
| 123 } | 126 } |
| 124 } | 127 } |
| 125 | 128 |
| 129 // GpuRasterizerClient interface |
| 130 virtual void OnGpuRasterTaskCompleted( |
| 131 Tile* tile, scoped_ptr<ScopedResource> resource) OVERRIDE; |
| 132 |
| 126 protected: | 133 protected: |
| 127 TileManager(TileManagerClient* client, | 134 TileManager(TileManagerClient* client, |
| 128 ResourceProvider* resource_provider, | 135 ResourceProvider* resource_provider, |
| 136 scoped_ptr<GpuRasterizer> gpu_rasterizer, |
| 129 scoped_ptr<RasterWorkerPool> raster_worker_pool, | 137 scoped_ptr<RasterWorkerPool> raster_worker_pool, |
| 130 size_t num_raster_threads, | 138 size_t num_raster_threads, |
| 131 size_t max_raster_usage_bytes, | 139 size_t max_raster_usage_bytes, |
| 132 RenderingStatsInstrumentation* rendering_stats_instrumentation); | 140 RenderingStatsInstrumentation* rendering_stats_instrumentation); |
| 133 | 141 |
| 134 // Methods called by Tile and TileBundle | 142 // Methods called by Tile and TileBundle |
| 135 friend class TileBundle; | 143 friend class TileBundle; |
| 136 friend class Tile; | 144 friend class Tile; |
| 137 | 145 |
| 138 void DidChangeTilePriority(Tile* tile); | 146 void DidChangeTilePriority(Tile* tile); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 157 | 165 |
| 158 // Virtual for test | 166 // Virtual for test |
| 159 virtual void ScheduleTasks( | 167 virtual void ScheduleTasks( |
| 160 const TileVector& tiles_that_need_to_be_rasterized); | 168 const TileVector& tiles_that_need_to_be_rasterized); |
| 161 | 169 |
| 162 void AssignGpuMemoryToTiles( | 170 void AssignGpuMemoryToTiles( |
| 163 PrioritizedTileSet* tiles, | 171 PrioritizedTileSet* tiles, |
| 164 TileVector* tiles_that_need_to_be_rasterized); | 172 TileVector* tiles_that_need_to_be_rasterized); |
| 165 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); | 173 void GetTilesWithAssignedBins(PrioritizedTileSet* tiles); |
| 166 | 174 |
| 175 GpuRasterizer* GetGpuRasterizerForTest() { return gpu_rasterizer_.get(); } |
| 176 |
| 167 private: | 177 private: |
| 168 void OnImageDecodeTaskCompleted( | 178 void OnImageDecodeTaskCompleted( |
| 169 int layer_id, | 179 int layer_id, |
| 170 skia::LazyPixelRef* pixel_ref, | 180 skia::LazyPixelRef* pixel_ref, |
| 171 bool was_canceled); | 181 bool was_canceled); |
| 172 void OnRasterTaskCompleted(Tile::Id tile, | 182 void OnRasterTaskCompleted(Tile::Id tile, |
| 173 scoped_ptr<ScopedResource> resource, | 183 scoped_ptr<ScopedResource> resource, |
| 174 RasterMode raster_mode, | 184 RasterMode raster_mode, |
| 175 const PicturePileImpl::Analysis& analysis, | 185 const PicturePileImpl::Analysis& analysis, |
| 176 bool was_canceled); | 186 bool was_canceled); |
| 177 | 187 |
| 178 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { | 188 inline size_t BytesConsumedIfAllocated(const Tile* tile) const { |
| 179 return Resource::MemorySizeBytes(tile->size(), | 189 return Resource::MemorySizeBytes(tile->size(), |
| 180 raster_worker_pool_->GetResourceFormat()); | 190 raster_worker_pool_->GetResourceFormat()); |
| 181 } | 191 } |
| 182 | 192 |
| 183 RasterMode DetermineRasterMode(const Tile* tile) const; | 193 RasterMode DetermineRasterMode(const Tile* tile) const; |
| 184 void FreeResourceForTile(Tile* tile, RasterMode mode); | 194 void FreeResourceForTile(Tile* tile, RasterMode mode); |
| 185 void FreeResourcesForTile(Tile* tile); | 195 void FreeResourcesForTile(Tile* tile); |
| 186 void FreeUnusedResourcesForTile(Tile* tile); | 196 void FreeUnusedResourcesForTile(Tile* tile); |
| 187 RasterWorkerPool::Task CreateImageDecodeTask( | 197 RasterWorkerPool::Task CreateImageDecodeTask( |
| 188 Tile* tile, skia::LazyPixelRef* pixel_ref); | 198 Tile* tile, skia::LazyPixelRef* pixel_ref); |
| 189 RasterWorkerPool::RasterTask CreateRasterTask(Tile* tile); | 199 RasterWorkerPool::RasterTask CreateRasterTask(Tile* tile); |
| 190 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; | 200 scoped_ptr<base::Value> GetMemoryRequirementsAsValue() const; |
| 191 void UpdatePrioritizedTileSetIfNeeded(); | 201 void UpdatePrioritizedTileSetIfNeeded(); |
| 192 | 202 |
| 193 TileManagerClient* client_; | 203 TileManagerClient* client_; |
| 194 scoped_ptr<ResourcePool> resource_pool_; | 204 scoped_ptr<ResourcePool> resource_pool_; |
| 205 scoped_ptr<GpuRasterizer> gpu_rasterizer_; |
| 195 scoped_ptr<RasterWorkerPool> raster_worker_pool_; | 206 scoped_ptr<RasterWorkerPool> raster_worker_pool_; |
| 196 GlobalStateThatImpactsTilePriority global_state_; | 207 GlobalStateThatImpactsTilePriority global_state_; |
| 197 | 208 |
| 198 typedef base::hash_map<Tile::Id, Tile*> TileMap; | 209 typedef base::hash_map<Tile::Id, Tile*> TileMap; |
| 199 TileMap tiles_; | 210 TileMap tiles_; |
| 200 | 211 |
| 201 typedef base::hash_map<TileBundle::Id, TileBundle*> TileBundleMap; | 212 typedef base::hash_map<TileBundle::Id, TileBundle*> TileBundleMap; |
| 202 TileBundleMap bundles_; | 213 TileBundleMap bundles_; |
| 203 | 214 |
| 204 PrioritizedTileSet prioritized_tiles_; | 215 PrioritizedTileSet prioritized_tiles_; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 233 | 244 |
| 234 std::vector<Tile*> released_tiles_; | 245 std::vector<Tile*> released_tiles_; |
| 235 std::vector<TileBundle*> released_tile_bundles_; | 246 std::vector<TileBundle*> released_tile_bundles_; |
| 236 | 247 |
| 237 DISALLOW_COPY_AND_ASSIGN(TileManager); | 248 DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 238 }; | 249 }; |
| 239 | 250 |
| 240 } // namespace cc | 251 } // namespace cc |
| 241 | 252 |
| 242 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 253 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
| OLD | NEW |