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 #include "cc/tiles/picture_layer_tiling.h" | 5 #include "cc/tiles/picture_layer_tiling.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "ui/gfx/geometry/rect_conversions.h" | 26 #include "ui/gfx/geometry/rect_conversions.h" |
| 27 #include "ui/gfx/geometry/rect_f.h" | 27 #include "ui/gfx/geometry/rect_f.h" |
| 28 #include "ui/gfx/geometry/safe_integer_conversions.h" | 28 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 29 #include "ui/gfx/geometry/size_conversions.h" | 29 #include "ui/gfx/geometry/size_conversions.h" |
| 30 | 30 |
| 31 namespace cc { | 31 namespace cc { |
| 32 | 32 |
| 33 PictureLayerTiling::PictureLayerTiling( | 33 PictureLayerTiling::PictureLayerTiling( |
| 34 WhichTree tree, | 34 WhichTree tree, |
| 35 float contents_scale, | 35 float contents_scale, |
| 36 const gfx::Vector2dF& contents_translation, | |
| 36 scoped_refptr<RasterSource> raster_source, | 37 scoped_refptr<RasterSource> raster_source, |
| 37 PictureLayerTilingClient* client) | 38 PictureLayerTilingClient* client) |
| 38 : contents_scale_(contents_scale), | 39 : contents_scale_(contents_scale), |
| 40 contents_translation_(contents_translation), | |
| 39 client_(client), | 41 client_(client), |
| 40 tree_(tree), | 42 tree_(tree), |
| 41 raster_source_(raster_source), | 43 raster_source_(raster_source), |
| 42 resolution_(NON_IDEAL_RESOLUTION), | 44 resolution_(NON_IDEAL_RESOLUTION), |
| 43 may_contain_low_resolution_tiles_(false), | 45 may_contain_low_resolution_tiles_(false), |
| 44 tiling_data_(gfx::Size(), gfx::Size(), kBorderTexels), | 46 tiling_data_(gfx::Size(), gfx::Size(), kBorderTexels), |
| 45 can_require_tiles_for_activation_(false), | 47 can_require_tiles_for_activation_(false), |
| 46 current_content_to_screen_scale_(0.f), | 48 current_content_to_screen_scale_(0.f), |
| 47 has_visible_rect_tiles_(false), | 49 has_visible_rect_tiles_(false), |
| 48 has_skewport_rect_tiles_(false), | 50 has_skewport_rect_tiles_(false), |
| 49 has_soon_border_rect_tiles_(false), | 51 has_soon_border_rect_tiles_(false), |
| 50 has_eventually_rect_tiles_(false), | 52 has_eventually_rect_tiles_(false), |
| 51 all_tiles_done_(true) { | 53 all_tiles_done_(true) { |
| 52 DCHECK(!raster_source->IsSolidColor()); | 54 DCHECK(!raster_source->IsSolidColor()); |
| 53 gfx::Size content_bounds = | 55 DCHECK(contents_translation.x() >= 0.f && contents_translation.x() < 1.f); |
|
enne (OOO)
2016/08/22 22:57:39
Please separate these conditions onto different li
trchen
2016/08/29 10:14:48
Done.
| |
| 54 gfx::ScaleToCeiledSize(raster_source_->GetSize(), contents_scale); | 56 DCHECK(contents_translation.y() >= 0.f && contents_translation.y() < 1.f); |
| 55 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); | 57 |
| 58 gfx::Rect content_bounds_rect = | |
| 59 EnclosingContentsRectFromLayerRect(gfx::Rect(raster_source_->GetSize())); | |
| 60 DCHECK(content_bounds_rect.origin() == gfx::Point()); | |
|
enne (OOO)
2016/08/22 22:57:39
Can you make this DCHECK_EQ or maybe make a separa
trchen
2016/08/29 10:14:48
I think we need to fix this in base/logging.h. log
| |
| 61 | |
| 62 gfx::Size tile_size = client_->CalculateTileSize(content_bounds_rect.size()); | |
| 56 | 63 |
| 57 DCHECK(!gfx::ScaleToFlooredSize(raster_source_->GetSize(), contents_scale) | 64 DCHECK(!gfx::ScaleToFlooredSize(raster_source_->GetSize(), contents_scale) |
| 58 .IsEmpty()) | 65 .IsEmpty()) |
| 59 << "Tiling created with scale too small as contents become empty." | 66 << "Tiling created with scale too small as contents become empty." |
| 60 << " Layer bounds: " << raster_source_->GetSize().ToString() | 67 << " Layer bounds: " << raster_source_->GetSize().ToString() |
| 61 << " Contents scale: " << contents_scale; | 68 << " Contents scale: " << contents_scale; |
| 62 | 69 |
| 63 tiling_data_.SetTilingSize(content_bounds); | 70 tiling_data_.SetTilingSize(content_bounds_rect.size()); |
| 64 tiling_data_.SetMaxTextureSize(tile_size); | 71 tiling_data_.SetMaxTextureSize(tile_size); |
| 65 } | 72 } |
| 66 | 73 |
| 67 PictureLayerTiling::~PictureLayerTiling() { | 74 PictureLayerTiling::~PictureLayerTiling() { |
| 68 } | 75 } |
| 69 | 76 |
| 70 Tile* PictureLayerTiling::CreateTile(const Tile::CreateInfo& info) { | 77 Tile* PictureLayerTiling::CreateTile(const Tile::CreateInfo& info) { |
| 71 const int i = info.tiling_i_index; | 78 const int i = info.tiling_i_index; |
| 72 const int j = info.tiling_j_index; | 79 const int j = info.tiling_j_index; |
| 73 TileMapKey key(i, j); | 80 TileMapKey key(i, j); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 // the previous content ID of these tiles. In that case, we need only | 114 // the previous content ID of these tiles. In that case, we need only |
| 108 // partially raster the tile content. | 115 // partially raster the tile content. |
| 109 if (tile && invalidation && TilingMatchesTileIndices(active_twin)) { | 116 if (tile && invalidation && TilingMatchesTileIndices(active_twin)) { |
| 110 if (const Tile* old_tile = | 117 if (const Tile* old_tile = |
| 111 active_twin->TileAt(key.index_x, key.index_y)) { | 118 active_twin->TileAt(key.index_x, key.index_y)) { |
| 112 gfx::Rect tile_rect = tile->content_rect(); | 119 gfx::Rect tile_rect = tile->content_rect(); |
| 113 gfx::Rect invalidated; | 120 gfx::Rect invalidated; |
| 114 for (Region::Iterator iter(*invalidation); iter.has_rect(); | 121 for (Region::Iterator iter(*invalidation); iter.has_rect(); |
| 115 iter.next()) { | 122 iter.next()) { |
| 116 gfx::Rect invalid_content_rect = | 123 gfx::Rect invalid_content_rect = |
| 117 gfx::ScaleToEnclosingRect(iter.rect(), contents_scale_); | 124 EnclosingContentsRectFromLayerRect(iter.rect()); |
| 118 invalid_content_rect.Intersect(tile_rect); | 125 invalid_content_rect.Intersect(tile_rect); |
| 119 invalidated.Union(invalid_content_rect); | 126 invalidated.Union(invalid_content_rect); |
| 120 } | 127 } |
| 121 tile->SetInvalidated(invalidated, old_tile->id()); | 128 tile->SetInvalidated(invalidated, old_tile->id()); |
| 122 } | 129 } |
| 123 } | 130 } |
| 124 } | 131 } |
| 125 } | 132 } |
| 126 VerifyLiveTilesRect(false); | 133 VerifyLiveTilesRect(false); |
| 127 } | 134 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 169 pending_twin->current_eventually_rect_, | 176 pending_twin->current_eventually_rect_, |
| 170 pending_twin->current_occlusion_in_layer_space_); | 177 pending_twin->current_occlusion_in_layer_space_); |
| 171 } | 178 } |
| 172 | 179 |
| 173 void PictureLayerTiling::SetRasterSourceAndResize( | 180 void PictureLayerTiling::SetRasterSourceAndResize( |
| 174 scoped_refptr<RasterSource> raster_source) { | 181 scoped_refptr<RasterSource> raster_source) { |
| 175 DCHECK(!raster_source->IsSolidColor()); | 182 DCHECK(!raster_source->IsSolidColor()); |
| 176 gfx::Size old_layer_bounds = raster_source_->GetSize(); | 183 gfx::Size old_layer_bounds = raster_source_->GetSize(); |
| 177 raster_source_ = std::move(raster_source); | 184 raster_source_ = std::move(raster_source); |
| 178 gfx::Size new_layer_bounds = raster_source_->GetSize(); | 185 gfx::Size new_layer_bounds = raster_source_->GetSize(); |
| 179 gfx::Size content_bounds = | 186 gfx::Rect content_rect = |
| 180 gfx::ScaleToCeiledSize(new_layer_bounds, contents_scale_); | 187 EnclosingContentsRectFromLayerRect(gfx::Rect(new_layer_bounds)); |
| 181 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); | 188 DCHECK(content_rect.origin() == gfx::Point()); |
| 189 gfx::Size tile_size = client_->CalculateTileSize(content_rect.size()); | |
| 182 | 190 |
| 183 if (tile_size != tiling_data_.max_texture_size()) { | 191 if (tile_size != tiling_data_.max_texture_size()) { |
| 184 tiling_data_.SetTilingSize(content_bounds); | 192 tiling_data_.SetTilingSize(content_rect.size()); |
| 185 tiling_data_.SetMaxTextureSize(tile_size); | 193 tiling_data_.SetMaxTextureSize(tile_size); |
| 186 // When the tile size changes, the TilingData positions no longer work | 194 // When the tile size changes, the TilingData positions no longer work |
| 187 // as valid keys to the TileMap, so just drop all tiles and clear the live | 195 // as valid keys to the TileMap, so just drop all tiles and clear the live |
| 188 // tiles rect. | 196 // tiles rect. |
| 189 Reset(); | 197 Reset(); |
| 190 return; | 198 return; |
| 191 } | 199 } |
| 192 | 200 |
| 193 if (old_layer_bounds == new_layer_bounds) | 201 if (old_layer_bounds == new_layer_bounds) |
| 194 return; | 202 return; |
| 195 | 203 |
| 196 // The SetLiveTilesRect() method would drop tiles outside the new bounds, | 204 // The SetLiveTilesRect() method would drop tiles outside the new bounds, |
| 197 // but may do so incorrectly if resizing the tiling causes the number of | 205 // but may do so incorrectly if resizing the tiling causes the number of |
| 198 // tiles in the tiling_data_ to change. | 206 // tiles in the tiling_data_ to change. |
| 199 gfx::Rect content_rect(content_bounds); | |
| 200 int before_left = tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.x()); | 207 int before_left = tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.x()); |
| 201 int before_top = tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.y()); | 208 int before_top = tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.y()); |
| 202 int before_right = | 209 int before_right = |
| 203 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); | 210 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); |
| 204 int before_bottom = | 211 int before_bottom = |
| 205 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); | 212 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); |
| 206 | 213 |
| 207 // The live_tiles_rect_ is clamped to stay within the tiling size as we | 214 // The live_tiles_rect_ is clamped to stay within the tiling size as we |
| 208 // change it. | 215 // change it. |
| 209 live_tiles_rect_.Intersect(content_rect); | 216 live_tiles_rect_.Intersect(content_rect); |
| 210 tiling_data_.SetTilingSize(content_bounds); | 217 tiling_data_.SetTilingSize(content_rect.size()); |
| 211 | 218 |
| 212 int after_right = -1; | 219 int after_right = -1; |
| 213 int after_bottom = -1; | 220 int after_bottom = -1; |
| 214 if (!live_tiles_rect_.IsEmpty()) { | 221 if (!live_tiles_rect_.IsEmpty()) { |
| 215 after_right = | 222 after_right = |
| 216 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); | 223 tiling_data_.TileXIndexFromSrcCoord(live_tiles_rect_.right() - 1); |
| 217 after_bottom = | 224 after_bottom = |
| 218 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); | 225 tiling_data_.TileYIndexFromSrcCoord(live_tiles_rect_.bottom() - 1); |
| 219 } | 226 } |
| 220 | 227 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 // unordered_map instead of a vector in the SmallMap. | 272 // unordered_map instead of a vector in the SmallMap. |
| 266 base::SmallMap<std::unordered_map<TileMapKey, gfx::Rect, TileMapKeyHash>, 16> | 273 base::SmallMap<std::unordered_map<TileMapKey, gfx::Rect, TileMapKeyHash>, 16> |
| 267 remove_tiles; | 274 remove_tiles; |
| 268 gfx::Rect expanded_live_tiles_rect = | 275 gfx::Rect expanded_live_tiles_rect = |
| 269 tiling_data_.ExpandRectToTileBounds(live_tiles_rect_); | 276 tiling_data_.ExpandRectToTileBounds(live_tiles_rect_); |
| 270 for (Region::Iterator iter(layer_invalidation); iter.has_rect(); | 277 for (Region::Iterator iter(layer_invalidation); iter.has_rect(); |
| 271 iter.next()) { | 278 iter.next()) { |
| 272 gfx::Rect layer_rect = iter.rect(); | 279 gfx::Rect layer_rect = iter.rect(); |
| 273 // The pixels which are invalid in content space. | 280 // The pixels which are invalid in content space. |
| 274 gfx::Rect invalid_content_rect = | 281 gfx::Rect invalid_content_rect = |
| 275 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); | 282 EnclosingContentsRectFromLayerRect(layer_rect); |
| 276 gfx::Rect coverage_content_rect = invalid_content_rect; | 283 gfx::Rect coverage_content_rect = invalid_content_rect; |
| 277 // Avoid needless work by not bothering to invalidate where there aren't | 284 // Avoid needless work by not bothering to invalidate where there aren't |
| 278 // tiles. | 285 // tiles. |
| 279 coverage_content_rect.Intersect(expanded_live_tiles_rect); | 286 coverage_content_rect.Intersect(expanded_live_tiles_rect); |
| 280 if (coverage_content_rect.IsEmpty()) | 287 if (coverage_content_rect.IsEmpty()) |
| 281 continue; | 288 continue; |
| 282 // Since the content_rect needs to invalidate things that only touch a | 289 // Since the content_rect needs to invalidate things that only touch a |
| 283 // border of a tile, we need to include the borders while iterating. | 290 // border of a tile, we need to include the borders while iterating. |
| 284 bool include_borders = true; | 291 bool include_borders = true; |
| 285 for (TilingData::Iterator iter(&tiling_data_, coverage_content_rect, | 292 for (TilingData::Iterator iter(&tiling_data_, coverage_content_rect, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 302 if (Tile* tile = CreateTile(info)) | 309 if (Tile* tile = CreateTile(info)) |
| 303 tile->SetInvalidated(invalid_content_rect, old_tile->id()); | 310 tile->SetInvalidated(invalid_content_rect, old_tile->id()); |
| 304 } | 311 } |
| 305 } | 312 } |
| 306 } | 313 } |
| 307 | 314 |
| 308 Tile::CreateInfo PictureLayerTiling::CreateInfoForTile(int i, int j) const { | 315 Tile::CreateInfo PictureLayerTiling::CreateInfoForTile(int i, int j) const { |
| 309 gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(i, j); | 316 gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(i, j); |
| 310 tile_rect.set_size(tiling_data_.max_texture_size()); | 317 tile_rect.set_size(tiling_data_.max_texture_size()); |
| 311 gfx::Rect enclosing_layer_rect = | 318 gfx::Rect enclosing_layer_rect = |
| 312 gfx::ScaleToEnclosingRect(tile_rect, 1.f / contents_scale_); | 319 EnclosingLayerRectFromContentsRect(tile_rect); |
| 313 return Tile::CreateInfo(i, j, enclosing_layer_rect, tile_rect, | 320 return Tile::CreateInfo(i, j, enclosing_layer_rect, tile_rect, |
| 314 contents_scale_); | 321 contents_scale_, contents_translation_); |
| 315 } | 322 } |
| 316 | 323 |
| 317 bool PictureLayerTiling::ShouldCreateTileAt( | 324 bool PictureLayerTiling::ShouldCreateTileAt( |
| 318 const Tile::CreateInfo& info) const { | 325 const Tile::CreateInfo& info) const { |
| 319 const int i = info.tiling_i_index; | 326 const int i = info.tiling_i_index; |
| 320 const int j = info.tiling_j_index; | 327 const int j = info.tiling_j_index; |
| 321 // Active tree should always create a tile. The reason for this is that active | 328 // Active tree should always create a tile. The reason for this is that active |
| 322 // tree represents content that we draw on screen, which means that whenever | 329 // tree represents content that we draw on screen, which means that whenever |
| 323 // we check whether a tile should exist somewhere, the answer is yes. This | 330 // we check whether a tile should exist somewhere, the answer is yes. This |
| 324 // doesn't mean it will actually be created (if raster source doesn't cover | 331 // doesn't mean it will actually be created (if raster source doesn't cover |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 344 return true; | 351 return true; |
| 345 | 352 |
| 346 const Region* layer_invalidation = client_->GetPendingInvalidation(); | 353 const Region* layer_invalidation = client_->GetPendingInvalidation(); |
| 347 | 354 |
| 348 // If this tile is invalidated, then the pending tree should create one. | 355 // If this tile is invalidated, then the pending tree should create one. |
| 349 // Do the intersection test in content space to match the corresponding check | 356 // Do the intersection test in content space to match the corresponding check |
| 350 // on the active tree and avoid floating point inconsistencies. | 357 // on the active tree and avoid floating point inconsistencies. |
| 351 for (Region::Iterator iter(*layer_invalidation); iter.has_rect(); | 358 for (Region::Iterator iter(*layer_invalidation); iter.has_rect(); |
| 352 iter.next()) { | 359 iter.next()) { |
| 353 gfx::Rect invalid_content_rect = | 360 gfx::Rect invalid_content_rect = |
| 354 gfx::ScaleToEnclosingRect(iter.rect(), contents_scale_); | 361 EnclosingContentsRectFromLayerRect(iter.rect()); |
| 355 if (invalid_content_rect.Intersects(info.content_rect)) | 362 if (invalid_content_rect.Intersects(info.content_rect)) |
| 356 return true; | 363 return true; |
| 357 } | 364 } |
| 358 // If the active tree doesn't have a tile here, but it's in the pending tree's | 365 // If the active tree doesn't have a tile here, but it's in the pending tree's |
| 359 // visible rect, then the pending tree should create a tile. This can happen | 366 // visible rect, then the pending tree should create a tile. This can happen |
| 360 // if the pending visible rect is outside of the active tree's live tiles | 367 // if the pending visible rect is outside of the active tree's live tiles |
| 361 // rect. In those situations, we need to block activation until we're ready to | 368 // rect. In those situations, we need to block activation until we're ready to |
| 362 // display content, which will have to come from the pending tree. | 369 // display content, which will have to come from the pending tree. |
| 363 if (!active_twin->TileAt(i, j) && | 370 if (!active_twin->TileAt(i, j) && |
| 364 current_visible_rect_.Intersects(info.content_rect)) | 371 current_visible_rect_.Intersects(info.content_rect)) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 398 left_(0), | 405 left_(0), |
| 399 top_(0), | 406 top_(0), |
| 400 right_(-1), | 407 right_(-1), |
| 401 bottom_(-1) { | 408 bottom_(-1) { |
| 402 DCHECK(tiling_); | 409 DCHECK(tiling_); |
| 403 if (dest_rect_.IsEmpty()) | 410 if (dest_rect_.IsEmpty()) |
| 404 return; | 411 return; |
| 405 | 412 |
| 406 dest_to_content_scale_ = tiling_->contents_scale_ / dest_scale; | 413 dest_to_content_scale_ = tiling_->contents_scale_ / dest_scale; |
| 407 | 414 |
| 408 gfx::Rect content_rect = | 415 gfx::RectF dest_rect_in_contents_space(dest_rect_); |
| 409 gfx::ScaleToEnclosingRect(dest_rect_, | 416 dest_rect_in_contents_space.Scale(dest_to_content_scale_); |
| 410 dest_to_content_scale_, | 417 dest_rect_in_contents_space.Offset(tiling->contents_translation()); |
|
enne (OOO)
2016/08/16 23:02:52
It seems that contents translation is in layer spa
trchen
2016/08/29 10:14:48
It is a cheat to take advantage of transform assoc
| |
| 411 dest_to_content_scale_); | 418 gfx::Rect content_rect = gfx::ToEnclosingRect(dest_rect_in_contents_space); |
| 419 | |
| 412 // IndexFromSrcCoord clamps to valid tile ranges, so it's necessary to | 420 // IndexFromSrcCoord clamps to valid tile ranges, so it's necessary to |
| 413 // check for non-intersection first. | 421 // check for non-intersection first. |
| 414 content_rect.Intersect(gfx::Rect(tiling_->tiling_size())); | 422 content_rect.Intersect(gfx::Rect(tiling_->tiling_size())); |
| 415 if (content_rect.IsEmpty()) | 423 if (content_rect.IsEmpty()) |
| 416 return; | 424 return; |
| 417 | 425 |
| 418 left_ = tiling_->tiling_data_.TileXIndexFromSrcCoord(content_rect.x()); | 426 left_ = tiling_->tiling_data_.TileXIndexFromSrcCoord(content_rect.x()); |
| 419 top_ = tiling_->tiling_data_.TileYIndexFromSrcCoord(content_rect.y()); | 427 top_ = tiling_->tiling_data_.TileYIndexFromSrcCoord(content_rect.y()); |
| 420 right_ = tiling_->tiling_data_.TileXIndexFromSrcCoord( | 428 right_ = tiling_->tiling_data_.TileXIndexFromSrcCoord( |
| 421 content_rect.right() - 1); | 429 content_rect.right() - 1); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 448 } | 456 } |
| 449 } | 457 } |
| 450 | 458 |
| 451 current_tile_ = tiling_->TileAt(tile_i_, tile_j_); | 459 current_tile_ = tiling_->TileAt(tile_i_, tile_j_); |
| 452 | 460 |
| 453 // Calculate the current geometry rect. Due to floating point rounding | 461 // Calculate the current geometry rect. Due to floating point rounding |
| 454 // and ToEnclosingRect, tiles might overlap in destination space on the | 462 // and ToEnclosingRect, tiles might overlap in destination space on the |
| 455 // edges. | 463 // edges. |
| 456 gfx::Rect last_geometry_rect = current_geometry_rect_; | 464 gfx::Rect last_geometry_rect = current_geometry_rect_; |
| 457 | 465 |
| 458 gfx::Rect content_rect = tiling_->tiling_data_.TileBounds(tile_i_, tile_j_); | 466 gfx::RectF tile_bounds_in_dest_space( |
| 459 | 467 tiling_->tiling_data_.TileBounds(tile_i_, tile_j_)); |
| 460 current_geometry_rect_ = | 468 tile_bounds_in_dest_space.Offset(-tiling_->contents_translation()); |
|
enne (OOO)
2016/08/22 22:57:39
I'm not 100% convinced that this satisfies the ass
trchen
2016/08/29 10:14:48
It will because the pre-rounding tile_bounds_in_de
| |
| 461 gfx::ScaleToEnclosingRect(content_rect, 1 / dest_to_content_scale_); | 469 tile_bounds_in_dest_space.Scale(1 / dest_to_content_scale_); |
| 470 current_geometry_rect_ = gfx::ToEnclosingRect(tile_bounds_in_dest_space); | |
| 462 | 471 |
| 463 current_geometry_rect_.Intersect(dest_rect_); | 472 current_geometry_rect_.Intersect(dest_rect_); |
| 464 DCHECK(!current_geometry_rect_.IsEmpty()); | 473 DCHECK(!current_geometry_rect_.IsEmpty()); |
| 465 | 474 |
| 466 if (first_time) | 475 if (first_time) |
| 467 return *this; | 476 return *this; |
| 468 | 477 |
| 469 // Iteration happens left->right, top->bottom. Running off the bottom-right | 478 // Iteration happens left->right, top->bottom. Running off the bottom-right |
| 470 // edge is handled by the intersection above with dest_rect_. Here we make | 479 // edge is handled by the intersection above with dest_rect_. Here we make |
| 471 // sure that the new current geometry rect doesn't overlap with the last. | 480 // sure that the new current geometry rect doesn't overlap with the last. |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 497 } | 506 } |
| 498 | 507 |
| 499 gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const { | 508 gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const { |
| 500 auto tex_origin = gfx::PointF( | 509 auto tex_origin = gfx::PointF( |
| 501 tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_).origin()); | 510 tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_).origin()); |
| 502 | 511 |
| 503 // Convert from dest space => content space => texture space. | 512 // Convert from dest space => content space => texture space. |
| 504 gfx::RectF texture_rect(current_geometry_rect_); | 513 gfx::RectF texture_rect(current_geometry_rect_); |
| 505 texture_rect.Scale(dest_to_content_scale_, | 514 texture_rect.Scale(dest_to_content_scale_, |
| 506 dest_to_content_scale_); | 515 dest_to_content_scale_); |
| 516 texture_rect.Offset(tiling_->contents_translation()); | |
| 507 texture_rect.Intersect(gfx::RectF(gfx::SizeF(tiling_->tiling_size()))); | 517 texture_rect.Intersect(gfx::RectF(gfx::SizeF(tiling_->tiling_size()))); |
| 508 if (texture_rect.IsEmpty()) | 518 if (texture_rect.IsEmpty()) |
| 509 return texture_rect; | 519 return texture_rect; |
| 510 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); | 520 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); |
| 511 | 521 |
| 512 return texture_rect; | 522 return texture_rect; |
| 513 } | 523 } |
| 514 | 524 |
| 515 ScopedTilePtr PictureLayerTiling::TakeTileAt(int i, int j) { | 525 ScopedTilePtr PictureLayerTiling::TakeTileAt(int i, int j) { |
| 516 TileMap::iterator found = tiles_.find(TileMapKey(i, j)); | 526 TileMap::iterator found = tiles_.find(TileMapKey(i, j)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 548 current_occlusion_in_layer_space_.HasOcclusion()) { | 558 current_occlusion_in_layer_space_.HasOcclusion()) { |
| 549 set_all_tiles_done(false); | 559 set_all_tiles_done(false); |
| 550 } | 560 } |
| 551 | 561 |
| 552 const float content_to_screen_scale = ideal_contents_scale / contents_scale_; | 562 const float content_to_screen_scale = ideal_contents_scale / contents_scale_; |
| 553 | 563 |
| 554 const gfx::Rect* input_rects[] = { | 564 const gfx::Rect* input_rects[] = { |
| 555 &visible_rect_in_layer_space, &skewport_in_layer_space, | 565 &visible_rect_in_layer_space, &skewport_in_layer_space, |
| 556 &soon_border_rect_in_layer_space, &eventually_rect_in_layer_space}; | 566 &soon_border_rect_in_layer_space, &eventually_rect_in_layer_space}; |
| 557 gfx::Rect output_rects[4]; | 567 gfx::Rect output_rects[4]; |
| 558 for (size_t i = 0; i < arraysize(input_rects); ++i) { | 568 for (size_t i = 0; i < arraysize(input_rects); ++i) |
| 559 output_rects[i] = gfx::ToEnclosingRect( | 569 output_rects[i] = EnclosingContentsRectFromLayerRect(*input_rects[i]); |
| 560 gfx::ScaleRect(gfx::RectF(*input_rects[i]), contents_scale_)); | |
| 561 } | |
| 562 // Make sure the eventually rect is aligned to tile bounds. | 570 // Make sure the eventually rect is aligned to tile bounds. |
| 563 output_rects[3] = | 571 output_rects[3] = |
| 564 tiling_data_.ExpandRectIgnoringBordersToTileBounds(output_rects[3]); | 572 tiling_data_.ExpandRectIgnoringBordersToTileBounds(output_rects[3]); |
| 565 | 573 |
| 566 SetTilePriorityRects(content_to_screen_scale, output_rects[0], | 574 SetTilePriorityRects(content_to_screen_scale, output_rects[0], |
| 567 output_rects[1], output_rects[2], output_rects[3], | 575 output_rects[1], output_rects[2], output_rects[3], |
| 568 occlusion_in_layer_space); | 576 occlusion_in_layer_space); |
| 569 SetLiveTilesRect(output_rects[3]); | 577 SetLiveTilesRect(output_rects[3]); |
| 570 } | 578 } |
| 571 | 579 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 bool PictureLayerTiling::IsTileOccludedOnCurrentTree(const Tile* tile) const { | 690 bool PictureLayerTiling::IsTileOccludedOnCurrentTree(const Tile* tile) const { |
| 683 if (!current_occlusion_in_layer_space_.HasOcclusion()) | 691 if (!current_occlusion_in_layer_space_.HasOcclusion()) |
| 684 return false; | 692 return false; |
| 685 gfx::Rect tile_query_rect = | 693 gfx::Rect tile_query_rect = |
| 686 gfx::IntersectRects(tile->content_rect(), current_visible_rect_); | 694 gfx::IntersectRects(tile->content_rect(), current_visible_rect_); |
| 687 // Explicitly check if the tile is outside the viewport. If so, we need to | 695 // Explicitly check if the tile is outside the viewport. If so, we need to |
| 688 // return false, since occlusion for this tile is unknown. | 696 // return false, since occlusion for this tile is unknown. |
| 689 if (tile_query_rect.IsEmpty()) | 697 if (tile_query_rect.IsEmpty()) |
| 690 return false; | 698 return false; |
| 691 | 699 |
| 692 if (contents_scale_ != 1.f) { | 700 if (contents_scale_ != 1.f || !contents_translation_.IsZero()) |
| 693 tile_query_rect = | 701 tile_query_rect = EnclosingLayerRectFromContentsRect(tile_query_rect); |
| 694 gfx::ScaleToEnclosingRect(tile_query_rect, 1.f / contents_scale_); | |
| 695 } | |
| 696 return current_occlusion_in_layer_space_.IsOccluded(tile_query_rect); | 702 return current_occlusion_in_layer_space_.IsOccluded(tile_query_rect); |
| 697 } | 703 } |
| 698 | 704 |
| 699 bool PictureLayerTiling::IsTileRequiredForActivation(const Tile* tile) const { | 705 bool PictureLayerTiling::IsTileRequiredForActivation(const Tile* tile) const { |
| 700 if (tree_ == PENDING_TREE) { | 706 if (tree_ == PENDING_TREE) { |
| 701 if (!can_require_tiles_for_activation_) | 707 if (!can_require_tiles_for_activation_) |
| 702 return false; | 708 return false; |
| 703 | 709 |
| 704 if (resolution_ != HIGH_RESOLUTION) | 710 if (resolution_ != HIGH_RESOLUTION) |
| 705 return false; | 711 return false; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 767 tile->set_required_for_activation(IsTileRequiredForActivation(tile)); | 773 tile->set_required_for_activation(IsTileRequiredForActivation(tile)); |
| 768 tile->set_required_for_draw(IsTileRequiredForDraw(tile)); | 774 tile->set_required_for_draw(IsTileRequiredForDraw(tile)); |
| 769 } | 775 } |
| 770 | 776 |
| 771 PrioritizedTile PictureLayerTiling::MakePrioritizedTile( | 777 PrioritizedTile PictureLayerTiling::MakePrioritizedTile( |
| 772 Tile* tile, | 778 Tile* tile, |
| 773 PriorityRectType priority_rect_type) const { | 779 PriorityRectType priority_rect_type) const { |
| 774 DCHECK(tile); | 780 DCHECK(tile); |
| 775 DCHECK(raster_source()->CoversRect(tile->enclosing_layer_rect())) | 781 DCHECK(raster_source()->CoversRect(tile->enclosing_layer_rect())) |
| 776 << "Recording rect: " | 782 << "Recording rect: " |
| 777 << gfx::ScaleToEnclosingRect(tile->content_rect(), | 783 << EnclosingLayerRectFromContentsRect(tile->content_rect()).ToString(); |
| 778 1.f / tile->contents_scale()) | |
| 779 .ToString(); | |
| 780 | 784 |
| 781 return PrioritizedTile(tile, this, | 785 return PrioritizedTile(tile, this, |
| 782 ComputePriorityForTile(tile, priority_rect_type), | 786 ComputePriorityForTile(tile, priority_rect_type), |
| 783 IsTileOccluded(tile)); | 787 IsTileOccluded(tile)); |
| 784 } | 788 } |
| 785 | 789 |
| 786 std::map<const Tile*, PrioritizedTile> | 790 std::map<const Tile*, PrioritizedTile> |
| 787 PictureLayerTiling::UpdateAndGetAllPrioritizedTilesForTesting() const { | 791 PictureLayerTiling::UpdateAndGetAllPrioritizedTilesForTesting() const { |
| 788 std::map<const Tile*, PrioritizedTile> result; | 792 std::map<const Tile*, PrioritizedTile> result; |
| 789 for (const auto& key_tile_pair : tiles_) { | 793 for (const auto& key_tile_pair : tiles_) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 861 Tile* tile = tile_pair.second.get(); | 865 Tile* tile = tile_pair.second.get(); |
| 862 prioritized_tiles->push_back( | 866 prioritized_tiles->push_back( |
| 863 MakePrioritizedTile(tile, ComputePriorityRectTypeForTile(tile))); | 867 MakePrioritizedTile(tile, ComputePriorityRectTypeForTile(tile))); |
| 864 } | 868 } |
| 865 } | 869 } |
| 866 | 870 |
| 867 void PictureLayerTiling::AsValueInto( | 871 void PictureLayerTiling::AsValueInto( |
| 868 base::trace_event::TracedValue* state) const { | 872 base::trace_event::TracedValue* state) const { |
| 869 state->SetInteger("num_tiles", base::saturated_cast<int>(tiles_.size())); | 873 state->SetInteger("num_tiles", base::saturated_cast<int>(tiles_.size())); |
| 870 state->SetDouble("content_scale", contents_scale_); | 874 state->SetDouble("content_scale", contents_scale_); |
| 875 MathUtil::AddToTracedValue("content_translation", contents_translation_, | |
| 876 state); | |
| 871 MathUtil::AddToTracedValue("visible_rect", current_visible_rect_, state); | 877 MathUtil::AddToTracedValue("visible_rect", current_visible_rect_, state); |
| 872 MathUtil::AddToTracedValue("skewport_rect", current_skewport_rect_, state); | 878 MathUtil::AddToTracedValue("skewport_rect", current_skewport_rect_, state); |
| 873 MathUtil::AddToTracedValue("soon_rect", current_soon_border_rect_, state); | 879 MathUtil::AddToTracedValue("soon_rect", current_soon_border_rect_, state); |
| 874 MathUtil::AddToTracedValue("eventually_rect", current_eventually_rect_, | 880 MathUtil::AddToTracedValue("eventually_rect", current_eventually_rect_, |
| 875 state); | 881 state); |
| 876 MathUtil::AddToTracedValue("tiling_size", tiling_size(), state); | 882 MathUtil::AddToTracedValue("tiling_size", tiling_size(), state); |
| 877 } | 883 } |
| 878 | 884 |
| 879 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { | 885 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { |
| 880 size_t amount = 0; | 886 size_t amount = 0; |
| 881 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 887 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
| 882 const Tile* tile = it->second.get(); | 888 const Tile* tile = it->second.get(); |
| 883 amount += tile->GPUMemoryUsageInBytes(); | 889 amount += tile->GPUMemoryUsageInBytes(); |
| 884 } | 890 } |
| 885 return amount; | 891 return amount; |
| 886 } | 892 } |
| 887 | 893 |
| 894 gfx::Rect PictureLayerTiling::EnclosingContentsRectFromLayerRect( | |
| 895 const gfx::Rect& layer_rect) const { | |
| 896 gfx::RectF contents_rect = | |
| 897 gfx::ScaleRect(gfx::RectF(layer_rect), contents_scale_); | |
| 898 contents_rect.Offset(contents_translation_); | |
| 899 return ToEnclosingRect(contents_rect); | |
| 900 } | |
| 901 | |
| 902 gfx::Rect PictureLayerTiling::EnclosingLayerRectFromContentsRect( | |
| 903 const gfx::Rect& contents_rect) const { | |
| 904 gfx::RectF layer_rect(contents_rect); | |
| 905 layer_rect.Offset(-contents_translation_); | |
| 906 layer_rect.Scale(1.f / contents_scale_); | |
| 907 return ToEnclosingRect(layer_rect); | |
| 908 } | |
| 909 | |
| 888 } // namespace cc | 910 } // namespace cc |
| OLD | NEW |