| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "cc/base/cc_export.h" | 14 #include "cc/base/cc_export.h" |
| 15 #include "cc/base/region.h" | 15 #include "cc/base/region.h" |
| 16 #include "cc/base/tiling_data.h" | 16 #include "cc/base/tiling_data.h" |
| 17 #include "cc/resources/tile.h" | 17 #include "cc/resources/tile.h" |
| 18 #include "cc/resources/tile_bundle.h" | |
| 19 #include "cc/resources/tile_priority.h" | 18 #include "cc/resources/tile_priority.h" |
| 20 #include "ui/gfx/rect.h" | 19 #include "ui/gfx/rect.h" |
| 21 | 20 |
| 22 namespace cc { | 21 namespace cc { |
| 23 | 22 |
| 24 class PictureLayerTiling; | 23 class PictureLayerTiling; |
| 25 | 24 |
| 26 class CC_EXPORT PictureLayerTilingClient { | 25 class CC_EXPORT PictureLayerTilingClient { |
| 27 public: | 26 public: |
| 28 // Create a tile at the given content_rect (in the contents scale of the | 27 // Create a tile at the given content_rect (in the contents scale of the |
| 29 // tiling) This might return null if the client cannot create such a tile. | 28 // tiling) This might return null if the client cannot create such a tile. |
| 30 virtual scoped_refptr<Tile> CreateTile( | 29 virtual scoped_refptr<Tile> CreateTile( |
| 31 PictureLayerTiling* tiling, | 30 PictureLayerTiling* tiling, |
| 32 gfx::Rect content_rect) = 0; | 31 gfx::Rect content_rect) = 0; |
| 33 virtual scoped_refptr<TileBundle> CreateTileBundle(int offset_x, | |
| 34 int offset_y, | |
| 35 int width, | |
| 36 int height) = 0; | |
| 37 virtual void UpdatePile(Tile* tile) = 0; | 32 virtual void UpdatePile(Tile* tile) = 0; |
| 38 virtual gfx::Size CalculateTileSize( | 33 virtual gfx::Size CalculateTileSize( |
| 39 gfx::Size content_bounds) const = 0; | 34 gfx::Size content_bounds) const = 0; |
| 40 virtual const Region* GetInvalidation() = 0; | 35 virtual const Region* GetInvalidation() = 0; |
| 41 virtual const PictureLayerTiling* GetTwinTiling( | 36 virtual const PictureLayerTiling* GetTwinTiling( |
| 42 const PictureLayerTiling* tiling) const = 0; | 37 const PictureLayerTiling* tiling) const = 0; |
| 43 | 38 |
| 44 protected: | 39 protected: |
| 45 virtual ~PictureLayerTilingClient() {} | 40 virtual ~PictureLayerTilingClient() {} |
| 46 }; | 41 }; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 64 void SetClient(PictureLayerTilingClient* client); | 59 void SetClient(PictureLayerTilingClient* client); |
| 65 void set_resolution(TileResolution resolution) { resolution_ = resolution; } | 60 void set_resolution(TileResolution resolution) { resolution_ = resolution; } |
| 66 TileResolution resolution() const { return resolution_; } | 61 TileResolution resolution() const { return resolution_; } |
| 67 | 62 |
| 68 gfx::Rect ContentRect() const; | 63 gfx::Rect ContentRect() const; |
| 69 gfx::SizeF ContentSizeF() const; | 64 gfx::SizeF ContentSizeF() const; |
| 70 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } | 65 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } |
| 71 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } | 66 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } |
| 72 float contents_scale() const { return contents_scale_; } | 67 float contents_scale() const { return contents_scale_; } |
| 73 | 68 |
| 74 Tile* TileAt(WhichTree tree, int, int) const; | |
| 75 | |
| 76 void SetTreeForTesting(WhichTree tree) { | |
| 77 current_tree_ = tree; | |
| 78 } | |
| 79 void CreateAllTilesForTesting() { | 69 void CreateAllTilesForTesting() { |
| 80 current_tree_ = ACTIVE_TREE; | |
| 81 SetLiveTilesRect(gfx::Rect(tiling_data_.total_size())); | |
| 82 live_tiles_rect_ = gfx::Rect(); | |
| 83 current_tree_ = PENDING_TREE; | |
| 84 SetLiveTilesRect(gfx::Rect(tiling_data_.total_size())); | 70 SetLiveTilesRect(gfx::Rect(tiling_data_.total_size())); |
| 85 } | 71 } |
| 86 void CreateTilesForTesting(WhichTree tree) { | 72 |
| 87 current_tree_ = tree; | |
| 88 SetLiveTilesRect(gfx::Rect(tiling_data_.total_size())); | |
| 89 } | |
| 90 std::vector<Tile*> AllTilesForTesting() const { | 73 std::vector<Tile*> AllTilesForTesting() const { |
| 91 std::vector<Tile*> all_tiles; | 74 std::vector<Tile*> all_tiles; |
| 92 for (TileBundleMap::const_iterator it = tile_bundles_.begin(); | 75 for (TileMap::const_iterator it = tiles_.begin(); |
| 93 it != tile_bundles_.end(); ++it) { | 76 it != tiles_.end(); ++it) |
| 94 for (TileBundle::Iterator tile_it(it->second.get()); tile_it; ++tile_it) | 77 all_tiles.push_back(it->second.get()); |
| 95 all_tiles.push_back(*tile_it); | |
| 96 } | |
| 97 return all_tiles; | |
| 98 } | |
| 99 std::vector<TileBundle*> AllTileBundlesForTesting() const { | |
| 100 std::vector<TileBundle*> all_bundles; | |
| 101 for (TileBundleMap::const_iterator it = tile_bundles_.begin(); | |
| 102 it != tile_bundles_.end(); ++it) { | |
| 103 all_bundles.push_back(it->second.get()); | |
| 104 } | |
| 105 return all_bundles; | |
| 106 } | |
| 107 std::vector<Tile*> TilesForTesting(WhichTree tree) const { | |
| 108 std::vector<Tile*> all_tiles; | |
| 109 for (TileBundleMap::const_iterator it = tile_bundles_.begin(); | |
| 110 it != tile_bundles_.end(); ++it) { | |
| 111 for (TileBundle::Iterator tile_it(it->second.get(), tree); | |
| 112 tile_it; | |
| 113 ++tile_it) { | |
| 114 all_tiles.push_back(*tile_it); | |
| 115 } | |
| 116 } | |
| 117 return all_tiles; | 78 return all_tiles; |
| 118 } | 79 } |
| 119 | 80 |
| 120 Tile* TileAt(int i, int j) const; | 81 Tile* TileAt(int i, int j) const; |
| 121 | 82 |
| 122 // Iterate over all tiles to fill content_rect. Even if tiles are invalid | 83 // Iterate over all tiles to fill content_rect. Even if tiles are invalid |
| 123 // (i.e. no valid resource) this tiling should still iterate over them. | 84 // (i.e. no valid resource) this tiling should still iterate over them. |
| 124 // The union of all geometry_rect calls for each element iterated over should | 85 // The union of all geometry_rect calls for each element iterated over should |
| 125 // exactly equal content_rect and no two geometry_rects should intersect. | 86 // exactly equal content_rect and no two geometry_rects should intersect. |
| 126 class CC_EXPORT CoverageIterator { | 87 class CC_EXPORT CoverageIterator { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 138 gfx::RectF texture_rect() const; | 99 gfx::RectF texture_rect() const; |
| 139 gfx::Size texture_size() const; | 100 gfx::Size texture_size() const; |
| 140 | 101 |
| 141 // Full rect (including borders) of the current tile, always in the space | 102 // Full rect (including borders) of the current tile, always in the space |
| 142 // of content_rect, regardless of the contents scale of the tiling. | 103 // of content_rect, regardless of the contents scale of the tiling. |
| 143 gfx::Rect full_tile_geometry_rect() const; | 104 gfx::Rect full_tile_geometry_rect() const; |
| 144 | 105 |
| 145 Tile* operator->() const { return current_tile_; } | 106 Tile* operator->() const { return current_tile_; } |
| 146 Tile* operator*() const { return current_tile_; } | 107 Tile* operator*() const { return current_tile_; } |
| 147 | 108 |
| 148 TilePriority priority(); | |
| 149 void SetPriorityForTesting(const TilePriority& priority); | |
| 150 | |
| 151 CoverageIterator& operator++(); | 109 CoverageIterator& operator++(); |
| 152 operator bool() const { return tile_j_ <= bottom_; } | 110 operator bool() const { return tile_j_ <= bottom_; } |
| 153 | 111 |
| 154 int i() const { return tile_i_; } | 112 int i() const { return tile_i_; } |
| 155 int j() const { return tile_j_; } | 113 int j() const { return tile_j_; } |
| 156 | 114 |
| 157 private: | 115 private: |
| 158 const PictureLayerTiling* tiling_; | 116 const PictureLayerTiling* tiling_; |
| 159 gfx::Rect dest_rect_; | 117 gfx::Rect dest_rect_; |
| 160 float dest_to_content_scale_; | 118 float dest_to_content_scale_; |
| 161 | 119 |
| 162 Tile* current_tile_; | 120 Tile* current_tile_; |
| 163 gfx::Rect current_geometry_rect_; | 121 gfx::Rect current_geometry_rect_; |
| 164 int tile_i_; | 122 int tile_i_; |
| 165 int tile_j_; | 123 int tile_j_; |
| 166 int left_; | 124 int left_; |
| 167 int top_; | 125 int top_; |
| 168 int right_; | 126 int right_; |
| 169 int bottom_; | 127 int bottom_; |
| 170 WhichTree tree_; | |
| 171 | 128 |
| 172 friend class PictureLayerTiling; | 129 friend class PictureLayerTiling; |
| 173 }; | 130 }; |
| 174 | 131 |
| 175 Region OpaqueRegionInContentRect(gfx::Rect content_rect) const; | 132 Region OpaqueRegionInContentRect(gfx::Rect content_rect) const; |
| 176 | 133 |
| 177 void Reset(); | 134 void Reset(); |
| 178 | 135 |
| 179 void UpdateTilePriorities( | 136 void UpdateTilePriorities( |
| 180 WhichTree tree, | 137 WhichTree tree, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 gfx::Rect starting_rect, | 182 gfx::Rect starting_rect, |
| 226 int64 target_area, | 183 int64 target_area, |
| 227 gfx::Rect bounding_rect, | 184 gfx::Rect bounding_rect, |
| 228 RectExpansionCache* cache); | 185 RectExpansionCache* cache); |
| 229 | 186 |
| 230 bool has_ever_been_updated() const { | 187 bool has_ever_been_updated() const { |
| 231 return last_impl_frame_time_in_seconds_ != 0.0; | 188 return last_impl_frame_time_in_seconds_ != 0.0; |
| 232 } | 189 } |
| 233 | 190 |
| 234 protected: | 191 protected: |
| 235 friend class CoverageIterator; | 192 typedef std::pair<int, int> TileMapKey; |
| 236 friend class TileBundle; | 193 typedef base::hash_map<TileMapKey, scoped_refptr<Tile> > TileMap; |
| 237 | |
| 238 typedef std::pair<int, int> TileBundleMapKey; | |
| 239 typedef base::hash_map<TileBundleMapKey, scoped_refptr<TileBundle> > | |
| 240 TileBundleMap; | |
| 241 | 194 |
| 242 PictureLayerTiling(float contents_scale, | 195 PictureLayerTiling(float contents_scale, |
| 243 gfx::Size layer_bounds, | 196 gfx::Size layer_bounds, |
| 244 PictureLayerTilingClient* client); | 197 PictureLayerTilingClient* client); |
| 245 void SetLiveTilesRect(gfx::Rect live_tiles_rect); | 198 void SetLiveTilesRect(gfx::Rect live_tiles_rect); |
| 246 void CreateTile(WhichTree tree, | 199 void CreateTile(int i, int j, const PictureLayerTiling* twin_tiling); |
| 247 int i, | |
| 248 int j, | |
| 249 const PictureLayerTiling* twin_tiling); | |
| 250 bool RemoveTile(WhichTree tree, int i, int j); | |
| 251 void RemoveBundleContainingTileAtIfEmpty(int i, int j); | |
| 252 TileBundle* TileBundleContainingTileAt(int, int) const; | |
| 253 TileBundle* CreateBundleForTileAt(int, | |
| 254 int, | |
| 255 const PictureLayerTiling* twin_tiling); | |
| 256 TileBundle* TileBundleAt(int, int) const; | |
| 257 | 200 |
| 258 // Given properties. | 201 // Given properties. |
| 259 float contents_scale_; | 202 float contents_scale_; |
| 260 gfx::Size layer_bounds_; | 203 gfx::Size layer_bounds_; |
| 261 TileResolution resolution_; | 204 TileResolution resolution_; |
| 262 PictureLayerTilingClient* client_; | 205 PictureLayerTilingClient* client_; |
| 263 | 206 |
| 264 // Internal data. | 207 // Internal data. |
| 265 TilingData tiling_data_; | 208 TilingData tiling_data_; |
| 266 TilingData bundle_tiling_data_; | 209 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map. |
| 267 // It is not legal to have a NULL tile bundle in the tile_bundles_ map. | |
| 268 TileBundleMap tile_bundles_; | |
| 269 gfx::Rect live_tiles_rect_; | 210 gfx::Rect live_tiles_rect_; |
| 270 WhichTree current_tree_; | |
| 271 | 211 |
| 272 // State saved for computing velocities based upon finite differences. | 212 // State saved for computing velocities based upon finite differences. |
| 273 double last_impl_frame_time_in_seconds_; | 213 double last_impl_frame_time_in_seconds_; |
| 274 | 214 |
| 215 friend class CoverageIterator; |
| 216 |
| 275 private: | 217 private: |
| 276 DISALLOW_ASSIGN(PictureLayerTiling); | 218 DISALLOW_ASSIGN(PictureLayerTiling); |
| 277 | 219 |
| 278 RectExpansionCache expansion_cache_; | 220 RectExpansionCache expansion_cache_; |
| 279 }; | 221 }; |
| 280 | 222 |
| 281 } // namespace cc | 223 } // namespace cc |
| 282 | 224 |
| 283 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ | 225 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ |
| OLD | NEW |