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