| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 1606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1617 metadata.root_overflow_y_hidden |= | 1617 metadata.root_overflow_y_hidden |= |
| 1618 !InnerViewportScrollLayer()->user_scrollable_vertical(); | 1618 !InnerViewportScrollLayer()->user_scrollable_vertical(); |
| 1619 | 1619 |
| 1620 // TODO(miletus) : Change the metadata to hold ScrollOffset. | 1620 // TODO(miletus) : Change the metadata to hold ScrollOffset. |
| 1621 metadata.root_scroll_offset = | 1621 metadata.root_scroll_offset = |
| 1622 gfx::ScrollOffsetToVector2dF(active_tree_->TotalScrollOffset()); | 1622 gfx::ScrollOffsetToVector2dF(active_tree_->TotalScrollOffset()); |
| 1623 | 1623 |
| 1624 return metadata; | 1624 return metadata; |
| 1625 } | 1625 } |
| 1626 | 1626 |
| 1627 void LayerTreeHostImpl::DrawLayers(FrameData* frame) { | 1627 bool LayerTreeHostImpl::DrawLayers(FrameData* frame) { |
| 1628 DCHECK(CanDraw()); |
| 1629 DCHECK_EQ(frame->has_no_damage, frame->render_passes.empty()); |
| 1630 |
| 1628 TRACE_EVENT0("cc", "LayerTreeHostImpl::DrawLayers"); | 1631 TRACE_EVENT0("cc", "LayerTreeHostImpl::DrawLayers"); |
| 1629 | 1632 |
| 1630 base::TimeTicks frame_begin_time = CurrentBeginFrameArgs().frame_time; | 1633 ResetRequiresHighResToDraw(); |
| 1631 DCHECK(CanDraw()); | |
| 1632 | 1634 |
| 1633 if (frame->has_no_damage) { | 1635 if (frame->has_no_damage) { |
| 1636 DCHECK(!resourceless_software_draw_); |
| 1637 |
| 1634 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoDamage", TRACE_EVENT_SCOPE_THREAD); | 1638 TRACE_EVENT_INSTANT0("cc", "EarlyOut_NoDamage", TRACE_EVENT_SCOPE_THREAD); |
| 1635 DCHECK(!resourceless_software_draw_); | 1639 active_tree()->BreakSwapPromises(SwapPromise::SWAP_FAILS); |
| 1636 return; | 1640 return false; |
| 1637 } | 1641 } |
| 1638 | 1642 |
| 1639 DCHECK(!frame->render_passes.empty()); | 1643 fps_counter_->SaveTimeStamp(CurrentBeginFrameArgs().frame_time, |
| 1640 | |
| 1641 fps_counter_->SaveTimeStamp(frame_begin_time, | |
| 1642 !output_surface_->context_provider()); | 1644 !output_surface_->context_provider()); |
| 1643 rendering_stats_instrumentation_->IncrementFrameCount(1); | 1645 rendering_stats_instrumentation_->IncrementFrameCount(1); |
| 1644 | 1646 |
| 1645 memory_history_->SaveEntry(tile_manager_.memory_stats_from_last_assign()); | 1647 memory_history_->SaveEntry(tile_manager_.memory_stats_from_last_assign()); |
| 1646 | 1648 |
| 1647 if (debug_state_.ShowHudRects()) { | 1649 if (debug_state_.ShowHudRects()) { |
| 1648 debug_rect_history_->SaveDebugRectsForCurrentFrame( | 1650 debug_rect_history_->SaveDebugRectsForCurrentFrame( |
| 1649 active_tree(), active_tree_->hud_layer(), | 1651 active_tree(), active_tree_->hud_layer(), |
| 1650 *frame->render_surface_layer_list, debug_state_); | 1652 *frame->render_surface_layer_list, debug_state_); |
| 1651 } | 1653 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1672 | 1674 |
| 1673 // Because the contents of the HUD depend on everything else in the frame, the | 1675 // Because the contents of the HUD depend on everything else in the frame, the |
| 1674 // contents of its texture are updated as the last thing before the frame is | 1676 // contents of its texture are updated as the last thing before the frame is |
| 1675 // drawn. | 1677 // drawn. |
| 1676 if (active_tree_->hud_layer()) { | 1678 if (active_tree_->hud_layer()) { |
| 1677 TRACE_EVENT0("cc", "DrawLayers.UpdateHudTexture"); | 1679 TRACE_EVENT0("cc", "DrawLayers.UpdateHudTexture"); |
| 1678 active_tree_->hud_layer()->UpdateHudTexture(draw_mode, | 1680 active_tree_->hud_layer()->UpdateHudTexture(draw_mode, |
| 1679 resource_provider_.get()); | 1681 resource_provider_.get()); |
| 1680 } | 1682 } |
| 1681 | 1683 |
| 1682 renderer_->DrawFrame(&frame->render_passes); | 1684 CompositorFrameMetadata metadata = MakeCompositorFrameMetadata(); |
| 1683 // The render passes should be consumed by the renderer. | 1685 metadata.may_contain_video = frame->may_contain_video; |
| 1684 DCHECK(frame->render_passes.empty()); | 1686 active_tree()->FinishSwapPromises(&metadata); |
| 1687 for (auto& latency : metadata.latency_info) { |
| 1688 TRACE_EVENT_WITH_FLOW1("input,benchmark", "LatencyInfo.Flow", |
| 1689 TRACE_ID_DONT_MANGLE(latency.trace_id()), |
| 1690 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, |
| 1691 "step", "SwapBuffers"); |
| 1692 // Only add the latency component once for renderer swap, not the browser |
| 1693 // swap. |
| 1694 if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT, 0, |
| 1695 nullptr)) { |
| 1696 latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT, |
| 1697 0, 0); |
| 1698 } |
| 1699 } |
| 1700 |
| 1701 renderer_->DrawFrame(std::move(metadata), std::move(frame->render_passes)); |
| 1702 |
| 1703 // The next frame should start by assuming nothing has changed, and changes |
| 1704 // are noted as they occur. |
| 1705 // TODO(boliu): If we did a temporary software renderer frame, propogate the |
| 1706 // damage forward to the next frame. |
| 1707 for (size_t i = 0; i < frame->render_surface_layer_list->size(); i++) { |
| 1708 auto* surface = (*frame->render_surface_layer_list)[i]->render_surface(); |
| 1709 surface->damage_tracker()->DidDrawDamagedArea(); |
| 1710 } |
| 1711 active_tree_->ResetAllChangeTracking(); |
| 1712 |
| 1713 active_tree_->set_has_ever_been_drawn(true); |
| 1714 devtools_instrumentation::DidDrawFrame(id_); |
| 1715 benchmark_instrumentation::IssueImplThreadRenderingStatsEvent( |
| 1716 rendering_stats_instrumentation_->impl_thread_rendering_stats()); |
| 1717 rendering_stats_instrumentation_->AccumulateAndClearImplThreadStats(); |
| 1718 return true; |
| 1685 } | 1719 } |
| 1686 | 1720 |
| 1687 void LayerTreeHostImpl::DidDrawAllLayers(const FrameData& frame) { | 1721 void LayerTreeHostImpl::DidDrawAllLayers(const FrameData& frame) { |
| 1688 for (size_t i = 0; i < frame.will_draw_layers.size(); ++i) | 1722 for (size_t i = 0; i < frame.will_draw_layers.size(); ++i) |
| 1689 frame.will_draw_layers[i]->DidDraw(resource_provider_.get()); | 1723 frame.will_draw_layers[i]->DidDraw(resource_provider_.get()); |
| 1690 | 1724 |
| 1691 for (auto* it : video_frame_controllers_) | 1725 for (auto* it : video_frame_controllers_) |
| 1692 it->DidDrawFrame(); | 1726 it->DidDrawFrame(); |
| 1693 } | 1727 } |
| 1694 | 1728 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1813 } | 1847 } |
| 1814 RecreateTreeResources(); | 1848 RecreateTreeResources(); |
| 1815 | 1849 |
| 1816 // We have released tilings for both active and pending tree. | 1850 // We have released tilings for both active and pending tree. |
| 1817 // We would not have any content to draw until the pending tree is activated. | 1851 // We would not have any content to draw until the pending tree is activated. |
| 1818 // Prevent the active tree from drawing until activation. | 1852 // Prevent the active tree from drawing until activation. |
| 1819 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw. | 1853 // TODO(crbug.com/469175): Replace with RequiresHighResToDraw. |
| 1820 SetRequiresHighResToDraw(); | 1854 SetRequiresHighResToDraw(); |
| 1821 } | 1855 } |
| 1822 | 1856 |
| 1823 bool LayerTreeHostImpl::SwapBuffers(const LayerTreeHostImpl::FrameData& frame) { | |
| 1824 ResetRequiresHighResToDraw(); | |
| 1825 | |
| 1826 if (frame.has_no_damage) { | |
| 1827 active_tree()->BreakSwapPromises(SwapPromise::SWAP_FAILS); | |
| 1828 return false; | |
| 1829 } | |
| 1830 | |
| 1831 CompositorFrameMetadata metadata = MakeCompositorFrameMetadata(); | |
| 1832 metadata.may_contain_video = frame.may_contain_video; | |
| 1833 active_tree()->FinishSwapPromises(&metadata); | |
| 1834 for (auto& latency : metadata.latency_info) { | |
| 1835 TRACE_EVENT_WITH_FLOW1("input,benchmark", "LatencyInfo.Flow", | |
| 1836 TRACE_ID_DONT_MANGLE(latency.trace_id()), | |
| 1837 TRACE_EVENT_FLAG_FLOW_IN | TRACE_EVENT_FLAG_FLOW_OUT, | |
| 1838 "step", "SwapBuffers"); | |
| 1839 // Only add the latency component once for renderer swap, not the browser | |
| 1840 // swap. | |
| 1841 if (!latency.FindLatency(ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT, 0, | |
| 1842 nullptr)) { | |
| 1843 latency.AddLatencyNumber(ui::INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT, | |
| 1844 0, 0); | |
| 1845 } | |
| 1846 } | |
| 1847 renderer_->SwapBuffers(std::move(metadata)); | |
| 1848 | |
| 1849 // The next frame should start by assuming nothing has changed, and changes | |
| 1850 // are noted as they occur. | |
| 1851 // TODO(boliu): If we did a temporary software renderer frame, propogate the | |
| 1852 // damage forward to the next frame. | |
| 1853 for (size_t i = 0; i < frame.render_surface_layer_list->size(); i++) { | |
| 1854 auto* surface = (*frame.render_surface_layer_list)[i]->render_surface(); | |
| 1855 surface->damage_tracker()->DidDrawDamagedArea(); | |
| 1856 } | |
| 1857 active_tree_->ResetAllChangeTracking(); | |
| 1858 | |
| 1859 active_tree_->set_has_ever_been_drawn(true); | |
| 1860 devtools_instrumentation::DidDrawFrame(id_); | |
| 1861 benchmark_instrumentation::IssueImplThreadRenderingStatsEvent( | |
| 1862 rendering_stats_instrumentation_->impl_thread_rendering_stats()); | |
| 1863 rendering_stats_instrumentation_->AccumulateAndClearImplThreadStats(); | |
| 1864 return true; | |
| 1865 } | |
| 1866 | |
| 1867 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { | 1857 void LayerTreeHostImpl::WillBeginImplFrame(const BeginFrameArgs& args) { |
| 1868 current_begin_frame_tracker_.Start(args); | 1858 current_begin_frame_tracker_.Start(args); |
| 1869 | 1859 |
| 1870 if (is_likely_to_require_a_draw_) { | 1860 if (is_likely_to_require_a_draw_) { |
| 1871 // Optimistically schedule a draw. This will let us expect the tile manager | 1861 // Optimistically schedule a draw. This will let us expect the tile manager |
| 1872 // to complete its work so that we can draw new tiles within the impl frame | 1862 // to complete its work so that we can draw new tiles within the impl frame |
| 1873 // we are beginning now. | 1863 // we are beginning now. |
| 1874 SetNeedsRedraw(); | 1864 SetNeedsRedraw(); |
| 1875 } | 1865 } |
| 1876 | 1866 |
| (...skipping 2319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4196 if (is_visible) { | 4186 if (is_visible) { |
| 4197 worker_context_visibility_ = | 4187 worker_context_visibility_ = |
| 4198 worker_context->CacheController()->ClientBecameVisible(); | 4188 worker_context->CacheController()->ClientBecameVisible(); |
| 4199 } else { | 4189 } else { |
| 4200 worker_context->CacheController()->ClientBecameNotVisible( | 4190 worker_context->CacheController()->ClientBecameNotVisible( |
| 4201 std::move(worker_context_visibility_)); | 4191 std::move(worker_context_visibility_)); |
| 4202 } | 4192 } |
| 4203 } | 4193 } |
| 4204 | 4194 |
| 4205 } // namespace cc | 4195 } // namespace cc |
| OLD | NEW |