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/resources/eviction_tile_priority_queue.h" | 20 #include "cc/layers/picture_layer_impl.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" | |
26 #include "cc/resources/rasterizer.h" | 25 #include "cc/resources/rasterizer.h" |
27 #include "cc/resources/resource_pool.h" | 26 #include "cc/resources/resource_pool.h" |
28 #include "cc/resources/tile.h" | 27 #include "cc/resources/tile.h" |
29 | 28 |
30 namespace cc { | 29 namespace cc { |
31 class PictureLayerImpl; | |
32 class ResourceProvider; | 30 class ResourceProvider; |
33 | 31 |
34 class CC_EXPORT TileManagerClient { | 32 class CC_EXPORT TileManagerClient { |
35 public: | 33 public: |
36 // Returns the set of layers that the tile manager should consider for raster. | 34 // Returns the set of layers that the tile manager should consider for raster. |
37 // TODO(vmpstr): Change the way we determine if we are ready to activate, so | 35 virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() = 0; |
38 // that this can be removed. | |
39 virtual const std::vector<PictureLayerImpl*>& GetPictureLayers() const = 0; | |
40 | 36 |
41 // Called when all tiles marked as required for activation are ready to draw. | 37 // Called when all tiles marked as required for activation are ready to draw. |
42 virtual void NotifyReadyToActivate() = 0; | 38 virtual void NotifyReadyToActivate() = 0; |
43 | 39 |
44 // Called when the visible representation of a tile might have changed. Some | 40 // Called when the visible representation of a tile might have changed. Some |
45 // examples are: | 41 // examples are: |
46 // - Tile version initialized. | 42 // - Tile version initialized. |
47 // - Tile resources freed. | 43 // - Tile resources freed. |
48 // - Tile marked for on-demand raster. | 44 // - Tile marked for on-demand raster. |
49 virtual void NotifyTileStateChanged(const Tile* tile) = 0; | 45 virtual void NotifyTileStateChanged(const Tile* tile) = 0; |
50 | 46 |
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 | |
63 protected: | 47 protected: |
64 virtual ~TileManagerClient() {} | 48 virtual ~TileManagerClient() {} |
65 }; | 49 }; |
66 | 50 |
67 struct RasterTaskCompletionStats { | 51 struct RasterTaskCompletionStats { |
68 RasterTaskCompletionStats(); | 52 RasterTaskCompletionStats(); |
69 | 53 |
70 size_t completed_count; | 54 size_t completed_count; |
71 size_t canceled_count; | 55 size_t canceled_count; |
72 }; | 56 }; |
73 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( | 57 scoped_ptr<base::Value> RasterTaskCompletionStatsAsValue( |
74 const RasterTaskCompletionStats& stats); | 58 const RasterTaskCompletionStats& stats); |
75 | 59 |
76 // This class manages tiles, deciding which should get rasterized and which | 60 // This class manages tiles, deciding which should get rasterized and which |
77 // should no longer have any memory assigned to them. Tile objects are "owned" | 61 // should no longer have any memory assigned to them. Tile objects are "owned" |
78 // by layers; they automatically register with the manager when they are | 62 // by layers; they automatically register with the manager when they are |
79 // created, and unregister from the manager when they are deleted. | 63 // created, and unregister from the manager when they are deleted. |
80 class CC_EXPORT TileManager : public RasterizerClient, | 64 class CC_EXPORT TileManager : public RasterizerClient, |
81 public RefCountedManager<Tile> { | 65 public RefCountedManager<Tile> { |
82 public: | 66 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 |
83 static scoped_ptr<TileManager> Create( | 166 static scoped_ptr<TileManager> Create( |
84 TileManagerClient* client, | 167 TileManagerClient* client, |
85 base::SequencedTaskRunner* task_runner, | 168 base::SequencedTaskRunner* task_runner, |
86 ResourcePool* resource_pool, | 169 ResourcePool* resource_pool, |
87 Rasterizer* rasterizer, | 170 Rasterizer* rasterizer, |
88 RenderingStatsInstrumentation* rendering_stats_instrumentation); | 171 RenderingStatsInstrumentation* rendering_stats_instrumentation); |
89 virtual ~TileManager(); | 172 virtual ~TileManager(); |
90 | 173 |
91 void ManageTiles(const GlobalStateThatImpactsTilePriority& state); | 174 void ManageTiles(const GlobalStateThatImpactsTilePriority& state); |
92 | 175 |
93 // Returns true when visible tiles have been initialized. | 176 // Returns true when visible tiles have been initialized. |
94 bool UpdateVisibleTiles(); | 177 bool UpdateVisibleTiles(); |
95 | 178 |
96 scoped_refptr<Tile> CreateTile(PicturePileImpl* picture_pile, | 179 scoped_refptr<Tile> CreateTile(PicturePileImpl* picture_pile, |
97 const gfx::Size& tile_size, | 180 const gfx::Size& tile_size, |
98 const gfx::Rect& content_rect, | 181 const gfx::Rect& content_rect, |
99 const gfx::Rect& opaque_rect, | 182 const gfx::Rect& opaque_rect, |
100 float contents_scale, | 183 float contents_scale, |
101 int layer_id, | 184 int layer_id, |
102 int source_frame_number, | 185 int source_frame_number, |
103 int flags); | 186 int flags); |
104 | 187 |
105 scoped_ptr<base::Value> BasicStateAsValue() const; | 188 scoped_ptr<base::Value> BasicStateAsValue() const; |
106 scoped_ptr<base::Value> AllTilesAsValue() const; | 189 scoped_ptr<base::Value> AllTilesAsValue() const; |
107 const MemoryHistory::Entry& memory_stats_from_last_assign() const { | 190 const MemoryHistory::Entry& memory_stats_from_last_assign() const { |
108 return memory_stats_from_last_assign_; | 191 return memory_stats_from_last_assign_; |
109 } | 192 } |
110 | 193 |
| 194 void GetPairedPictureLayers(std::vector<PairedPictureLayer>* layers) const; |
| 195 |
111 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { | 196 void InitializeTilesWithResourcesForTesting(const std::vector<Tile*>& tiles) { |
112 for (size_t i = 0; i < tiles.size(); ++i) { | 197 for (size_t i = 0; i < tiles.size(); ++i) { |
113 ManagedTileState& mts = tiles[i]->managed_state(); | 198 ManagedTileState& mts = tiles[i]->managed_state(); |
114 ManagedTileState::TileVersion& tile_version = | 199 ManagedTileState::TileVersion& tile_version = |
115 mts.tile_versions[HIGH_QUALITY_RASTER_MODE]; | 200 mts.tile_versions[HIGH_QUALITY_RASTER_MODE]; |
116 | 201 |
117 tile_version.resource_ = resource_pool_->AcquireResource(gfx::Size(1, 1)); | 202 tile_version.resource_ = resource_pool_->AcquireResource(gfx::Size(1, 1)); |
118 | 203 |
119 bytes_releasable_ += BytesConsumedIfAllocated(tiles[i]); | 204 bytes_releasable_ += BytesConsumedIfAllocated(tiles[i]); |
120 ++resources_releasable_; | 205 ++resources_releasable_; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; | 334 std::vector<scoped_refptr<RasterTask> > orphan_raster_tasks_; |
250 | 335 |
251 UniqueNotifier ready_to_activate_check_notifier_; | 336 UniqueNotifier ready_to_activate_check_notifier_; |
252 | 337 |
253 DISALLOW_COPY_AND_ASSIGN(TileManager); | 338 DISALLOW_COPY_AND_ASSIGN(TileManager); |
254 }; | 339 }; |
255 | 340 |
256 } // namespace cc | 341 } // namespace cc |
257 | 342 |
258 #endif // CC_RESOURCES_TILE_MANAGER_H_ | 343 #endif // CC_RESOURCES_TILE_MANAGER_H_ |
OLD | NEW |