| 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/layer_tree_host_impl.h" | 5 #include "cc/layer_tree_host_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/stringprintf.h" |
| 14 #include "cc/append_quads_data.h" | 15 #include "cc/append_quads_data.h" |
| 15 #include "cc/compositor_frame_metadata.h" | 16 #include "cc/compositor_frame_metadata.h" |
| 16 #include "cc/damage_tracker.h" | 17 #include "cc/damage_tracker.h" |
| 17 #include "cc/debug_rect_history.h" | 18 #include "cc/debug_rect_history.h" |
| 18 #include "cc/delay_based_time_source.h" | 19 #include "cc/delay_based_time_source.h" |
| 19 #include "cc/delegating_renderer.h" | 20 #include "cc/delegating_renderer.h" |
| 20 #include "cc/frame_rate_counter.h" | 21 #include "cc/frame_rate_counter.h" |
| 21 #include "cc/gl_renderer.h" | 22 #include "cc/gl_renderer.h" |
| 22 #include "cc/heads_up_display_layer_impl.h" | 23 #include "cc/heads_up_display_layer_impl.h" |
| 23 #include "cc/layer_iterator.h" | 24 #include "cc/layer_iterator.h" |
| 24 #include "cc/layer_tree_host.h" | 25 #include "cc/layer_tree_host.h" |
| 25 #include "cc/layer_tree_host_common.h" | 26 #include "cc/layer_tree_host_common.h" |
| 26 #include "cc/layer_tree_impl.h" | 27 #include "cc/layer_tree_impl.h" |
| 27 #include "cc/math_util.h" | 28 #include "cc/math_util.h" |
| 28 #include "cc/memory_history.h" | 29 #include "cc/memory_history.h" |
| 29 #include "cc/overdraw_metrics.h" | 30 #include "cc/overdraw_metrics.h" |
| 30 #include "cc/page_scale_animation.h" | 31 #include "cc/page_scale_animation.h" |
| 31 #include "cc/paint_time_counter.h" | 32 #include "cc/paint_time_counter.h" |
| 33 #include "cc/picture_layer_tiling.h" |
| 32 #include "cc/prioritized_resource_manager.h" | 34 #include "cc/prioritized_resource_manager.h" |
| 33 #include "cc/quad_culler.h" | 35 #include "cc/quad_culler.h" |
| 34 #include "cc/render_pass_draw_quad.h" | 36 #include "cc/render_pass_draw_quad.h" |
| 35 #include "cc/rendering_stats.h" | 37 #include "cc/rendering_stats.h" |
| 36 #include "cc/scrollbar_animation_controller.h" | 38 #include "cc/scrollbar_animation_controller.h" |
| 37 #include "cc/scrollbar_layer_impl.h" | 39 #include "cc/scrollbar_layer_impl.h" |
| 38 #include "cc/shared_quad_state.h" | 40 #include "cc/shared_quad_state.h" |
| 39 #include "cc/single_thread_proxy.h" | 41 #include "cc/single_thread_proxy.h" |
| 40 #include "cc/software_renderer.h" | 42 #include "cc/software_renderer.h" |
| 41 #include "cc/solid_color_draw_quad.h" | 43 #include "cc/solid_color_draw_quad.h" |
| 42 #include "cc/texture_uploader.h" | 44 #include "cc/texture_uploader.h" |
| 43 #include "cc/top_controls_manager.h" | 45 #include "cc/top_controls_manager.h" |
| 44 #include "cc/tree_synchronizer.h" | 46 #include "cc/tree_synchronizer.h" |
| 45 #include "cc/util.h" | 47 #include "cc/util.h" |
| 46 #include "ui/gfx/size_conversions.h" | 48 #include "ui/gfx/size_conversions.h" |
| 47 #include "ui/gfx/vector2d_conversions.h" | 49 #include "ui/gfx/vector2d_conversions.h" |
| 48 | 50 |
| 49 namespace { | 51 namespace { |
| 50 | 52 |
| 51 void didVisibilityChange(cc::LayerTreeHostImpl* id, bool visible) | 53 void didVisibilityChange(cc::LayerTreeHostImpl* id, bool visible) |
| 52 { | 54 { |
| 53 if (visible) { | 55 if (visible) { |
| 54 TRACE_EVENT_ASYNC_BEGIN1("webkit", "LayerTreeHostImpl::setVisible", id,
"LayerTreeHostImpl", id); | 56 TRACE_EVENT_ASYNC_BEGIN1("webkit", "LayerTreeHostImpl::setVisible", id,
"LayerTreeHostImpl", id); |
| 55 return; | 57 return; |
| 56 } | 58 } |
| 57 | 59 |
| 58 TRACE_EVENT_ASYNC_END0("webkit", "LayerTreeHostImpl::setVisible", id); | 60 TRACE_EVENT_ASYNC_END0("webkit", "LayerTreeHostImpl::setVisible", id); |
| 59 } | 61 } |
| 60 | 62 |
| 63 std::string ValueToString(scoped_ptr<base::Value> value) |
| 64 { |
| 65 std::string str; |
| 66 base::JSONWriter::Write(value.get(), &str); |
| 67 return str; |
| 68 } |
| 69 |
| 61 } // namespace | 70 } // namespace |
| 62 | 71 |
| 63 namespace cc { | 72 namespace cc { |
| 64 | 73 |
| 65 class LayerTreeHostImplTimeSourceAdapter : public TimeSourceClient { | 74 class LayerTreeHostImplTimeSourceAdapter : public TimeSourceClient { |
| 66 public: | 75 public: |
| 67 static scoped_ptr<LayerTreeHostImplTimeSourceAdapter> create(LayerTreeHostIm
pl* layerTreeHostImpl, scoped_refptr<DelayBasedTimeSource> timeSource) | 76 static scoped_ptr<LayerTreeHostImplTimeSourceAdapter> create(LayerTreeHostIm
pl* layerTreeHostImpl, scoped_refptr<DelayBasedTimeSource> timeSource) |
| 68 { | 77 { |
| 69 return make_scoped_ptr(new LayerTreeHostImplTimeSourceAdapter(layerTreeH
ostImpl, timeSource)); | 78 return make_scoped_ptr(new LayerTreeHostImplTimeSourceAdapter(layerTreeH
ostImpl, timeSource)); |
| 70 } | 79 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 , m_cumulativeNumLayersDrawn(0) | 165 , m_cumulativeNumLayersDrawn(0) |
| 157 , m_cumulativeNumMissingTiles(0) | 166 , m_cumulativeNumMissingTiles(0) |
| 158 , m_lastSentMemoryVisibleBytes(0) | 167 , m_lastSentMemoryVisibleBytes(0) |
| 159 , m_lastSentMemoryVisibleAndNearbyBytes(0) | 168 , m_lastSentMemoryVisibleAndNearbyBytes(0) |
| 160 , m_lastSentMemoryUseBytes(0) | 169 , m_lastSentMemoryUseBytes(0) |
| 161 , m_animationRegistrar(AnimationRegistrar::create()) | 170 , m_animationRegistrar(AnimationRegistrar::create()) |
| 162 { | 171 { |
| 163 DCHECK(m_proxy->isImplThread()); | 172 DCHECK(m_proxy->isImplThread()); |
| 164 didVisibilityChange(this, m_visible); | 173 didVisibilityChange(this, m_visible); |
| 165 | 174 |
| 175 setDebugState(settings.initialDebugState); |
| 176 |
| 166 if (settings.calculateTopControlsPosition) | 177 if (settings.calculateTopControlsPosition) |
| 167 m_topControlsManager = TopControlsManager::Create(this, settings.topCont
rolsHeight); | 178 m_topControlsManager = TopControlsManager::Create(this, settings.topCont
rolsHeight); |
| 168 | 179 |
| 169 setDebugState(settings.initialDebugState); | 180 setDebugState(settings.initialDebugState); |
| 170 | 181 |
| 171 // LTHI always has an active tree. | 182 // LTHI always has an active tree. |
| 172 m_activeTree = LayerTreeImpl::create(this); | 183 m_activeTree = LayerTreeImpl::create(this); |
| 173 } | 184 } |
| 174 | 185 |
| 175 LayerTreeHostImpl::~LayerTreeHostImpl() | 186 LayerTreeHostImpl::~LayerTreeHostImpl() |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 m_fpsCounter->saveTimeStamp(base::TimeTicks::Now()); | 805 m_fpsCounter->saveTimeStamp(base::TimeTicks::Now()); |
| 795 | 806 |
| 796 if (m_tileManager) { | 807 if (m_tileManager) { |
| 797 m_memoryHistory->SaveEntry( | 808 m_memoryHistory->SaveEntry( |
| 798 m_tileManager->memory_stats_from_last_assign()); | 809 m_tileManager->memory_stats_from_last_assign()); |
| 799 } | 810 } |
| 800 | 811 |
| 801 if (m_debugState.showHudRects()) | 812 if (m_debugState.showHudRects()) |
| 802 m_debugRectHistory->saveDebugRectsForCurrentFrame(rootLayer(), *frame.re
nderSurfaceLayerList, frame.occludingScreenSpaceRects, frame.nonOccludingScreenS
paceRects, m_debugState); | 813 m_debugRectHistory->saveDebugRectsForCurrentFrame(rootLayer(), *frame.re
nderSurfaceLayerList, frame.occludingScreenSpaceRects, frame.nonOccludingScreenS
paceRects, m_debugState); |
| 803 | 814 |
| 815 if (m_debugState.traceAllRenderedFrames) { |
| 816 TRACE_EVENT_INSTANT1("cc.debug", "Frame", |
| 817 "frame", ValueToString(frameStateAsValue())); |
| 818 } |
| 819 |
| 804 // Because the contents of the HUD depend on everything else in the frame, t
he contents | 820 // Because the contents of the HUD depend on everything else in the frame, t
he contents |
| 805 // of its texture are updated as the last thing before the frame is drawn. | 821 // of its texture are updated as the last thing before the frame is drawn. |
| 806 if (m_activeTree->hud_layer()) | 822 if (m_activeTree->hud_layer()) |
| 807 m_activeTree->hud_layer()->updateHudTexture(m_resourceProvider.get()); | 823 m_activeTree->hud_layer()->updateHudTexture(m_resourceProvider.get()); |
| 808 | 824 |
| 809 m_renderer->drawFrame(frame.renderPasses); | 825 m_renderer->drawFrame(frame.renderPasses); |
| 810 // The render passes should be consumed by the renderer. | 826 // The render passes should be consumed by the renderer. |
| 811 DCHECK(frame.renderPasses.empty()); | 827 DCHECK(frame.renderPasses.empty()); |
| 812 frame.renderPassesById.clear(); | 828 frame.renderPassesById.clear(); |
| 813 | 829 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 void LayerTreeHostImpl::createPendingTree() | 937 void LayerTreeHostImpl::createPendingTree() |
| 922 { | 938 { |
| 923 CHECK(!m_pendingTree); | 939 CHECK(!m_pendingTree); |
| 924 if (m_recycleTree) | 940 if (m_recycleTree) |
| 925 m_recycleTree.swap(m_pendingTree); | 941 m_recycleTree.swap(m_pendingTree); |
| 926 else | 942 else |
| 927 m_pendingTree = LayerTreeImpl::create(this); | 943 m_pendingTree = LayerTreeImpl::create(this); |
| 928 m_client->onCanDrawStateChanged(canDraw()); | 944 m_client->onCanDrawStateChanged(canDraw()); |
| 929 m_client->onHasPendingTreeStateChanged(pendingTree()); | 945 m_client->onHasPendingTreeStateChanged(pendingTree()); |
| 930 TRACE_EVENT_ASYNC_BEGIN0("cc", "PendingTree", m_pendingTree.get()); | 946 TRACE_EVENT_ASYNC_BEGIN0("cc", "PendingTree", m_pendingTree.get()); |
| 947 TRACE_EVENT_ASYNC_STEP0("cc", |
| 948 "PendingTree", m_pendingTree.get(), "waiting"); |
| 931 } | 949 } |
| 932 | 950 |
| 933 void LayerTreeHostImpl::checkForCompletedTileUploads() | 951 void LayerTreeHostImpl::checkForCompletedTileUploads() |
| 934 { | 952 { |
| 935 DCHECK(!m_client->isInsideDraw()) << "Checking for completed uploads within
a draw may trigger spurious redraws."; | 953 DCHECK(!m_client->isInsideDraw()) << "Checking for completed uploads within
a draw may trigger spurious redraws."; |
| 936 if (m_tileManager) | 954 if (m_tileManager) |
| 937 m_tileManager->CheckForCompletedTileUploads(); | 955 m_tileManager->CheckForCompletedTileUploads(); |
| 938 } | 956 } |
| 939 | 957 |
| 940 scoped_ptr<base::Value> LayerTreeHostImpl::activationStateAsValue() const | |
| 941 { | |
| 942 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); | |
| 943 state->SetBoolean("visible_resources_ready", pendingTree()->AreVisibleResour
cesReady()); | |
| 944 state->Set("tile_manager", m_tileManager->AsValue().release()); | |
| 945 return state.PassAs<base::Value>(); | |
| 946 } | |
| 947 | |
| 948 namespace { | |
| 949 | |
| 950 std::string ValueToString(scoped_ptr<base::Value> value) | |
| 951 { | |
| 952 std::string str; | |
| 953 base::JSONWriter::Write(value.get(), &str); | |
| 954 return str; | |
| 955 } | |
| 956 | |
| 957 } | |
| 958 | |
| 959 void LayerTreeHostImpl::activatePendingTreeIfNeeded() | 958 void LayerTreeHostImpl::activatePendingTreeIfNeeded() |
| 960 { | 959 { |
| 961 if (!pendingTree()) | 960 if (!pendingTree()) |
| 962 return; | 961 return; |
| 963 | 962 |
| 964 CHECK(m_tileManager); | 963 CHECK(m_tileManager); |
| 965 | 964 |
| 966 pendingTree()->UpdateDrawProperties(LayerTreeImpl::UPDATE_PENDING_TREE); | 965 pendingTree()->UpdateDrawProperties(LayerTreeImpl::UPDATE_PENDING_TREE); |
| 967 | 966 |
| 968 TRACE_EVENT_ASYNC_STEP1("cc", | 967 TRACE_EVENT_ASYNC_STEP1("cc", |
| 969 "PendingTree", m_pendingTree.get(), "activate", | 968 "PendingTree", m_pendingTree.get(), "activate", |
| 970 "state", ValueToString(activationStateAsValue())); | 969 "state", ValueToString(activationStateAsValue())); |
| 971 | 970 |
| 972 // It's always fine to activate to an empty tree. Otherwise, only | 971 // It's always fine to activate to an empty tree. Otherwise, only |
| 973 // activate once all visible resources in pending tree are ready | 972 // activate once all visible resources in pending tree are ready |
| 974 // or tile manager has no work scheduled for pending tree. | 973 // or tile manager has no work scheduled for pending tree. |
| 975 if (activeTree()->RootLayer() && | 974 if (activeTree()->RootLayer() && |
| 976 !pendingTree()->AreVisibleResourcesReady() && | 975 !pendingTree()->AreVisibleResourcesReady() && |
| 977 m_tileManager->HasPendingWorkScheduled(PENDING_TREE)) | 976 m_tileManager->HasPendingWorkScheduled(PENDING_TREE)) { |
| 977 TRACE_EVENT_ASYNC_STEP0("cc", |
| 978 "PendingTree", m_pendingTree.get(), "waiting"); |
| 978 return; | 979 return; |
| 980 } |
| 979 | 981 |
| 980 activatePendingTree(); | 982 activatePendingTree(); |
| 981 } | 983 } |
| 982 | 984 |
| 983 void LayerTreeHostImpl::activatePendingTree() | 985 void LayerTreeHostImpl::activatePendingTree() |
| 984 { | 986 { |
| 985 CHECK(m_pendingTree); | 987 CHECK(m_pendingTree); |
| 986 TRACE_EVENT_ASYNC_END0("cc", "PendingTree", m_pendingTree.get()); | 988 TRACE_EVENT_ASYNC_END0("cc", "PendingTree", m_pendingTree.get()); |
| 987 | 989 |
| 988 m_activeTree->PushPersistedState(m_pendingTree.get()); | 990 m_activeTree->PushPersistedState(m_pendingTree.get()); |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1688 m_currentFrameTime = base::TimeTicks(); | 1690 m_currentFrameTime = base::TimeTicks(); |
| 1689 } | 1691 } |
| 1690 | 1692 |
| 1691 base::TimeTicks LayerTreeHostImpl::currentFrameTime() | 1693 base::TimeTicks LayerTreeHostImpl::currentFrameTime() |
| 1692 { | 1694 { |
| 1693 if (m_currentFrameTime.is_null()) | 1695 if (m_currentFrameTime.is_null()) |
| 1694 m_currentFrameTime = base::TimeTicks::Now(); | 1696 m_currentFrameTime = base::TimeTicks::Now(); |
| 1695 return m_currentFrameTime; | 1697 return m_currentFrameTime; |
| 1696 } | 1698 } |
| 1697 | 1699 |
| 1700 scoped_ptr<base::Value> LayerTreeHostImpl::asValue() const |
| 1701 { |
| 1702 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 1703 state->Set("activation_state", activationStateAsValue().release()); |
| 1704 state->Set("frame_state", frameStateAsValue().release()); |
| 1705 return state.PassAs<base::Value>(); |
| 1706 } |
| 1707 |
| 1708 scoped_ptr<base::Value> LayerTreeHostImpl::activationStateAsValue() const |
| 1709 { |
| 1710 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 1711 state->SetString("lthi_id", StringPrintf("%p", this)); |
| 1712 state->SetBoolean("visible_resources_ready", pendingTree()->AreVisibleResour
cesReady()); |
| 1713 state->Set("tile_manager", m_tileManager->BasicStateAsValue().release()); |
| 1714 return state.PassAs<base::Value>(); |
| 1715 } |
| 1716 |
| 1717 scoped_ptr<base::Value> LayerTreeHostImpl::frameStateAsValue() const |
| 1718 { |
| 1719 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 1720 state->SetString("lthi_id", StringPrintf("%p", this)); |
| 1721 state->Set("device_viewport_size", MathUtil::asValue(m_deviceViewportSize).r
elease()); |
| 1722 if (m_tileManager) |
| 1723 state->Set("tiles", m_tileManager->AllTilesAsValue().release()); |
| 1724 return state.PassAs<base::Value>(); |
| 1725 } |
| 1726 |
| 1698 // static | 1727 // static |
| 1699 LayerImpl* LayerTreeHostImpl::getNonCompositedContentLayerRecursive(LayerImpl* l
ayer) | 1728 LayerImpl* LayerTreeHostImpl::getNonCompositedContentLayerRecursive(LayerImpl* l
ayer) |
| 1700 { | 1729 { |
| 1701 if (!layer) | 1730 if (!layer) |
| 1702 return NULL; | 1731 return NULL; |
| 1703 | 1732 |
| 1704 if (layer->drawsContent()) | 1733 if (layer->drawsContent()) |
| 1705 return layer; | 1734 return layer; |
| 1706 | 1735 |
| 1707 for (LayerImpl::LayerList::const_iterator it = layer->children().begin(); | 1736 for (LayerImpl::LayerList::const_iterator it = layer->children().begin(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1728 if (m_tileManager) | 1757 if (m_tileManager) |
| 1729 m_tileManager->SetRecordRenderingStats(m_debugState.recordRenderingStats
()); | 1758 m_tileManager->SetRecordRenderingStats(m_debugState.recordRenderingStats
()); |
| 1730 } | 1759 } |
| 1731 | 1760 |
| 1732 void LayerTreeHostImpl::savePaintTime(const base::TimeDelta& totalPaintTime) | 1761 void LayerTreeHostImpl::savePaintTime(const base::TimeDelta& totalPaintTime) |
| 1733 { | 1762 { |
| 1734 m_paintTimeCounter->SavePaintTime(totalPaintTime); | 1763 m_paintTimeCounter->SavePaintTime(totalPaintTime); |
| 1735 } | 1764 } |
| 1736 | 1765 |
| 1737 } // namespace cc | 1766 } // namespace cc |
| OLD | NEW |