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