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