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/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/debug/trace_event_argument.h" | 10 #include "base/debug/trace_event_argument.h" |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 visible_geometry_rect, | 257 visible_geometry_rect, |
258 color, | 258 color, |
259 width); | 259 width); |
260 } | 260 } |
261 } | 261 } |
262 | 262 |
263 // Keep track of the tilings that were used so that tilings that are | 263 // Keep track of the tilings that were used so that tilings that are |
264 // unused can be considered for removal. | 264 // unused can be considered for removal. |
265 std::vector<PictureLayerTiling*> seen_tilings; | 265 std::vector<PictureLayerTiling*> seen_tilings; |
266 | 266 |
| 267 gfx::Rect scaled_activation_rect = GetActivationRectInContentSpace(); |
| 268 scaled_activation_rect = |
| 269 gfx::ScaleToEnclosingRect(scaled_activation_rect, max_contents_scale); |
| 270 |
267 size_t missing_tile_count = 0u; | 271 size_t missing_tile_count = 0u; |
268 size_t on_demand_missing_tile_count = 0u; | 272 size_t on_demand_missing_tile_count = 0u; |
269 for (PictureLayerTilingSet::CoverageIterator iter(tilings_.get(), | 273 for (PictureLayerTilingSet::CoverageIterator iter(tilings_.get(), |
270 max_contents_scale, | 274 max_contents_scale, |
271 scaled_visible_content_rect, | 275 scaled_visible_content_rect, |
272 ideal_contents_scale_); | 276 ideal_contents_scale_); |
273 iter; | 277 iter; |
274 ++iter) { | 278 ++iter) { |
275 gfx::Rect geometry_rect = iter.geometry_rect(); | 279 gfx::Rect geometry_rect = iter.geometry_rect(); |
276 gfx::Rect visible_geometry_rect = occlusion_tracker.UnoccludedContentRect( | 280 gfx::Rect visible_geometry_rect = occlusion_tracker.UnoccludedContentRect( |
277 geometry_rect, scaled_draw_transform); | 281 geometry_rect, scaled_draw_transform); |
278 if (visible_geometry_rect.IsEmpty()) | 282 if (visible_geometry_rect.IsEmpty()) |
279 continue; | 283 continue; |
280 | 284 |
281 append_quads_data->visible_content_area += | 285 append_quads_data->visible_content_area += |
282 visible_geometry_rect.width() * visible_geometry_rect.height(); | 286 visible_geometry_rect.width() * visible_geometry_rect.height(); |
283 | 287 |
284 if (*iter && iter->IsReadyToDraw()) { | 288 if (*iter && iter->IsReadyToDraw()) { |
285 const ManagedTileState::TileVersion& tile_version = | 289 const ManagedTileState::TileVersion& tile_version = |
286 iter->GetTileVersionForDrawing(); | 290 iter->GetTileVersionForDrawing(); |
287 switch (tile_version.mode()) { | 291 switch (tile_version.mode()) { |
288 case ManagedTileState::TileVersion::RESOURCE_MODE: { | 292 case ManagedTileState::TileVersion::RESOURCE_MODE: { |
289 gfx::RectF texture_rect = iter.texture_rect(); | 293 gfx::RectF texture_rect = iter.texture_rect(); |
290 gfx::Rect opaque_rect = iter->opaque_rect(); | 294 gfx::Rect opaque_rect = iter->opaque_rect(); |
291 opaque_rect.Intersect(geometry_rect); | 295 opaque_rect.Intersect(geometry_rect); |
292 | 296 |
293 if (iter->contents_scale() != ideal_contents_scale_) | 297 if (iter->contents_scale() != ideal_contents_scale_) { |
294 append_quads_data->num_incomplete_tiles++; | 298 append_quads_data->num_incomplete_tiles++; |
| 299 if (geometry_rect.Intersects(scaled_activation_rect)) { |
| 300 append_quads_data->num_incomplete_tiles_inside_activation_rect++; |
| 301 } |
| 302 } |
295 | 303 |
296 TileDrawQuad* quad = | 304 TileDrawQuad* quad = |
297 render_pass->CreateAndAppendDrawQuad<TileDrawQuad>(); | 305 render_pass->CreateAndAppendDrawQuad<TileDrawQuad>(); |
298 quad->SetNew(shared_quad_state, | 306 quad->SetNew(shared_quad_state, |
299 geometry_rect, | 307 geometry_rect, |
300 opaque_rect, | 308 opaque_rect, |
301 visible_geometry_rect, | 309 visible_geometry_rect, |
302 tile_version.get_resource_id(), | 310 tile_version.get_resource_id(), |
303 texture_rect, | 311 texture_rect, |
304 iter.texture_size(), | 312 iter.texture_size(), |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 SolidColorDrawQuad* quad = | 366 SolidColorDrawQuad* quad = |
359 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | 367 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
360 quad->SetNew(shared_quad_state, | 368 quad->SetNew(shared_quad_state, |
361 geometry_rect, | 369 geometry_rect, |
362 visible_geometry_rect, | 370 visible_geometry_rect, |
363 color, | 371 color, |
364 false); | 372 false); |
365 } | 373 } |
366 | 374 |
367 append_quads_data->num_missing_tiles++; | 375 append_quads_data->num_missing_tiles++; |
| 376 if (geometry_rect.Intersects(scaled_activation_rect)) { |
| 377 append_quads_data->num_missing_tiles_inside_activation_rect++; |
| 378 } |
368 append_quads_data->approximated_visible_content_area += | 379 append_quads_data->approximated_visible_content_area += |
369 visible_geometry_rect.width() * visible_geometry_rect.height(); | 380 visible_geometry_rect.width() * visible_geometry_rect.height(); |
370 ++missing_tile_count; | 381 ++missing_tile_count; |
371 continue; | 382 continue; |
372 } | 383 } |
373 | 384 |
374 if (iter->priority(ACTIVE_TREE).resolution != HIGH_RESOLUTION) { | 385 if (iter->priority(ACTIVE_TREE).resolution != HIGH_RESOLUTION) { |
375 append_quads_data->approximated_visible_content_area += | 386 append_quads_data->approximated_visible_content_area += |
376 visible_geometry_rect.width() * visible_geometry_rect.height(); | 387 visible_geometry_rect.width() * visible_geometry_rect.height(); |
377 } | 388 } |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | 476 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
466 if (tilings_->tiling_at(i)->NeedsUpdateForFrameAtTime( | 477 if (tilings_->tiling_at(i)->NeedsUpdateForFrameAtTime( |
467 current_frame_time_in_seconds)) { | 478 current_frame_time_in_seconds)) { |
468 tiling_needs_update = true; | 479 tiling_needs_update = true; |
469 break; | 480 break; |
470 } | 481 } |
471 } | 482 } |
472 if (!tiling_needs_update) | 483 if (!tiling_needs_update) |
473 return; | 484 return; |
474 | 485 |
| 486 gfx::Rect visible_rect_in_content_space(GetActivationRectInContentSpace()); |
| 487 visible_rect_in_content_space.Intersect(visible_content_rect()); |
| 488 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect( |
| 489 visible_rect_in_content_space, 1.f / contents_scale_x()); |
| 490 WhichTree tree = |
| 491 layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; |
| 492 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
| 493 tilings_->tiling_at(i)->UpdateTilePriorities(tree, |
| 494 visible_layer_rect, |
| 495 ideal_contents_scale_, |
| 496 current_frame_time_in_seconds, |
| 497 occlusion_tracker, |
| 498 render_target(), |
| 499 draw_transform()); |
| 500 } |
| 501 |
| 502 // Tile priorities were modified. |
| 503 layer_tree_impl()->DidModifyTilePriorities(); |
| 504 } |
| 505 |
| 506 gfx::Rect PictureLayerImpl::GetActivationRectInContentSpace() const { |
475 // If visible_rect_for_tile_priority_ is empty or | 507 // If visible_rect_for_tile_priority_ is empty or |
476 // viewport_rect_for_tile_priority_ is set to be different from the device | 508 // viewport_rect_for_tile_priority_ is set to be different from the device |
477 // viewport, try to inverse project the viewport into layer space and use | 509 // viewport, try to inverse project the viewport into layer space and use |
478 // that. Otherwise just use visible_rect_for_tile_priority_ | 510 // that. Otherwise just use visible_rect_for_tile_priority_ |
479 gfx::Rect visible_rect_in_content_space = visible_rect_for_tile_priority_; | 511 gfx::Rect visible_rect_in_content_space = visible_rect_for_tile_priority_; |
480 | 512 |
481 if (visible_rect_in_content_space.IsEmpty() || | 513 if (visible_rect_in_content_space.IsEmpty() || |
482 layer_tree_impl()->DeviceViewport() != viewport_rect_for_tile_priority_) { | 514 layer_tree_impl()->DeviceViewport() != viewport_rect_for_tile_priority_) { |
483 gfx::Transform view_to_layer(gfx::Transform::kSkipInitialization); | 515 gfx::Transform view_to_layer(gfx::Transform::kSkipInitialization); |
484 | 516 |
485 if (screen_space_transform_for_tile_priority_.GetInverse(&view_to_layer)) { | 517 if (screen_space_transform_for_tile_priority_.GetInverse(&view_to_layer)) { |
486 // Transform from view space to content space. | 518 // Transform from view space to content space. |
487 visible_rect_in_content_space = | 519 visible_rect_in_content_space = |
488 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 520 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( |
489 view_to_layer, viewport_rect_for_tile_priority_)); | 521 view_to_layer, viewport_rect_for_tile_priority_)); |
490 | 522 |
491 visible_rect_in_content_space.Intersect(gfx::Rect(content_bounds())); | 523 visible_rect_in_content_space.Intersect(gfx::Rect(content_bounds())); |
492 } | 524 } |
493 } | 525 } |
494 | 526 |
495 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect( | 527 return visible_rect_in_content_space; |
496 visible_rect_in_content_space, 1.f / contents_scale_x()); | |
497 WhichTree tree = | |
498 layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; | |
499 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { | |
500 tilings_->tiling_at(i)->UpdateTilePriorities(tree, | |
501 visible_layer_rect, | |
502 ideal_contents_scale_, | |
503 current_frame_time_in_seconds, | |
504 occlusion_tracker, | |
505 render_target(), | |
506 draw_transform()); | |
507 } | |
508 | |
509 // Tile priorities were modified. | |
510 layer_tree_impl()->DidModifyTilePriorities(); | |
511 } | 528 } |
512 | 529 |
513 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { | 530 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { |
514 if (layer_tree_impl()->IsActiveTree()) { | 531 if (layer_tree_impl()->IsActiveTree()) { |
515 gfx::RectF layer_damage_rect = | 532 gfx::RectF layer_damage_rect = |
516 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); | 533 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); |
517 AddDamageRect(layer_damage_rect); | 534 AddDamageRect(layer_damage_rect); |
518 } | 535 } |
519 } | 536 } |
520 | 537 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 | 774 |
758 // The goal of this function is to find the minimum set of tiles that need to | 775 // The goal of this function is to find the minimum set of tiles that need to |
759 // be ready to draw in order to activate without flashing content from a | 776 // be ready to draw in order to activate without flashing content from a |
760 // higher res on the active tree to a lower res on the pending tree. | 777 // higher res on the active tree to a lower res on the pending tree. |
761 | 778 |
762 // First, early out for layers with no visible content. | 779 // First, early out for layers with no visible content. |
763 if (visible_content_rect().IsEmpty()) | 780 if (visible_content_rect().IsEmpty()) |
764 return; | 781 return; |
765 | 782 |
766 gfx::Rect rect(visible_content_rect()); | 783 gfx::Rect rect(visible_content_rect()); |
| 784 rect.Intersect(GetActivationRectInContentSpace()); |
767 | 785 |
768 float min_acceptable_scale = | 786 float min_acceptable_scale = |
769 std::min(raster_contents_scale_, ideal_contents_scale_); | 787 std::min(raster_contents_scale_, ideal_contents_scale_); |
770 | 788 |
771 if (PictureLayerImpl* twin = twin_layer_) { | 789 if (PictureLayerImpl* twin = twin_layer_) { |
772 float twin_min_acceptable_scale = | 790 float twin_min_acceptable_scale = |
773 std::min(twin->ideal_contents_scale_, twin->raster_contents_scale_); | 791 std::min(twin->ideal_contents_scale_, twin->raster_contents_scale_); |
774 // Ignore 0 scale in case CalculateContentsScale() has never been | 792 // Ignore 0 scale in case CalculateContentsScale() has never been |
775 // called for active twin. | 793 // called for active twin. |
776 if (twin_min_acceptable_scale != 0.0f) { | 794 if (twin_min_acceptable_scale != 0.0f) { |
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1696 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); | 1714 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); |
1697 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; | 1715 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; |
1698 return tiling_range.end - 1 - current_tiling_range_offset; | 1716 return tiling_range.end - 1 - current_tiling_range_offset; |
1699 } | 1717 } |
1700 } | 1718 } |
1701 NOTREACHED(); | 1719 NOTREACHED(); |
1702 return 0; | 1720 return 0; |
1703 } | 1721 } |
1704 | 1722 |
1705 } // namespace cc | 1723 } // namespace cc |
OLD | NEW |