| 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 <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 virtual size_t GetMaxTilesForInterestArea() const = 0; | 38 virtual size_t GetMaxTilesForInterestArea() const = 0; |
| 39 virtual float GetSkewportTargetTimeInSeconds() const = 0; | 39 virtual float GetSkewportTargetTimeInSeconds() const = 0; |
| 40 virtual int GetSkewportExtrapolationLimitInContentPixels() const = 0; | 40 virtual int GetSkewportExtrapolationLimitInContentPixels() const = 0; |
| 41 | 41 |
| 42 protected: | 42 protected: |
| 43 virtual ~PictureLayerTilingClient() {} | 43 virtual ~PictureLayerTilingClient() {} |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class CC_EXPORT PictureLayerTiling { | 46 class CC_EXPORT PictureLayerTiling { |
| 47 public: | 47 public: |
| 48 class CC_EXPORT TilingRasterTileIterator { |
| 49 public: |
| 50 enum Type { VISIBLE, SKEWPORT, EVENTUALLY }; |
| 51 |
| 52 TilingRasterTileIterator(); |
| 53 TilingRasterTileIterator(PictureLayerTiling* tiling, WhichTree tree); |
| 54 ~TilingRasterTileIterator(); |
| 55 |
| 56 operator bool() const { |
| 57 return current_tile_ && TileNeedsRaster(current_tile_); |
| 58 } |
| 59 Tile* operator*() { return current_tile_; } |
| 60 Type get_type() const { return type_; } |
| 61 |
| 62 TilingRasterTileIterator& operator++(); |
| 63 |
| 64 gfx::Rect TileBounds() const { |
| 65 DCHECK(*this); |
| 66 if (type_ == VISIBLE) { |
| 67 return tiling_->tiling_data_.TileBounds(visible_iterator_.index_x(), |
| 68 visible_iterator_.index_y()); |
| 69 } |
| 70 return tiling_->tiling_data_.TileBounds(spiral_iterator_.index_x(), |
| 71 spiral_iterator_.index_y()); |
| 72 } |
| 73 |
| 74 private: |
| 75 void AdvancePhase(); |
| 76 bool TileNeedsRaster(Tile* tile) const { |
| 77 RasterMode mode = tile->DetermineRasterModeForTree(tree_); |
| 78 return tile->NeedsRasterForMode(mode); |
| 79 }; |
| 80 |
| 81 void UpdateCurrentTilePriority(); |
| 82 |
| 83 PictureLayerTiling* tiling_; |
| 84 |
| 85 Type type_; |
| 86 gfx::Rect visible_rect_in_content_space_; |
| 87 gfx::Rect skewport_in_content_space_; |
| 88 gfx::Rect eventually_rect_in_content_space_; |
| 89 WhichTree tree_; |
| 90 |
| 91 Tile* current_tile_; |
| 92 bool current_tile_priority_updated_; |
| 93 TilingData::Iterator visible_iterator_; |
| 94 TilingData::SpiralDifferenceIterator spiral_iterator_; |
| 95 }; |
| 96 |
| 48 ~PictureLayerTiling(); | 97 ~PictureLayerTiling(); |
| 49 | 98 |
| 50 // Create a tiling with no tiles. CreateTiles must be called to add some. | 99 // Create a tiling with no tiles. CreateTiles must be called to add some. |
| 51 static scoped_ptr<PictureLayerTiling> Create( | 100 static scoped_ptr<PictureLayerTiling> Create( |
| 52 float contents_scale, | 101 float contents_scale, |
| 53 const gfx::Size& layer_bounds, | 102 const gfx::Size& layer_bounds, |
| 54 PictureLayerTilingClient* client); | 103 PictureLayerTilingClient* client); |
| 55 gfx::Size layer_bounds() const { return layer_bounds_; } | 104 gfx::Size layer_bounds() const { return layer_bounds_; } |
| 56 void SetLayerBounds(const gfx::Size& layer_bounds); | 105 void SetLayerBounds(const gfx::Size& layer_bounds); |
| 57 void Invalidate(const Region& layer_region); | 106 void Invalidate(const Region& layer_region); |
| 58 void CreateMissingTilesInLiveTilesRect(); | 107 void CreateMissingTilesInLiveTilesRect(); |
| 59 | 108 |
| 60 void SetCanUseLCDText(bool can_use_lcd_text); | 109 void SetCanUseLCDText(bool can_use_lcd_text); |
| 61 | 110 |
| 62 void SetClient(PictureLayerTilingClient* client); | 111 void SetClient(PictureLayerTilingClient* client); |
| 63 void set_resolution(TileResolution resolution) { resolution_ = resolution; } | 112 void set_resolution(TileResolution resolution) { resolution_ = resolution; } |
| 64 TileResolution resolution() const { return resolution_; } | 113 TileResolution resolution() const { return resolution_; } |
| 65 | 114 |
| 66 gfx::Rect ContentRect() const; | 115 gfx::Rect ContentRect() const; |
| 67 gfx::SizeF ContentSizeF() const; | 116 gfx::SizeF ContentSizeF() const; |
| 68 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } | 117 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } |
| 69 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } | 118 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } |
| 70 float contents_scale() const { return contents_scale_; } | 119 float contents_scale() const { return contents_scale_; } |
| 71 | 120 |
| 121 Tile* TileAt(int i, int j) const { |
| 122 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); |
| 123 return (iter == tiles_.end()) ? NULL : iter->second.get(); |
| 124 } |
| 125 |
| 72 void CreateAllTilesForTesting() { | 126 void CreateAllTilesForTesting() { |
| 73 SetLiveTilesRect(gfx::Rect(tiling_data_.total_size())); | 127 SetLiveTilesRect(gfx::Rect(tiling_data_.total_size())); |
| 74 } | 128 } |
| 75 | 129 |
| 76 std::vector<Tile*> AllTilesForTesting() const { | 130 std::vector<Tile*> AllTilesForTesting() const { |
| 77 std::vector<Tile*> all_tiles; | 131 std::vector<Tile*> all_tiles; |
| 78 for (TileMap::const_iterator it = tiles_.begin(); | 132 for (TileMap::const_iterator it = tiles_.begin(); |
| 79 it != tiles_.end(); ++it) | 133 it != tiles_.end(); ++it) |
| 80 all_tiles.push_back(it->second.get()); | 134 all_tiles.push_back(it->second.get()); |
| 81 return all_tiles; | 135 return all_tiles; |
| 82 } | 136 } |
| 83 | 137 |
| 84 Tile* TileAt(int i, int j) const; | |
| 85 | |
| 86 // Iterate over all tiles to fill content_rect. Even if tiles are invalid | 138 // Iterate over all tiles to fill content_rect. Even if tiles are invalid |
| 87 // (i.e. no valid resource) this tiling should still iterate over them. | 139 // (i.e. no valid resource) this tiling should still iterate over them. |
| 88 // The union of all geometry_rect calls for each element iterated over should | 140 // The union of all geometry_rect calls for each element iterated over should |
| 89 // exactly equal content_rect and no two geometry_rects should intersect. | 141 // exactly equal content_rect and no two geometry_rects should intersect. |
| 90 class CC_EXPORT CoverageIterator { | 142 class CC_EXPORT CoverageIterator { |
| 91 public: | 143 public: |
| 92 CoverageIterator(); | 144 CoverageIterator(); |
| 93 CoverageIterator(const PictureLayerTiling* tiling, | 145 CoverageIterator(const PictureLayerTiling* tiling, |
| 94 float dest_scale, | 146 float dest_scale, |
| 95 const gfx::Rect& rect); | 147 const gfx::Rect& rect); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 const gfx::Rect& starting_rect, | 228 const gfx::Rect& starting_rect, |
| 177 int64 target_area, | 229 int64 target_area, |
| 178 const gfx::Rect& bounding_rect, | 230 const gfx::Rect& bounding_rect, |
| 179 RectExpansionCache* cache); | 231 RectExpansionCache* cache); |
| 180 | 232 |
| 181 bool has_ever_been_updated() const { | 233 bool has_ever_been_updated() const { |
| 182 return last_impl_frame_time_in_seconds_ != 0.0; | 234 return last_impl_frame_time_in_seconds_ != 0.0; |
| 183 } | 235 } |
| 184 | 236 |
| 185 protected: | 237 protected: |
| 238 friend class TilingRasterTileIterator; |
| 239 |
| 186 typedef std::pair<int, int> TileMapKey; | 240 typedef std::pair<int, int> TileMapKey; |
| 187 typedef base::hash_map<TileMapKey, scoped_refptr<Tile> > TileMap; | 241 typedef base::hash_map<TileMapKey, scoped_refptr<Tile> > TileMap; |
| 188 | 242 |
| 189 PictureLayerTiling(float contents_scale, | 243 PictureLayerTiling(float contents_scale, |
| 190 const gfx::Size& layer_bounds, | 244 const gfx::Size& layer_bounds, |
| 191 PictureLayerTilingClient* client); | 245 PictureLayerTilingClient* client); |
| 192 void SetLiveTilesRect(const gfx::Rect& live_tiles_rect); | 246 void SetLiveTilesRect(const gfx::Rect& live_tiles_rect); |
| 193 void CreateTile(int i, int j, const PictureLayerTiling* twin_tiling); | 247 Tile* CreateTile(int i, int j, const PictureLayerTiling* twin_tiling); |
| 194 | 248 |
| 195 // Computes a skewport. The calculation extrapolates the last visible | 249 // Computes a skewport. The calculation extrapolates the last visible |
| 196 // rect and the current visible rect to expand the skewport to where it | 250 // rect and the current visible rect to expand the skewport to where it |
| 197 // would be in |skewport_target_time| seconds. Note that the skewport | 251 // would be in |skewport_target_time| seconds. Note that the skewport |
| 198 // is guaranteed to contain the current visible rect. | 252 // is guaranteed to contain the current visible rect. |
| 199 gfx::Rect ComputeSkewport(double current_frame_time_in_seconds, | 253 gfx::Rect ComputeSkewport(double current_frame_time_in_seconds, |
| 200 const gfx::Rect& visible_rect_in_content_space) | 254 const gfx::Rect& visible_rect_in_content_space) |
| 201 const; | 255 const; |
| 202 | 256 |
| 203 // Given properties. | 257 // Given properties. |
| 204 float contents_scale_; | 258 float contents_scale_; |
| 205 gfx::Size layer_bounds_; | 259 gfx::Size layer_bounds_; |
| 206 TileResolution resolution_; | 260 TileResolution resolution_; |
| 207 PictureLayerTilingClient* client_; | 261 PictureLayerTilingClient* client_; |
| 208 | 262 |
| 209 // Internal data. | 263 // Internal data. |
| 210 TilingData tiling_data_; | 264 TilingData tiling_data_; |
| 211 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map. | 265 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map. |
| 212 gfx::Rect live_tiles_rect_; | 266 gfx::Rect live_tiles_rect_; |
| 213 | 267 |
| 214 // State saved for computing velocities based upon finite differences. | 268 // State saved for computing velocities based upon finite differences. |
| 215 double last_impl_frame_time_in_seconds_; | 269 double last_impl_frame_time_in_seconds_; |
| 216 gfx::RectF last_visible_rect_in_content_space_; | 270 gfx::Rect last_visible_rect_in_content_space_; |
| 271 |
| 272 gfx::Rect current_visible_rect_in_content_space_; |
| 273 gfx::Rect current_skewport_; |
| 274 gfx::Rect current_eventually_rect_; |
| 217 | 275 |
| 218 friend class CoverageIterator; | 276 friend class CoverageIterator; |
| 219 | 277 |
| 220 private: | 278 private: |
| 221 DISALLOW_ASSIGN(PictureLayerTiling); | 279 DISALLOW_ASSIGN(PictureLayerTiling); |
| 222 | 280 |
| 223 RectExpansionCache expansion_cache_; | 281 RectExpansionCache expansion_cache_; |
| 224 }; | 282 }; |
| 225 | 283 |
| 226 } // namespace cc | 284 } // namespace cc |
| 227 | 285 |
| 228 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ | 286 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ |
| OLD | NEW |