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 11 matching lines...) Expand all Loading... |
22 #include "cc/tiles/prioritized_tile.h" | 22 #include "cc/tiles/prioritized_tile.h" |
23 #include "cc/tiles/tile.h" | 23 #include "cc/tiles/tile.h" |
24 #include "cc/tiles/tile_priority.h" | 24 #include "cc/tiles/tile_priority.h" |
25 #include "ui/gfx/geometry/point_conversions.h" | 25 #include "ui/gfx/geometry/point_conversions.h" |
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 namespace { | |
33 // The math is similar to gfx::Rect::ManhattanInternalDistance except that each | |
34 // component is scaled by the specified |scale|. | |
35 float ComputeScaledManhattalInternalDistance(const gfx::Rect& a, | |
36 const gfx::Rect& b, | |
37 const gfx::SizeF& scale) { | |
38 gfx::Rect combined(a); | |
39 combined.Union(b); | |
40 | |
41 float x = | |
42 scale.width() * std::max(0, combined.width() - a.width() - b.width() + 1); | |
43 float y = scale.height() * | |
44 std::max(0, combined.height() - a.height() - b.height() + 1); | |
45 return x + y; | |
46 } | |
47 } // namespace | |
48 | 32 |
49 PictureLayerTiling::PictureLayerTiling( | 33 PictureLayerTiling::PictureLayerTiling( |
50 WhichTree tree, | 34 WhichTree tree, |
51 const gfx::SizeF& raster_scales, | 35 float contents_scale, |
52 scoped_refptr<RasterSource> raster_source, | 36 scoped_refptr<RasterSource> raster_source, |
53 PictureLayerTilingClient* client, | 37 PictureLayerTilingClient* client, |
54 float min_preraster_distance, | 38 float min_preraster_distance, |
55 float max_preraster_distance) | 39 float max_preraster_distance) |
56 : raster_scales_(raster_scales), | 40 : contents_scale_(contents_scale), |
57 client_(client), | 41 client_(client), |
58 tree_(tree), | 42 tree_(tree), |
59 raster_source_(raster_source), | 43 raster_source_(raster_source), |
60 min_preraster_distance_(min_preraster_distance), | 44 min_preraster_distance_(min_preraster_distance), |
61 max_preraster_distance_(max_preraster_distance) { | 45 max_preraster_distance_(max_preraster_distance) { |
62 DCHECK(!raster_source->IsSolidColor()); | 46 DCHECK(!raster_source->IsSolidColor()); |
63 gfx::Size content_bounds = | 47 gfx::Size content_bounds = |
64 gfx::ScaleToCeiledSize(raster_source_->GetSize(), raster_scales_.width(), | 48 gfx::ScaleToCeiledSize(raster_source_->GetSize(), contents_scale_); |
65 raster_scales_.height()); | |
66 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); | 49 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); |
67 | 50 |
68 DCHECK(!gfx::ScaleToFlooredSize(raster_source_->GetSize(), | 51 DCHECK(!gfx::ScaleToFlooredSize(raster_source_->GetSize(), contents_scale_) |
69 raster_scales_.width(), | |
70 raster_scales_.height()) | |
71 .IsEmpty()) | 52 .IsEmpty()) |
72 << "Tiling created with scale too small as contents become empty." | 53 << "Tiling created with scale too small as contents become empty." |
73 << " Layer bounds: " << raster_source_->GetSize().ToString() | 54 << " Layer bounds: " << raster_source_->GetSize().ToString() |
74 << " Raster scales: " << raster_scales_.ToString(); | 55 << " Raster scale: " << contents_scale_; |
75 | 56 |
76 tiling_data_.SetTilingSize(content_bounds); | 57 tiling_data_.SetTilingSize(content_bounds); |
77 tiling_data_.SetMaxTextureSize(tile_size); | 58 tiling_data_.SetMaxTextureSize(tile_size); |
78 } | 59 } |
79 | 60 |
80 PictureLayerTiling::~PictureLayerTiling() { | 61 PictureLayerTiling::~PictureLayerTiling() { |
81 } | 62 } |
82 | 63 |
83 Tile* PictureLayerTiling::CreateTile(const Tile::CreateInfo& info) { | 64 Tile* PictureLayerTiling::CreateTile(const Tile::CreateInfo& info) { |
84 const int i = info.tiling_i_index; | 65 const int i = info.tiling_i_index; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 // If this is the pending tree, then the active twin tiling may contain | 100 // If this is the pending tree, then the active twin tiling may contain |
120 // the previous content ID of these tiles. In that case, we need only | 101 // the previous content ID of these tiles. In that case, we need only |
121 // partially raster the tile content. | 102 // partially raster the tile content. |
122 if (tile && invalidation && TilingMatchesTileIndices(active_twin)) { | 103 if (tile && invalidation && TilingMatchesTileIndices(active_twin)) { |
123 if (const Tile* old_tile = | 104 if (const Tile* old_tile = |
124 active_twin->TileAt(key.index_x, key.index_y)) { | 105 active_twin->TileAt(key.index_x, key.index_y)) { |
125 gfx::Rect tile_rect = tile->content_rect(); | 106 gfx::Rect tile_rect = tile->content_rect(); |
126 gfx::Rect invalidated; | 107 gfx::Rect invalidated; |
127 for (Region::Iterator iter(*invalidation); iter.has_rect(); | 108 for (Region::Iterator iter(*invalidation); iter.has_rect(); |
128 iter.next()) { | 109 iter.next()) { |
129 gfx::Rect invalid_content_rect = gfx::ScaleToEnclosingRect( | 110 gfx::Rect invalid_content_rect = |
130 iter.rect(), raster_scales_.width(), raster_scales_.height()); | 111 gfx::ScaleToEnclosingRect(iter.rect(), contents_scale_); |
131 invalid_content_rect.Intersect(tile_rect); | 112 invalid_content_rect.Intersect(tile_rect); |
132 invalidated.Union(invalid_content_rect); | 113 invalidated.Union(invalid_content_rect); |
133 } | 114 } |
134 tile->SetInvalidated(invalidated, old_tile->id()); | 115 tile->SetInvalidated(invalidated, old_tile->id()); |
135 } | 116 } |
136 } | 117 } |
137 } | 118 } |
138 } | 119 } |
139 VerifyLiveTilesRect(false); | 120 VerifyLiveTilesRect(false); |
140 } | 121 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 pending_twin->current_eventually_rect_, | 160 pending_twin->current_eventually_rect_, |
180 pending_twin->current_occlusion_in_layer_space_); | 161 pending_twin->current_occlusion_in_layer_space_); |
181 } | 162 } |
182 | 163 |
183 void PictureLayerTiling::SetRasterSourceAndResize( | 164 void PictureLayerTiling::SetRasterSourceAndResize( |
184 scoped_refptr<RasterSource> raster_source) { | 165 scoped_refptr<RasterSource> raster_source) { |
185 DCHECK(!raster_source->IsSolidColor()); | 166 DCHECK(!raster_source->IsSolidColor()); |
186 gfx::Size old_layer_bounds = raster_source_->GetSize(); | 167 gfx::Size old_layer_bounds = raster_source_->GetSize(); |
187 raster_source_ = std::move(raster_source); | 168 raster_source_ = std::move(raster_source); |
188 gfx::Size new_layer_bounds = raster_source_->GetSize(); | 169 gfx::Size new_layer_bounds = raster_source_->GetSize(); |
189 gfx::Size content_bounds = gfx::ScaleToCeiledSize( | 170 gfx::Size content_bounds = |
190 new_layer_bounds, raster_scales_.width(), raster_scales_.height()); | 171 gfx::ScaleToCeiledSize(new_layer_bounds, contents_scale_); |
191 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); | 172 gfx::Size tile_size = client_->CalculateTileSize(content_bounds); |
192 | 173 |
193 if (tile_size != tiling_data_.max_texture_size()) { | 174 if (tile_size != tiling_data_.max_texture_size()) { |
194 tiling_data_.SetTilingSize(content_bounds); | 175 tiling_data_.SetTilingSize(content_bounds); |
195 tiling_data_.SetMaxTextureSize(tile_size); | 176 tiling_data_.SetMaxTextureSize(tile_size); |
196 // When the tile size changes, the TilingData positions no longer work | 177 // When the tile size changes, the TilingData positions no longer work |
197 // as valid keys to the TileMap, so just drop all tiles and clear the live | 178 // as valid keys to the TileMap, so just drop all tiles and clear the live |
198 // tiles rect. | 179 // tiles rect. |
199 Reset(); | 180 Reset(); |
200 return; | 181 return; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 // 16 is fast enough. If an invalidation is huge we will fall back to a | 255 // 16 is fast enough. If an invalidation is huge we will fall back to a |
275 // unordered_map instead of a vector in the SmallMap. | 256 // unordered_map instead of a vector in the SmallMap. |
276 base::SmallMap<std::unordered_map<TileMapKey, gfx::Rect, TileMapKeyHash>, 16> | 257 base::SmallMap<std::unordered_map<TileMapKey, gfx::Rect, TileMapKeyHash>, 16> |
277 remove_tiles; | 258 remove_tiles; |
278 gfx::Rect expanded_live_tiles_rect = | 259 gfx::Rect expanded_live_tiles_rect = |
279 tiling_data_.ExpandRectToTileBounds(live_tiles_rect_); | 260 tiling_data_.ExpandRectToTileBounds(live_tiles_rect_); |
280 for (Region::Iterator iter(layer_invalidation); iter.has_rect(); | 261 for (Region::Iterator iter(layer_invalidation); iter.has_rect(); |
281 iter.next()) { | 262 iter.next()) { |
282 gfx::Rect layer_rect = iter.rect(); | 263 gfx::Rect layer_rect = iter.rect(); |
283 // The pixels which are invalid in content space. | 264 // The pixels which are invalid in content space. |
284 gfx::Rect invalid_content_rect = gfx::ScaleToEnclosingRect( | 265 gfx::Rect invalid_content_rect = |
285 layer_rect, raster_scales_.width(), raster_scales_.height()); | 266 gfx::ScaleToEnclosingRect(layer_rect, contents_scale_); |
286 gfx::Rect coverage_content_rect = invalid_content_rect; | 267 gfx::Rect coverage_content_rect = invalid_content_rect; |
287 // Avoid needless work by not bothering to invalidate where there aren't | 268 // Avoid needless work by not bothering to invalidate where there aren't |
288 // tiles. | 269 // tiles. |
289 coverage_content_rect.Intersect(expanded_live_tiles_rect); | 270 coverage_content_rect.Intersect(expanded_live_tiles_rect); |
290 if (coverage_content_rect.IsEmpty()) | 271 if (coverage_content_rect.IsEmpty()) |
291 continue; | 272 continue; |
292 // Since the content_rect needs to invalidate things that only touch a | 273 // Since the content_rect needs to invalidate things that only touch a |
293 // border of a tile, we need to include the borders while iterating. | 274 // border of a tile, we need to include the borders while iterating. |
294 bool include_borders = true; | 275 bool include_borders = true; |
295 for (TilingData::Iterator iter(&tiling_data_, coverage_content_rect, | 276 for (TilingData::Iterator iter(&tiling_data_, coverage_content_rect, |
(...skipping 15 matching lines...) Expand all Loading... |
311 Tile::CreateInfo info = CreateInfoForTile(key.index_x, key.index_y); | 292 Tile::CreateInfo info = CreateInfoForTile(key.index_x, key.index_y); |
312 if (Tile* tile = CreateTile(info)) | 293 if (Tile* tile = CreateTile(info)) |
313 tile->SetInvalidated(invalid_content_rect, old_tile->id()); | 294 tile->SetInvalidated(invalid_content_rect, old_tile->id()); |
314 } | 295 } |
315 } | 296 } |
316 } | 297 } |
317 | 298 |
318 Tile::CreateInfo PictureLayerTiling::CreateInfoForTile(int i, int j) const { | 299 Tile::CreateInfo PictureLayerTiling::CreateInfoForTile(int i, int j) const { |
319 gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(i, j); | 300 gfx::Rect tile_rect = tiling_data_.TileBoundsWithBorder(i, j); |
320 tile_rect.set_size(tiling_data_.max_texture_size()); | 301 tile_rect.set_size(tiling_data_.max_texture_size()); |
321 gfx::Rect enclosing_layer_rect = gfx::ScaleToEnclosingRect( | 302 gfx::Rect enclosing_layer_rect = |
322 tile_rect, 1.f / raster_scales_.width(), 1.f / raster_scales_.height()); | 303 gfx::ScaleToEnclosingRect(tile_rect, 1.f / contents_scale_); |
323 return Tile::CreateInfo(this, i, j, enclosing_layer_rect, tile_rect, | 304 return Tile::CreateInfo(this, i, j, enclosing_layer_rect, tile_rect, |
324 raster_scales_); | 305 contents_scale_); |
325 } | 306 } |
326 | 307 |
327 bool PictureLayerTiling::ShouldCreateTileAt( | 308 bool PictureLayerTiling::ShouldCreateTileAt( |
328 const Tile::CreateInfo& info) const { | 309 const Tile::CreateInfo& info) const { |
329 const int i = info.tiling_i_index; | 310 const int i = info.tiling_i_index; |
330 const int j = info.tiling_j_index; | 311 const int j = info.tiling_j_index; |
331 // Active tree should always create a tile. The reason for this is that active | 312 // Active tree should always create a tile. The reason for this is that active |
332 // tree represents content that we draw on screen, which means that whenever | 313 // tree represents content that we draw on screen, which means that whenever |
333 // we check whether a tile should exist somewhere, the answer is yes. This | 314 // we check whether a tile should exist somewhere, the answer is yes. This |
334 // doesn't mean it will actually be created (if raster source doesn't cover | 315 // doesn't mean it will actually be created (if raster source doesn't cover |
(...skipping 18 matching lines...) Expand all Loading... |
353 if (!active_twin->raster_source()->CoversRect(info.enclosing_layer_rect)) | 334 if (!active_twin->raster_source()->CoversRect(info.enclosing_layer_rect)) |
354 return true; | 335 return true; |
355 | 336 |
356 const Region* layer_invalidation = client_->GetPendingInvalidation(); | 337 const Region* layer_invalidation = client_->GetPendingInvalidation(); |
357 | 338 |
358 // If this tile is invalidated, then the pending tree should create one. | 339 // If this tile is invalidated, then the pending tree should create one. |
359 // Do the intersection test in content space to match the corresponding check | 340 // Do the intersection test in content space to match the corresponding check |
360 // on the active tree and avoid floating point inconsistencies. | 341 // on the active tree and avoid floating point inconsistencies. |
361 for (Region::Iterator iter(*layer_invalidation); iter.has_rect(); | 342 for (Region::Iterator iter(*layer_invalidation); iter.has_rect(); |
362 iter.next()) { | 343 iter.next()) { |
363 gfx::Rect invalid_content_rect = gfx::ScaleToEnclosingRect( | 344 gfx::Rect invalid_content_rect = |
364 iter.rect(), raster_scales_.width(), raster_scales_.height()); | 345 gfx::ScaleToEnclosingRect(iter.rect(), contents_scale_); |
365 if (invalid_content_rect.Intersects(info.content_rect)) | 346 if (invalid_content_rect.Intersects(info.content_rect)) |
366 return true; | 347 return true; |
367 } | 348 } |
368 // If the active tree doesn't have a tile here, but it's in the pending tree's | 349 // If the active tree doesn't have a tile here, but it's in the pending tree's |
369 // visible rect, then the pending tree should create a tile. This can happen | 350 // visible rect, then the pending tree should create a tile. This can happen |
370 // if the pending visible rect is outside of the active tree's live tiles | 351 // if the pending visible rect is outside of the active tree's live tiles |
371 // rect. In those situations, we need to block activation until we're ready to | 352 // rect. In those situations, we need to block activation until we're ready to |
372 // display content, which will have to come from the pending tree. | 353 // display content, which will have to come from the pending tree. |
373 if (!active_twin->TileAt(i, j) && | 354 if (!active_twin->TileAt(i, j) && |
374 current_visible_rect_.Intersects(info.content_rect)) | 355 current_visible_rect_.Intersects(info.content_rect)) |
(...skipping 13 matching lines...) Expand all Loading... |
388 | 369 |
389 PictureLayerTiling::CoverageIterator::CoverageIterator( | 370 PictureLayerTiling::CoverageIterator::CoverageIterator( |
390 const PictureLayerTiling* tiling, | 371 const PictureLayerTiling* tiling, |
391 float coverage_scale, | 372 float coverage_scale, |
392 const gfx::Rect& coverage_rect) | 373 const gfx::Rect& coverage_rect) |
393 : tiling_(tiling), coverage_rect_(coverage_rect) { | 374 : tiling_(tiling), coverage_rect_(coverage_rect) { |
394 DCHECK(tiling_); | 375 DCHECK(tiling_); |
395 // In order to avoid artifacts in geometry_rect scaling and clamping to ints, | 376 // In order to avoid artifacts in geometry_rect scaling and clamping to ints, |
396 // the |coverage_scale| should always be at least as big as the tiling's | 377 // the |coverage_scale| should always be at least as big as the tiling's |
397 // raster scales. | 378 // raster scales. |
398 DCHECK_GE(coverage_scale, tiling_->raster_scales_.width()); | 379 DCHECK_GE(coverage_scale, tiling_->contents_scale_); |
399 DCHECK_GE(coverage_scale, tiling_->raster_scales_.height()); | |
400 | 380 |
401 // Clamp |coverage_rect| to the bounds of this tiling's raster source. | 381 // Clamp |coverage_rect| to the bounds of this tiling's raster source. |
402 coverage_rect_max_bounds_ = | 382 coverage_rect_max_bounds_ = |
403 gfx::ScaleToCeiledSize(tiling->raster_source_->GetSize(), coverage_scale); | 383 gfx::ScaleToCeiledSize(tiling->raster_source_->GetSize(), coverage_scale); |
404 coverage_rect_.Intersect(gfx::Rect(coverage_rect_max_bounds_)); | 384 coverage_rect_.Intersect(gfx::Rect(coverage_rect_max_bounds_)); |
405 if (coverage_rect_.IsEmpty()) | 385 if (coverage_rect_.IsEmpty()) |
406 return; | 386 return; |
407 | 387 |
408 coverage_to_content_scale_ = | 388 coverage_to_content_scale_ = tiling_->contents_scale_ / coverage_scale; |
409 gfx::SizeF(tiling_->raster_scales_.width() / coverage_scale, | |
410 tiling_->raster_scales_.height() / coverage_scale); | |
411 | 389 |
412 // Find the indices of the texel samples that enclose the rect we want to | 390 // Find the indices of the texel samples that enclose the rect we want to |
413 // cover. | 391 // cover. |
414 // Because we don't know the target transform at this point, we have to be | 392 // Because we don't know the target transform at this point, we have to be |
415 // pessimistic, i.e. assume every point (a pair of real number, not necessary | 393 // pessimistic, i.e. assume every point (a pair of real number, not necessary |
416 // snapped to a pixel sample) inside of the content rect may be sampled. | 394 // snapped to a pixel sample) inside of the content rect may be sampled. |
417 // This code maps the boundary points into contents space, then find out the | 395 // This code maps the boundary points into contents space, then find out the |
418 // enclosing texture samples. For example, assume we have: | 396 // enclosing texture samples. For example, assume we have: |
419 // dest_scale : content_scale = 1.23 : 1 | 397 // dest_scale : content_scale = 1.23 : 1 |
420 // dest_rect = (l:123, t:234, r:345, b:456) | 398 // dest_rect = (l:123, t:234, r:345, b:456) |
421 // Then it follows that: | 399 // Then it follows that: |
422 // content_rect = (l:100.00, t:190.24, r:280.49, b:370.73) | 400 // content_rect = (l:100.00, t:190.24, r:280.49, b:370.73) |
423 // Without MSAA, the sample point of a texel is at the center of that texel, | 401 // Without MSAA, the sample point of a texel is at the center of that texel, |
424 // thus the sample points we need to cover content_rect are: | 402 // thus the sample points we need to cover content_rect are: |
425 // wanted_texels(sample coordinates) = (l:99.5, t:189.5, r:280.5, b:371.5) | 403 // wanted_texels(sample coordinates) = (l:99.5, t:189.5, r:280.5, b:371.5) |
426 // Or in integer index: | 404 // Or in integer index: |
427 // wanted_texels(integer index) = (l:99, t:189, r:280, b:371) | 405 // wanted_texels(integer index) = (l:99, t:189, r:280, b:371) |
428 gfx::RectF content_rect = gfx::ScaleRect(gfx::RectF(coverage_rect_), | 406 gfx::RectF content_rect = |
429 coverage_to_content_scale_.width(), | 407 gfx::ScaleRect(gfx::RectF(coverage_rect_), coverage_to_content_scale_); |
430 coverage_to_content_scale_.height()); | |
431 content_rect.Offset(-0.5f, -0.5f); | 408 content_rect.Offset(-0.5f, -0.5f); |
432 gfx::Rect wanted_texels = gfx::ToEnclosingRect(content_rect); | 409 gfx::Rect wanted_texels = gfx::ToEnclosingRect(content_rect); |
433 | 410 |
434 const TilingData& data = tiling_->tiling_data_; | 411 const TilingData& data = tiling_->tiling_data_; |
435 left_ = data.LastBorderTileXIndexFromSrcCoord(wanted_texels.x()); | 412 left_ = data.LastBorderTileXIndexFromSrcCoord(wanted_texels.x()); |
436 top_ = data.LastBorderTileYIndexFromSrcCoord(wanted_texels.y()); | 413 top_ = data.LastBorderTileYIndexFromSrcCoord(wanted_texels.y()); |
437 right_ = std::max( | 414 right_ = std::max( |
438 left_, data.FirstBorderTileXIndexFromSrcCoord(wanted_texels.right())); | 415 left_, data.FirstBorderTileXIndexFromSrcCoord(wanted_texels.right())); |
439 bottom_ = std::max( | 416 bottom_ = std::max( |
440 top_, data.FirstBorderTileYIndexFromSrcCoord(wanted_texels.bottom())); | 417 top_, data.FirstBorderTileYIndexFromSrcCoord(wanted_texels.bottom())); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 // error in both u/v axis can't exceed | 459 // error in both u/v axis can't exceed |
483 // 255 * (1 - (1 - 1/1024) * (1 - 1/1024)) ~= 0.498 | 460 // 255 * (1 - (1 - 1/1024) * (1 - 1/1024)) ~= 0.498 |
484 // i.e. The color value can never flip over a rounding threshold. | 461 // i.e. The color value can never flip over a rounding threshold. |
485 constexpr float epsilon = 1.f / 1024.f; | 462 constexpr float epsilon = 1.f / 1024.f; |
486 texel_extent.Inset(-epsilon, -epsilon); | 463 texel_extent.Inset(-epsilon, -epsilon); |
487 } | 464 } |
488 | 465 |
489 // Convert texel_extent to coverage scale, which is what we have to report | 466 // Convert texel_extent to coverage scale, which is what we have to report |
490 // geometry_rect in. | 467 // geometry_rect in. |
491 current_geometry_rect_ = gfx::ToEnclosedRect( | 468 current_geometry_rect_ = gfx::ToEnclosedRect( |
492 gfx::ScaleRect(texel_extent, 1.f / coverage_to_content_scale_.width(), | 469 gfx::ScaleRect(texel_extent, 1.f / coverage_to_content_scale_)); |
493 1.f / coverage_to_content_scale_.height())); | |
494 { | 470 { |
495 // Adjust external edges to cover the whole layer in dest space. | 471 // Adjust external edges to cover the whole layer in dest space. |
496 // | 472 // |
497 // For external edges, extend the tile to scaled layer bounds. This is | 473 // For external edges, extend the tile to scaled layer bounds. This is |
498 // needed to fully cover the coverage space because the sample extent | 474 // needed to fully cover the coverage space because the sample extent |
499 // doesn't cover the last 0.5 texel to layer edge, and also the coverage | 475 // doesn't cover the last 0.5 texel to layer edge, and also the coverage |
500 // space can be rounded up for up to 1 pixel. This overhang will never be | 476 // space can be rounded up for up to 1 pixel. This overhang will never be |
501 // sampled as the AA fragment shader clamps sample coordinate and | 477 // sampled as the AA fragment shader clamps sample coordinate and |
502 // antialiasing itself. | 478 // antialiasing itself. |
503 const TilingData& data = tiling_->tiling_data_; | 479 const TilingData& data = tiling_->tiling_data_; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 gfx::Rect PictureLayerTiling::CoverageIterator::geometry_rect() const { | 524 gfx::Rect PictureLayerTiling::CoverageIterator::geometry_rect() const { |
549 return current_geometry_rect_; | 525 return current_geometry_rect_; |
550 } | 526 } |
551 | 527 |
552 gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const { | 528 gfx::RectF PictureLayerTiling::CoverageIterator::texture_rect() const { |
553 auto tex_origin = gfx::PointF( | 529 auto tex_origin = gfx::PointF( |
554 tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_).origin()); | 530 tiling_->tiling_data_.TileBoundsWithBorder(tile_i_, tile_j_).origin()); |
555 | 531 |
556 // Convert from dest space => content space => texture space. | 532 // Convert from dest space => content space => texture space. |
557 gfx::RectF texture_rect(current_geometry_rect_); | 533 gfx::RectF texture_rect(current_geometry_rect_); |
558 texture_rect.Scale(coverage_to_content_scale_.width(), | 534 texture_rect.Scale(coverage_to_content_scale_); |
559 coverage_to_content_scale_.height()); | |
560 texture_rect.Intersect(gfx::RectF(gfx::SizeF(tiling_->tiling_size()))); | 535 texture_rect.Intersect(gfx::RectF(gfx::SizeF(tiling_->tiling_size()))); |
561 if (texture_rect.IsEmpty()) | 536 if (texture_rect.IsEmpty()) |
562 return texture_rect; | 537 return texture_rect; |
563 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); | 538 texture_rect.Offset(-tex_origin.OffsetFromOrigin()); |
564 | 539 |
565 return texture_rect; | 540 return texture_rect; |
566 } | 541 } |
567 | 542 |
568 std::unique_ptr<Tile> PictureLayerTiling::TakeTileAt(int i, int j) { | 543 std::unique_ptr<Tile> PictureLayerTiling::TakeTileAt(int i, int j) { |
569 TileMap::iterator found = tiles_.find(TileMapKey(i, j)); | 544 TileMap::iterator found = tiles_.find(TileMapKey(i, j)); |
(...skipping 25 matching lines...) Expand all Loading... |
595 const gfx::Rect& eventually_rect_in_layer_space, | 570 const gfx::Rect& eventually_rect_in_layer_space, |
596 float ideal_contents_scale, | 571 float ideal_contents_scale, |
597 const Occlusion& occlusion_in_layer_space) { | 572 const Occlusion& occlusion_in_layer_space) { |
598 // If we have, or had occlusions, mark the tiles as 'not done' to ensure that | 573 // If we have, or had occlusions, mark the tiles as 'not done' to ensure that |
599 // we reiterate the tiles for rasterization. | 574 // we reiterate the tiles for rasterization. |
600 if (occlusion_in_layer_space.HasOcclusion() || | 575 if (occlusion_in_layer_space.HasOcclusion() || |
601 current_occlusion_in_layer_space_.HasOcclusion()) { | 576 current_occlusion_in_layer_space_.HasOcclusion()) { |
602 set_all_tiles_done(false); | 577 set_all_tiles_done(false); |
603 } | 578 } |
604 | 579 |
605 gfx::SizeF content_to_screen_scale( | 580 float content_to_screen_scale = ideal_contents_scale / contents_scale_; |
606 ideal_contents_scale / raster_scales_.width(), | |
607 ideal_contents_scale / raster_scales_.height()); | |
608 | 581 |
609 const gfx::Rect* input_rects[] = { | 582 const gfx::Rect* input_rects[] = { |
610 &visible_rect_in_layer_space, &skewport_in_layer_space, | 583 &visible_rect_in_layer_space, &skewport_in_layer_space, |
611 &soon_border_rect_in_layer_space, &eventually_rect_in_layer_space}; | 584 &soon_border_rect_in_layer_space, &eventually_rect_in_layer_space}; |
612 gfx::Rect output_rects[4]; | 585 gfx::Rect output_rects[4]; |
613 for (size_t i = 0; i < arraysize(input_rects); ++i) { | 586 for (size_t i = 0; i < arraysize(input_rects); ++i) { |
614 output_rects[i] = gfx::ToEnclosingRect( | 587 output_rects[i] = gfx::ToEnclosingRect( |
615 gfx::ScaleRect(gfx::RectF(*input_rects[i]), raster_scales_.width(), | 588 gfx::ScaleRect(gfx::RectF(*input_rects[i]), contents_scale_)); |
616 raster_scales_.height())); | |
617 } | 589 } |
618 // Make sure the eventually rect is aligned to tile bounds. | 590 // Make sure the eventually rect is aligned to tile bounds. |
619 output_rects[3] = | 591 output_rects[3] = |
620 tiling_data_.ExpandRectIgnoringBordersToTileBounds(output_rects[3]); | 592 tiling_data_.ExpandRectIgnoringBordersToTileBounds(output_rects[3]); |
621 | 593 |
622 SetTilePriorityRects(content_to_screen_scale, output_rects[0], | 594 SetTilePriorityRects(content_to_screen_scale, output_rects[0], |
623 output_rects[1], output_rects[2], output_rects[3], | 595 output_rects[1], output_rects[2], output_rects[3], |
624 occlusion_in_layer_space); | 596 occlusion_in_layer_space); |
625 SetLiveTilesRect(output_rects[3]); | 597 SetLiveTilesRect(output_rects[3]); |
626 } | 598 } |
627 | 599 |
628 void PictureLayerTiling::SetTilePriorityRects( | 600 void PictureLayerTiling::SetTilePriorityRects( |
629 const gfx::SizeF& content_to_screen_scale, | 601 float content_to_screen_scale, |
630 const gfx::Rect& visible_rect_in_content_space, | 602 const gfx::Rect& visible_rect_in_content_space, |
631 const gfx::Rect& skewport, | 603 const gfx::Rect& skewport, |
632 const gfx::Rect& soon_border_rect, | 604 const gfx::Rect& soon_border_rect, |
633 const gfx::Rect& eventually_rect, | 605 const gfx::Rect& eventually_rect, |
634 const Occlusion& occlusion_in_layer_space) { | 606 const Occlusion& occlusion_in_layer_space) { |
635 current_visible_rect_ = visible_rect_in_content_space; | 607 current_visible_rect_ = visible_rect_in_content_space; |
636 current_skewport_rect_ = skewport; | 608 current_skewport_rect_ = skewport; |
637 current_soon_border_rect_ = soon_border_rect; | 609 current_soon_border_rect_ = soon_border_rect; |
638 current_eventually_rect_ = eventually_rect; | 610 current_eventually_rect_ = eventually_rect; |
639 current_occlusion_in_layer_space_ = occlusion_in_layer_space; | 611 current_occlusion_in_layer_space_ = occlusion_in_layer_space; |
640 current_content_to_screen_scale_ = content_to_screen_scale; | 612 current_content_to_screen_scale_ = content_to_screen_scale; |
641 | 613 |
642 gfx::Rect tiling_rect(tiling_size()); | 614 gfx::Rect tiling_rect(tiling_size()); |
643 has_visible_rect_tiles_ = tiling_rect.Intersects(current_visible_rect_); | 615 has_visible_rect_tiles_ = tiling_rect.Intersects(current_visible_rect_); |
644 has_skewport_rect_tiles_ = tiling_rect.Intersects(current_skewport_rect_); | 616 has_skewport_rect_tiles_ = tiling_rect.Intersects(current_skewport_rect_); |
645 has_soon_border_rect_tiles_ = | 617 has_soon_border_rect_tiles_ = |
646 tiling_rect.Intersects(current_soon_border_rect_); | 618 tiling_rect.Intersects(current_soon_border_rect_); |
647 has_eventually_rect_tiles_ = tiling_rect.Intersects(current_eventually_rect_); | 619 has_eventually_rect_tiles_ = tiling_rect.Intersects(current_eventually_rect_); |
648 | 620 |
649 // Note that we use the largest skewport extent from the viewport as the | 621 // Note that we use the largest skewport extent from the viewport as the |
650 // "skewport extent". Also note that this math can't produce negative numbers, | 622 // "skewport extent". Also note that this math can't produce negative numbers, |
651 // since skewport.Contains(visible_rect) is always true. | 623 // since skewport.Contains(visible_rect) is always true. |
652 max_skewport_extent_in_screen_space_ = std::max( | 624 max_skewport_extent_in_screen_space_ = |
653 current_content_to_screen_scale_.width() * | 625 current_content_to_screen_scale_ * |
654 std::max( | 626 std::max(std::max(current_visible_rect_.x() - current_skewport_rect_.x(), |
655 current_visible_rect_.x() - current_skewport_rect_.x(), | 627 current_skewport_rect_.right() - |
656 current_skewport_rect_.right() - current_visible_rect_.right()), | 628 current_visible_rect_.right()), |
657 current_content_to_screen_scale_.height() * | 629 std::max(current_visible_rect_.y() - current_skewport_rect_.y(), |
658 std::max(current_visible_rect_.y() - current_skewport_rect_.y(), | 630 current_skewport_rect_.bottom() - |
659 current_skewport_rect_.bottom() - | 631 current_visible_rect_.bottom())); |
660 current_visible_rect_.bottom())); | |
661 } | 632 } |
662 | 633 |
663 void PictureLayerTiling::SetLiveTilesRect( | 634 void PictureLayerTiling::SetLiveTilesRect( |
664 const gfx::Rect& new_live_tiles_rect) { | 635 const gfx::Rect& new_live_tiles_rect) { |
665 DCHECK(new_live_tiles_rect.IsEmpty() || | 636 DCHECK(new_live_tiles_rect.IsEmpty() || |
666 gfx::Rect(tiling_size()).Contains(new_live_tiles_rect)) | 637 gfx::Rect(tiling_size()).Contains(new_live_tiles_rect)) |
667 << "tiling_size: " << tiling_size().ToString() | 638 << "tiling_size: " << tiling_size().ToString() |
668 << " new_live_tiles_rect: " << new_live_tiles_rect.ToString(); | 639 << " new_live_tiles_rect: " << new_live_tiles_rect.ToString(); |
669 if (live_tiles_rect_ == new_live_tiles_rect) | 640 if (live_tiles_rect_ == new_live_tiles_rect) |
670 return; | 641 return; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 bool PictureLayerTiling::IsTileOccludedOnCurrentTree(const Tile* tile) const { | 722 bool PictureLayerTiling::IsTileOccludedOnCurrentTree(const Tile* tile) const { |
752 if (!current_occlusion_in_layer_space_.HasOcclusion()) | 723 if (!current_occlusion_in_layer_space_.HasOcclusion()) |
753 return false; | 724 return false; |
754 gfx::Rect tile_query_rect = | 725 gfx::Rect tile_query_rect = |
755 gfx::IntersectRects(tile->content_rect(), current_visible_rect_); | 726 gfx::IntersectRects(tile->content_rect(), current_visible_rect_); |
756 // Explicitly check if the tile is outside the viewport. If so, we need to | 727 // Explicitly check if the tile is outside the viewport. If so, we need to |
757 // return false, since occlusion for this tile is unknown. | 728 // return false, since occlusion for this tile is unknown. |
758 if (tile_query_rect.IsEmpty()) | 729 if (tile_query_rect.IsEmpty()) |
759 return false; | 730 return false; |
760 | 731 |
761 if (raster_scales_ != gfx::SizeF(1.f, 1.f)) { | 732 if (contents_scale_ != 1.f) { |
762 tile_query_rect = | 733 tile_query_rect = |
763 gfx::ScaleToEnclosingRect(tile_query_rect, 1.f / raster_scales_.width(), | 734 gfx::ScaleToEnclosingRect(tile_query_rect, 1.f / contents_scale_); |
764 1.f / raster_scales_.height()); | |
765 } | 735 } |
766 return current_occlusion_in_layer_space_.IsOccluded(tile_query_rect); | 736 return current_occlusion_in_layer_space_.IsOccluded(tile_query_rect); |
767 } | 737 } |
768 | 738 |
769 bool PictureLayerTiling::IsTileRequiredForActivation(const Tile* tile) const { | 739 bool PictureLayerTiling::IsTileRequiredForActivation(const Tile* tile) const { |
770 if (tree_ == PENDING_TREE) { | 740 if (tree_ == PENDING_TREE) { |
771 if (!can_require_tiles_for_activation_) | 741 if (!can_require_tiles_for_activation_) |
772 return false; | 742 return false; |
773 | 743 |
774 if (resolution_ != HIGH_RESOLUTION) | 744 if (resolution_ != HIGH_RESOLUTION) |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
836 DCHECK(tile); | 806 DCHECK(tile); |
837 tile->set_required_for_activation(IsTileRequiredForActivation(tile)); | 807 tile->set_required_for_activation(IsTileRequiredForActivation(tile)); |
838 tile->set_required_for_draw(IsTileRequiredForDraw(tile)); | 808 tile->set_required_for_draw(IsTileRequiredForDraw(tile)); |
839 } | 809 } |
840 | 810 |
841 PrioritizedTile PictureLayerTiling::MakePrioritizedTile( | 811 PrioritizedTile PictureLayerTiling::MakePrioritizedTile( |
842 Tile* tile, | 812 Tile* tile, |
843 PriorityRectType priority_rect_type) const { | 813 PriorityRectType priority_rect_type) const { |
844 DCHECK(tile); | 814 DCHECK(tile); |
845 DCHECK(raster_source()->CoversRect(tile->enclosing_layer_rect())) | 815 DCHECK(raster_source()->CoversRect(tile->enclosing_layer_rect())) |
846 << "Recording rect: " | 816 << "Tile layer rect: " << tile->enclosing_layer_rect().ToString(); |
847 << gfx::ScaleToEnclosingRect(tile->content_rect(), | |
848 1.f / tile->raster_scales().width(), | |
849 1.f / tile->raster_scales().height()) | |
850 .ToString(); | |
851 | 817 |
852 const auto& tile_priority = ComputePriorityForTile(tile, priority_rect_type); | 818 const auto& tile_priority = ComputePriorityForTile(tile, priority_rect_type); |
853 // Note that TileManager will consider this flag but may rasterize the tile | 819 // Note that TileManager will consider this flag but may rasterize the tile |
854 // anyway (if tile is required for activation for example). We should process | 820 // anyway (if tile is required for activation for example). We should process |
855 // the tile for images only if it's further than half of the skewport extent. | 821 // the tile for images only if it's further than half of the skewport extent. |
856 bool process_for_images_only = | 822 bool process_for_images_only = |
857 tile_priority.distance_to_visible > min_preraster_distance_ && | 823 tile_priority.distance_to_visible > min_preraster_distance_ && |
858 (tile_priority.distance_to_visible > max_preraster_distance_ || | 824 (tile_priority.distance_to_visible > max_preraster_distance_ || |
859 tile_priority.distance_to_visible > | 825 tile_priority.distance_to_visible > |
860 0.5f * max_skewport_extent_in_screen_space_); | 826 0.5f * max_skewport_extent_in_screen_space_); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 if (priority_bin < TilePriority::SOON) | 860 if (priority_bin < TilePriority::SOON) |
895 priority_bin = TilePriority::SOON; | 861 priority_bin = TilePriority::SOON; |
896 break; | 862 break; |
897 case EVENTUALLY_RECT: | 863 case EVENTUALLY_RECT: |
898 priority_bin = TilePriority::EVENTUALLY; | 864 priority_bin = TilePriority::EVENTUALLY; |
899 break; | 865 break; |
900 } | 866 } |
901 | 867 |
902 gfx::Rect tile_bounds = | 868 gfx::Rect tile_bounds = |
903 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); | 869 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); |
904 DCHECK_GT(current_content_to_screen_scale_.width(), 0.f); | 870 DCHECK_GT(current_content_to_screen_scale_, 0.f); |
905 DCHECK_GT(current_content_to_screen_scale_.height(), 0.f); | 871 float distance_to_visible = |
906 float distance_to_visible = ComputeScaledManhattalInternalDistance( | 872 current_content_to_screen_scale_ * |
907 current_visible_rect_, tile_bounds, current_content_to_screen_scale_); | 873 current_visible_rect_.ManhattanInternalDistance(tile_bounds); |
908 | 874 |
909 return TilePriority(resolution_, priority_bin, distance_to_visible); | 875 return TilePriority(resolution_, priority_bin, distance_to_visible); |
910 } | 876 } |
911 | 877 |
912 PictureLayerTiling::PriorityRectType | 878 PictureLayerTiling::PriorityRectType |
913 PictureLayerTiling::ComputePriorityRectTypeForTile(const Tile* tile) const { | 879 PictureLayerTiling::ComputePriorityRectTypeForTile(const Tile* tile) const { |
914 DCHECK_EQ(TileAt(tile->tiling_i_index(), tile->tiling_j_index()), tile); | 880 DCHECK_EQ(TileAt(tile->tiling_i_index(), tile->tiling_j_index()), tile); |
915 gfx::Rect tile_bounds = | 881 gfx::Rect tile_bounds = |
916 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); | 882 tiling_data_.TileBounds(tile->tiling_i_index(), tile->tiling_j_index()); |
917 | 883 |
(...skipping 18 matching lines...) Expand all Loading... |
936 for (const auto& tile_pair : tiles_) { | 902 for (const auto& tile_pair : tiles_) { |
937 Tile* tile = tile_pair.second.get(); | 903 Tile* tile = tile_pair.second.get(); |
938 prioritized_tiles->push_back( | 904 prioritized_tiles->push_back( |
939 MakePrioritizedTile(tile, ComputePriorityRectTypeForTile(tile))); | 905 MakePrioritizedTile(tile, ComputePriorityRectTypeForTile(tile))); |
940 } | 906 } |
941 } | 907 } |
942 | 908 |
943 void PictureLayerTiling::AsValueInto( | 909 void PictureLayerTiling::AsValueInto( |
944 base::trace_event::TracedValue* state) const { | 910 base::trace_event::TracedValue* state) const { |
945 state->SetInteger("num_tiles", base::saturated_cast<int>(tiles_.size())); | 911 state->SetInteger("num_tiles", base::saturated_cast<int>(tiles_.size())); |
946 // TODO(vmpstr): Change frameviewer to use raster scales. | 912 state->SetDouble("content_scale", contents_scale()); |
947 state->SetDouble("content_scale", contents_scale_key()); | |
948 | |
949 state->BeginArray("raster_scales"); | |
950 state->AppendDouble(raster_scales_.width()); | |
951 state->AppendDouble(raster_scales_.height()); | |
952 state->EndArray(); | |
953 | 913 |
954 MathUtil::AddToTracedValue("visible_rect", current_visible_rect_, state); | 914 MathUtil::AddToTracedValue("visible_rect", current_visible_rect_, state); |
955 MathUtil::AddToTracedValue("skewport_rect", current_skewport_rect_, state); | 915 MathUtil::AddToTracedValue("skewport_rect", current_skewport_rect_, state); |
956 MathUtil::AddToTracedValue("soon_rect", current_soon_border_rect_, state); | 916 MathUtil::AddToTracedValue("soon_rect", current_soon_border_rect_, state); |
957 MathUtil::AddToTracedValue("eventually_rect", current_eventually_rect_, | 917 MathUtil::AddToTracedValue("eventually_rect", current_eventually_rect_, |
958 state); | 918 state); |
959 MathUtil::AddToTracedValue("tiling_size", tiling_size(), state); | 919 MathUtil::AddToTracedValue("tiling_size", tiling_size(), state); |
960 } | 920 } |
961 | 921 |
962 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { | 922 size_t PictureLayerTiling::GPUMemoryUsageInBytes() const { |
963 size_t amount = 0; | 923 size_t amount = 0; |
964 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { | 924 for (TileMap::const_iterator it = tiles_.begin(); it != tiles_.end(); ++it) { |
965 const Tile* tile = it->second.get(); | 925 const Tile* tile = it->second.get(); |
966 amount += tile->GPUMemoryUsageInBytes(); | 926 amount += tile->GPUMemoryUsageInBytes(); |
967 } | 927 } |
968 return amount; | 928 return amount; |
969 } | 929 } |
970 | 930 |
971 } // namespace cc | 931 } // namespace cc |
OLD | NEW |