| 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 <deque> | 8 #include <deque> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "cc/base/ref_counted_managed.h" | 17 #include "cc/base/ref_counted_managed.h" |
| 18 #include "cc/base/unique_notifier.h" | 18 #include "cc/base/unique_notifier.h" |
| 19 #include "cc/debug/rendering_stats_instrumentation.h" | 19 #include "cc/debug/rendering_stats_instrumentation.h" |
| 20 #include "cc/layers/picture_layer_impl.h" | 20 #include "cc/resources/eviction_tile_priority_queue.h" |
| 21 #include "cc/resources/managed_tile_state.h" | 21 #include "cc/resources/managed_tile_state.h" |
| 22 #include "cc/resources/memory_history.h" | 22 #include "cc/resources/memory_history.h" |
| 23 #include "cc/resources/picture_pile_impl.h" | 23 #include "cc/resources/picture_pile_impl.h" |
| 24 #include "cc/resources/prioritized_tile_set.h" | 24 #include "cc/resources/prioritized_tile_set.h" |
| 25 #include "cc/resources/raster_tile_priority_queue.h" |
| 25 #include "cc/resources/rasterizer.h" | 26 #include "cc/resources/rasterizer.h" |
| 26 #include "cc/resources/resource_pool.h" | 27 #include "cc/resources/resource_pool.h" |
| 27 #include "cc/resources/tile.h" | 28 #include "cc/resources/tile.h" |
| 28 | 29 |
| 29 namespace cc { | 30 namespace cc { |
| 31 class PictureLayerImpl; |
| 30 class ResourceProvider; | 32 class ResourceProvider; |
| 31 | 33 |
| 32 class CC_EXPORT TileManagerClient { | 34 class CC_EXPORT TileManagerClient { |
| 33 public: | 35 public: |
| 34 // Returns the set of layers that the tile manager should consider for raster. | 36 // Returns the set of layers that the tile manager should consider for raster. |
| 35 virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() = 0; | 37 // TODO(vmpstr): Change the way we determine if we are ready to activate, so |
| 38 // that this can be removed. |
| 39 virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() const = 0; |
| 36 | 40 |
| 37 // Called when all tiles marked as required for activation are ready to draw. | 41 // Called when all tiles marked as required for activation are ready to draw. |
| 38 virtual void NotifyReadyToActivate() = 0; | 42 virtual void NotifyReadyToActivate() = 0; |
| 39 | 43 |
| 40 // Called when the visible representation of a tile might have changed. Some | 44 // Called when the visible representation of a tile might have changed. Some |
| 41 // examples are: | 45 // examples are: |
| 42 // - Tile version initialized. | 46 // - Tile version initialized. |
| 43 // - Tile resources freed. | 47 // - Tile resources freed. |
| 44 // - Tile marked for on-demand raster. | 48 // - Tile marked for on-demand raster. |
| 45 virtual void NotifyTileStateChanged(const Tile* tile) = 0; | 49 virtual void NotifyTileStateChanged(const Tile* tile) = 0; |
| 46 | 50 |
| 51 // Given an empty raster tile priority queue, this will build a priority queue |
| 52 // that will return tiles in order in which they should be rasterized. |
| 53 // Note if the queue was previous built, Reset must be called on it. |
| 54 virtual void BuildRasterQueue(RasterTilePriorityQueue* queue, |
| 55 TreePriority tree_priority) = 0; |
| 56 |
| 57 // Given an empty eviction tile priority queue, this will build a priority |
| 58 // queue that will return tiles in order in which they should be evicted. |
| 59 // Note if the queue was previous built, Reset must be called on it. |
| 60 virtual void BuildEvictionQueue(EvictionTilePriorityQueue* queue, |
| 61 TreePriority tree_priority) = 0; |
| 62 |
| 47 protected: | 63 protected: |
| 48 virtual ~TileManagerClient() {} | 64 virtual ~TileManagerClient() {} |
| 49 }; | 65 }; |
| 50 | 66 |
| 51 struct RasterTaskCompletionStats { | 67 struct RasterTaskCompletionStats { |
| 52 RasterTaskCompletionStats(); | 68 RasterTaskCompletionStats(); |
| 53 | 69 |
| 54 size_t completed_count; | 70 size_t completed_count; |
| 55 size_t canceled_count; | 71 size_t canceled_count; |
| 56 }; | 72 }; |
| 57 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( | 73 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( |
| 58 const RasterTaskCompletionStats& stats); | 74 const RasterTaskCompletionStats& stats); |
| 59 | 75 |
| 60 // This class manages tiles, deciding which should get rasterized and which | 76 // This class manages tiles, deciding which should get rasterized and which |
| 61 // should no longer have any memory assigned to them. Tile objects are "owned" | 77 // should no longer have any memory assigned to them. Tile objects are "owned" |
| 62 // by layers; they automatically register with the manager when they are | 78 // by layers; they automatically register with the manager when they are |
| 63 // created, and unregister from the manager when they are deleted. | 79 // created, and unregister from the manager when they are deleted. |
| 64 class CC_EXPORT TileManager : public RasterizerClient, | 80 class CC_EXPORT TileManager : public RasterizerClient, |
| 65 public RefCountedManager<Tile> { | 81 public RefCountedManager<Tile> { |
| 66 public: | 82 public: |
| 67 struct CC_EXPORT PairedPictureLayer { | |
| 68 PairedPictureLayer(); | |
| 69 ~PairedPictureLayer(); | |
| 70 | |
| 71 PictureLayerImpl* active_layer; | |
| 72 PictureLayerImpl* pending_layer; | |
| 73 }; | |
| 74 | |
| 75 class CC_EXPORT RasterTileIterator { | |
| 76 public: | |
| 77 RasterTileIterator(TileManager* tile_manager, TreePriority tree_priority); | |
| 78 ~RasterTileIterator(); | |
| 79 | |
| 80 RasterTileIterator& operator++(); | |
| 81 operator bool() const; | |
| 82 Tile* operator*(); | |
| 83 | |
| 84 private: | |
| 85 struct PairedPictureLayerIterator { | |
| 86 PairedPictureLayerIterator(); | |
| 87 ~PairedPictureLayerIterator(); | |
| 88 | |
| 89 Tile* PeekTile(TreePriority tree_priority); | |
| 90 void PopTile(TreePriority tree_priority); | |
| 91 | |
| 92 std::pair<PictureLayerImpl::LayerRasterTileIterator*, WhichTree> | |
| 93 NextTileIterator(TreePriority tree_priority); | |
| 94 | |
| 95 PictureLayerImpl::LayerRasterTileIterator active_iterator; | |
| 96 PictureLayerImpl::LayerRasterTileIterator pending_iterator; | |
| 97 | |
| 98 std::vector<Tile*> returned_shared_tiles; | |
| 99 }; | |
| 100 | |
| 101 class RasterOrderComparator { | |
| 102 public: | |
| 103 explicit RasterOrderComparator(TreePriority tree_priority); | |
| 104 | |
| 105 bool operator()(PairedPictureLayerIterator* a, | |
| 106 PairedPictureLayerIterator* b) const; | |
| 107 | |
| 108 private: | |
| 109 TreePriority tree_priority_; | |
| 110 }; | |
| 111 | |
| 112 std::vector<PairedPictureLayerIterator> paired_iterators_; | |
| 113 std::vector<PairedPictureLayerIterator*> iterator_heap_; | |
| 114 TreePriority tree_priority_; | |
| 115 RasterOrderComparator comparator_; | |
| 116 | |
| 117 DISALLOW_COPY_AND_ASSIGN(RasterTileIterator); | |
| 118 }; | |
| 119 | |
| 120 struct CC_EXPORT EvictionTileIterator { | |
| 121 public: | |
| 122 EvictionTileIterator(); | |
| 123 EvictionTileIterator(TileManager* tile_manager, TreePriority tree_priority); | |
| 124 ~EvictionTileIterator(); | |
| 125 | |
| 126 EvictionTileIterator& operator++(); | |
| 127 operator bool() const; | |
| 128 Tile* operator*(); | |
| 129 | |
| 130 private: | |
| 131 struct PairedPictureLayerIterator { | |
| 132 PairedPictureLayerIterator(); | |
| 133 ~PairedPictureLayerIterator(); | |
| 134 | |
| 135 Tile* PeekTile(TreePriority tree_priority); | |
| 136 void PopTile(TreePriority tree_priority); | |
| 137 | |
| 138 PictureLayerImpl::LayerEvictionTileIterator* NextTileIterator( | |
| 139 TreePriority tree_priority); | |
| 140 | |
| 141 PictureLayerImpl::LayerEvictionTileIterator active_iterator; | |
| 142 PictureLayerImpl::LayerEvictionTileIterator pending_iterator; | |
| 143 | |
| 144 std::vector<Tile*> returned_shared_tiles; | |
| 145 }; | |
| 146 | |
| 147 class EvictionOrderComparator { | |
| 148 public: | |
| 149 explicit EvictionOrderComparator(TreePriority tree_priority); | |
| 150 | |
| 151 bool operator()(PairedPictureLayerIterator* a, | |
| 152 PairedPictureLayerIterator* b) const; | |
| 153 | |
| 154 private: | |
| 155 TreePriority tree_priority_; | |
| 156 }; | |
| 157 | |
| 158 std::vector<PairedPictureLayerIterator> paired_iterators_; | |
| 159 std::vector<PairedPictureLayerIterator*> iterator_heap_; | |
| 160 TreePriority tree_priority_; | |
| 161 EvictionOrderComparator comparator_; | |
| 162 | |
| 163 DISALLOW_COPY_AND_ASSIGN(EvictionTileIterator); | |
| 164 }; | |
| 165 | |
| 166 static scoped_ptr<TileManager> Create( | 83 static scoped_ptr<TileManager> Create( |
| 167 TileManagerClient* client, | 84 TileManagerClient* client, |
| 168 base::SequencedTaskRunner* task_runner, | 85 base::SequencedTaskRunner* task_runner, |
| 169 ResourcePool* resource_pool, | 86 ResourcePool* resource_pool, |
| 170 Rasterizer* rasterizer, | 87 Rasterizer* rasterizer, |
| 171 RenderingStatsInstrumentation* rendering_stats_instrumentation); | 88 RenderingStatsInstrumentation* rendering_stats_instrumentation); |
| 172 virtual ~TileManager(); | 89 virtual ~TileManager(); |
| 173 | 90 |
| 174 void ManageTiles(const GlobalStateThatImpactsTilePriority& state); | 91 void ManageTiles(const GlobalStateThatImpactsTilePriority& state); |
| 175 | 92 |
| 176 // Returns true when visible tiles have been initialized. | 93 // Returns true when visible tiles have been initialized. |
| 177 bool UpdateVisibleTiles(); | 94 bool UpdateVisibleTiles(); |
| 178 | 95 |
| 179 scoped_refptr<Tile> CreateTile(PicturePileImpl* picture_pile, | 96 scoped_refptr<Tile> CreateTile(PicturePileImpl* picture_pile, |
| 180 const gfx::Size& tile_size, | 97 const gfx::Size& tile_size, |
| 181 const gfx::Rect& content_rect, | 98 const gfx::Rect& content_rect, |
| 182 const gfx::Rect& opaque_rect, | 99 const gfx::Rect& opaque_rect, |
| 183 float contents_scale, | 100 float contents_scale, |
| 184 int layer_id, | 101 int layer_id, |
| 185 int source_frame_number, | 102 int source_frame_number, |
| 186 int flags); | 103 int flags); |
| 187 | 104 |
| 188 scoped_ptr<base::Value> BasicStateAsValue() const; | 105 scoped_ptr<base::Value> BasicStateAsValue() const; |
| 189 scoped_ptr<base::Value> AllTilesAsValue() const; | 106 scoped_ptr<base::Value> AllTilesAsValue() const; |
| 190 const MemoryHistory::Entry& memory_stats_from_last_assign() const { | 107 const MemoryHistory::Entry& memory_stats_from_last_assign() const { |
| 191 return memory_stats_from_last_assign_; | 108 return memory_stats_from_last_assign_; |
| 192 } | 109 } |
| 193 | 110 |
| 194 void GetPairedPictureLayers(std::vector<PairedPictureLayer>* layers) const; | |
| 195 | |
| 196 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { | 111 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { |
| 197 for (size_t i = 0; i < tiles.size(); ++i) { | 112 for (size_t i = 0; i < tiles.size(); ++i) { |
| 198 ManagedTileState& mts = tiles[i]->managed_state(); | 113 ManagedTileState& mts = tiles[i]->managed_state(); |
| 199 ManagedTileState::TileVersion& tile_version = | 114 ManagedTileState::TileVersion& tile_version = |
| 200 mts.tile_versions[HIGH_QUALITY_RASTER_MODE]; | 115 mts.tile_versions[HIGH_QUALITY_RASTER_MODE]; |
| 201 | 116 |
| 202 tile_version.resource_ = resource_pool_->AcquireResource(gfx::Size(1, 1)); | 117 tile_version.resource_ = resource_pool_->AcquireResource(gfx::Size(1, 1)); |
| 203 | 118 |
| 204 bytes_releasable_ += BytesConsumedIfAllocated(tiles[i]); | 119 bytes_releasable_ += BytesConsumedIfAllocated(tiles[i]); |
| 205 ++resources_releasable_; | 120 ++resources_releasable_; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; | 249 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; |
| 335 | 250 |
| 336 UniqueNotifier ready_to_activate_check_notifier_; | 251 UniqueNotifier ready_to_activate_check_notifier_; |
| 337 | 252 |
| 338 DISALLOW_COPY_AND_ASSIGN(TileManager); | 253 DISALLOW_COPY_AND_ASSIGN(TileManager); |
| 339 }; | 254 }; |
| 340 | 255 |
| 341 } // namespace cc | 256 } // namespace cc |
| 342 | 257 |
| 343 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 258 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
| OLD | NEW |