| 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 <set> | 8 #include <set> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 virtual bool RequiresHighResToDraw() const = 0; | 51 virtual bool RequiresHighResToDraw() const = 0; |
| 52 | 52 |
| 53 protected: | 53 protected: |
| 54 virtual ~PictureLayerTilingClient() {} | 54 virtual ~PictureLayerTilingClient() {} |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 class CC_EXPORT PictureLayerTiling { | 57 class CC_EXPORT PictureLayerTiling { |
| 58 public: | 58 public: |
| 59 static const int kBorderTexels = 1; | 59 static const int kBorderTexels = 1; |
| 60 | 60 |
| 61 class CC_EXPORT TilingRasterTileIterator { | |
| 62 public: | |
| 63 TilingRasterTileIterator(); | |
| 64 explicit TilingRasterTileIterator(PictureLayerTiling* tiling); | |
| 65 ~TilingRasterTileIterator(); | |
| 66 | |
| 67 operator bool() const { return !!current_tile_; } | |
| 68 const Tile* operator*() const { return current_tile_; } | |
| 69 Tile* operator*() { return current_tile_; } | |
| 70 TilePriority::PriorityBin get_type() const { | |
| 71 switch (phase_) { | |
| 72 case VISIBLE_RECT: | |
| 73 return TilePriority::NOW; | |
| 74 case SKEWPORT_RECT: | |
| 75 case SOON_BORDER_RECT: | |
| 76 return TilePriority::SOON; | |
| 77 case EVENTUALLY_RECT: | |
| 78 return TilePriority::EVENTUALLY; | |
| 79 } | |
| 80 NOTREACHED(); | |
| 81 return TilePriority::EVENTUALLY; | |
| 82 } | |
| 83 | |
| 84 TilingRasterTileIterator& operator++(); | |
| 85 | |
| 86 private: | |
| 87 enum Phase { | |
| 88 VISIBLE_RECT, | |
| 89 SKEWPORT_RECT, | |
| 90 SOON_BORDER_RECT, | |
| 91 EVENTUALLY_RECT | |
| 92 }; | |
| 93 | |
| 94 void AdvancePhase(); | |
| 95 bool TileNeedsRaster(Tile* tile) const { | |
| 96 return tile->NeedsRaster() && !tiling_->IsTileOccluded(tile); | |
| 97 } | |
| 98 | |
| 99 PictureLayerTiling* tiling_; | |
| 100 | |
| 101 Phase phase_; | |
| 102 | |
| 103 Tile* current_tile_; | |
| 104 TilingData::Iterator visible_iterator_; | |
| 105 TilingData::SpiralDifferenceIterator spiral_iterator_; | |
| 106 }; | |
| 107 | |
| 108 ~PictureLayerTiling(); | 61 ~PictureLayerTiling(); |
| 109 | 62 |
| 110 // Create a tiling with no tiles. CreateTile() must be called to add some. | 63 // Create a tiling with no tiles. CreateTile() must be called to add some. |
| 111 static scoped_ptr<PictureLayerTiling> Create( | 64 static scoped_ptr<PictureLayerTiling> Create( |
| 112 float contents_scale, | 65 float contents_scale, |
| 113 scoped_refptr<RasterSource> raster_source, | 66 scoped_refptr<RasterSource> raster_source, |
| 114 PictureLayerTilingClient* client, | 67 PictureLayerTilingClient* client, |
| 115 size_t max_tiles_for_interest_area, | 68 size_t max_tiles_for_interest_area, |
| 116 float skewport_target_time_in_seconds, | 69 float skewport_target_time_in_seconds, |
| 117 int skewport_extrapolation_limit_in_content_pixels); | 70 int skewport_extrapolation_limit_in_content_pixels); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 148 | 101 |
| 149 std::vector<Tile*> AllTilesForTesting() const { | 102 std::vector<Tile*> AllTilesForTesting() const { |
| 150 std::vector<Tile*> all_tiles; | 103 std::vector<Tile*> all_tiles; |
| 151 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 104 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 152 all_tiles.push_back(it->second.get()); | 105 all_tiles.push_back(it->second.get()); |
| 153 return all_tiles; | 106 return all_tiles; |
| 154 } | 107 } |
| 155 | 108 |
| 156 void UpdateAllTilePrioritiesForTesting() { | 109 void UpdateAllTilePrioritiesForTesting() { |
| 157 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 110 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 158 UpdateTileAndTwinPriority(it->second.get()); | 111 UpdateTilePriority(it->second.get()); |
| 159 } | 112 } |
| 160 | 113 |
| 161 std::vector<scoped_refptr<Tile>> AllRefTilesForTesting() const { | 114 std::vector<scoped_refptr<Tile>> AllRefTilesForTesting() const { |
| 162 std::vector<scoped_refptr<Tile>> all_tiles; | 115 std::vector<scoped_refptr<Tile>> all_tiles; |
| 163 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 116 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 164 all_tiles.push_back(it->second); | 117 all_tiles.push_back(it->second); |
| 165 return all_tiles; | 118 return all_tiles; |
| 166 } | 119 } |
| 167 | 120 |
| 168 void SetAllTilesOccludedForTesting() { | 121 void SetAllTilesOccludedForTesting() { |
| 169 gfx::Rect viewport_in_layer_space = | 122 gfx::Rect viewport_in_layer_space = |
| 170 ScaleToEnclosingRect(current_visible_rect_, 1.0f / contents_scale_); | 123 ScaleToEnclosingRect(current_visible_rect_, 1.0f / contents_scale_); |
| 171 current_occlusion_in_layer_space_ = | 124 current_occlusion_in_layer_space_ = |
| 172 Occlusion(gfx::Transform(), | 125 Occlusion(gfx::Transform(), |
| 173 SimpleEnclosedRegion(viewport_in_layer_space), | 126 SimpleEnclosedRegion(viewport_in_layer_space), |
| 174 SimpleEnclosedRegion(viewport_in_layer_space)); | 127 SimpleEnclosedRegion(viewport_in_layer_space)); |
| 175 } | 128 } |
| 176 | 129 |
| 177 const gfx::Rect& GetCurrentVisibleRectForTesting() const { | 130 const gfx::Rect& GetCurrentVisibleRectForTesting() const { |
| 178 return current_visible_rect_; | 131 return current_visible_rect_; |
| 179 } | 132 } |
| 180 | 133 |
| 181 bool IsTileOccluded(const Tile* tile) const; | 134 bool IsTileOccluded(const Tile* tile) const; |
| 182 bool IsTileRequiredForActivationIfVisible(const Tile* tile) const; | 135 bool IsTileRequiredForActivationIfVisible(const Tile* tile) const; |
| 183 bool IsTileRequiredForDrawIfVisible(const Tile* tile) const; | 136 bool IsTileRequiredForDrawIfVisible(const Tile* tile) const; |
| 184 | 137 |
| 138 void UpdateTilePriority(Tile* tile) const; |
| 139 bool has_visible_rect_tiles() const { return has_visible_rect_tiles_; } |
| 140 bool has_skewport_rect_tiles() const { return has_skewport_rect_tiles_; } |
| 141 bool has_soon_border_rect_tiles() const { |
| 142 return has_soon_border_rect_tiles_; |
| 143 } |
| 144 bool has_eventually_rect_tiles() const { return has_eventually_rect_tiles_; } |
| 145 |
| 146 const gfx::Rect& current_visible_rect() const { |
| 147 return current_visible_rect_; |
| 148 } |
| 149 const gfx::Rect& current_skewport_rect() const { |
| 150 return current_skewport_rect_; |
| 151 } |
| 152 const gfx::Rect& current_soon_border_rect() const { |
| 153 return current_soon_border_rect_; |
| 154 } |
| 155 const gfx::Rect& current_eventually_rect() const { |
| 156 return current_eventually_rect_; |
| 157 } |
| 158 |
| 185 // Iterate over all tiles to fill content_rect. Even if tiles are invalid | 159 // Iterate over all tiles to fill content_rect. Even if tiles are invalid |
| 186 // (i.e. no valid resource) this tiling should still iterate over them. | 160 // (i.e. no valid resource) this tiling should still iterate over them. |
| 187 // The union of all geometry_rect calls for each element iterated over should | 161 // The union of all geometry_rect calls for each element iterated over should |
| 188 // exactly equal content_rect and no two geometry_rects should intersect. | 162 // exactly equal content_rect and no two geometry_rects should intersect. |
| 189 class CC_EXPORT CoverageIterator { | 163 class CC_EXPORT CoverageIterator { |
| 190 public: | 164 public: |
| 191 CoverageIterator(); | 165 CoverageIterator(); |
| 192 CoverageIterator(const PictureLayerTiling* tiling, | 166 CoverageIterator(const PictureLayerTiling* tiling, |
| 193 float dest_scale, | 167 float dest_scale, |
| 194 const gfx::Rect& rect); | 168 const gfx::Rect& rect); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 int64 target_area, | 226 int64 target_area, |
| 253 const gfx::Rect& bounding_rect, | 227 const gfx::Rect& bounding_rect, |
| 254 RectExpansionCache* cache); | 228 RectExpansionCache* cache); |
| 255 | 229 |
| 256 bool has_ever_been_updated() const { | 230 bool has_ever_been_updated() const { |
| 257 return last_impl_frame_time_in_seconds_ != 0.0; | 231 return last_impl_frame_time_in_seconds_ != 0.0; |
| 258 } | 232 } |
| 259 | 233 |
| 260 protected: | 234 protected: |
| 261 friend class CoverageIterator; | 235 friend class CoverageIterator; |
| 262 friend class TilingRasterTileIterator; | 236 friend class TilingSetRasterQueue; |
| 263 friend class TilingSetEvictionQueue; | 237 friend class TilingSetEvictionQueue; |
| 264 | 238 |
| 265 typedef std::pair<int, int> TileMapKey; | 239 typedef std::pair<int, int> TileMapKey; |
| 266 typedef base::hash_map<TileMapKey, scoped_refptr<Tile>> TileMap; | 240 typedef base::hash_map<TileMapKey, scoped_refptr<Tile>> TileMap; |
| 267 | 241 |
| 268 PictureLayerTiling(float contents_scale, | 242 PictureLayerTiling(float contents_scale, |
| 269 scoped_refptr<RasterSource> raster_source, | 243 scoped_refptr<RasterSource> raster_source, |
| 270 PictureLayerTilingClient* client, | 244 PictureLayerTilingClient* client, |
| 271 size_t max_tiles_for_interest_area, | 245 size_t max_tiles_for_interest_area, |
| 272 float skewport_target_time_in_seconds, | 246 float skewport_target_time_in_seconds, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 289 const; | 263 const; |
| 290 | 264 |
| 291 // Save the required data for computing tile priorities later. | 265 // Save the required data for computing tile priorities later. |
| 292 void UpdateTilePriorityRects(float content_to_screen_scale_, | 266 void UpdateTilePriorityRects(float content_to_screen_scale_, |
| 293 const gfx::Rect& visible_rect_in_content_space, | 267 const gfx::Rect& visible_rect_in_content_space, |
| 294 const gfx::Rect& skewport, | 268 const gfx::Rect& skewport, |
| 295 const gfx::Rect& soon_border_rect, | 269 const gfx::Rect& soon_border_rect, |
| 296 const gfx::Rect& eventually_rect, | 270 const gfx::Rect& eventually_rect, |
| 297 const Occlusion& occlusion_in_layer_space); | 271 const Occlusion& occlusion_in_layer_space); |
| 298 | 272 |
| 299 void UpdateTileAndTwinPriority(Tile* tile) const; | 273 void UpdateTilePriorityForTree(Tile* tile, WhichTree tree) const; |
| 300 void UpdateTilePriority(Tile* tile) const; | |
| 301 bool NeedsUpdateForFrameAtTimeAndViewport( | 274 bool NeedsUpdateForFrameAtTimeAndViewport( |
| 302 double frame_time_in_seconds, | 275 double frame_time_in_seconds, |
| 303 const gfx::Rect& viewport_in_layer_space) { | 276 const gfx::Rect& viewport_in_layer_space) { |
| 304 return frame_time_in_seconds != last_impl_frame_time_in_seconds_ || | 277 return frame_time_in_seconds != last_impl_frame_time_in_seconds_ || |
| 305 viewport_in_layer_space != last_viewport_in_layer_space_; | 278 viewport_in_layer_space != last_viewport_in_layer_space_; |
| 306 } | 279 } |
| 307 | 280 |
| 308 const size_t max_tiles_for_interest_area_; | 281 const size_t max_tiles_for_interest_area_; |
| 309 const float skewport_target_time_in_seconds_; | 282 const float skewport_target_time_in_seconds_; |
| 310 const int skewport_extrapolation_limit_in_content_pixels_; | 283 const int skewport_extrapolation_limit_in_content_pixels_; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 316 |
| 344 private: | 317 private: |
| 345 DISALLOW_ASSIGN(PictureLayerTiling); | 318 DISALLOW_ASSIGN(PictureLayerTiling); |
| 346 | 319 |
| 347 RectExpansionCache expansion_cache_; | 320 RectExpansionCache expansion_cache_; |
| 348 }; | 321 }; |
| 349 | 322 |
| 350 } // namespace cc | 323 } // namespace cc |
| 351 | 324 |
| 352 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ | 325 #endif // CC_RESOURCES_PICTURE_LAYER_TILING_H_ |
| OLD | NEW |