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_TILES_PICTURE_LAYER_TILING_H_ | 5 #ifndef CC_TILES_PICTURE_LAYER_TILING_H_ |
6 #define CC_TILES_PICTURE_LAYER_TILING_H_ | 6 #define CC_TILES_PICTURE_LAYER_TILING_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 uint16_t value2 = static_cast<uint16_t>(key.index_y); | 73 uint16_t value2 = static_cast<uint16_t>(key.index_y); |
74 uint32_t value1_32 = value1; | 74 uint32_t value1_32 = value1; |
75 return (value1_32 << 16) | value2; | 75 return (value1_32 << 16) | value2; |
76 } | 76 } |
77 }; | 77 }; |
78 | 78 |
79 class CC_EXPORT PictureLayerTiling { | 79 class CC_EXPORT PictureLayerTiling { |
80 public: | 80 public: |
81 static const int kBorderTexels = 1; | 81 static const int kBorderTexels = 1; |
82 | 82 |
83 PictureLayerTilingClient* client() const { return client_; } | 83 PictureLayerTiling(WhichTree tree, |
| 84 float contents_scale, |
| 85 scoped_refptr<RasterSource> raster_source, |
| 86 PictureLayerTilingClient* client); |
84 ~PictureLayerTiling(); | 87 ~PictureLayerTiling(); |
85 | 88 |
86 static float CalculateSoonBorderDistance( | 89 PictureLayerTilingClient* client() const { return client_; } |
87 const gfx::Rect& visible_rect_in_content_space, | |
88 float content_to_screen_scale); | |
89 | |
90 // Create a tiling with no tiles. CreateTile() must be called to add some. | |
91 static std::unique_ptr<PictureLayerTiling> Create( | |
92 WhichTree tree, | |
93 float contents_scale, | |
94 scoped_refptr<RasterSource> raster_source, | |
95 PictureLayerTilingClient* client, | |
96 size_t tiling_interest_area_padding, | |
97 float skewport_target_time_in_seconds, | |
98 int skewport_extrapolation_limit_in_content_pixels); | |
99 | 90 |
100 void SetRasterSourceAndResize(scoped_refptr<RasterSource> raster_source); | 91 void SetRasterSourceAndResize(scoped_refptr<RasterSource> raster_source); |
101 void Invalidate(const Region& layer_invalidation); | 92 void Invalidate(const Region& layer_invalidation); |
102 void CreateMissingTilesInLiveTilesRect(); | 93 void CreateMissingTilesInLiveTilesRect(); |
103 void TakeTilesAndPropertiesFrom(PictureLayerTiling* pending_twin, | 94 void TakeTilesAndPropertiesFrom(PictureLayerTiling* pending_twin, |
104 const Region& layer_invalidation); | 95 const Region& layer_invalidation); |
105 | 96 |
106 bool IsTileRequiredForActivation(const Tile* tile) const; | 97 bool IsTileRequiredForActivation(const Tile* tile) const; |
107 bool IsTileRequiredForDraw(const Tile* tile) const; | 98 bool IsTileRequiredForDraw(const Tile* tile) const; |
108 | 99 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 int left_; | 220 int left_; |
230 int top_; | 221 int top_; |
231 int right_; | 222 int right_; |
232 int bottom_; | 223 int bottom_; |
233 | 224 |
234 friend class PictureLayerTiling; | 225 friend class PictureLayerTiling; |
235 }; | 226 }; |
236 | 227 |
237 void Reset(); | 228 void Reset(); |
238 | 229 |
239 bool ComputeTilePriorityRects(const gfx::Rect& viewport_in_layer_space, | 230 void ComputeTilePriorityRects( |
240 float ideal_contents_scale, | 231 const gfx::Rect& visible_rect_in_layer_space, |
241 double current_frame_time_in_seconds, | 232 const gfx::Rect& skewport_in_layer_space, |
242 const Occlusion& occlusion_in_layer_space); | 233 const gfx::Rect& soon_border_rect_in_layer_space, |
| 234 const gfx::Rect& eventually_rect_in_layer_space, |
| 235 float ideal_contents_scale, |
| 236 const Occlusion& occlusion_in_layer_space); |
243 | 237 |
244 void GetAllPrioritizedTilesForTracing( | 238 void GetAllPrioritizedTilesForTracing( |
245 std::vector<PrioritizedTile>* prioritized_tiles) const; | 239 std::vector<PrioritizedTile>* prioritized_tiles) const; |
246 void AsValueInto(base::trace_event::TracedValue* array) const; | 240 void AsValueInto(base::trace_event::TracedValue* array) const; |
247 size_t GPUMemoryUsageInBytes() const; | 241 size_t GPUMemoryUsageInBytes() const; |
248 | 242 |
249 protected: | 243 protected: |
250 friend class CoverageIterator; | 244 friend class CoverageIterator; |
251 friend class PrioritizedTile; | 245 friend class PrioritizedTile; |
252 friend class TilingSetRasterQueueAll; | 246 friend class TilingSetRasterQueueAll; |
253 friend class TilingSetRasterQueueRequired; | 247 friend class TilingSetRasterQueueRequired; |
254 friend class TilingSetEvictionQueue; | 248 friend class TilingSetEvictionQueue; |
255 | 249 |
256 // PENDING VISIBLE RECT refers to the visible rect that will become current | 250 // PENDING VISIBLE RECT refers to the visible rect that will become current |
257 // upon activation (ie, the pending tree's visible rect). Tiles in this | 251 // upon activation (ie, the pending tree's visible rect). Tiles in this |
258 // region that are not part of the current visible rect are all handled | 252 // region that are not part of the current visible rect are all handled |
259 // here. Note that when processing a pending tree, this rect is the same as | 253 // here. Note that when processing a pending tree, this rect is the same as |
260 // the visible rect so no tiles are processed in this case. | 254 // the visible rect so no tiles are processed in this case. |
261 enum PriorityRectType { | 255 enum PriorityRectType { |
262 VISIBLE_RECT, | 256 VISIBLE_RECT, |
263 PENDING_VISIBLE_RECT, | 257 PENDING_VISIBLE_RECT, |
264 SKEWPORT_RECT, | 258 SKEWPORT_RECT, |
265 SOON_BORDER_RECT, | 259 SOON_BORDER_RECT, |
266 EVENTUALLY_RECT | 260 EVENTUALLY_RECT |
267 }; | 261 }; |
268 | 262 |
269 using TileMap = std::unordered_map<TileMapKey, ScopedTilePtr, TileMapKeyHash>; | 263 using TileMap = std::unordered_map<TileMapKey, ScopedTilePtr, TileMapKeyHash>; |
270 | 264 |
271 struct FrameVisibleRect { | |
272 gfx::Rect visible_rect_in_content_space; | |
273 double frame_time_in_seconds = 0.0; | |
274 }; | |
275 | |
276 PictureLayerTiling(WhichTree tree, | |
277 float contents_scale, | |
278 scoped_refptr<RasterSource> raster_source, | |
279 PictureLayerTilingClient* client, | |
280 size_t tiling_interest_area_padding, | |
281 float skewport_target_time_in_seconds, | |
282 int skewport_extrapolation_limit_in_content_pixels); | |
283 void SetLiveTilesRect(const gfx::Rect& live_tiles_rect); | 265 void SetLiveTilesRect(const gfx::Rect& live_tiles_rect); |
284 void VerifyLiveTilesRect(bool is_on_recycle_tree) const; | 266 void VerifyLiveTilesRect(bool is_on_recycle_tree) const; |
285 Tile* CreateTile(const Tile::CreateInfo& info); | 267 Tile* CreateTile(const Tile::CreateInfo& info); |
286 ScopedTilePtr TakeTileAt(int i, int j); | 268 ScopedTilePtr TakeTileAt(int i, int j); |
287 // Returns true if the Tile existed and was removed from the tiling. | 269 // Returns true if the Tile existed and was removed from the tiling. |
288 bool RemoveTileAt(int i, int j); | 270 bool RemoveTileAt(int i, int j); |
289 bool TilingMatchesTileIndices(const PictureLayerTiling* twin) const; | 271 bool TilingMatchesTileIndices(const PictureLayerTiling* twin) const; |
290 | 272 |
291 // Computes a skewport. The calculation extrapolates the last visible | |
292 // rect and the current visible rect to expand the skewport to where it | |
293 // would be in |skewport_target_time| seconds. Note that the skewport | |
294 // is guaranteed to contain the current visible rect. | |
295 gfx::Rect ComputeSkewport(double current_frame_time_in_seconds, | |
296 const gfx::Rect& visible_rect_in_content_space) | |
297 const; | |
298 | |
299 // Save the required data for computing tile priorities later. | 273 // Save the required data for computing tile priorities later. |
300 void SetTilePriorityRects(float content_to_screen_scale_, | 274 void SetTilePriorityRects(float content_to_screen_scale_, |
301 const gfx::Rect& visible_rect_in_content_space, | 275 const gfx::Rect& visible_rect_in_content_space, |
302 const gfx::Rect& skewport, | 276 const gfx::Rect& skewport, |
303 const gfx::Rect& soon_border_rect, | 277 const gfx::Rect& soon_border_rect, |
304 const gfx::Rect& eventually_rect, | 278 const gfx::Rect& eventually_rect, |
305 const Occlusion& occlusion_in_layer_space); | 279 const Occlusion& occlusion_in_layer_space); |
306 | 280 |
307 bool NeedsUpdateForFrameAtTimeAndViewport( | |
308 double frame_time_in_seconds, | |
309 const gfx::Rect& viewport_in_layer_space) { | |
310 return frame_time_in_seconds != | |
311 visible_rect_history_[0].frame_time_in_seconds || | |
312 viewport_in_layer_space != last_viewport_in_layer_space_; | |
313 } | |
314 void UpdateVisibleRectHistory( | |
315 double frame_time_in_seconds, | |
316 const gfx::Rect& visible_rect_in_content_space) { | |
317 visible_rect_history_[1] = visible_rect_history_[0]; | |
318 visible_rect_history_[0].frame_time_in_seconds = frame_time_in_seconds; | |
319 visible_rect_history_[0].visible_rect_in_content_space = | |
320 visible_rect_in_content_space; | |
321 // If we don't have a second history item, set it to the most recent one. | |
322 if (visible_rect_history_[1].frame_time_in_seconds == 0.0) | |
323 visible_rect_history_[1] = visible_rect_history_[0]; | |
324 } | |
325 bool IsTileOccludedOnCurrentTree(const Tile* tile) const; | 281 bool IsTileOccludedOnCurrentTree(const Tile* tile) const; |
326 Tile::CreateInfo CreateInfoForTile(int i, int j) const; | 282 Tile::CreateInfo CreateInfoForTile(int i, int j) const; |
327 bool ShouldCreateTileAt(const Tile::CreateInfo& info) const; | 283 bool ShouldCreateTileAt(const Tile::CreateInfo& info) const; |
328 bool IsTileOccluded(const Tile* tile) const; | 284 bool IsTileOccluded(const Tile* tile) const; |
329 void UpdateRequiredStatesOnTile(Tile* tile) const; | 285 void UpdateRequiredStatesOnTile(Tile* tile) const; |
330 PrioritizedTile MakePrioritizedTile( | 286 PrioritizedTile MakePrioritizedTile( |
331 Tile* tile, | 287 Tile* tile, |
332 PriorityRectType priority_rect_type) const; | 288 PriorityRectType priority_rect_type) const; |
333 TilePriority ComputePriorityForTile( | 289 TilePriority ComputePriorityForTile( |
334 const Tile* tile, | 290 const Tile* tile, |
(...skipping 19 matching lines...) Expand all Loading... |
354 } | 310 } |
355 const gfx::Rect& current_skewport_rect() const { | 311 const gfx::Rect& current_skewport_rect() const { |
356 return current_skewport_rect_; | 312 return current_skewport_rect_; |
357 } | 313 } |
358 const gfx::Rect& current_soon_border_rect() const { | 314 const gfx::Rect& current_soon_border_rect() const { |
359 return current_soon_border_rect_; | 315 return current_soon_border_rect_; |
360 } | 316 } |
361 const gfx::Rect& current_eventually_rect() const { | 317 const gfx::Rect& current_eventually_rect() const { |
362 return current_eventually_rect_; | 318 return current_eventually_rect_; |
363 } | 319 } |
364 bool has_ever_been_updated() const { | |
365 return visible_rect_history_[0].frame_time_in_seconds != 0.0; | |
366 } | |
367 void RemoveTilesInRegion(const Region& layer_region, bool recreate_tiles); | 320 void RemoveTilesInRegion(const Region& layer_region, bool recreate_tiles); |
368 | 321 |
369 const size_t tiling_interest_area_padding_; | |
370 const float skewport_target_time_in_seconds_; | |
371 const int skewport_extrapolation_limit_in_content_pixels_; | |
372 | |
373 // Given properties. | 322 // Given properties. |
374 const float contents_scale_; | 323 const float contents_scale_; |
375 PictureLayerTilingClient* const client_; | 324 PictureLayerTilingClient* const client_; |
376 const WhichTree tree_; | 325 const WhichTree tree_; |
377 scoped_refptr<RasterSource> raster_source_; | 326 scoped_refptr<RasterSource> raster_source_; |
378 TileResolution resolution_; | 327 TileResolution resolution_; |
379 bool may_contain_low_resolution_tiles_; | 328 bool may_contain_low_resolution_tiles_; |
380 | 329 |
381 // Internal data. | 330 // Internal data. |
382 TilingData tiling_data_; | 331 TilingData tiling_data_; |
383 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map. | 332 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map. |
384 gfx::Rect live_tiles_rect_; | 333 gfx::Rect live_tiles_rect_; |
385 | 334 |
386 gfx::Rect last_viewport_in_layer_space_; | |
387 // State saved for computing velocities based upon finite differences. | |
388 FrameVisibleRect visible_rect_history_[2]; | |
389 | |
390 bool can_require_tiles_for_activation_; | 335 bool can_require_tiles_for_activation_; |
391 | 336 |
392 // Iteration rects in content space. | 337 // Iteration rects in content space. |
393 gfx::Rect current_visible_rect_; | 338 gfx::Rect current_visible_rect_; |
394 gfx::Rect current_skewport_rect_; | 339 gfx::Rect current_skewport_rect_; |
395 gfx::Rect current_soon_border_rect_; | 340 gfx::Rect current_soon_border_rect_; |
396 gfx::Rect current_eventually_rect_; | 341 gfx::Rect current_eventually_rect_; |
397 // Other properties used for tile iteration and prioritization. | 342 // Other properties used for tile iteration and prioritization. |
398 float current_content_to_screen_scale_; | 343 float current_content_to_screen_scale_; |
399 Occlusion current_occlusion_in_layer_space_; | 344 Occlusion current_occlusion_in_layer_space_; |
400 | 345 |
401 bool has_visible_rect_tiles_; | 346 bool has_visible_rect_tiles_; |
402 bool has_skewport_rect_tiles_; | 347 bool has_skewport_rect_tiles_; |
403 bool has_soon_border_rect_tiles_; | 348 bool has_soon_border_rect_tiles_; |
404 bool has_eventually_rect_tiles_; | 349 bool has_eventually_rect_tiles_; |
405 bool all_tiles_done_; | 350 bool all_tiles_done_; |
406 bool invalidated_since_last_compute_priority_rects_; | |
407 | 351 |
408 private: | 352 private: |
409 DISALLOW_COPY_AND_ASSIGN(PictureLayerTiling); | 353 DISALLOW_COPY_AND_ASSIGN(PictureLayerTiling); |
410 }; | 354 }; |
411 | 355 |
412 } // namespace cc | 356 } // namespace cc |
413 | 357 |
414 #endif // CC_TILES_PICTURE_LAYER_TILING_H_ | 358 #endif // CC_TILES_PICTURE_LAYER_TILING_H_ |
OLD | NEW |