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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 if (settings_.impl_side_painting) { | 314 if (settings_.impl_side_painting) { |
315 // Impl-side painting needs an update immediately post-commit to have the | 315 // Impl-side painting needs an update immediately post-commit to have the |
316 // opportunity to create tilings. Other paths can call UpdateDrawProperties | 316 // opportunity to create tilings. Other paths can call UpdateDrawProperties |
317 // more lazily when needed prior to drawing. Because invalidations may | 317 // more lazily when needed prior to drawing. Because invalidations may |
318 // be coming from the main thread, it's safe to do an update for lcd text | 318 // be coming from the main thread, it's safe to do an update for lcd text |
319 // at this point and see if lcd text needs to be disabled on any layers. | 319 // at this point and see if lcd text needs to be disabled on any layers. |
320 bool update_lcd_text = true; | 320 bool update_lcd_text = true; |
321 sync_tree()->UpdateDrawProperties(update_lcd_text); | 321 sync_tree()->UpdateDrawProperties(update_lcd_text); |
322 // Start working on newly created tiles immediately if needed. | 322 // Start working on newly created tiles immediately if needed. |
323 if (tile_manager_ && tile_priorities_dirty_) { | 323 if (tile_manager_ && tile_priorities_dirty_) { |
324 PrepareTiles(); | 324 bool for_commit = true; |
| 325 client_->SetNeedsPrepareTilesOnImplThread(for_commit); |
325 } else { | 326 } else { |
326 NotifyReadyToActivate(); | 327 NotifyReadyToActivate(); |
327 | 328 |
328 // Ensure we get ReadyToDraw signal even when PrepareTiles not run. This | 329 // Ensure we get ReadyToDraw signal even when PrepareTiles not run. This |
329 // is important for SingleThreadProxy and impl-side painting case. For | 330 // is important for SingleThreadProxy and impl-side painting case. For |
330 // STP, we commit to active tree and RequiresHighResToDraw, and set | 331 // STP, we commit to active tree and RequiresHighResToDraw, and set |
331 // Scheduler to wait for ReadyToDraw signal to avoid Checkerboard. | 332 // Scheduler to wait for ReadyToDraw signal to avoid Checkerboard. |
332 if (proxy_->CommitToActiveTree()) | 333 if (proxy_->CommitToActiveTree()) |
333 NotifyReadyToDraw(); | 334 NotifyReadyToDraw(); |
334 } | 335 } |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 } | 404 } |
404 | 405 |
405 void LayerTreeHostImpl::PrepareTiles() { | 406 void LayerTreeHostImpl::PrepareTiles() { |
406 if (!tile_manager_) | 407 if (!tile_manager_) |
407 return; | 408 return; |
408 if (!tile_priorities_dirty_) | 409 if (!tile_priorities_dirty_) |
409 return; | 410 return; |
410 | 411 |
411 tile_priorities_dirty_ = false; | 412 tile_priorities_dirty_ = false; |
412 tile_manager_->PrepareTiles(global_tile_state_); | 413 tile_manager_->PrepareTiles(global_tile_state_); |
413 | |
414 client_->DidPrepareTiles(); | |
415 } | 414 } |
416 | 415 |
417 void LayerTreeHostImpl::StartPageScaleAnimation( | 416 void LayerTreeHostImpl::StartPageScaleAnimation( |
418 const gfx::Vector2d& target_offset, | 417 const gfx::Vector2d& target_offset, |
419 bool anchor_point, | 418 bool anchor_point, |
420 float page_scale, | 419 float page_scale, |
421 base::TimeDelta duration) { | 420 base::TimeDelta duration) { |
422 if (!InnerViewportScrollLayer()) | 421 if (!InnerViewportScrollLayer()) |
423 return; | 422 return; |
424 | 423 |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 // Typically when we are missing a texture and use a checkerboard quad, we | 779 // Typically when we are missing a texture and use a checkerboard quad, we |
781 // still draw the frame. However when the layer being checkerboarded is moving | 780 // still draw the frame. However when the layer being checkerboarded is moving |
782 // due to an impl-animation, we drop the frame to avoid flashing due to the | 781 // due to an impl-animation, we drop the frame to avoid flashing due to the |
783 // texture suddenly appearing in the future. | 782 // texture suddenly appearing in the future. |
784 DrawResult draw_result = DRAW_SUCCESS; | 783 DrawResult draw_result = DRAW_SUCCESS; |
785 | 784 |
786 int layers_drawn = 0; | 785 int layers_drawn = 0; |
787 | 786 |
788 const DrawMode draw_mode = GetDrawMode(); | 787 const DrawMode draw_mode = GetDrawMode(); |
789 | 788 |
| 789 int num_tiles_missing_raster_source = 0; |
790 int num_missing_tiles = 0; | 790 int num_missing_tiles = 0; |
791 int num_incomplete_tiles = 0; | 791 int num_incomplete_tiles = 0; |
792 bool have_copy_request = false; | 792 bool have_copy_request = false; |
793 bool have_missing_animated_tiles = false; | 793 bool have_missing_animated_tiles = false; |
794 | 794 |
795 auto end = LayerIterator<LayerImpl>::End(frame->render_surface_layer_list); | 795 auto end = LayerIterator<LayerImpl>::End(frame->render_surface_layer_list); |
796 for (auto it = | 796 for (auto it = |
797 LayerIterator<LayerImpl>::Begin(frame->render_surface_layer_list); | 797 LayerIterator<LayerImpl>::Begin(frame->render_surface_layer_list); |
798 it != end; ++it) { | 798 it != end; ++it) { |
799 RenderPassId target_render_pass_id = | 799 RenderPassId target_render_pass_id = |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 ++layers_drawn; | 862 ++layers_drawn; |
863 } | 863 } |
864 | 864 |
865 rendering_stats_instrumentation_->AddVisibleContentArea( | 865 rendering_stats_instrumentation_->AddVisibleContentArea( |
866 append_quads_data.visible_content_area); | 866 append_quads_data.visible_content_area); |
867 rendering_stats_instrumentation_->AddApproximatedVisibleContentArea( | 867 rendering_stats_instrumentation_->AddApproximatedVisibleContentArea( |
868 append_quads_data.approximated_visible_content_area); | 868 append_quads_data.approximated_visible_content_area); |
869 rendering_stats_instrumentation_->AddCheckerboardedVisibleContentArea( | 869 rendering_stats_instrumentation_->AddCheckerboardedVisibleContentArea( |
870 append_quads_data.checkerboarded_visible_content_area); | 870 append_quads_data.checkerboarded_visible_content_area); |
871 | 871 |
| 872 num_tiles_missing_raster_source += |
| 873 append_quads_data.num_tiles_missing_raster_source; |
872 num_missing_tiles += append_quads_data.num_missing_tiles; | 874 num_missing_tiles += append_quads_data.num_missing_tiles; |
873 num_incomplete_tiles += append_quads_data.num_incomplete_tiles; | 875 num_incomplete_tiles += append_quads_data.num_incomplete_tiles; |
874 | 876 |
875 if (append_quads_data.num_missing_tiles) { | 877 if (append_quads_data.num_missing_tiles) { |
| 878 // TODO(brianderson): Figure out what to do in this case and |
| 879 // differentiate and prioritize scroll wheel, touch scroll, and |
| 880 // animations. |
876 bool layer_has_animating_transform = | 881 bool layer_has_animating_transform = |
877 it->screen_space_transform_is_animating() || | 882 it->screen_space_transform_is_animating() || |
878 it->draw_transform_is_animating(); | 883 it->draw_transform_is_animating(); |
879 if (layer_has_animating_transform) | 884 if (layer_has_animating_transform) |
880 have_missing_animated_tiles = true; | 885 have_missing_animated_tiles = true; |
881 } | 886 } |
882 } | 887 } |
883 | 888 |
884 if (have_missing_animated_tiles) | 889 if (output_surface_->capabilities().draw_and_swap_full_viewport_every_frame) { |
885 draw_result = DRAW_ABORTED_CHECKERBOARD_ANIMATIONS; | 890 // When this capability is set we don't have control over the surface the |
886 | 891 // compositor draws to, so even though the frame may not be complete, the |
887 // When we require high res to draw, abort the draw (almost) always. This does | 892 // previous frame has already been potentially lost, so an incomplete frame |
888 // not cause the scheduler to do a main frame, instead it will continue to try | 893 // is |
889 // drawing until we finally complete, so the copy request will not be lost. | 894 // better than nothing, so this takes highest precidence. |
890 // TODO(weiliangc): Remove RequiresHighResToDraw. crbug.com/469175 | 895 // TODO(brianderson): Use a forced draw instead of lying about the draw |
891 if (num_incomplete_tiles || num_missing_tiles) { | 896 // result. |
892 if (RequiresHighResToDraw()) | 897 draw_result = DRAW_SUCCESS; |
893 draw_result = DRAW_ABORTED_MISSING_HIGH_RES_CONTENT; | 898 } else if (num_tiles_missing_raster_source) { |
| 899 draw_result = DRAW_ABORTED_MISSING_RASTER_SOURCE; |
| 900 } else if (num_missing_tiles) { |
| 901 draw_result = DRAW_ABORTED_MISSING_RASTER_OUTPUT_ANY; |
| 902 } else if (num_incomplete_tiles) { |
| 903 draw_result = DRAW_ABORTED_MISSING_RASTER_OUTPUT_HIGH_RES; |
894 } | 904 } |
895 | 905 |
896 // When this capability is set we don't have control over the surface the | |
897 // compositor draws to, so even though the frame may not be complete, the | |
898 // previous frame has already been potentially lost, so an incomplete frame is | |
899 // better than nothing, so this takes highest precidence. | |
900 if (output_surface_->capabilities().draw_and_swap_full_viewport_every_frame) | |
901 draw_result = DRAW_SUCCESS; | |
902 | |
903 #if DCHECK_IS_ON() | 906 #if DCHECK_IS_ON() |
904 for (const auto& render_pass : frame->render_passes) { | 907 for (const auto& render_pass : frame->render_passes) { |
905 for (const auto& quad : render_pass->quad_list) | 908 for (const auto& quad : render_pass->quad_list) |
906 DCHECK(quad->shared_quad_state); | 909 DCHECK(quad->shared_quad_state); |
907 DCHECK(frame->render_passes_by_id.find(render_pass->id) != | 910 DCHECK(frame->render_passes_by_id.find(render_pass->id) != |
908 frame->render_passes_by_id.end()); | 911 frame->render_passes_by_id.end()); |
909 } | 912 } |
910 #endif | 913 #endif |
911 DCHECK(frame->render_passes.back()->output_rect.origin().IsOrigin()); | 914 DCHECK(frame->render_passes.back()->output_rect.origin().IsOrigin()); |
912 | 915 |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 visible_ ? GetMaxStagingResourceCount() : 0); | 1213 visible_ ? GetMaxStagingResourceCount() : 0); |
1211 } | 1214 } |
1212 | 1215 |
1213 DidModifyTilePriorities(); | 1216 DidModifyTilePriorities(); |
1214 } | 1217 } |
1215 | 1218 |
1216 void LayerTreeHostImpl::DidModifyTilePriorities() { | 1219 void LayerTreeHostImpl::DidModifyTilePriorities() { |
1217 DCHECK(settings_.impl_side_painting); | 1220 DCHECK(settings_.impl_side_painting); |
1218 // Mark priorities as dirty and schedule a PrepareTiles(). | 1221 // Mark priorities as dirty and schedule a PrepareTiles(). |
1219 tile_priorities_dirty_ = true; | 1222 tile_priorities_dirty_ = true; |
1220 client_->SetNeedsPrepareTilesOnImplThread(); | 1223 bool for_commit = false; |
| 1224 client_->SetNeedsPrepareTilesOnImplThread(for_commit); |
1221 } | 1225 } |
1222 | 1226 |
1223 scoped_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue( | 1227 scoped_ptr<RasterTilePriorityQueue> LayerTreeHostImpl::BuildRasterQueue( |
1224 TreePriority tree_priority, | 1228 TreePriority tree_priority, |
1225 RasterTilePriorityQueue::Type type) { | 1229 RasterTilePriorityQueue::Type type) { |
1226 TRACE_EVENT0("cc", "LayerTreeHostImpl::BuildRasterQueue"); | 1230 TRACE_EVENT0("cc", "LayerTreeHostImpl::BuildRasterQueue"); |
1227 | 1231 |
1228 return RasterTilePriorityQueue::Create(active_tree_->picture_layers(), | 1232 return RasterTilePriorityQueue::Create(active_tree_->picture_layers(), |
1229 pending_tree_ | 1233 pending_tree_ |
1230 ? pending_tree_->picture_layers() | 1234 ? pending_tree_->picture_layers() |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1626 ReleaseTreeResources(); | 1630 ReleaseTreeResources(); |
1627 if (tile_manager_) { | 1631 if (tile_manager_) { |
1628 DestroyTileManager(); | 1632 DestroyTileManager(); |
1629 CreateAndSetTileManager(); | 1633 CreateAndSetTileManager(); |
1630 } | 1634 } |
1631 RecreateTreeResources(); | 1635 RecreateTreeResources(); |
1632 | 1636 |
1633 // We have released tilings for both active and pending tree. | 1637 // We have released tilings for both active and pending tree. |
1634 // We would not have any content to draw until the pending tree is activated. | 1638 // We would not have any content to draw until the pending tree is activated. |
1635 // Prevent the active tree from drawing until activation. | 1639 // Prevent the active tree from drawing until activation. |
1636 SetRequiresHighResToDraw(); | 1640 SetRequiresHighResToDraw(true); |
1637 } | 1641 } |
1638 | 1642 |
1639 const RendererCapabilitiesImpl& | 1643 const RendererCapabilitiesImpl& |
1640 LayerTreeHostImpl::GetRendererCapabilities() const { | 1644 LayerTreeHostImpl::GetRendererCapabilities() const { |
1641 CHECK(renderer_); | 1645 CHECK(renderer_); |
1642 return renderer_->Capabilities(); | 1646 return renderer_->Capabilities(); |
1643 } | 1647 } |
1644 | 1648 |
1645 bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) { | 1649 bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) { |
1646 ResetRequiresHighResToDraw(); | 1650 SetRequiresHighResToDraw(false); |
1647 if (frame.has_no_damage) { | 1651 if (frame.has_no_damage) { |
1648 active_tree()->BreakSwapPromises(SwapPromise::SWAP_FAILS); | 1652 active_tree()->BreakSwapPromises(SwapPromise::SWAP_FAILS); |
1649 return false; | 1653 return false; |
1650 } | 1654 } |
1651 CompositorFrameMetadata metadata = MakeCompositorFrameMetadata(); | 1655 CompositorFrameMetadata metadata = MakeCompositorFrameMetadata(); |
1652 active_tree()->FinishSwapPromises(&metadata); | 1656 active_tree()->FinishSwapPromises(&metadata); |
1653 for (auto& latency : metadata.latency_info) { | 1657 for (auto& latency : metadata.latency_info) { |
1654 TRACE_EVENT_FLOW_STEP0( | 1658 TRACE_EVENT_FLOW_STEP0( |
1655 "input,benchmark", | 1659 "input,benchmark", |
1656 "LatencyInfo.Flow", | 1660 "LatencyInfo.Flow", |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1898 | 1902 |
1899 if (visible_ == visible) | 1903 if (visible_ == visible) |
1900 return; | 1904 return; |
1901 visible_ = visible; | 1905 visible_ = visible; |
1902 DidVisibilityChange(this, visible_); | 1906 DidVisibilityChange(this, visible_); |
1903 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); | 1907 EnforceManagedMemoryPolicy(ActualManagedMemoryPolicy()); |
1904 | 1908 |
1905 // If we just became visible, we have to ensure that we draw high res tiles, | 1909 // If we just became visible, we have to ensure that we draw high res tiles, |
1906 // to prevent checkerboard/low res flashes. | 1910 // to prevent checkerboard/low res flashes. |
1907 if (visible_) | 1911 if (visible_) |
1908 SetRequiresHighResToDraw(); | 1912 SetRequiresHighResToDraw(true); |
1909 else | 1913 else |
1910 EvictAllUIResources(); | 1914 EvictAllUIResources(); |
1911 | 1915 |
1912 // Evict tiles immediately if invisible since this tab may never get another | |
1913 // draw or timer tick. | |
1914 if (!visible_) | |
1915 PrepareTiles(); | |
1916 | |
1917 if (!renderer_) | 1916 if (!renderer_) |
1918 return; | 1917 return; |
1919 | 1918 |
1920 renderer_->SetVisible(visible); | 1919 renderer_->SetVisible(visible); |
1921 } | 1920 } |
1922 | 1921 |
1923 void LayerTreeHostImpl::SetNeedsAnimate() { | 1922 void LayerTreeHostImpl::SetNeedsAnimate() { |
1924 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); | 1923 NotifySwapPromiseMonitorsOfSetNeedsRedraw(); |
1925 client_->SetNeedsAnimateOnImplThread(); | 1924 client_->SetNeedsAnimateOnImplThread(); |
1926 } | 1925 } |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2197 | 2196 |
2198 int max_frames_pending = output_surface_->capabilities().max_frames_pending; | 2197 int max_frames_pending = output_surface_->capabilities().max_frames_pending; |
2199 if (max_frames_pending <= 0) | 2198 if (max_frames_pending <= 0) |
2200 max_frames_pending = OutputSurface::DEFAULT_MAX_FRAMES_PENDING; | 2199 max_frames_pending = OutputSurface::DEFAULT_MAX_FRAMES_PENDING; |
2201 client_->SetMaxSwapsPendingOnImplThread(max_frames_pending); | 2200 client_->SetMaxSwapsPendingOnImplThread(max_frames_pending); |
2202 client_->OnCanDrawStateChanged(CanDraw()); | 2201 client_->OnCanDrawStateChanged(CanDraw()); |
2203 | 2202 |
2204 // There will not be anything to draw here, so set high res | 2203 // There will not be anything to draw here, so set high res |
2205 // to avoid checkerboards, typically when we are recovering | 2204 // to avoid checkerboards, typically when we are recovering |
2206 // from lost context. | 2205 // from lost context. |
2207 SetRequiresHighResToDraw(); | 2206 SetRequiresHighResToDraw(true); |
2208 | 2207 |
2209 return true; | 2208 return true; |
2210 } | 2209 } |
2211 | 2210 |
2212 void LayerTreeHostImpl::CommitVSyncParameters(base::TimeTicks timebase, | 2211 void LayerTreeHostImpl::CommitVSyncParameters(base::TimeTicks timebase, |
2213 base::TimeDelta interval) { | 2212 base::TimeDelta interval) { |
2214 client_->CommitVSyncParameters(timebase, interval); | 2213 client_->CommitVSyncParameters(timebase, interval); |
2215 } | 2214 } |
2216 | 2215 |
2217 void LayerTreeHostImpl::SetViewportSize(const gfx::Size& device_viewport_size) { | 2216 void LayerTreeHostImpl::SetViewportSize(const gfx::Size& device_viewport_size) { |
(...skipping 1178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3396 new_target.SetToMin(layer_impl->MaxScrollOffset()); | 3395 new_target.SetToMin(layer_impl->MaxScrollOffset()); |
3397 | 3396 |
3398 curve->UpdateTarget( | 3397 curve->UpdateTarget( |
3399 animation->TrimTimeToCurrentIteration(CurrentBeginFrameArgs().frame_time) | 3398 animation->TrimTimeToCurrentIteration(CurrentBeginFrameArgs().frame_time) |
3400 .InSecondsF(), | 3399 .InSecondsF(), |
3401 new_target); | 3400 new_target); |
3402 | 3401 |
3403 return true; | 3402 return true; |
3404 } | 3403 } |
3405 } // namespace cc | 3404 } // namespace cc |
OLD | NEW |