| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 const gfx::Size& content_bounds) const = 0; | 43 const gfx::Size& content_bounds) const = 0; |
| 44 virtual const Region* GetInvalidation() = 0; | 44 virtual const Region* GetInvalidation() = 0; |
| 45 virtual const PictureLayerTiling* GetTwinTiling( | 45 virtual const PictureLayerTiling* GetTwinTiling( |
| 46 const PictureLayerTiling* tiling) const = 0; | 46 const PictureLayerTiling* tiling) const = 0; |
| 47 virtual PictureLayerTiling* GetRecycledTwinTiling( | 47 virtual PictureLayerTiling* GetRecycledTwinTiling( |
| 48 const PictureLayerTiling* tiling) = 0; | 48 const PictureLayerTiling* tiling) = 0; |
| 49 virtual size_t GetMaxTilesForInterestArea() const = 0; | 49 virtual size_t GetMaxTilesForInterestArea() const = 0; |
| 50 virtual float GetSkewportTargetTimeInSeconds() const = 0; | 50 virtual float GetSkewportTargetTimeInSeconds() const = 0; |
| 51 virtual int GetSkewportExtrapolationLimitInContentPixels() const = 0; | 51 virtual int GetSkewportExtrapolationLimitInContentPixels() const = 0; |
| 52 virtual WhichTree GetTree() const = 0; | 52 virtual WhichTree GetTree() const = 0; |
| 53 virtual bool RequiresHighResToDraw() const = 0; |
| 53 | 54 |
| 54 protected: | 55 protected: |
| 55 virtual ~PictureLayerTilingClient() {} | 56 virtual ~PictureLayerTilingClient() {} |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 class CC_EXPORT PictureLayerTiling { | 59 class CC_EXPORT PictureLayerTiling { |
| 59 public: | 60 public: |
| 60 enum EvictionCategory { | 61 enum EvictionCategory { |
| 61 EVENTUALLY, | 62 EVENTUALLY, |
| 62 EVENTUALLY_AND_REQUIRED_FOR_ACTIVATION, | 63 EVENTUALLY_AND_REQUIRED_FOR_ACTIVATION, |
| 63 SOON, | 64 SOON, |
| 64 SOON_AND_REQUIRED_FOR_ACTIVATION, | 65 SOON_AND_REQUIRED_FOR_ACTIVATION, |
| 65 NOW, | 66 NOW, |
| 66 NOW_AND_REQUIRED_FOR_ACTIVATION | 67 NOW_AND_REQUIRED_FOR_ACTIVATION |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 class CC_EXPORT TilingRasterTileIterator { | 70 class CC_EXPORT TilingRasterTileIterator { |
| 70 public: | 71 public: |
| 71 TilingRasterTileIterator(); | 72 TilingRasterTileIterator(); |
| 72 TilingRasterTileIterator(PictureLayerTiling* tiling, WhichTree tree); | 73 explicit TilingRasterTileIterator(PictureLayerTiling* tiling); |
| 73 ~TilingRasterTileIterator(); | 74 ~TilingRasterTileIterator(); |
| 74 | 75 |
| 75 operator bool() const { return !!current_tile_; } | 76 operator bool() const { return !!current_tile_; } |
| 76 const Tile* operator*() const { return current_tile_; } | 77 const Tile* operator*() const { return current_tile_; } |
| 77 Tile* operator*() { return current_tile_; } | 78 Tile* operator*() { return current_tile_; } |
| 78 TilePriority::PriorityBin get_type() const { | 79 TilePriority::PriorityBin get_type() const { |
| 79 switch (phase_) { | 80 switch (phase_) { |
| 80 case VISIBLE_RECT: | 81 case VISIBLE_RECT: |
| 81 return TilePriority::NOW; | 82 return TilePriority::NOW; |
| 82 case SKEWPORT_RECT: | 83 case SKEWPORT_RECT: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 94 private: | 95 private: |
| 95 enum Phase { | 96 enum Phase { |
| 96 VISIBLE_RECT, | 97 VISIBLE_RECT, |
| 97 SKEWPORT_RECT, | 98 SKEWPORT_RECT, |
| 98 SOON_BORDER_RECT, | 99 SOON_BORDER_RECT, |
| 99 EVENTUALLY_RECT | 100 EVENTUALLY_RECT |
| 100 }; | 101 }; |
| 101 | 102 |
| 102 void AdvancePhase(); | 103 void AdvancePhase(); |
| 103 bool TileNeedsRaster(Tile* tile) const { | 104 bool TileNeedsRaster(Tile* tile) const { |
| 104 return !tile->is_occluded(tree_) && !tile->IsReadyToDraw(); | 105 return tile->NeedsRaster() && !tiling_->IsTileOccluded(tile); |
| 105 } | 106 } |
| 106 | 107 |
| 107 PictureLayerTiling* tiling_; | 108 PictureLayerTiling* tiling_; |
| 108 | 109 |
| 109 Phase phase_; | 110 Phase phase_; |
| 110 WhichTree tree_; | |
| 111 | 111 |
| 112 Tile* current_tile_; | 112 Tile* current_tile_; |
| 113 TilingData::Iterator visible_iterator_; | 113 TilingData::Iterator visible_iterator_; |
| 114 TilingData::SpiralDifferenceIterator spiral_iterator_; | 114 TilingData::SpiralDifferenceIterator spiral_iterator_; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 class CC_EXPORT TilingEvictionTileIterator { | 117 class CC_EXPORT TilingEvictionTileIterator { |
| 118 public: | 118 public: |
| 119 TilingEvictionTileIterator(); | 119 TilingEvictionTileIterator(); |
| 120 TilingEvictionTileIterator(PictureLayerTiling* tiling, | 120 TilingEvictionTileIterator(PictureLayerTiling* tiling, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 141 PictureLayerTilingClient* client); | 141 PictureLayerTilingClient* client); |
| 142 gfx::Size layer_bounds() const { return layer_bounds_; } | 142 gfx::Size layer_bounds() const { return layer_bounds_; } |
| 143 void UpdateTilesToCurrentPile(const Region& layer_invalidation, | 143 void UpdateTilesToCurrentPile(const Region& layer_invalidation, |
| 144 const gfx::Size& new_layer_bounds); | 144 const gfx::Size& new_layer_bounds); |
| 145 void CreateMissingTilesInLiveTilesRect(); | 145 void CreateMissingTilesInLiveTilesRect(); |
| 146 void RemoveTilesInRegion(const Region& layer_region); | 146 void RemoveTilesInRegion(const Region& layer_region); |
| 147 | 147 |
| 148 void SetClient(PictureLayerTilingClient* client); | 148 void SetClient(PictureLayerTilingClient* client); |
| 149 void set_resolution(TileResolution resolution) { resolution_ = resolution; } | 149 void set_resolution(TileResolution resolution) { resolution_ = resolution; } |
| 150 TileResolution resolution() const { return resolution_; } | 150 TileResolution resolution() const { return resolution_; } |
| 151 void set_can_require_tiles_for_activation(bool can_require_tiles) { |
| 152 can_require_tiles_for_activation_ = can_require_tiles; |
| 153 } |
| 151 | 154 |
| 152 gfx::Size tiling_size() const { return tiling_data_.tiling_size(); } | 155 gfx::Size tiling_size() const { return tiling_data_.tiling_size(); } |
| 153 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } | 156 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } |
| 154 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } | 157 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } |
| 155 float contents_scale() const { return contents_scale_; } | 158 float contents_scale() const { return contents_scale_; } |
| 156 | 159 |
| 157 Tile* TileAt(int i, int j) const { | 160 Tile* TileAt(int i, int j) const { |
| 158 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); | 161 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); |
| 159 return (iter == tiles_.end()) ? NULL : iter->second.get(); | 162 return (iter == tiles_.end()) ? NULL : iter->second.get(); |
| 160 } | 163 } |
| 161 | 164 |
| 162 void CreateAllTilesForTesting() { | 165 void CreateAllTilesForTesting() { |
| 163 SetLiveTilesRect(gfx::Rect(tiling_data_.tiling_size())); | 166 SetLiveTilesRect(gfx::Rect(tiling_data_.tiling_size())); |
| 164 } | 167 } |
| 165 | 168 |
| 166 const TilingData& TilingDataForTesting() const { return tiling_data_; } | 169 const TilingData& TilingDataForTesting() const { return tiling_data_; } |
| 167 | 170 |
| 168 std::vector<Tile*> AllTilesForTesting() const { | 171 std::vector<Tile*> AllTilesForTesting() const { |
| 169 std::vector<Tile*> all_tiles; | 172 std::vector<Tile*> all_tiles; |
| 170 for (TileMap::const_iterator it = tiles_.begin(); | 173 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 171 it != tiles_.end(); ++it) | |
| 172 all_tiles.push_back(it->second.get()); | 174 all_tiles.push_back(it->second.get()); |
| 173 return all_tiles; | 175 return all_tiles; |
| 174 } | 176 } |
| 175 | 177 |
| 178 void UpdateAllTilePrioritiesForTesting() { |
| 179 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 180 UpdateTileAndTwinPriority(it->second.get()); |
| 181 } |
| 182 |
| 176 std::vector<scoped_refptr<Tile> > AllRefTilesForTesting() const { | 183 std::vector<scoped_refptr<Tile> > AllRefTilesForTesting() const { |
| 177 std::vector<scoped_refptr<Tile> > all_tiles; | 184 std::vector<scoped_refptr<Tile> > all_tiles; |
| 178 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 185 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 179 all_tiles.push_back(it->second); | 186 all_tiles.push_back(it->second); |
| 180 return all_tiles; | 187 return all_tiles; |
| 181 } | 188 } |
| 182 | 189 |
| 190 void SetAllTilesOccludedForTesting() { |
| 191 gfx::Rect viewport_in_layer_space = |
| 192 ScaleToEnclosingRect(current_visible_rect_, 1.0f / contents_scale_); |
| 193 current_occlusion_in_layer_space_ = |
| 194 Occlusion(gfx::Transform(), |
| 195 SimpleEnclosedRegion(viewport_in_layer_space), |
| 196 SimpleEnclosedRegion(viewport_in_layer_space)); |
| 197 } |
| 198 |
| 183 const gfx::Rect& GetCurrentVisibleRectForTesting() const { | 199 const gfx::Rect& GetCurrentVisibleRectForTesting() const { |
| 184 return current_visible_rect_; | 200 return current_visible_rect_; |
| 185 } | 201 } |
| 186 | 202 |
| 203 bool IsTileOccluded(const Tile* tile) const; |
| 204 bool IsTileRequiredForActivation(const Tile* tile) const; |
| 205 |
| 187 // Iterate over all tiles to fill content_rect. Even if tiles are invalid | 206 // Iterate over all tiles to fill content_rect. Even if tiles are invalid |
| 188 // (i.e. no valid resource) this tiling should still iterate over them. | 207 // (i.e. no valid resource) this tiling should still iterate over them. |
| 189 // The union of all geometry_rect calls for each element iterated over should | 208 // The union of all geometry_rect calls for each element iterated over should |
| 190 // exactly equal content_rect and no two geometry_rects should intersect. | 209 // exactly equal content_rect and no two geometry_rects should intersect. |
| 191 class CC_EXPORT CoverageIterator { | 210 class CC_EXPORT CoverageIterator { |
| 192 public: | 211 public: |
| 193 CoverageIterator(); | 212 CoverageIterator(); |
| 194 CoverageIterator(const PictureLayerTiling* tiling, | 213 CoverageIterator(const PictureLayerTiling* tiling, |
| 195 float dest_scale, | 214 float dest_scale, |
| 196 const gfx::Rect& rect); | 215 const gfx::Rect& rect); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 int left_; | 247 int left_; |
| 229 int top_; | 248 int top_; |
| 230 int right_; | 249 int right_; |
| 231 int bottom_; | 250 int bottom_; |
| 232 | 251 |
| 233 friend class PictureLayerTiling; | 252 friend class PictureLayerTiling; |
| 234 }; | 253 }; |
| 235 | 254 |
| 236 void Reset(); | 255 void Reset(); |
| 237 | 256 |
| 238 void UpdateTilePriorities(WhichTree tree, | 257 void ComputeTilePriorityRects(WhichTree tree, |
| 239 const gfx::Rect& viewport_in_layer_space, | 258 const gfx::Rect& viewport_in_layer_space, |
| 240 float ideal_contents_scale, | 259 float ideal_contents_scale, |
| 241 double current_frame_time_in_seconds, | 260 double current_frame_time_in_seconds, |
| 242 const Occlusion& occlusion_in_layer_space); | 261 const Occlusion& occlusion_in_layer_space); |
| 243 | |
| 244 // Copies the src_tree priority into the dst_tree priority for all tiles. | |
| 245 // The src_tree priority is reset to the lowest priority possible. This | |
| 246 // also updates the pile on each tile to be the current client's pile. | |
| 247 void DidBecomeActive(); | |
| 248 | |
| 249 // Resets the active priority for all tiles in a tiling, when an active | |
| 250 // tiling is becoming recycled. This may include some tiles which are | |
| 251 // not in the the pending tiling (due to invalidations). This must | |
| 252 // be called before DidBecomeActive, as it resets the active priority | |
| 253 // while DidBecomeActive promotes pending priority on a similar set of tiles. | |
| 254 void DidBecomeRecycled(); | |
| 255 | 262 |
| 256 bool NeedsUpdateForFrameAtTime(double frame_time_in_seconds) { | 263 bool NeedsUpdateForFrameAtTime(double frame_time_in_seconds) { |
| 257 return frame_time_in_seconds != last_impl_frame_time_in_seconds_; | 264 return frame_time_in_seconds != last_impl_frame_time_in_seconds_; |
| 258 } | 265 } |
| 259 | 266 |
| 260 void GetAllTilesForTracing(std::set<const Tile*>* tiles) const; | 267 void GetAllTilesForTracing(std::set<const Tile*>* tiles) const; |
| 261 void AsValueInto(base::debug::TracedValue* array) const; | 268 void AsValueInto(base::debug::TracedValue* array) const; |
| 262 size_t GPUMemoryUsageInBytes() const; | 269 size_t GPUMemoryUsageInBytes() const; |
| 263 | 270 |
| 264 struct RectExpansionCache { | 271 struct RectExpansionCache { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 315 |
| 309 void UpdateEvictionCacheIfNeeded(TreePriority tree_priority); | 316 void UpdateEvictionCacheIfNeeded(TreePriority tree_priority); |
| 310 const std::vector<Tile*>* GetEvictionTiles(TreePriority tree_priority, | 317 const std::vector<Tile*>* GetEvictionTiles(TreePriority tree_priority, |
| 311 EvictionCategory category); | 318 EvictionCategory category); |
| 312 | 319 |
| 313 void Invalidate(const Region& layer_region); | 320 void Invalidate(const Region& layer_region); |
| 314 | 321 |
| 315 void DoInvalidate(const Region& layer_region, | 322 void DoInvalidate(const Region& layer_region, |
| 316 bool recreate_invalidated_tiles); | 323 bool recreate_invalidated_tiles); |
| 317 | 324 |
| 325 void UpdateTileAndTwinPriority(Tile* tile) const; |
| 326 void UpdateTilePriority(Tile* tile) const; |
| 327 |
| 318 // Given properties. | 328 // Given properties. |
| 319 float contents_scale_; | 329 float contents_scale_; |
| 320 gfx::Size layer_bounds_; | 330 gfx::Size layer_bounds_; |
| 321 TileResolution resolution_; | 331 TileResolution resolution_; |
| 322 PictureLayerTilingClient* client_; | 332 PictureLayerTilingClient* client_; |
| 323 | 333 |
| 324 // Internal data. | 334 // Internal data. |
| 325 TilingData tiling_data_; | 335 TilingData tiling_data_; |
| 326 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map. | 336 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map. |
| 327 gfx::Rect live_tiles_rect_; | 337 gfx::Rect live_tiles_rect_; |
| 328 | 338 |
| 329 // State saved for computing velocities based upon finite differences. | 339 // State saved for computing velocities based upon finite differences. |
| 330 double last_impl_frame_time_in_seconds_; | 340 double last_impl_frame_time_in_seconds_; |
| 331 gfx::Rect last_visible_rect_in_content_space_; | 341 gfx::Rect last_visible_rect_in_content_space_; |
| 342 float content_to_screen_scale_; |
| 343 |
| 344 bool can_require_tiles_for_activation_; |
| 332 | 345 |
| 333 // Iteration rects in content space | 346 // Iteration rects in content space |
| 334 gfx::Rect current_visible_rect_; | 347 gfx::Rect current_visible_rect_; |
| 335 gfx::Rect current_skewport_rect_; | 348 gfx::Rect current_skewport_rect_; |
| 336 gfx::Rect current_soon_border_rect_; | 349 gfx::Rect current_soon_border_rect_; |
| 337 gfx::Rect current_eventually_rect_; | 350 gfx::Rect current_eventually_rect_; |
| 338 | 351 |
| 339 bool has_visible_rect_tiles_; | 352 bool has_visible_rect_tiles_; |
| 340 bool has_skewport_rect_tiles_; | 353 bool has_skewport_rect_tiles_; |
| 341 bool has_soon_border_rect_tiles_; | 354 bool has_soon_border_rect_tiles_; |
| 342 bool has_eventually_rect_tiles_; | 355 bool has_eventually_rect_tiles_; |
| 343 | 356 |
| 357 Occlusion current_occlusion_in_layer_space_; |
| 358 |
| 344 // TODO(reveman): Remove this in favour of an array of eviction_tiles_ when we | 359 // TODO(reveman): Remove this in favour of an array of eviction_tiles_ when we |
| 345 // change all enums to have a consistent way of getting the count/last | 360 // change all enums to have a consistent way of getting the count/last |
| 346 // element. | 361 // element. |
| 347 std::vector<Tile*> eviction_tiles_now_; | 362 std::vector<Tile*> eviction_tiles_now_; |
| 348 std::vector<Tile*> eviction_tiles_now_and_required_for_activation_; | 363 std::vector<Tile*> eviction_tiles_now_and_required_for_activation_; |
| 349 std::vector<Tile*> eviction_tiles_soon_; | 364 std::vector<Tile*> eviction_tiles_soon_; |
| 350 std::vector<Tile*> eviction_tiles_soon_and_required_for_activation_; | 365 std::vector<Tile*> eviction_tiles_soon_and_required_for_activation_; |
| 351 std::vector<Tile*> eviction_tiles_eventually_; | 366 std::vector<Tile*> eviction_tiles_eventually_; |
| 352 std::vector<Tile*> eviction_tiles_eventually_and_required_for_activation_; | 367 std::vector<Tile*> eviction_tiles_eventually_and_required_for_activation_; |
| 353 | 368 |
| 354 bool eviction_tiles_cache_valid_; | 369 bool eviction_tiles_cache_valid_; |
| 355 TreePriority eviction_cache_tree_priority_; | 370 TreePriority eviction_cache_tree_priority_; |
| 356 | 371 |
| 357 private: | 372 private: |
| 358 DISALLOW_ASSIGN(PictureLayerTiling); | 373 DISALLOW_ASSIGN(PictureLayerTiling); |
| 359 | 374 |
| 360 RectExpansionCache expansion_cache_; | 375 RectExpansionCache expansion_cache_; |
| 361 }; | 376 }; |
| 362 | 377 |
| 363 } // namespace cc | 378 } // namespace cc |
| 364 | 379 |
| 365 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ | 380 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ |
| OLD | NEW |