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/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 overriden by | |
| 270 // clients like Android WebView with SetExternalDrawConstraints to control. | |
| 271 gfx::Rect scaled_viewport_for_tile_priority = gfx::ScaleToEnclosingRect( | |
| 272 GetViewportForTilePriorityInContentSpace(), max_contents_scale); | |
| 273 // Optmization to avoid Contains checks. No need for checks for | |
|
danakj
2014/08/20 15:31:12
s/Contains/Intersects/?
boliu
2014/08/20 15:38:04
Done.
And fixed spelling in other comments too..
| |
| 274 // viewport_for_tile_priority if it contains the visible rect already. | |
| 275 bool skip_viewport_for_tile_priority_check = | |
| 276 scaled_viewport_for_tile_priority.Contains(scaled_visible_content_rect); | |
| 277 | |
| 268 size_t missing_tile_count = 0u; | 278 size_t missing_tile_count = 0u; |
| 269 size_t on_demand_missing_tile_count = 0u; | 279 size_t on_demand_missing_tile_count = 0u; |
| 270 for (PictureLayerTilingSet::CoverageIterator iter(tilings_.get(), | 280 for (PictureLayerTilingSet::CoverageIterator iter(tilings_.get(), |
| 271 max_contents_scale, | 281 max_contents_scale, |
| 272 scaled_visible_content_rect, | 282 scaled_visible_content_rect, |
| 273 ideal_contents_scale_); | 283 ideal_contents_scale_); |
| 274 iter; | 284 iter; |
| 275 ++iter) { | 285 ++iter) { |
| 276 gfx::Rect geometry_rect = iter.geometry_rect(); | 286 gfx::Rect geometry_rect = iter.geometry_rect(); |
| 277 gfx::Rect visible_geometry_rect = occlusion_tracker.UnoccludedContentRect( | 287 gfx::Rect visible_geometry_rect = occlusion_tracker.UnoccludedContentRect( |
| 278 geometry_rect, scaled_draw_transform); | 288 geometry_rect, scaled_draw_transform); |
| 279 if (visible_geometry_rect.IsEmpty()) | 289 if (visible_geometry_rect.IsEmpty()) |
| 280 continue; | 290 continue; |
| 281 | 291 |
| 282 append_quads_data->visible_content_area += | 292 append_quads_data->visible_content_area += |
| 283 visible_geometry_rect.width() * visible_geometry_rect.height(); | 293 visible_geometry_rect.width() * visible_geometry_rect.height(); |
| 284 | 294 |
| 285 if (*iter && iter->IsReadyToDraw()) { | 295 if (*iter && iter->IsReadyToDraw()) { |
| 286 const ManagedTileState::TileVersion& tile_version = | 296 const ManagedTileState::TileVersion& tile_version = |
| 287 iter->GetTileVersionForDrawing(); | 297 iter->GetTileVersionForDrawing(); |
| 288 switch (tile_version.mode()) { | 298 switch (tile_version.mode()) { |
| 289 case ManagedTileState::TileVersion::RESOURCE_MODE: { | 299 case ManagedTileState::TileVersion::RESOURCE_MODE: { |
| 290 gfx::RectF texture_rect = iter.texture_rect(); | 300 gfx::RectF texture_rect = iter.texture_rect(); |
| 291 gfx::Rect opaque_rect = iter->opaque_rect(); | 301 gfx::Rect opaque_rect = iter->opaque_rect(); |
| 292 opaque_rect.Intersect(geometry_rect); | 302 opaque_rect.Intersect(geometry_rect); |
| 293 | 303 |
| 294 if (iter->contents_scale() != ideal_contents_scale_) | 304 if (iter->contents_scale() != ideal_contents_scale_ && |
| 305 (skip_viewport_for_tile_priority_check || | |
| 306 geometry_rect.Intersects(scaled_viewport_for_tile_priority))) { | |
| 295 append_quads_data->num_incomplete_tiles++; | 307 append_quads_data->num_incomplete_tiles++; |
| 308 } | |
| 296 | 309 |
| 297 TileDrawQuad* quad = | 310 TileDrawQuad* quad = |
| 298 render_pass->CreateAndAppendDrawQuad<TileDrawQuad>(); | 311 render_pass->CreateAndAppendDrawQuad<TileDrawQuad>(); |
| 299 quad->SetNew(shared_quad_state, | 312 quad->SetNew(shared_quad_state, |
| 300 geometry_rect, | 313 geometry_rect, |
| 301 opaque_rect, | 314 opaque_rect, |
| 302 visible_geometry_rect, | 315 visible_geometry_rect, |
| 303 tile_version.get_resource_id(), | 316 tile_version.get_resource_id(), |
| 304 texture_rect, | 317 texture_rect, |
| 305 iter.texture_size(), | 318 iter.texture_size(), |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 SkColor color = SafeOpaqueBackgroundColor(); | 371 SkColor color = SafeOpaqueBackgroundColor(); |
| 359 SolidColorDrawQuad* quad = | 372 SolidColorDrawQuad* quad = |
| 360 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | 373 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
| 361 quad->SetNew(shared_quad_state, | 374 quad->SetNew(shared_quad_state, |
| 362 geometry_rect, | 375 geometry_rect, |
| 363 visible_geometry_rect, | 376 visible_geometry_rect, |
| 364 color, | 377 color, |
| 365 false); | 378 false); |
| 366 } | 379 } |
| 367 | 380 |
| 368 append_quads_data->num_missing_tiles++; | 381 if (skip_viewport_for_tile_priority_check || |
| 382 geometry_rect.Intersects(scaled_viewport_for_tile_priority)) { | |
| 383 append_quads_data->num_missing_tiles++; | |
| 384 ++missing_tile_count; | |
| 385 } | |
| 369 append_quads_data->approximated_visible_content_area += | 386 append_quads_data->approximated_visible_content_area += |
| 370 visible_geometry_rect.width() * visible_geometry_rect.height(); | 387 visible_geometry_rect.width() * visible_geometry_rect.height(); |
| 371 ++missing_tile_count; | |
| 372 continue; | 388 continue; |
| 373 } | 389 } |
| 374 | 390 |
| 375 if (iter->priority(ACTIVE_TREE).resolution != HIGH_RESOLUTION) { | 391 if (iter->priority(ACTIVE_TREE).resolution != HIGH_RESOLUTION) { |
| 376 append_quads_data->approximated_visible_content_area += | 392 append_quads_data->approximated_visible_content_area += |
| 377 visible_geometry_rect.width() * visible_geometry_rect.height(); | 393 visible_geometry_rect.width() * visible_geometry_rect.height(); |
| 378 } | 394 } |
| 379 | 395 |
| 380 if (seen_tilings.empty() || seen_tilings.back() != iter.CurrentTiling()) | 396 if (seen_tilings.empty() || seen_tilings.back() != iter.CurrentTiling()) |
| 381 seen_tilings.push_back(iter.CurrentTiling()); | 397 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) { | 482 for (size_t i = 0; i < tilings_->num_tilings(); ++i) { |
| 467 if (tilings_->tiling_at(i)->NeedsUpdateForFrameAtTime( | 483 if (tilings_->tiling_at(i)->NeedsUpdateForFrameAtTime( |
| 468 current_frame_time_in_seconds)) { | 484 current_frame_time_in_seconds)) { |
| 469 tiling_needs_update = true; | 485 tiling_needs_update = true; |
| 470 break; | 486 break; |
| 471 } | 487 } |
| 472 } | 488 } |
| 473 if (!tiling_needs_update) | 489 if (!tiling_needs_update) |
| 474 return; | 490 return; |
| 475 | 491 |
| 492 gfx::Rect visible_rect_in_content_space( | |
| 493 GetViewportForTilePriorityInContentSpace()); | |
| 494 visible_rect_in_content_space.Intersect(visible_content_rect()); | |
| 495 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect( | |
| 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 } | |
| 512 | |
| 513 gfx::Rect PictureLayerImpl::GetViewportForTilePriorityInContentSpace() const { | |
| 476 // If visible_rect_for_tile_priority_ is empty or | 514 // If visible_rect_for_tile_priority_ is empty or |
| 477 // viewport_rect_for_tile_priority_ is set to be different from the device | 515 // 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 | 516 // viewport, try to inverse project the viewport into layer space and use |
| 479 // that. Otherwise just use visible_rect_for_tile_priority_ | 517 // that. Otherwise just use visible_rect_for_tile_priority_ |
| 480 gfx::Rect visible_rect_in_content_space = visible_rect_for_tile_priority_; | 518 gfx::Rect visible_rect_in_content_space = visible_rect_for_tile_priority_; |
| 481 | 519 |
| 482 if (visible_rect_in_content_space.IsEmpty() || | 520 if (visible_rect_in_content_space.IsEmpty() || |
| 483 layer_tree_impl()->DeviceViewport() != viewport_rect_for_tile_priority_) { | 521 layer_tree_impl()->DeviceViewport() != viewport_rect_for_tile_priority_) { |
| 484 gfx::Transform view_to_layer(gfx::Transform::kSkipInitialization); | 522 gfx::Transform view_to_layer(gfx::Transform::kSkipInitialization); |
| 485 | 523 |
| 486 if (screen_space_transform_for_tile_priority_.GetInverse(&view_to_layer)) { | 524 if (screen_space_transform_for_tile_priority_.GetInverse(&view_to_layer)) { |
| 487 // Transform from view space to content space. | 525 // Transform from view space to content space. |
| 488 visible_rect_in_content_space = | 526 visible_rect_in_content_space = |
| 489 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 527 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( |
| 490 view_to_layer, viewport_rect_for_tile_priority_)); | 528 view_to_layer, viewport_rect_for_tile_priority_)); |
| 491 | 529 |
| 492 visible_rect_in_content_space.Intersect(gfx::Rect(content_bounds())); | 530 visible_rect_in_content_space.Intersect(gfx::Rect(content_bounds())); |
| 493 } | 531 } |
| 494 } | 532 } |
| 495 | 533 |
| 496 gfx::Rect visible_layer_rect = gfx::ScaleToEnclosingRect( | 534 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 } | 535 } |
| 513 | 536 |
| 514 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { | 537 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { |
| 515 if (layer_tree_impl()->IsActiveTree()) { | 538 if (layer_tree_impl()->IsActiveTree()) { |
| 516 gfx::RectF layer_damage_rect = | 539 gfx::RectF layer_damage_rect = |
| 517 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); | 540 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); |
| 518 AddDamageRect(layer_damage_rect); | 541 AddDamageRect(layer_damage_rect); |
| 519 } | 542 } |
| 520 } | 543 } |
| 521 | 544 |
| (...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 | 782 // 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 | 783 // 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. | 784 // higher res on the active tree to a lower res on the pending tree. |
| 762 | 785 |
| 763 // First, early out for layers with no visible content. | 786 // First, early out for layers with no visible content. |
| 764 if (visible_content_rect().IsEmpty()) | 787 if (visible_content_rect().IsEmpty()) |
| 765 return; | 788 return; |
| 766 | 789 |
| 767 gfx::Rect rect(visible_content_rect()); | 790 gfx::Rect rect(visible_content_rect()); |
| 768 | 791 |
| 792 // Only mark tiles inside the viewport for tile priority as requried for | |
| 793 // activation. This viewport is normally the same as the draw viewport but | |
| 794 // can be independently overriden by clients like Android WebView with | |
| 795 // SetExternalDrawConstraints to control. | |
| 796 rect.Intersect(GetViewportForTilePriorityInContentSpace()); | |
| 797 | |
| 769 float min_acceptable_scale = | 798 float min_acceptable_scale = |
| 770 std::min(raster_contents_scale_, ideal_contents_scale_); | 799 std::min(raster_contents_scale_, ideal_contents_scale_); |
| 771 | 800 |
| 772 if (PictureLayerImpl* twin = twin_layer_) { | 801 if (PictureLayerImpl* twin = twin_layer_) { |
| 773 float twin_min_acceptable_scale = | 802 float twin_min_acceptable_scale = |
| 774 std::min(twin->ideal_contents_scale_, twin->raster_contents_scale_); | 803 std::min(twin->ideal_contents_scale_, twin->raster_contents_scale_); |
| 775 // Ignore 0 scale in case CalculateContentsScale() has never been | 804 // Ignore 0 scale in case CalculateContentsScale() has never been |
| 776 // called for active twin. | 805 // called for active twin. |
| 777 if (twin_min_acceptable_scale != 0.0f) { | 806 if (twin_min_acceptable_scale != 0.0f) { |
| 778 min_acceptable_scale = | 807 min_acceptable_scale = |
| (...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1697 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); | 1726 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); |
| 1698 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; | 1727 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; |
| 1699 return tiling_range.end - 1 - current_tiling_range_offset; | 1728 return tiling_range.end - 1 - current_tiling_range_offset; |
| 1700 } | 1729 } |
| 1701 } | 1730 } |
| 1702 NOTREACHED(); | 1731 NOTREACHED(); |
| 1703 return 0; | 1732 return 0; |
| 1704 } | 1733 } |
| 1705 | 1734 |
| 1706 } // namespace cc | 1735 } // namespace cc |
| OLD | NEW |