| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 if (settings_.impl_side_painting) { | 319 if (settings_.impl_side_painting) { |
| 320 // Impl-side painting needs an update immediately post-commit to have the | 320 // Impl-side painting needs an update immediately post-commit to have the |
| 321 // opportunity to create tilings. Other paths can call UpdateDrawProperties | 321 // opportunity to create tilings. Other paths can call UpdateDrawProperties |
| 322 // more lazily when needed prior to drawing. Because invalidations may | 322 // more lazily when needed prior to drawing. Because invalidations may |
| 323 // be coming from the main thread, it's safe to do an update for lcd text | 323 // be coming from the main thread, it's safe to do an update for lcd text |
| 324 // at this point and see if lcd text needs to be disabled on any layers. | 324 // at this point and see if lcd text needs to be disabled on any layers. |
| 325 bool update_lcd_text = true; | 325 bool update_lcd_text = true; |
| 326 sync_tree()->UpdateDrawProperties(update_lcd_text); | 326 sync_tree()->UpdateDrawProperties(update_lcd_text); |
| 327 // Start working on newly created tiles immediately if needed. | 327 // Start working on newly created tiles immediately if needed. |
| 328 if (tile_manager_ && tile_priorities_dirty_) { | 328 if (tile_manager_ && tile_priorities_dirty_) { |
| 329 PrepareTiles(); | 329 bool for_commit = true; |
| 330 client_->SetNeedsPrepareTilesOnImplThread(for_commit); |
| 330 } else { | 331 } else { |
| 331 NotifyReadyToActivate(); | 332 NotifyReadyToActivate(); |
| 332 | 333 |
| 333 // Ensure we get ReadyToDraw signal even when PrepareTiles not run. This | 334 // Ensure we get ReadyToDraw signal even when PrepareTiles not run. This |
| 334 // is important for SingleThreadProxy and impl-side painting case. For | 335 // is important for SingleThreadProxy and impl-side painting case. For |
| 335 // STP, we commit to active tree and RequiresHighResToDraw, and set | 336 // STP, we commit to active tree and RequiresHighResToDraw, and set |
| 336 // Scheduler to wait for ReadyToDraw signal to avoid Checkerboard. | 337 // Scheduler to wait for ReadyToDraw signal to avoid Checkerboard. |
| 337 if (proxy_->CommitToActiveTree()) | 338 if (proxy_->CommitToActiveTree()) |
| 338 NotifyReadyToDraw(); | 339 NotifyReadyToDraw(); |
| 339 } | 340 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time) { | 402 void LayerTreeHostImpl::Animate(base::TimeTicks monotonic_time) { |
| 402 if (input_handler_client_) | 403 if (input_handler_client_) |
| 403 input_handler_client_->Animate(monotonic_time); | 404 input_handler_client_->Animate(monotonic_time); |
| 404 AnimatePageScale(monotonic_time); | 405 AnimatePageScale(monotonic_time); |
| 405 AnimateLayers(monotonic_time); | 406 AnimateLayers(monotonic_time); |
| 406 AnimateScrollbars(monotonic_time); | 407 AnimateScrollbars(monotonic_time); |
| 407 AnimateTopControls(monotonic_time); | 408 AnimateTopControls(monotonic_time); |
| 408 } | 409 } |
| 409 | 410 |
| 410 void LayerTreeHostImpl::PrepareTiles() { | 411 void LayerTreeHostImpl::PrepareTiles() { |
| 412 bool update_lcd_text = false; |
| 413 if (pending_tree_) |
| 414 pending_tree_->UpdateDrawProperties(update_lcd_text); |
| 415 if (active_tree_) |
| 416 active_tree_->UpdateDrawProperties(update_lcd_text); |
| 417 |
| 411 if (!tile_manager_) | 418 if (!tile_manager_) |
| 412 return; | 419 return; |
| 413 if (!tile_priorities_dirty_) | 420 if (!tile_priorities_dirty_) |
| 414 return; | 421 return; |
| 415 | 422 |
| 416 tile_priorities_dirty_ = false; | 423 tile_priorities_dirty_ = false; |
| 417 tile_manager_->PrepareTiles(global_tile_state_); | 424 tile_manager_->PrepareTiles(global_tile_state_); |
| 418 | |
| 419 client_->DidPrepareTiles(); | |
| 420 } | 425 } |
| 421 | 426 |
| 422 void LayerTreeHostImpl::StartPageScaleAnimation( | 427 void LayerTreeHostImpl::StartPageScaleAnimation( |
| 423 const gfx::Vector2d& target_offset, | 428 const gfx::Vector2d& target_offset, |
| 424 bool anchor_point, | 429 bool anchor_point, |
| 425 float page_scale, | 430 float page_scale, |
| 426 base::TimeDelta duration) { | 431 base::TimeDelta duration) { |
| 427 if (!InnerViewportScrollLayer()) | 432 if (!InnerViewportScrollLayer()) |
| 428 return; | 433 return; |
| 429 | 434 |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 // Typically when we are missing a texture and use a checkerboard quad, we | 790 // Typically when we are missing a texture and use a checkerboard quad, we |
| 786 // still draw the frame. However when the layer being checkerboarded is moving | 791 // still draw the frame. However when the layer being checkerboarded is moving |
| 787 // due to an impl-animation, we drop the frame to avoid flashing due to the | 792 // due to an impl-animation, we drop the frame to avoid flashing due to the |
| 788 // texture suddenly appearing in the future. | 793 // texture suddenly appearing in the future. |
| 789 DrawResult draw_result = DRAW_SUCCESS; | 794 DrawResult draw_result = DRAW_SUCCESS; |
| 790 | 795 |
| 791 int layers_drawn = 0; | 796 int layers_drawn = 0; |
| 792 | 797 |
| 793 const DrawMode draw_mode = GetDrawMode(); | 798 const DrawMode draw_mode = GetDrawMode(); |
| 794 | 799 |
| 800 int num_layers_missing_raster_source = 0; |
| 795 int num_missing_tiles = 0; | 801 int num_missing_tiles = 0; |
| 796 int num_incomplete_tiles = 0; | 802 int num_incomplete_tiles = 0; |
| 797 bool have_copy_request = false; | 803 bool have_copy_request = false; |
| 798 bool have_missing_animated_tiles = false; | 804 bool have_missing_animated_tiles = false; |
| 799 | 805 |
| 800 auto end = LayerIterator<LayerImpl>::End(frame->render_surface_layer_list); | 806 auto end = LayerIterator<LayerImpl>::End(frame->render_surface_layer_list); |
| 801 for (auto it = | 807 for (auto it = |
| 802 LayerIterator<LayerImpl>::Begin(frame->render_surface_layer_list); | 808 LayerIterator<LayerImpl>::Begin(frame->render_surface_layer_list); |
| 803 it != end; ++it) { | 809 it != end; ++it) { |
| 804 RenderPassId target_render_pass_id = | 810 RenderPassId target_render_pass_id = |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 ++layers_drawn; | 873 ++layers_drawn; |
| 868 } | 874 } |
| 869 | 875 |
| 870 rendering_stats_instrumentation_->AddVisibleContentArea( | 876 rendering_stats_instrumentation_->AddVisibleContentArea( |
| 871 append_quads_data.visible_content_area); | 877 append_quads_data.visible_content_area); |
| 872 rendering_stats_instrumentation_->AddApproximatedVisibleContentArea( | 878 rendering_stats_instrumentation_->AddApproximatedVisibleContentArea( |
| 873 append_quads_data.approximated_visible_content_area); | 879 append_quads_data.approximated_visible_content_area); |
| 874 rendering_stats_instrumentation_->AddCheckerboardedVisibleContentArea( | 880 rendering_stats_instrumentation_->AddCheckerboardedVisibleContentArea( |
| 875 append_quads_data.checkerboarded_visible_content_area); | 881 append_quads_data.checkerboarded_visible_content_area); |
| 876 | 882 |
| 883 if (!append_quads_data.raster_source_covers_visible_high_res_tiles) |
| 884 num_layers_missing_raster_source++; |
| 885 |
| 877 num_missing_tiles += append_quads_data.num_missing_tiles; | 886 num_missing_tiles += append_quads_data.num_missing_tiles; |
| 878 num_incomplete_tiles += append_quads_data.num_incomplete_tiles; | 887 num_incomplete_tiles += append_quads_data.num_incomplete_tiles; |
| 879 | 888 |
| 880 if (append_quads_data.num_missing_tiles) { | 889 if (append_quads_data.num_missing_tiles) { |
| 890 // TODO(brianderson): Figure out what to do in this case and |
| 891 // differentiate and prioritize scroll wheel, touch scroll, and |
| 892 // animations. |
| 881 bool layer_has_animating_transform = | 893 bool layer_has_animating_transform = |
| 882 it->screen_space_transform_is_animating() || | 894 it->screen_space_transform_is_animating() || |
| 883 it->draw_transform_is_animating(); | 895 it->draw_transform_is_animating(); |
| 884 if (layer_has_animating_transform) | 896 if (layer_has_animating_transform) |
| 885 have_missing_animated_tiles = true; | 897 have_missing_animated_tiles = true; |
| 886 } | 898 } |
| 887 } | 899 } |
| 888 | 900 |
| 889 if (have_missing_animated_tiles) | 901 if (output_surface_->capabilities().draw_and_swap_full_viewport_every_frame) { |
| 890 draw_result = DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 902 // When this capability is set we don't have control over the surface the |
| 891 | 903 // compositor draws to, so even though the frame may not be complete, the |
| 892 // When we require high res to draw, abort the draw (almost) always. This does | 904 // previous frame has already been potentially lost, so an incomplete frame |
| 893 // not cause the scheduler to do a main frame, instead it will continue to try | 905 // is |
| 894 // drawing until we finally complete, so the copy request will not be lost. | 906 // better than nothing, so this takes highest precidence. |
| 895 // TODO(weiliangc): Remove RequiresHighResToDraw. crbug.com/469175 | 907 // TODO(brianderson): Use a forced draw instead of lying about the draw |
| 896 if (num_incomplete_tiles || num_missing_tiles) { | 908 // result. |
| 897 if (RequiresHighResToDraw()) | 909 draw_result = DRAW_SUCCESS; |
| 898 draw_result = DRAW_ABORTED_MISSING_HIGH_RES_CONTENT; | 910 } else if (num_layers_missing_raster_source) { |
| 911 TRACE_EVENT_INSTANT0("cc", "Raster missing source.", |
| 912 TRACE_EVENT_SCOPE_THREAD); |
| 913 draw_result = DRAW_ABORTED_MISSING_RASTER_SOURCE; |
| 914 } else if (num_missing_tiles) { |
| 915 TRACE_EVENT_INSTANT0("cc", "Raster missing output.", |
| 916 TRACE_EVENT_SCOPE_THREAD); |
| 917 draw_result = DRAW_ABORTED_MISSING_RASTER_OUTPUT_ANY_RES; |
| 918 } else if (num_incomplete_tiles) { |
| 919 TRACE_EVENT_INSTANT0("cc", "Raster missing high res.", |
| 920 TRACE_EVENT_SCOPE_THREAD); |
| 921 draw_result = DRAW_ABORTED_MISSING_RASTER_OUTPUT_HIGH_RES; |
| 899 } | 922 } |
| 900 | 923 |
| 901 // When this capability is set we don't have control over the surface the | |
| 902 // compositor draws to, so even though the frame may not be complete, the | |
| 903 // previous frame has already been potentially lost, so an incomplete frame is | |
| 904 // better than nothing, so this takes highest precidence. | |
| 905 if (output_surface_->capabilities().draw_and_swap_full_viewport_every_frame) | |
| 906 draw_result = DRAW_SUCCESS; | |
| 907 | |
| 908 #if DCHECK_IS_ON() | 924 #if DCHECK_IS_ON() |
| 909 for (const auto& render_pass : frame->render_passes) { | 925 for (const auto& render_pass : frame->render_passes) { |
| 910 for (const auto& quad : render_pass->quad_list) | 926 for (const auto& quad : render_pass->quad_list) |
| 911 DCHECK(quad->shared_quad_state); | 927 DCHECK(quad->shared_quad_state); |
| 912 DCHECK(frame->render_passes_by_id.find(render_pass->id) != | 928 DCHECK(frame->render_passes_by_id.find(render_pass->id) != |
| 913 frame->render_passes_by_id.end()); | 929 frame->render_passes_by_id.end()); |
| 914 } | 930 } |
| 915 #endif | 931 #endif |
| 916 DCHECK(frame->render_passes.back()->output_rect.origin().IsOrigin()); | 932 DCHECK(frame->render_passes.back()->output_rect.origin().IsOrigin()); |
| 917 | 933 |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 visible_ ? GetMaxStagingResourceCount() : 0); | 1231 visible_ ? GetMaxStagingResourceCount() : 0); |
| 1216 } | 1232 } |
| 1217 | 1233 |
| 1218 DidModifyTilePriorities(); | 1234 DidModifyTilePriorities(); |
| 1219 } | 1235 } |
| 1220 | 1236 |
| 1221 void LayerTreeHostImpl::DidModifyTilePriorities() { | 1237 void LayerTreeHostImpl::DidModifyTilePriorities() { |
| 1222 DCHECK(settings_.impl_side_painting); | 1238 DCHECK(settings_.impl_side_painting); |
| 1223 // Mark priorities as dirty and schedule a PrepareTiles(). | 1239 // Mark priorities as dirty and schedule a PrepareTiles(). |
| 1224 tile_priorities_dirty_ = true; | 1240 tile_priorities_dirty_ = true; |
| 1225 client_->SetNeedsPrepareTilesOnImplThread(); | 1241 bool for_commit = false; |
| 1242 client_->SetNeedsPrepareTilesOnImplThread(for_commit); |
| 1226 } | 1243 } |
| 1227 | 1244 |
| 1228 scoped_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue( | 1245 scoped_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue( |
| 1229 TreePriority tree_priority, | 1246 TreePriority tree_priority, |
| 1230 RasterTilePriorityQueue::Type type) { | 1247 RasterTilePriorityQueue::Type type) { |
| 1231 TRACE_EVENT0("cc", "LayerTreeHostImpl::BuildRasterQueue"); | 1248 TRACE_EVENT0("cc", "LayerTreeHostImpl::BuildRasterQueue"); |
| 1232 | 1249 |
| 1233 return RasterTilePriorityQueue::Create(active_tree_->picture_layers(), | 1250 return RasterTilePriorityQueue::Create(active_tree_->picture_layers(), |
| 1234 pending_tree_ | 1251 pending_tree_ |
| 1235 ? pending_tree_->picture_layers() | 1252 ? pending_tree_->picture_layers() |
| (...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 ReleaseTreeResources(); | 1680 ReleaseTreeResources(); |
| 1664 if (tile_manager_) { | 1681 if (tile_manager_) { |
| 1665 DestroyTileManager(); | 1682 DestroyTileManager(); |
| 1666 CreateAndSetTileManager(); | 1683 CreateAndSetTileManager(); |
| 1667 } | 1684 } |
| 1668 RecreateTreeResources(); | 1685 RecreateTreeResources(); |
| 1669 | 1686 |
| 1670 // We have released tilings for both active and pending tree. | 1687 // We have released tilings for both active and pending tree. |
| 1671 // We would not have any content to draw until the pending tree is activated. | 1688 // We would not have any content to draw until the pending tree is activated. |
| 1672 // Prevent the active tree from drawing until activation. | 1689 // Prevent the active tree from drawing until activation. |
| 1673 SetRequiresHighResToDraw(); | 1690 SetRequiresHighResToDraw(true); |
| 1674 | 1691 |
| 1675 tree_resources_for_gpu_rasterization_dirty_ = false; | 1692 tree_resources_for_gpu_rasterization_dirty_ = false; |
| 1676 } | 1693 } |
| 1677 | 1694 |
| 1678 const RendererCapabilitiesImpl& | 1695 const RendererCapabilitiesImpl& |
| 1679 LayerTreeHostImpl::GetRendererCapabilities() const { | 1696 LayerTreeHostImpl::GetRendererCapabilities() const { |
| 1680 CHECK(renderer_); | 1697 CHECK(renderer_); |
| 1681 return renderer_->Capabilities(); | 1698 return renderer_->Capabilities(); |
| 1682 } | 1699 } |
| 1683 | 1700 |
| 1684 bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) { | 1701 bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) { |
| 1685 ResetRequiresHighResToDraw(); | 1702 SetRequiresHighResToDraw(false); |
| 1686 if (frame.has_no_damage) { | 1703 if (frame.has_no_damage) { |
| 1687 active_tree()->BreakSwapPromises(SwapPromise::SWAP_FAILS); | 1704 active_tree()->BreakSwapPromises(SwapPromise::SWAP_FAILS); |
| 1688 return false; | 1705 return false; |
| 1689 } | 1706 } |
| 1690 CompositorFrameMetadata metadata = MakeCompositorFrameMetadata(); | 1707 CompositorFrameMetadata metadata = MakeCompositorFrameMetadata(); |
| 1691 active_tree()->FinishSwapPromises(&metadata); | 1708 active_tree()->FinishSwapPromises(&metadata); |
| 1692 for (auto& latency : metadata.latency_info) { | 1709 for (auto& latency : metadata.latency_info) { |
| 1693 TRACE_EVENT_FLOW_STEP0( | 1710 TRACE_EVENT_FLOW_STEP0( |
| 1694 "input,benchmark", | 1711 "input,benchmark", |
| 1695 "LatencyInfo.Flow", | 1712 "LatencyInfo.Flow", |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1937 | 1954 |
| 1938 if (visible_ == visible) | 1955 if (visible_ == visible) |
| 1939 return; | 1956 return; |
| 1940 visible_ = visible; | 1957 visible_ = visible; |
| 1941 DidVisibilityChange(this, visible_); | 1958 DidVisibilityChange(this, visible_); |
| 1942 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); | 1959 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); |
| 1943 | 1960 |
| 1944 // If we just became visible, we have to ensure that we draw high res tiles, | 1961 // If we just became visible, we have to ensure that we draw high res tiles, |
| 1945 // to prevent checkerboard/low res flashes. | 1962 // to prevent checkerboard/low res flashes. |
| 1946 if (visible_) | 1963 if (visible_) |
| 1947 SetRequiresHighResToDraw(); | 1964 SetRequiresHighResToDraw(true); |
| 1948 else | 1965 else |
| 1949 EvictAllUIResources(); | 1966 EvictAllUIResources(); |
| 1950 | 1967 |
| 1951 // Evict tiles immediately if invisible since this tab may never get another | |
| 1952 // draw or timer tick. | |
| 1953 if (!visible_) | |
| 1954 PrepareTiles(); | |
| 1955 | |
| 1956 if (!renderer_) | 1968 if (!renderer_) |
| 1957 return; | 1969 return; |
| 1958 | 1970 |
| 1959 renderer_->SetVisible(visible); | 1971 renderer_->SetVisible(visible); |
| 1960 } | 1972 } |
| 1961 | 1973 |
| 1962 void LayerTreeHostImpl::SetNeedsAnimate() { | 1974 void LayerTreeHostImpl::SetNeedsAnimate() { |
| 1963 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); | 1975 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); |
| 1964 client_->SetNeedsAnimateOnImplThread(); | 1976 client_->SetNeedsAnimateOnImplThread(); |
| 1965 } | 1977 } |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2241 | 2253 |
| 2242 int max_frames_pending = output_surface_->capabilities().max_frames_pending; | 2254 int max_frames_pending = output_surface_->capabilities().max_frames_pending; |
| 2243 if (max_frames_pending <= 0) | 2255 if (max_frames_pending <= 0) |
| 2244 max_frames_pending = OutputSurface::DEFAULT_MAX_FRAMES_PENDING; | 2256 max_frames_pending = OutputSurface::DEFAULT_MAX_FRAMES_PENDING; |
| 2245 client_->SetMaxSwapsPendingOnImplThread(max_frames_pending); | 2257 client_->SetMaxSwapsPendingOnImplThread(max_frames_pending); |
| 2246 client_->OnCanDrawStateChanged(CanDraw()); | 2258 client_->OnCanDrawStateChanged(CanDraw()); |
| 2247 | 2259 |
| 2248 // There will not be anything to draw here, so set high res | 2260 // There will not be anything to draw here, so set high res |
| 2249 // to avoid checkerboards, typically when we are recovering | 2261 // to avoid checkerboards, typically when we are recovering |
| 2250 // from lost context. | 2262 // from lost context. |
| 2251 SetRequiresHighResToDraw(); | 2263 SetRequiresHighResToDraw(true); |
| 2252 | 2264 |
| 2253 return true; | 2265 return true; |
| 2254 } | 2266 } |
| 2255 | 2267 |
| 2256 void LayerTreeHostImpl::CommitVSyncParameters(base::TimeTicks timebase, | 2268 void LayerTreeHostImpl::CommitVSyncParameters(base::TimeTicks timebase, |
| 2257 base::TimeDelta interval) { | 2269 base::TimeDelta interval) { |
| 2258 client_->CommitVSyncParameters(timebase, interval); | 2270 client_->CommitVSyncParameters(timebase, interval); |
| 2259 } | 2271 } |
| 2260 | 2272 |
| 2261 void LayerTreeHostImpl::SetViewportSize(const gfx::Size& device_viewport_size) { | 2273 void LayerTreeHostImpl::SetViewportSize(const gfx::Size& device_viewport_size) { |
| (...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3442 new_target.SetToMin(layer_impl->MaxScrollOffset()); | 3454 new_target.SetToMin(layer_impl->MaxScrollOffset()); |
| 3443 | 3455 |
| 3444 curve->UpdateTarget( | 3456 curve->UpdateTarget( |
| 3445 animation->TrimTimeToCurrentIteration(CurrentBeginFrameArgs().frame_time) | 3457 animation->TrimTimeToCurrentIteration(CurrentBeginFrameArgs().frame_time) |
| 3446 .InSecondsF(), | 3458 .InSecondsF(), |
| 3447 new_target); | 3459 new_target); |
| 3448 | 3460 |
| 3449 return true; | 3461 return true; |
| 3450 } | 3462 } |
| 3451 } // namespace cc | 3463 } // namespace cc |
| OLD | NEW |