| 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 <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 virtual gfx::Size CalculateTileSize( | 41 virtual gfx::Size CalculateTileSize( |
| 42 const gfx::Size& content_bounds) const = 0; | 42 const gfx::Size& content_bounds) const = 0; |
| 43 // This invalidation region defines the area (if any, it can by null) that | 43 // This invalidation region defines the area (if any, it can by null) that |
| 44 // tiles can not be shared between pending and active trees. | 44 // tiles can not be shared between pending and active trees. |
| 45 virtual const Region* GetPendingInvalidation() = 0; | 45 virtual const Region* GetPendingInvalidation() = 0; |
| 46 virtual const PictureLayerTiling* GetPendingOrActiveTwinTiling( | 46 virtual const PictureLayerTiling* GetPendingOrActiveTwinTiling( |
| 47 const PictureLayerTiling* tiling) const = 0; | 47 const PictureLayerTiling* tiling) const = 0; |
| 48 virtual PictureLayerTiling* GetRecycledTwinTiling( | 48 virtual PictureLayerTiling* GetRecycledTwinTiling( |
| 49 const PictureLayerTiling* tiling) = 0; | 49 const PictureLayerTiling* tiling) = 0; |
| 50 virtual TilePriority::PriorityBin GetMaxTilePriorityBin() const = 0; | 50 virtual TilePriority::PriorityBin GetMaxTilePriorityBin() const = 0; |
| 51 virtual size_t GetMaxTilesForInterestArea() const = 0; | |
| 52 virtual float GetSkewportTargetTimeInSeconds() const = 0; | |
| 53 virtual int GetSkewportExtrapolationLimitInContentPixels() const = 0; | |
| 54 virtual WhichTree GetTree() const = 0; | 51 virtual WhichTree GetTree() const = 0; |
| 55 virtual bool RequiresHighResToDraw() const = 0; | 52 virtual bool RequiresHighResToDraw() const = 0; |
| 56 | 53 |
| 57 protected: | 54 protected: |
| 58 virtual ~PictureLayerTilingClient() {} | 55 virtual ~PictureLayerTilingClient() {} |
| 59 }; | 56 }; |
| 60 | 57 |
| 61 class CC_EXPORT PictureLayerTiling { | 58 class CC_EXPORT PictureLayerTiling { |
| 62 public: | 59 public: |
| 63 static const int kBorderTexels = 1; | 60 static const int kBorderTexels = 1; |
| 64 | 61 |
| 65 enum EvictionCategory { | |
| 66 EVENTUALLY, | |
| 67 EVENTUALLY_AND_REQUIRED_FOR_ACTIVATION, | |
| 68 SOON, | |
| 69 SOON_AND_REQUIRED_FOR_ACTIVATION, | |
| 70 NOW, | |
| 71 NOW_AND_REQUIRED_FOR_ACTIVATION | |
| 72 }; | |
| 73 | |
| 74 class CC_EXPORT TilingRasterTileIterator { | 62 class CC_EXPORT TilingRasterTileIterator { |
| 75 public: | 63 public: |
| 76 TilingRasterTileIterator(); | 64 TilingRasterTileIterator(); |
| 77 explicit TilingRasterTileIterator(PictureLayerTiling* tiling); | 65 explicit TilingRasterTileIterator(PictureLayerTiling* tiling); |
| 78 ~TilingRasterTileIterator(); | 66 ~TilingRasterTileIterator(); |
| 79 | 67 |
| 80 operator bool() const { return !!current_tile_; } | 68 operator bool() const { return !!current_tile_; } |
| 81 const Tile* operator*() const { return current_tile_; } | 69 const Tile* operator*() const { return current_tile_; } |
| 82 Tile* operator*() { return current_tile_; } | 70 Tile* operator*() { return current_tile_; } |
| 83 TilePriority::PriorityBin get_type() const { | 71 TilePriority::PriorityBin get_type() const { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 114 Phase phase_; | 102 Phase phase_; |
| 115 | 103 |
| 116 Tile* current_tile_; | 104 Tile* current_tile_; |
| 117 TilingData::Iterator visible_iterator_; | 105 TilingData::Iterator visible_iterator_; |
| 118 TilingData::SpiralDifferenceIterator spiral_iterator_; | 106 TilingData::SpiralDifferenceIterator spiral_iterator_; |
| 119 }; | 107 }; |
| 120 | 108 |
| 121 ~PictureLayerTiling(); | 109 ~PictureLayerTiling(); |
| 122 | 110 |
| 123 // Create a tiling with no tiles. CreateTiles must be called to add some. | 111 // Create a tiling with no tiles. CreateTiles must be called to add some. |
| 112 // TODO(danakj): Pass the raster_source here instead of the size, store the |
| 113 // raster source instead of layer bounds? |
| 124 static scoped_ptr<PictureLayerTiling> Create( | 114 static scoped_ptr<PictureLayerTiling> Create( |
| 125 float contents_scale, | 115 float contents_scale, |
| 126 const gfx::Size& layer_bounds, | 116 const gfx::Size& layer_bounds, |
| 127 PictureLayerTilingClient* client); | 117 PictureLayerTilingClient* client, |
| 118 size_t max_tiles_for_interest_area, |
| 119 float skewport_target_time_in_seconds, |
| 120 int skewport_extrapolation_limit_in_content_pixels); |
| 121 |
| 128 gfx::Size layer_bounds() const { return layer_bounds_; } | 122 gfx::Size layer_bounds() const { return layer_bounds_; } |
| 129 void UpdateTilesToCurrentRasterSource(RasterSource* raster_source, | 123 void Resize(const gfx::Size& new_layer_bounds); |
| 130 const Region& layer_invalidation, | 124 void Invalidate(const Region& layer_invalidation); |
| 131 const gfx::Size& new_layer_bounds); | 125 void SetRasterSource(scoped_refptr<RasterSource> raster_source); |
| 132 void CreateMissingTilesInLiveTilesRect(); | 126 void CreateMissingTilesInLiveTilesRect(); |
| 133 void RemoveTilesInRegion(const Region& layer_region); | |
| 134 | 127 |
| 135 void SetClient(PictureLayerTilingClient* client); | 128 void CloneTilesAndPropertiesFrom(const PictureLayerTiling& twin_tiling); |
| 129 |
| 136 void set_resolution(TileResolution resolution) { resolution_ = resolution; } | 130 void set_resolution(TileResolution resolution) { resolution_ = resolution; } |
| 137 TileResolution resolution() const { return resolution_; } | 131 TileResolution resolution() const { return resolution_; } |
| 138 void set_can_require_tiles_for_activation(bool can_require_tiles) { | 132 void set_can_require_tiles_for_activation(bool can_require_tiles) { |
| 139 can_require_tiles_for_activation_ = can_require_tiles; | 133 can_require_tiles_for_activation_ = can_require_tiles; |
| 140 } | 134 } |
| 141 | 135 |
| 142 gfx::Size tiling_size() const { return tiling_data_.tiling_size(); } | 136 gfx::Size tiling_size() const { return tiling_data_.tiling_size(); } |
| 143 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } | 137 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } |
| 144 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } | 138 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } |
| 145 float contents_scale() const { return contents_scale_; } | 139 float contents_scale() const { return contents_scale_; } |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 protected: | 275 protected: |
| 282 friend class CoverageIterator; | 276 friend class CoverageIterator; |
| 283 friend class TilingRasterTileIterator; | 277 friend class TilingRasterTileIterator; |
| 284 friend class TilingSetEvictionQueue; | 278 friend class TilingSetEvictionQueue; |
| 285 | 279 |
| 286 typedef std::pair<int, int> TileMapKey; | 280 typedef std::pair<int, int> TileMapKey; |
| 287 typedef base::hash_map<TileMapKey, scoped_refptr<Tile>> TileMap; | 281 typedef base::hash_map<TileMapKey, scoped_refptr<Tile>> TileMap; |
| 288 | 282 |
| 289 PictureLayerTiling(float contents_scale, | 283 PictureLayerTiling(float contents_scale, |
| 290 const gfx::Size& layer_bounds, | 284 const gfx::Size& layer_bounds, |
| 291 PictureLayerTilingClient* client); | 285 PictureLayerTilingClient* client, |
| 286 size_t max_tiles_for_interest_area, |
| 287 float skewport_target_time_in_seconds, |
| 288 int skewport_extrapolation_limit_in_content_pixels); |
| 292 void SetLiveTilesRect(const gfx::Rect& live_tiles_rect); | 289 void SetLiveTilesRect(const gfx::Rect& live_tiles_rect); |
| 293 void VerifyLiveTilesRect(); | 290 void VerifyLiveTilesRect(bool is_on_recycle_tree) const; |
| 294 Tile* CreateTile(int i, int j, const PictureLayerTiling* twin_tiling); | 291 Tile* CreateTile(int i, |
| 292 int j, |
| 293 const PictureLayerTiling* twin_tiling, |
| 294 PictureLayerTiling* recycled_twin); |
| 295 // Returns true if the Tile existed and was removed from the tiling. | 295 // Returns true if the Tile existed and was removed from the tiling. |
| 296 bool RemoveTileAt(int i, int j, PictureLayerTiling* recycled_twin); | 296 bool RemoveTileAt(int i, int j, PictureLayerTiling* recycled_twin); |
| 297 | 297 |
| 298 // Computes a skewport. The calculation extrapolates the last visible | 298 // Computes a skewport. The calculation extrapolates the last visible |
| 299 // rect and the current visible rect to expand the skewport to where it | 299 // rect and the current visible rect to expand the skewport to where it |
| 300 // would be in |skewport_target_time| seconds. Note that the skewport | 300 // would be in |skewport_target_time| seconds. Note that the skewport |
| 301 // is guaranteed to contain the current visible rect. | 301 // is guaranteed to contain the current visible rect. |
| 302 gfx::Rect ComputeSkewport(double current_frame_time_in_seconds, | 302 gfx::Rect ComputeSkewport(double current_frame_time_in_seconds, |
| 303 const gfx::Rect& visible_rect_in_content_space) | 303 const gfx::Rect& visible_rect_in_content_space) |
| 304 const; | 304 const; |
| 305 | 305 |
| 306 void UpdateEvictionCacheIfNeeded(TreePriority tree_priority); | 306 // Save the required data for computing tile priorities later. |
| 307 const std::vector<Tile*>* GetEvictionTiles(TreePriority tree_priority, | 307 void UpdateTilePriorityRects(float content_to_screen_scale_, |
| 308 EvictionCategory category); | 308 const gfx::Rect& visible_rect_in_content_space, |
| 309 | 309 const gfx::Rect& skewport, |
| 310 void Invalidate(const Region& layer_region); | 310 const gfx::Rect& soon_border_rect, |
| 311 | 311 const gfx::Rect& eventually_rect, |
| 312 void DoInvalidate(const Region& layer_region, | 312 const Occlusion& occlusion_in_layer_space); |
| 313 bool recreate_invalidated_tiles); | |
| 314 | 313 |
| 315 void UpdateTileAndTwinPriority(Tile* tile) const; | 314 void UpdateTileAndTwinPriority(Tile* tile) const; |
| 316 void UpdateTilePriority(Tile* tile) const; | 315 void UpdateTilePriority(Tile* tile) const; |
| 317 | 316 |
| 317 const size_t max_tiles_for_interest_area_; |
| 318 const float skewport_target_time_in_seconds_; |
| 319 const int skewport_extrapolation_limit_in_content_pixels_; |
| 320 |
| 318 // Given properties. | 321 // Given properties. |
| 319 float contents_scale_; | 322 float contents_scale_; |
| 320 gfx::Size layer_bounds_; | 323 gfx::Size layer_bounds_; |
| 321 TileResolution resolution_; | 324 TileResolution resolution_; |
| 322 PictureLayerTilingClient* client_; | 325 PictureLayerTilingClient* client_; |
| 323 | 326 |
| 324 // Internal data. | 327 // Internal data. |
| 325 TilingData tiling_data_; | 328 TilingData tiling_data_; |
| 326 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map. | 329 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map. |
| 327 gfx::Rect live_tiles_rect_; | 330 gfx::Rect live_tiles_rect_; |
| 328 | 331 |
| 329 // State saved for computing velocities based upon finite differences. | 332 // State saved for computing velocities based upon finite differences. |
| 330 double last_impl_frame_time_in_seconds_; | 333 double last_impl_frame_time_in_seconds_; |
| 331 gfx::Rect last_viewport_in_layer_space_; | 334 gfx::Rect last_viewport_in_layer_space_; |
| 332 gfx::Rect last_visible_rect_in_content_space_; | 335 gfx::Rect last_visible_rect_in_content_space_; |
| 333 float content_to_screen_scale_; | |
| 334 | 336 |
| 335 bool can_require_tiles_for_activation_; | 337 bool can_require_tiles_for_activation_; |
| 336 | 338 |
| 337 // Iteration rects in content space | 339 // Iteration rects in content space. |
| 338 gfx::Rect current_visible_rect_; | 340 gfx::Rect current_visible_rect_; |
| 339 gfx::Rect current_skewport_rect_; | 341 gfx::Rect current_skewport_rect_; |
| 340 gfx::Rect current_soon_border_rect_; | 342 gfx::Rect current_soon_border_rect_; |
| 341 gfx::Rect current_eventually_rect_; | 343 gfx::Rect current_eventually_rect_; |
| 344 // Other properties used for tile iteration and prioritization. |
| 345 float current_content_to_screen_scale_; |
| 346 Occlusion current_occlusion_in_layer_space_; |
| 342 | 347 |
| 343 bool has_visible_rect_tiles_; | 348 bool has_visible_rect_tiles_; |
| 344 bool has_skewport_rect_tiles_; | 349 bool has_skewport_rect_tiles_; |
| 345 bool has_soon_border_rect_tiles_; | 350 bool has_soon_border_rect_tiles_; |
| 346 bool has_eventually_rect_tiles_; | 351 bool has_eventually_rect_tiles_; |
| 347 | 352 |
| 348 Occlusion current_occlusion_in_layer_space_; | |
| 349 | |
| 350 // TODO(reveman): Remove this in favour of an array of eviction_tiles_ when we | |
| 351 // change all enums to have a consistent way of getting the count/last | |
| 352 // element. | |
| 353 std::vector<Tile*> eviction_tiles_now_; | |
| 354 std::vector<Tile*> eviction_tiles_now_and_required_for_activation_; | |
| 355 std::vector<Tile*> eviction_tiles_soon_; | |
| 356 std::vector<Tile*> eviction_tiles_soon_and_required_for_activation_; | |
| 357 std::vector<Tile*> eviction_tiles_eventually_; | |
| 358 std::vector<Tile*> eviction_tiles_eventually_and_required_for_activation_; | |
| 359 | |
| 360 bool eviction_tiles_cache_valid_; | |
| 361 TreePriority eviction_cache_tree_priority_; | |
| 362 | |
| 363 private: | 353 private: |
| 364 DISALLOW_ASSIGN(PictureLayerTiling); | 354 DISALLOW_ASSIGN(PictureLayerTiling); |
| 365 | 355 |
| 366 RectExpansionCache expansion_cache_; | 356 RectExpansionCache expansion_cache_; |
| 367 }; | 357 }; |
| 368 | 358 |
| 369 } // namespace cc | 359 } // namespace cc |
| 370 | 360 |
| 371 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ | 361 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ |
| OLD | NEW |