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