| 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_TILES_PICTURE_LAYER_TILING_H_ | 5 #ifndef CC_TILES_PICTURE_LAYER_TILING_H_ |
| 6 #define CC_TILES_PICTURE_LAYER_TILING_H_ | 6 #define CC_TILES_PICTURE_LAYER_TILING_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <unordered_map> |
| 12 #include <utility> | 13 #include <utility> |
| 13 #include <vector> | 14 #include <vector> |
| 14 | 15 |
| 15 #include "base/containers/scoped_ptr_hash_map.h" | |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "cc/base/cc_export.h" | 18 #include "cc/base/cc_export.h" |
| 19 #include "cc/base/region.h" | 19 #include "cc/base/region.h" |
| 20 #include "cc/base/tiling_data.h" | 20 #include "cc/base/tiling_data.h" |
| 21 #include "cc/tiles/tile.h" | 21 #include "cc/tiles/tile.h" |
| 22 #include "cc/tiles/tile_priority.h" | 22 #include "cc/tiles/tile_priority.h" |
| 23 #include "cc/trees/occlusion.h" | 23 #include "cc/trees/occlusion.h" |
| 24 #include "ui/gfx/geometry/rect.h" | 24 #include "ui/gfx/geometry/rect.h" |
| 25 | 25 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 : index_x(index.first), index_y(index.second) {} | 60 : index_x(index.first), index_y(index.second) {} |
| 61 | 61 |
| 62 bool operator==(const TileMapKey& other) const { | 62 bool operator==(const TileMapKey& other) const { |
| 63 return index_x == other.index_x && index_y == other.index_y; | 63 return index_x == other.index_x && index_y == other.index_y; |
| 64 } | 64 } |
| 65 | 65 |
| 66 int index_x; | 66 int index_x; |
| 67 int index_y; | 67 int index_y; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 } // namespace cc | 70 struct TileMapKeyHash { |
| 71 | 71 size_t operator()(const TileMapKey& key) const { |
| 72 namespace BASE_HASH_NAMESPACE { | |
| 73 template <> | |
| 74 struct hash<cc::TileMapKey> { | |
| 75 size_t operator()(const cc::TileMapKey& key) const { | |
| 76 uint16_t value1 = static_cast<uint16_t>(key.index_x); | 72 uint16_t value1 = static_cast<uint16_t>(key.index_x); |
| 77 uint16_t value2 = static_cast<uint16_t>(key.index_y); | 73 uint16_t value2 = static_cast<uint16_t>(key.index_y); |
| 78 uint32_t value1_32 = value1; | 74 uint32_t value1_32 = value1; |
| 79 return (value1_32 << 16) | value2; | 75 return (value1_32 << 16) | value2; |
| 80 } | 76 } |
| 81 }; | 77 }; |
| 82 } // namespace BASE_HASH_NAMESPACE | |
| 83 | |
| 84 namespace cc { | |
| 85 | 78 |
| 86 class CC_EXPORT PictureLayerTiling { | 79 class CC_EXPORT PictureLayerTiling { |
| 87 public: | 80 public: |
| 88 static const int kBorderTexels = 1; | 81 static const int kBorderTexels = 1; |
| 89 | 82 |
| 90 PictureLayerTilingClient* client() const { return client_; } | 83 PictureLayerTilingClient* client() const { return client_; } |
| 91 ~PictureLayerTiling(); | 84 ~PictureLayerTiling(); |
| 92 | 85 |
| 93 static float CalculateSoonBorderDistance( | 86 static float CalculateSoonBorderDistance( |
| 94 const gfx::Rect& visible_rect_in_content_space, | 87 const gfx::Rect& visible_rect_in_content_space, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 return raster_source_.get(); | 126 return raster_source_.get(); |
| 134 } | 127 } |
| 135 gfx::Size tiling_size() const { return tiling_data_.tiling_size(); } | 128 gfx::Size tiling_size() const { return tiling_data_.tiling_size(); } |
| 136 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } | 129 gfx::Rect live_tiles_rect() const { return live_tiles_rect_; } |
| 137 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } | 130 gfx::Size tile_size() const { return tiling_data_.max_texture_size(); } |
| 138 float contents_scale() const { return contents_scale_; } | 131 float contents_scale() const { return contents_scale_; } |
| 139 const TilingData* tiling_data() const { return &tiling_data_; } | 132 const TilingData* tiling_data() const { return &tiling_data_; } |
| 140 | 133 |
| 141 Tile* TileAt(int i, int j) const { | 134 Tile* TileAt(int i, int j) const { |
| 142 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); | 135 TileMap::const_iterator iter = tiles_.find(TileMapKey(i, j)); |
| 143 return iter == tiles_.end() ? nullptr : iter->second; | 136 return iter == tiles_.end() ? nullptr : iter->second.get(); |
| 144 } | 137 } |
| 145 | 138 |
| 146 bool has_tiles() const { return !tiles_.empty(); } | 139 bool has_tiles() const { return !tiles_.empty(); } |
| 147 // all_tiles_done() can return false negatives. | 140 // all_tiles_done() can return false negatives. |
| 148 bool all_tiles_done() const { return all_tiles_done_; } | 141 bool all_tiles_done() const { return all_tiles_done_; } |
| 149 void set_all_tiles_done(bool all_tiles_done) { | 142 void set_all_tiles_done(bool all_tiles_done) { |
| 150 all_tiles_done_ = all_tiles_done; | 143 all_tiles_done_ = all_tiles_done; |
| 151 } | 144 } |
| 152 | 145 |
| 153 void VerifyNoTileNeedsRaster() const { | 146 void VerifyNoTileNeedsRaster() const { |
| 154 #if DCHECK_IS_ON() | 147 #if DCHECK_IS_ON() |
| 155 for (const auto tile_pair : tiles_) { | 148 for (const auto& tile_pair : tiles_) { |
| 156 DCHECK(!tile_pair.second->draw_info().NeedsRaster() || | 149 DCHECK(!tile_pair.second->draw_info().NeedsRaster() || |
| 157 IsTileOccluded(tile_pair.second)); | 150 IsTileOccluded(tile_pair.second.get())); |
| 158 } | 151 } |
| 159 #endif // DCHECK_IS_ON() | 152 #endif // DCHECK_IS_ON() |
| 160 } | 153 } |
| 161 | 154 |
| 162 // For testing functionality. | 155 // For testing functionality. |
| 163 void CreateAllTilesForTesting() { | 156 void CreateAllTilesForTesting() { |
| 164 SetLiveTilesRect(gfx::Rect(tiling_data_.tiling_size())); | 157 SetLiveTilesRect(gfx::Rect(tiling_data_.tiling_size())); |
| 165 } | 158 } |
| 166 const TilingData& TilingDataForTesting() const { return tiling_data_; } | 159 const TilingData& TilingDataForTesting() const { return tiling_data_; } |
| 167 std::vector<Tile*> AllTilesForTesting() const { | 160 std::vector<Tile*> AllTilesForTesting() const { |
| 168 std::vector<Tile*> all_tiles; | 161 std::vector<Tile*> all_tiles; |
| 169 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) | 162 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) |
| 170 all_tiles.push_back(it->second); | 163 all_tiles.push_back(it->second.get()); |
| 171 return all_tiles; | 164 return all_tiles; |
| 172 } | 165 } |
| 173 | 166 |
| 174 void UpdateAllRequiredStateForTesting() { | 167 void UpdateAllRequiredStateForTesting() { |
| 175 for (const auto& key_tile_pair : tiles_) | 168 for (const auto& key_tile_pair : tiles_) |
| 176 UpdateRequiredStatesOnTile(key_tile_pair.second); | 169 UpdateRequiredStatesOnTile(key_tile_pair.second.get()); |
| 177 } | 170 } |
| 178 std::map<const Tile*, PrioritizedTile> | 171 std::map<const Tile*, PrioritizedTile> |
| 179 UpdateAndGetAllPrioritizedTilesForTesting() const; | 172 UpdateAndGetAllPrioritizedTilesForTesting() const; |
| 180 | 173 |
| 181 void SetAllTilesOccludedForTesting() { | 174 void SetAllTilesOccludedForTesting() { |
| 182 gfx::Rect viewport_in_layer_space = | 175 gfx::Rect viewport_in_layer_space = |
| 183 ScaleToEnclosingRect(current_visible_rect_, 1.0f / contents_scale_); | 176 ScaleToEnclosingRect(current_visible_rect_, 1.0f / contents_scale_); |
| 184 current_occlusion_in_layer_space_ = | 177 current_occlusion_in_layer_space_ = |
| 185 Occlusion(gfx::Transform(), | 178 Occlusion(gfx::Transform(), |
| 186 SimpleEnclosedRegion(viewport_in_layer_space), | 179 SimpleEnclosedRegion(viewport_in_layer_space), |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // here. Note that when processing a pending tree, this rect is the same as | 260 // here. Note that when processing a pending tree, this rect is the same as |
| 268 // the visible rect so no tiles are processed in this case. | 261 // the visible rect so no tiles are processed in this case. |
| 269 enum PriorityRectType { | 262 enum PriorityRectType { |
| 270 VISIBLE_RECT, | 263 VISIBLE_RECT, |
| 271 PENDING_VISIBLE_RECT, | 264 PENDING_VISIBLE_RECT, |
| 272 SKEWPORT_RECT, | 265 SKEWPORT_RECT, |
| 273 SOON_BORDER_RECT, | 266 SOON_BORDER_RECT, |
| 274 EVENTUALLY_RECT | 267 EVENTUALLY_RECT |
| 275 }; | 268 }; |
| 276 | 269 |
| 277 using TileMap = base::ScopedPtrHashMap<TileMapKey, ScopedTilePtr>; | 270 using TileMap = std::unordered_map<TileMapKey, ScopedTilePtr, TileMapKeyHash>; |
| 278 | 271 |
| 279 struct FrameVisibleRect { | 272 struct FrameVisibleRect { |
| 280 gfx::Rect visible_rect_in_content_space; | 273 gfx::Rect visible_rect_in_content_space; |
| 281 double frame_time_in_seconds = 0.0; | 274 double frame_time_in_seconds = 0.0; |
| 282 }; | 275 }; |
| 283 | 276 |
| 284 PictureLayerTiling(WhichTree tree, | 277 PictureLayerTiling(WhichTree tree, |
| 285 float contents_scale, | 278 float contents_scale, |
| 286 scoped_refptr<DisplayListRasterSource> raster_source, | 279 scoped_refptr<DisplayListRasterSource> raster_source, |
| 287 PictureLayerTilingClient* client, | 280 PictureLayerTilingClient* client, |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 float current_content_to_screen_scale_; | 399 float current_content_to_screen_scale_; |
| 407 Occlusion current_occlusion_in_layer_space_; | 400 Occlusion current_occlusion_in_layer_space_; |
| 408 | 401 |
| 409 bool has_visible_rect_tiles_; | 402 bool has_visible_rect_tiles_; |
| 410 bool has_skewport_rect_tiles_; | 403 bool has_skewport_rect_tiles_; |
| 411 bool has_soon_border_rect_tiles_; | 404 bool has_soon_border_rect_tiles_; |
| 412 bool has_eventually_rect_tiles_; | 405 bool has_eventually_rect_tiles_; |
| 413 bool all_tiles_done_; | 406 bool all_tiles_done_; |
| 414 | 407 |
| 415 private: | 408 private: |
| 416 DISALLOW_ASSIGN(PictureLayerTiling); | 409 DISALLOW_COPY_AND_ASSIGN(PictureLayerTiling); |
| 417 }; | 410 }; |
| 418 | 411 |
| 419 } // namespace cc | 412 } // namespace cc |
| 420 | 413 |
| 421 #endif // CC_TILES_PICTURE_LAYER_TILING_H_ | 414 #endif // CC_TILES_PICTURE_LAYER_TILING_H_ |
| OLD | NEW |