Chromium Code Reviews| 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 ~PictureLayerTiling(); | 61 virtual ~PictureLayerTiling(); |
| 62 | 62 |
| 63 static float CalculateSoonBorderDistance( | 63 static float CalculateSoonBorderDistance( |
| 64 const gfx::Rect& visible_rect_in_content_space, | 64 const gfx::Rect& visible_rect_in_content_space, |
| 65 float content_to_screen_scale); | 65 float content_to_screen_scale); |
| 66 | 66 |
| 67 // Create a tiling with no tiles. CreateTile() must be called to add some. | 67 virtual void SetRasterSourceAndResize( |
| 68 static scoped_ptr<PictureLayerTiling> Create( | 68 scoped_refptr<RasterSource> raster_source) = 0; |
| 69 float contents_scale, | 69 virtual void Invalidate(const Region& layer_invalidation) = 0; |
| 70 scoped_refptr<RasterSource> raster_source, | 70 virtual void SetRasterSourceOnTiles() = 0; |
|
enne (OOO)
2015/04/02 21:45:34
This function has some api smell for me. It's wei
vmpstr
2015/04/02 22:33:27
With unshared tiles, I think this could be done as
| |
| 71 PictureLayerTilingClient* client, | 71 virtual void CreateMissingTilesInLiveTilesRect() = 0; |
| 72 size_t max_tiles_for_interest_area, | |
| 73 float skewport_target_time_in_seconds, | |
| 74 int skewport_extrapolation_limit_in_content_pixels); | |
| 75 | 72 |
| 76 void SetRasterSourceAndResize(scoped_refptr<RasterSource> raster_source); | 73 virtual void TakeTilesAndPropertiesFrom(PictureLayerTiling* pending_twin) = 0; |
| 77 void Invalidate(const Region& layer_invalidation); | |
| 78 void SetRasterSourceOnTiles(); | |
| 79 void CreateMissingTilesInLiveTilesRect(); | |
| 80 | 74 |
| 81 void CloneTilesAndPropertiesFrom(const PictureLayerTiling& twin_tiling); | 75 virtual bool IsTileOccluded(const Tile* tile) const = 0; |
| 76 virtual bool IsTileRequiredForActivation(const Tile* tile) const = 0; | |
|
enne (OOO)
2015/04/02 21:45:34
This is weird to me to have base level functions t
vmpstr
2015/04/02 22:33:27
Well, both trees implement these (aside from TakeT
| |
| 77 virtual bool IsTileRequiredForDraw(const Tile* tile) const = 0; | |
| 82 | 78 |
| 83 void set_resolution(TileResolution resolution) { resolution_ = resolution; } | 79 void set_resolution(TileResolution resolution) { resolution_ = resolution; } |
| 84 TileResolution resolution() const { return resolution_; } | 80 TileResolution resolution() const { return resolution_; } |
| 85 void set_can_require_tiles_for_activation(bool can_require_tiles) { | 81 void set_can_require_tiles_for_activation(bool can_require_tiles) { |
| 86 can_require_tiles_for_activation_ = can_require_tiles; | 82 can_require_tiles_for_activation_ = can_require_tiles; |
| 87 } | 83 } |
| 84 bool IsActiveTree() const { return client_->GetTree() == ACTIVE_TREE; } | |
| 88 | 85 |
| 89 RasterSource* raster_source() const { return raster_source_.get(); } | 86 RasterSource* raster_source() const { return raster_source_.get(); } |
| 90 gfx::Size tiling_size() const { return tiling_data_.tiling_size(); } | 87 gfx::Size tiling_size() const { return tiling_data_.tiling_size(); } |
| 91 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } | 88 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } |
| 92 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } | 89 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } |
| 93 float contents_scale() const { return contents_scale_; } | 90 float contents_scale() const { return contents_scale_; } |
| 94 | 91 |
| 95 Tile* TileAt(int i, int j) const { | 92 Tile* TileAt(int i, int j) const { |
| 96 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); | 93 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); |
| 97 return (iter == tiles_.end()) ? NULL : iter->second.get(); | 94 return (iter == tiles_.end()) ? nullptr : iter->second.get(); |
| 98 } | 95 } |
| 99 | 96 |
| 97 void UpdateTileAndTwinPriority(Tile* tile) const; | |
| 98 TilePriority ComputePriorityForTile(const Tile* tile) const; | |
| 99 void UpdateRequiredStateForTile(Tile* tile, WhichTree tree) const; | |
| 100 bool has_visible_rect_tiles() const { return has_visible_rect_tiles_; } | |
| 101 bool has_skewport_rect_tiles() const { return has_skewport_rect_tiles_; } | |
| 102 bool has_soon_border_rect_tiles() const { | |
| 103 return has_soon_border_rect_tiles_; | |
| 104 } | |
| 105 bool has_eventually_rect_tiles() const { return has_eventually_rect_tiles_; } | |
| 106 | |
| 107 const gfx::Rect& current_visible_rect() const { | |
| 108 return current_visible_rect_; | |
| 109 } | |
| 110 const gfx::Rect& pending_visible_rect() const { | |
| 111 const PictureLayerTiling* twin = | |
| 112 client_->GetTree() == ACTIVE_TREE | |
| 113 ? client_->GetPendingOrActiveTwinTiling(this) | |
| 114 : this; | |
| 115 if (twin) | |
| 116 return twin->current_visible_rect(); | |
| 117 return current_visible_rect(); | |
| 118 } | |
| 119 const gfx::Rect& current_skewport_rect() const { | |
| 120 return current_skewport_rect_; | |
| 121 } | |
| 122 const gfx::Rect& current_soon_border_rect() const { | |
| 123 return current_soon_border_rect_; | |
| 124 } | |
| 125 const gfx::Rect& current_eventually_rect() const { | |
| 126 return current_eventually_rect_; | |
| 127 } | |
| 128 | |
| 129 // For testing functionality. | |
| 100 void CreateAllTilesForTesting() { | 130 void CreateAllTilesForTesting() { |
| 101 SetLiveTilesRect(gfx::Rect(tiling_data_.tiling_size())); | 131 SetLiveTilesRect(gfx::Rect(tiling_data_.tiling_size())); |
| 102 } | 132 } |
| 103 | |
| 104 const TilingData& TilingDataForTesting() const { return tiling_data_; } | 133 const TilingData& TilingDataForTesting() const { return tiling_data_; } |
| 105 | |
| 106 std::vector<Tile*> AllTilesForTesting() const { | 134 std::vector<Tile*> AllTilesForTesting() const { |
| 107 std::vector<Tile*> all_tiles; | 135 std::vector<Tile*> all_tiles; |
| 108 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 136 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 109 all_tiles.push_back(it->second.get()); | 137 all_tiles.push_back(it->second.get()); |
| 110 return all_tiles; | 138 return all_tiles; |
| 111 } | 139 } |
| 112 | |
| 113 void UpdateAllTilePrioritiesForTesting() { | 140 void UpdateAllTilePrioritiesForTesting() { |
| 114 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 141 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 115 UpdateTileAndTwinPriority(it->second.get()); | 142 UpdateTileAndTwinPriority(it->second.get()); |
| 116 } | 143 } |
| 117 | |
| 118 std::vector<scoped_refptr<Tile>> AllRefTilesForTesting() const { | 144 std::vector<scoped_refptr<Tile>> AllRefTilesForTesting() const { |
| 119 std::vector<scoped_refptr<Tile>> all_tiles; | 145 std::vector<scoped_refptr<Tile>> all_tiles; |
| 120 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 146 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 121 all_tiles.push_back(it->second); | 147 all_tiles.push_back(it->second); |
| 122 return all_tiles; | 148 return all_tiles; |
| 123 } | 149 } |
| 124 | |
| 125 void SetAllTilesOccludedForTesting() { | 150 void SetAllTilesOccludedForTesting() { |
| 126 gfx::Rect viewport_in_layer_space = | 151 gfx::Rect viewport_in_layer_space = |
| 127 ScaleToEnclosingRect(current_visible_rect_, 1.0f / contents_scale_); | 152 ScaleToEnclosingRect(current_visible_rect_, 1.0f / contents_scale_); |
| 128 current_occlusion_in_layer_space_ = | 153 current_occlusion_in_layer_space_ = |
| 129 Occlusion(gfx::Transform(), | 154 Occlusion(gfx::Transform(), |
| 130 SimpleEnclosedRegion(viewport_in_layer_space), | 155 SimpleEnclosedRegion(viewport_in_layer_space), |
| 131 SimpleEnclosedRegion(viewport_in_layer_space)); | 156 SimpleEnclosedRegion(viewport_in_layer_space)); |
| 132 } | 157 } |
| 133 | |
| 134 const gfx::Rect& GetCurrentVisibleRectForTesting() const { | 158 const gfx::Rect& GetCurrentVisibleRectForTesting() const { |
| 135 return current_visible_rect_; | 159 return current_visible_rect_; |
| 136 } | 160 } |
| 137 | 161 |
| 138 bool IsTileOccluded(const Tile* tile) const; | |
| 139 bool IsTileRequiredForActivationIfVisible(const Tile* tile) const; | |
| 140 bool IsTileRequiredForDrawIfVisible(const Tile* tile) const; | |
| 141 | |
| 142 void UpdateTileAndTwinPriority(Tile* tile) const; | |
| 143 TilePriority ComputePriorityForTile(const Tile* tile) const; | |
| 144 void UpdateRequiredStateForTile(Tile* tile, WhichTree tree) const; | |
| 145 bool has_visible_rect_tiles() const { return has_visible_rect_tiles_; } | |
| 146 bool has_skewport_rect_tiles() const { return has_skewport_rect_tiles_; } | |
| 147 bool has_soon_border_rect_tiles() const { | |
| 148 return has_soon_border_rect_tiles_; | |
| 149 } | |
| 150 bool has_eventually_rect_tiles() const { return has_eventually_rect_tiles_; } | |
| 151 | |
| 152 const gfx::Rect& current_visible_rect() const { | |
| 153 return current_visible_rect_; | |
| 154 } | |
| 155 const gfx::Rect& current_skewport_rect() const { | |
| 156 return current_skewport_rect_; | |
| 157 } | |
| 158 const gfx::Rect& current_soon_border_rect() const { | |
| 159 return current_soon_border_rect_; | |
| 160 } | |
| 161 const gfx::Rect& current_eventually_rect() const { | |
| 162 return current_eventually_rect_; | |
| 163 } | |
| 164 | |
| 165 // Iterate over all tiles to fill content_rect. Even if tiles are invalid | 162 // Iterate over all tiles to fill content_rect. Even if tiles are invalid |
| 166 // (i.e. no valid resource) this tiling should still iterate over them. | 163 // (i.e. no valid resource) this tiling should still iterate over them. |
| 167 // The union of all geometry_rect calls for each element iterated over should | 164 // The union of all geometry_rect calls for each element iterated over should |
| 168 // exactly equal content_rect and no two geometry_rects should intersect. | 165 // exactly equal content_rect and no two geometry_rects should intersect. |
| 169 class CC_EXPORT CoverageIterator { | 166 class CC_EXPORT CoverageIterator { |
| 170 public: | 167 public: |
| 171 CoverageIterator(); | 168 CoverageIterator(); |
| 172 CoverageIterator(const PictureLayerTiling* tiling, | 169 CoverageIterator(const PictureLayerTiling* tiling, |
| 173 float dest_scale, | 170 float dest_scale, |
| 174 const gfx::Rect& rect); | 171 const gfx::Rect& rect); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 | 233 |
| 237 bool has_ever_been_updated() const { | 234 bool has_ever_been_updated() const { |
| 238 return visible_rect_history_[0].frame_time_in_seconds != 0.0; | 235 return visible_rect_history_[0].frame_time_in_seconds != 0.0; |
| 239 } | 236 } |
| 240 | 237 |
| 241 protected: | 238 protected: |
| 242 friend class CoverageIterator; | 239 friend class CoverageIterator; |
| 243 friend class TilingSetRasterQueueAll; | 240 friend class TilingSetRasterQueueAll; |
| 244 friend class TilingSetRasterQueueRequired; | 241 friend class TilingSetRasterQueueRequired; |
| 245 friend class TilingSetEvictionQueue; | 242 friend class TilingSetEvictionQueue; |
| 243 friend class ActivePictureLayerTiling; | |
| 244 friend class PendingPictureLayerTiling; | |
| 246 | 245 |
| 247 typedef std::pair<int, int> TileMapKey; | 246 typedef std::pair<int, int> TileMapKey; |
| 248 typedef base::hash_map<TileMapKey, scoped_refptr<Tile>> TileMap; | 247 typedef base::hash_map<TileMapKey, scoped_refptr<Tile>> TileMap; |
| 249 | 248 |
| 250 struct FrameVisibleRect { | 249 struct FrameVisibleRect { |
| 251 gfx::Rect visible_rect_in_content_space; | 250 gfx::Rect visible_rect_in_content_space; |
| 252 double frame_time_in_seconds = 0.0; | 251 double frame_time_in_seconds = 0.0; |
| 253 }; | 252 }; |
| 254 | 253 |
| 255 PictureLayerTiling(float contents_scale, | 254 PictureLayerTiling(float contents_scale, |
| 256 scoped_refptr<RasterSource> raster_source, | 255 scoped_refptr<RasterSource> raster_source, |
| 257 PictureLayerTilingClient* client, | 256 PictureLayerTilingClient* client, |
| 258 size_t max_tiles_for_interest_area, | 257 size_t max_tiles_for_interest_area, |
| 259 float skewport_target_time_in_seconds, | 258 float skewport_target_time_in_seconds, |
| 260 int skewport_extrapolation_limit_in_content_pixels); | 259 int skewport_extrapolation_limit_in_content_pixels); |
| 261 void SetLiveTilesRect(const gfx::Rect& live_tiles_rect); | 260 virtual void SetLiveTilesRect(const gfx::Rect& live_tiles_rect) = 0; |
| 262 void VerifyLiveTilesRect(bool is_on_recycle_tree) const; | 261 void VerifyLiveTilesRect(bool is_on_recycle_tree) const; |
| 263 Tile* CreateTile(int i, | 262 Tile* CreateTile(int i, int j); |
| 264 int j, | |
| 265 const PictureLayerTiling* twin_tiling, | |
| 266 PictureLayerTiling* recycled_twin); | |
| 267 // Returns true if the Tile existed and was removed from the tiling. | 263 // Returns true if the Tile existed and was removed from the tiling. |
| 268 bool RemoveTileAt(int i, int j, PictureLayerTiling* recycled_twin); | 264 bool RemoveTileAt(int i, int j); |
| 265 bool TilingMatchesTileIndecies(const PictureLayerTiling* twin) const; | |
| 269 | 266 |
| 270 // Computes a skewport. The calculation extrapolates the last visible | 267 // Computes a skewport. The calculation extrapolates the last visible |
| 271 // rect and the current visible rect to expand the skewport to where it | 268 // rect and the current visible rect to expand the skewport to where it |
| 272 // would be in |skewport_target_time| seconds. Note that the skewport | 269 // would be in |skewport_target_time| seconds. Note that the skewport |
| 273 // is guaranteed to contain the current visible rect. | 270 // is guaranteed to contain the current visible rect. |
| 274 gfx::Rect ComputeSkewport(double current_frame_time_in_seconds, | 271 gfx::Rect ComputeSkewport(double current_frame_time_in_seconds, |
| 275 const gfx::Rect& visible_rect_in_content_space) | 272 const gfx::Rect& visible_rect_in_content_space) |
| 276 const; | 273 const; |
| 277 | 274 |
| 278 // Save the required data for computing tile priorities later. | 275 // Save the required data for computing tile priorities later. |
| 279 void UpdateTilePriorityRects(float content_to_screen_scale_, | 276 void SetTilePriorityRects(float content_to_screen_scale_, |
| 280 const gfx::Rect& visible_rect_in_content_space, | 277 const gfx::Rect& visible_rect_in_content_space, |
| 281 const gfx::Rect& skewport, | 278 const gfx::Rect& skewport, |
| 282 const gfx::Rect& soon_border_rect, | 279 const gfx::Rect& soon_border_rect, |
| 283 const gfx::Rect& eventually_rect, | 280 const gfx::Rect& eventually_rect, |
| 284 const Occlusion& occlusion_in_layer_space); | 281 const Occlusion& occlusion_in_layer_space); |
| 285 | 282 |
| 286 void UpdateTilePriorityForTree(Tile* tile, WhichTree tree) const; | 283 void UpdateTilePriorityForTree(Tile* tile, WhichTree tree) const; |
| 287 bool NeedsUpdateForFrameAtTimeAndViewport( | 284 bool NeedsUpdateForFrameAtTimeAndViewport( |
| 288 double frame_time_in_seconds, | 285 double frame_time_in_seconds, |
| 289 const gfx::Rect& viewport_in_layer_space) { | 286 const gfx::Rect& viewport_in_layer_space) { |
| 290 return frame_time_in_seconds != | 287 return frame_time_in_seconds != |
| 291 visible_rect_history_[0].frame_time_in_seconds || | 288 visible_rect_history_[0].frame_time_in_seconds || |
| 292 viewport_in_layer_space != last_viewport_in_layer_space_; | 289 viewport_in_layer_space != last_viewport_in_layer_space_; |
| 293 } | 290 } |
| 294 void UpdateVisibleRectHistory( | 291 void UpdateVisibleRectHistory( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 | 337 |
| 341 private: | 338 private: |
| 342 DISALLOW_ASSIGN(PictureLayerTiling); | 339 DISALLOW_ASSIGN(PictureLayerTiling); |
| 343 | 340 |
| 344 RectExpansionCache expansion_cache_; | 341 RectExpansionCache expansion_cache_; |
| 345 }; | 342 }; |
| 346 | 343 |
| 347 } // namespace cc | 344 } // namespace cc |
| 348 | 345 |
| 349 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ | 346 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ |
| OLD | NEW |