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 <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) = 0; | 42 const PictureLayerTiling* tiling) = 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 // 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 |
| 82 // (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. |
| 83 // 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 |
| 84 // exactly equal content_rect and no two geometry_rects should intersect. | 123 // exactly equal content_rect and no two geometry_rects should intersect. |
| 85 class CC_EXPORT CoverageIterator { | 124 class CC_EXPORT CoverageIterator { |
| 86 public: | 125 public: |
| 87 CoverageIterator(); | 126 CoverageIterator(); |
| 88 CoverageIterator(const PictureLayerTiling* tiling, | 127 CoverageIterator(const PictureLayerTiling* tiling, |
| 89 float dest_scale, | 128 float dest_scale, |
| 90 gfx::Rect rect); | 129 gfx::Rect rect); |
| 91 ~CoverageIterator(); | 130 ~CoverageIterator(); |
| 92 | 131 |
| 93 // Visible rect (no borders), always in the space of content_rect, | 132 // Visible rect (no borders), always in the space of content_rect, |
| 94 // regardless of the contents scale of the tiling. | 133 // regardless of the contents scale of the tiling. |
| 95 gfx::Rect geometry_rect() const; | 134 gfx::Rect geometry_rect() const; |
| 96 // Texture rect (in texels) for geometry_rect | 135 // Texture rect (in texels) for geometry_rect |
| 97 gfx::RectF texture_rect() const; | 136 gfx::RectF texture_rect() const; |
| 98 gfx::Size texture_size() const; | 137 gfx::Size texture_size() const; |
| 99 | 138 |
| 100 // 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 |
| 101 // of content_rect, regardless of the contents scale of the tiling. | 140 // of content_rect, regardless of the contents scale of the tiling. |
| 102 gfx::Rect full_tile_geometry_rect() const; | 141 gfx::Rect full_tile_geometry_rect() const; |
| 103 | 142 |
| 104 Tile* operator->() const { return current_tile_; } | 143 Tile* operator->() const { return current_tile_; } |
| 105 Tile* operator*() const { return current_tile_; } | 144 Tile* operator*() const { return current_tile_; } |
| 106 | 145 |
| 146 TilePriority priority(); | |
| 147 void SetPriorityForTesting(const TilePriority& priority); | |
| 148 | |
| 107 CoverageIterator& operator++(); | 149 CoverageIterator& operator++(); |
| 108 operator bool() const { return tile_j_ <= bottom_; } | 150 operator bool() const { return tile_j_ <= bottom_; } |
| 109 | 151 |
| 110 private: | 152 private: |
| 111 const PictureLayerTiling* tiling_; | 153 const PictureLayerTiling* tiling_; |
| 112 gfx::Rect dest_rect_; | 154 gfx::Rect dest_rect_; |
| 113 float dest_to_content_scale_; | 155 float dest_to_content_scale_; |
| 114 | 156 |
| 115 Tile* current_tile_; | 157 Tile* current_tile_; |
| 116 gfx::Rect current_geometry_rect_; | 158 gfx::Rect current_geometry_rect_; |
| 117 int tile_i_; | 159 int tile_i_; |
| 118 int tile_j_; | 160 int tile_j_; |
| 119 int left_; | 161 int left_; |
| 120 int top_; | 162 int top_; |
| 121 int right_; | 163 int right_; |
| 122 int bottom_; | 164 int bottom_; |
| 165 WhichTree tree_; | |
| 123 | 166 |
| 124 friend class PictureLayerTiling; | 167 friend class PictureLayerTiling; |
| 125 }; | 168 }; |
| 126 | 169 |
| 127 Region OpaqueRegionInContentRect(gfx::Rect content_rect) const; | 170 Region OpaqueRegionInContentRect(gfx::Rect content_rect) const; |
| 128 | 171 |
| 129 void Reset(); | 172 void Reset(); |
| 130 | 173 |
| 131 void UpdateTilePriorities( | 174 void UpdateTilePriorities( |
| 132 WhichTree tree, | 175 WhichTree tree, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 gfx::Rect starting_rect, | 220 gfx::Rect starting_rect, |
| 178 int64 target_area, | 221 int64 target_area, |
| 179 gfx::Rect bounding_rect, | 222 gfx::Rect bounding_rect, |
| 180 RectExpansionCache* cache); | 223 RectExpansionCache* cache); |
| 181 | 224 |
| 182 bool has_ever_been_updated() const { | 225 bool has_ever_been_updated() const { |
| 183 return last_impl_frame_time_in_seconds_ != 0.0; | 226 return last_impl_frame_time_in_seconds_ != 0.0; |
| 184 } | 227 } |
| 185 | 228 |
| 186 protected: | 229 protected: |
| 187 typedef std::pair<int, int> TileMapKey; | 230 friend class TileBundle; |
| 188 typedef base::hash_map<TileMapKey, scoped_refptr<Tile> > TileMap; | 231 |
| 232 typedef std::pair<int, int> TileBundleMapKey; | |
| 233 typedef base::hash_map<TileBundleMapKey, scoped_refptr<TileBundle> > | |
| 234 TileBundleMap; | |
| 189 | 235 |
| 190 PictureLayerTiling(float contents_scale, | 236 PictureLayerTiling(float contents_scale, |
| 191 gfx::Size layer_bounds, | 237 gfx::Size layer_bounds, |
| 192 PictureLayerTilingClient* client); | 238 PictureLayerTilingClient* client); |
| 193 void SetLiveTilesRect(gfx::Rect live_tiles_rect); | 239 void SetLiveTilesRect(gfx::Rect live_tiles_rect); |
| 194 void CreateTile(int i, int j, const PictureLayerTiling* twin_tiling); | 240 void CreateTile(WhichTree tree, |
| 195 Tile* TileAt(int, int) const; | 241 int i, |
| 242 int j, | |
| 243 const PictureLayerTiling* twin_tiling); | |
| 244 bool RemoveTile(WhichTree tree, int i, int j); | |
| 245 void RemoveBundleContainingTileAtIfEmpty(int i, int j); | |
| 246 TileBundle* TileBundleContainingTileAt(int, int) const; | |
| 247 TileBundle* CreateBundleForTileAt(int, | |
| 248 int, | |
| 249 const PictureLayerTiling* twin_tiling); | |
| 250 TileBundle* TileBundleAt(int, int) const; | |
| 196 | 251 |
| 197 // Given properties. | 252 // Given properties. |
| 198 float contents_scale_; | 253 float contents_scale_; |
| 199 gfx::Size layer_bounds_; | 254 gfx::Size layer_bounds_; |
| 200 TileResolution resolution_; | 255 TileResolution resolution_; |
| 201 PictureLayerTilingClient* client_; | 256 PictureLayerTilingClient* client_; |
| 202 | 257 |
| 203 // Internal data. | 258 // Internal data. |
| 204 TilingData tiling_data_; | 259 TilingData tiling_data_; |
| 205 TileMap tiles_; // It is not legal to have a NULL tile in the tiles_ map. | 260 TilingData bundle_tiling_data_; |
| 261 // It is not legal to have a NULL tile bundle in the tile_bundles_ map. | |
| 262 TileBundleMap tile_bundles_; | |
| 206 gfx::Rect live_tiles_rect_; | 263 gfx::Rect live_tiles_rect_; |
| 264 WhichTree current_tree_; | |
| 207 | 265 |
| 208 // State saved for computing velocities based upon finite differences. | 266 // State saved for computing velocities based upon finite differences. |
| 209 double last_impl_frame_time_in_seconds_; | 267 double last_impl_frame_time_in_seconds_; |
| 210 | 268 |
| 211 friend class CoverageIterator; | 269 friend class CoverageIterator; |
|
enne (OOO)
2013/12/04 01:01:38
Not your fault, but can you move this friend to be
vmpstr
2013/12/04 01:11:57
Done.
| |
| 212 | 270 |
| 213 private: | 271 private: |
| 214 DISALLOW_ASSIGN(PictureLayerTiling); | 272 DISALLOW_ASSIGN(PictureLayerTiling); |
| 215 | 273 |
| 216 RectExpansionCache expansion_cache_; | 274 RectExpansionCache expansion_cache_; |
| 217 }; | 275 }; |
| 218 | 276 |
| 219 } // namespace cc | 277 } // namespace cc |
| 220 | 278 |
| 221 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ | 279 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ |
| OLD | NEW |