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