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_PICTURE_LAYER_TILING_H_ | 5 #ifndef CC_RESOURCES_PICTURE_LAYER_TILING_H_ |
6 #define CC_RESOURCES_PICTURE_LAYER_TILING_H_ | 6 #define CC_RESOURCES_PICTURE_LAYER_TILING_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 scoped_refptr<RasterSource> raster_source, | 70 scoped_refptr<RasterSource> raster_source, |
71 PictureLayerTilingClient* client, | 71 PictureLayerTilingClient* client, |
72 size_t max_tiles_for_interest_area, | 72 size_t max_tiles_for_interest_area, |
73 float skewport_target_time_in_seconds, | 73 float skewport_target_time_in_seconds, |
74 int skewport_extrapolation_limit_in_content_pixels); | 74 int skewport_extrapolation_limit_in_content_pixels); |
75 | 75 |
76 void SetRasterSourceAndResize(scoped_refptr<RasterSource> raster_source); | 76 void SetRasterSourceAndResize(scoped_refptr<RasterSource> raster_source); |
77 void Invalidate(const Region& layer_invalidation); | 77 void Invalidate(const Region& layer_invalidation); |
78 void SetRasterSourceOnTiles(); | 78 void SetRasterSourceOnTiles(); |
79 void CreateMissingTilesInLiveTilesRect(); | 79 void CreateMissingTilesInLiveTilesRect(); |
80 void TakeTilesAndPropertiesFrom(PictureLayerTiling* pending_twin); | |
80 | 81 |
81 void CloneTilesAndPropertiesFrom(const PictureLayerTiling& twin_tiling); | 82 bool IsTileRequiredForActivation(const Tile* tile) const; |
83 bool IsTileRequiredForDraw(const Tile* tile) const; | |
82 | 84 |
83 void set_resolution(TileResolution resolution) { resolution_ = resolution; } | 85 void set_resolution(TileResolution resolution) { resolution_ = resolution; } |
84 TileResolution resolution() const { return resolution_; } | 86 TileResolution resolution() const { return resolution_; } |
85 void set_can_require_tiles_for_activation(bool can_require_tiles) { | 87 void set_can_require_tiles_for_activation(bool can_require_tiles) { |
86 can_require_tiles_for_activation_ = can_require_tiles; | 88 can_require_tiles_for_activation_ = can_require_tiles; |
87 } | 89 } |
88 | 90 |
89 RasterSource* raster_source() const { return raster_source_.get(); } | 91 RasterSource* raster_source() const { return raster_source_.get(); } |
90 gfx::Size tiling_size() const { return tiling_data_.tiling_size(); } | 92 gfx::Size tiling_size() const { return tiling_data_.tiling_size(); } |
91 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } | 93 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } |
92 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } | 94 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } |
93 float contents_scale() const { return contents_scale_; } | 95 float contents_scale() const { return contents_scale_; } |
94 const TilingData* tiling_data() const { return &tiling_data_; } | 96 const TilingData* tiling_data() const { return &tiling_data_; } |
95 | 97 |
96 Tile* TileAt(int i, int j) const { | 98 Tile* TileAt(int i, int j) const { |
97 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); | 99 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); |
98 return (iter == tiles_.end()) ? NULL : iter->second.get(); | 100 return iter == tiles_.end() ? nullptr : iter->second.get(); |
99 } | 101 } |
100 | 102 |
103 // For testing functionality. | |
101 void CreateAllTilesForTesting() { | 104 void CreateAllTilesForTesting() { |
102 SetLiveTilesRect(gfx::Rect(tiling_data_.tiling_size())); | 105 SetLiveTilesRect(gfx::Rect(tiling_data_.tiling_size())); |
103 } | 106 } |
104 | |
105 const TilingData& TilingDataForTesting() const { return tiling_data_; } | 107 const TilingData& TilingDataForTesting() const { return tiling_data_; } |
106 | |
107 std::vector<Tile*> AllTilesForTesting() const { | 108 std::vector<Tile*> AllTilesForTesting() const { |
108 std::vector<Tile*> all_tiles; | 109 std::vector<Tile*> all_tiles; |
109 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 110 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
110 all_tiles.push_back(it->second.get()); | 111 all_tiles.push_back(it->second.get()); |
111 return all_tiles; | 112 return all_tiles; |
112 } | 113 } |
113 | |
114 void UpdateAllTilePrioritiesForTesting() { | 114 void UpdateAllTilePrioritiesForTesting() { |
115 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 115 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
116 UpdateTileAndTwinPriority(it->second.get()); | 116 UpdateTileAndTwinPriority(it->second.get()); |
117 } | 117 } |
118 | |
119 std::vector<scoped_refptr<Tile>> AllRefTilesForTesting() const { | 118 std::vector<scoped_refptr<Tile>> AllRefTilesForTesting() const { |
120 std::vector<scoped_refptr<Tile>> all_tiles; | 119 std::vector<scoped_refptr<Tile>> all_tiles; |
121 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 120 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
122 all_tiles.push_back(it->second); | 121 all_tiles.push_back(it->second); |
123 return all_tiles; | 122 return all_tiles; |
124 } | 123 } |
125 | |
126 void SetAllTilesOccludedForTesting() { | 124 void SetAllTilesOccludedForTesting() { |
127 gfx::Rect viewport_in_layer_space = | 125 gfx::Rect viewport_in_layer_space = |
128 ScaleToEnclosingRect(current_visible_rect_, 1.0f / contents_scale_); | 126 ScaleToEnclosingRect(current_visible_rect_, 1.0f / contents_scale_); |
129 current_occlusion_in_layer_space_ = | 127 current_occlusion_in_layer_space_ = |
130 Occlusion(gfx::Transform(), | 128 Occlusion(gfx::Transform(), |
131 SimpleEnclosedRegion(viewport_in_layer_space), | 129 SimpleEnclosedRegion(viewport_in_layer_space), |
132 SimpleEnclosedRegion(viewport_in_layer_space)); | 130 SimpleEnclosedRegion(viewport_in_layer_space)); |
133 } | 131 } |
134 | |
135 const gfx::Rect& GetCurrentVisibleRectForTesting() const { | 132 const gfx::Rect& GetCurrentVisibleRectForTesting() const { |
136 return current_visible_rect_; | 133 return current_visible_rect_; |
137 } | 134 } |
138 | 135 |
139 bool IsTileOccluded(const Tile* tile) const; | |
140 bool IsTileRequiredForActivationIfVisible(const Tile* tile) const; | |
141 bool IsTileRequiredForDrawIfVisible(const Tile* tile) const; | |
142 | |
143 void UpdateTileAndTwinPriority(Tile* tile) const; | |
144 TilePriority ComputePriorityForTile(const Tile* tile) const; | |
145 void UpdateRequiredStateForTile(Tile* tile, WhichTree tree) const; | |
146 bool has_visible_rect_tiles() const { return has_visible_rect_tiles_; } | |
147 bool has_skewport_rect_tiles() const { return has_skewport_rect_tiles_; } | |
148 bool has_soon_border_rect_tiles() const { | |
149 return has_soon_border_rect_tiles_; | |
150 } | |
151 bool has_eventually_rect_tiles() const { return has_eventually_rect_tiles_; } | |
152 | |
153 const gfx::Rect& current_visible_rect() const { | |
154 return current_visible_rect_; | |
155 } | |
156 const gfx::Rect& current_skewport_rect() const { | |
157 return current_skewport_rect_; | |
158 } | |
159 const gfx::Rect& current_soon_border_rect() const { | |
160 return current_soon_border_rect_; | |
161 } | |
162 const gfx::Rect& current_eventually_rect() const { | |
163 return current_eventually_rect_; | |
164 } | |
165 void VerifyAllTilesHaveCurrentRasterSource() const; | 136 void VerifyAllTilesHaveCurrentRasterSource() const; |
166 | 137 |
167 // Iterate over all tiles to fill content_rect. Even if tiles are invalid | 138 // Iterate over all tiles to fill content_rect. Even if tiles are invalid |
168 // (i.e. no valid resource) this tiling should still iterate over them. | 139 // (i.e. no valid resource) this tiling should still iterate over them. |
169 // The union of all geometry_rect calls for each element iterated over should | 140 // The union of all geometry_rect calls for each element iterated over should |
170 // exactly equal content_rect and no two geometry_rects should intersect. | 141 // exactly equal content_rect and no two geometry_rects should intersect. |
171 class CC_EXPORT CoverageIterator { | 142 class CC_EXPORT CoverageIterator { |
172 public: | 143 public: |
173 CoverageIterator(); | 144 CoverageIterator(); |
174 CoverageIterator(const PictureLayerTiling* tiling, | 145 CoverageIterator(const PictureLayerTiling* tiling, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
229 int64 previous_target; | 200 int64 previous_target; |
230 }; | 201 }; |
231 | 202 |
232 static | 203 static |
233 gfx::Rect ExpandRectEquallyToAreaBoundedBy( | 204 gfx::Rect ExpandRectEquallyToAreaBoundedBy( |
234 const gfx::Rect& starting_rect, | 205 const gfx::Rect& starting_rect, |
235 int64 target_area, | 206 int64 target_area, |
236 const gfx::Rect& bounding_rect, | 207 const gfx::Rect& bounding_rect, |
237 RectExpansionCache* cache); | 208 RectExpansionCache* cache); |
238 | 209 |
239 bool has_ever_been_updated() const { | |
240 return visible_rect_history_[0].frame_time_in_seconds != 0.0; | |
241 } | |
242 | |
243 protected: | 210 protected: |
244 friend class CoverageIterator; | 211 friend class CoverageIterator; |
245 friend class TilingSetRasterQueueAll; | 212 friend class TilingSetRasterQueueAll; |
246 friend class TilingSetRasterQueueRequired; | 213 friend class TilingSetRasterQueueRequired; |
247 friend class TilingSetEvictionQueue; | 214 friend class TilingSetEvictionQueue; |
248 | 215 |
249 typedef std::pair<int, int> TileMapKey; | 216 typedef std::pair<int, int> TileMapKey; |
250 typedef base::hash_map<TileMapKey, scoped_refptr<Tile>> TileMap; | 217 typedef base::hash_map<TileMapKey, scoped_refptr<Tile>> TileMap; |
251 | 218 |
252 struct FrameVisibleRect { | 219 struct FrameVisibleRect { |
253 gfx::Rect visible_rect_in_content_space; | 220 gfx::Rect visible_rect_in_content_space; |
254 double frame_time_in_seconds = 0.0; | 221 double frame_time_in_seconds = 0.0; |
255 }; | 222 }; |
256 | 223 |
257 PictureLayerTiling(float contents_scale, | 224 PictureLayerTiling(float contents_scale, |
258 scoped_refptr<RasterSource> raster_source, | 225 scoped_refptr<RasterSource> raster_source, |
259 PictureLayerTilingClient* client, | 226 PictureLayerTilingClient* client, |
260 size_t max_tiles_for_interest_area, | 227 size_t max_tiles_for_interest_area, |
261 float skewport_target_time_in_seconds, | 228 float skewport_target_time_in_seconds, |
262 int skewport_extrapolation_limit_in_content_pixels); | 229 int skewport_extrapolation_limit_in_content_pixels); |
263 void SetLiveTilesRect(const gfx::Rect& live_tiles_rect); | 230 void SetLiveTilesRect(const gfx::Rect& live_tiles_rect); |
264 void VerifyLiveTilesRect(bool is_on_recycle_tree) const; | 231 void VerifyLiveTilesRect(bool is_on_recycle_tree) const; |
265 Tile* CreateTile(int i, | 232 Tile* CreateTile(int i, int j); |
266 int j, | |
267 const PictureLayerTiling* twin_tiling, | |
268 PictureLayerTiling* recycled_twin); | |
269 // Returns true if the Tile existed and was removed from the tiling. | 233 // Returns true if the Tile existed and was removed from the tiling. |
270 bool RemoveTileAt(int i, int j, PictureLayerTiling* recycled_twin); | 234 bool RemoveTileAt(int i, int j); |
235 bool TilingMatchesTileIndices(const PictureLayerTiling* twin) const; | |
271 | 236 |
272 // Computes a skewport. The calculation extrapolates the last visible | 237 // Computes a skewport. The calculation extrapolates the last visible |
273 // rect and the current visible rect to expand the skewport to where it | 238 // rect and the current visible rect to expand the skewport to where it |
274 // would be in |skewport_target_time| seconds. Note that the skewport | 239 // would be in |skewport_target_time| seconds. Note that the skewport |
275 // is guaranteed to contain the current visible rect. | 240 // is guaranteed to contain the current visible rect. |
276 gfx::Rect ComputeSkewport(double current_frame_time_in_seconds, | 241 gfx::Rect ComputeSkewport(double current_frame_time_in_seconds, |
277 const gfx::Rect& visible_rect_in_content_space) | 242 const gfx::Rect& visible_rect_in_content_space) |
278 const; | 243 const; |
279 | 244 |
280 // Save the required data for computing tile priorities later. | 245 // Save the required data for computing tile priorities later. |
281 void UpdateTilePriorityRects(float content_to_screen_scale_, | 246 void SetTilePriorityRects(float content_to_screen_scale_, |
282 const gfx::Rect& visible_rect_in_content_space, | 247 const gfx::Rect& visible_rect_in_content_space, |
283 const gfx::Rect& skewport, | 248 const gfx::Rect& skewport, |
284 const gfx::Rect& soon_border_rect, | 249 const gfx::Rect& soon_border_rect, |
285 const gfx::Rect& eventually_rect, | 250 const gfx::Rect& eventually_rect, |
286 const Occlusion& occlusion_in_layer_space); | 251 const Occlusion& occlusion_in_layer_space); |
287 | 252 |
288 void UpdateTilePriorityForTree(Tile* tile, WhichTree tree) const; | 253 void UpdateTilePriorityForTree(Tile* tile, WhichTree tree) const; |
289 bool NeedsUpdateForFrameAtTimeAndViewport( | 254 bool NeedsUpdateForFrameAtTimeAndViewport( |
290 double frame_time_in_seconds, | 255 double frame_time_in_seconds, |
291 const gfx::Rect& viewport_in_layer_space) { | 256 const gfx::Rect& viewport_in_layer_space) { |
292 return frame_time_in_seconds != | 257 return frame_time_in_seconds != |
293 visible_rect_history_[0].frame_time_in_seconds || | 258 visible_rect_history_[0].frame_time_in_seconds || |
294 viewport_in_layer_space != last_viewport_in_layer_space_; | 259 viewport_in_layer_space != last_viewport_in_layer_space_; |
295 } | 260 } |
296 void UpdateVisibleRectHistory( | 261 void UpdateVisibleRectHistory( |
297 double frame_time_in_seconds, | 262 double frame_time_in_seconds, |
298 const gfx::Rect& visible_rect_in_content_space) { | 263 const gfx::Rect& visible_rect_in_content_space) { |
299 visible_rect_history_[1] = visible_rect_history_[0]; | 264 visible_rect_history_[1] = visible_rect_history_[0]; |
300 visible_rect_history_[0].frame_time_in_seconds = frame_time_in_seconds; | 265 visible_rect_history_[0].frame_time_in_seconds = frame_time_in_seconds; |
301 visible_rect_history_[0].visible_rect_in_content_space = | 266 visible_rect_history_[0].visible_rect_in_content_space = |
302 visible_rect_in_content_space; | 267 visible_rect_in_content_space; |
303 // If we don't have a second history item, set it to the most recent one. | 268 // If we don't have a second history item, set it to the most recent one. |
304 if (visible_rect_history_[1].frame_time_in_seconds == 0.0) | 269 if (visible_rect_history_[1].frame_time_in_seconds == 0.0) |
305 visible_rect_history_[1] = visible_rect_history_[0]; | 270 visible_rect_history_[1] = visible_rect_history_[0]; |
306 } | 271 } |
272 bool IsTileOccludedOnCurrentTree(const Tile* tile) const; | |
273 bool ShouldCreateTileAt(int i, int j) const; | |
274 bool IsTileOccluded(const Tile* tile) const; | |
275 void UpdateTileAndTwinPriority(Tile* tile) const; | |
276 TilePriority ComputePriorityForTile(const Tile* tile) const; | |
277 bool has_visible_rect_tiles() const { return has_visible_rect_tiles_; } | |
278 bool has_skewport_rect_tiles() const { return has_skewport_rect_tiles_; } | |
279 bool has_soon_border_rect_tiles() const { | |
280 return has_soon_border_rect_tiles_; | |
281 } | |
282 bool has_eventually_rect_tiles() const { return has_eventually_rect_tiles_; } | |
283 | |
284 const gfx::Rect& current_visible_rect() const { | |
285 return current_visible_rect_; | |
286 } | |
287 const gfx::Rect& pending_visible_rect() const { | |
288 const PictureLayerTiling* twin = | |
enne (OOO)
2015/04/13 22:36:02
This needs a serious comment. It's still hard to
vmpstr
2015/04/13 23:52:13
Well... to be fair, it doesn't just happen, it was
| |
289 client_->GetTree() == ACTIVE_TREE | |
290 ? client_->GetPendingOrActiveTwinTiling(this) | |
291 : this; | |
292 if (twin) | |
293 return twin->current_visible_rect(); | |
294 return current_visible_rect(); | |
295 } | |
296 const gfx::Rect& current_skewport_rect() const { | |
297 return current_skewport_rect_; | |
298 } | |
299 const gfx::Rect& current_soon_border_rect() const { | |
300 return current_soon_border_rect_; | |
301 } | |
302 const gfx::Rect& current_eventually_rect() const { | |
303 return current_eventually_rect_; | |
304 } | |
305 bool has_ever_been_updated() const { | |
306 return visible_rect_history_[0].frame_time_in_seconds != 0.0; | |
307 } | |
307 | 308 |
308 const size_t max_tiles_for_interest_area_; | 309 const size_t max_tiles_for_interest_area_; |
309 const float skewport_target_time_in_seconds_; | 310 const float skewport_target_time_in_seconds_; |
310 const int skewport_extrapolation_limit_in_content_pixels_; | 311 const int skewport_extrapolation_limit_in_content_pixels_; |
311 | 312 |
312 // Given properties. | 313 // Given properties. |
313 const float contents_scale_; | 314 const float contents_scale_; |
314 PictureLayerTilingClient* const client_; | 315 PictureLayerTilingClient* const client_; |
315 scoped_refptr<RasterSource> raster_source_; | 316 scoped_refptr<RasterSource> raster_source_; |
316 TileResolution resolution_; | 317 TileResolution resolution_; |
(...skipping 25 matching lines...) Expand all Loading... | |
342 | 343 |
343 private: | 344 private: |
344 DISALLOW_ASSIGN(PictureLayerTiling); | 345 DISALLOW_ASSIGN(PictureLayerTiling); |
345 | 346 |
346 RectExpansionCache expansion_cache_; | 347 RectExpansionCache expansion_cache_; |
347 }; | 348 }; |
348 | 349 |
349 } // namespace cc | 350 } // namespace cc |
350 | 351 |
351 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ | 352 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ |
OLD | NEW |