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" |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "cc/render_pass_draw_quad.h" | 32 #include "cc/render_pass_draw_quad.h" |
33 #include "cc/rendering_stats.h" | 33 #include "cc/rendering_stats.h" |
34 #include "cc/scrollbar_animation_controller.h" | 34 #include "cc/scrollbar_animation_controller.h" |
35 #include "cc/scrollbar_layer_impl.h" | 35 #include "cc/scrollbar_layer_impl.h" |
36 #include "cc/shared_quad_state.h" | 36 #include "cc/shared_quad_state.h" |
37 #include "cc/single_thread_proxy.h" | 37 #include "cc/single_thread_proxy.h" |
38 #include "cc/software_renderer.h" | 38 #include "cc/software_renderer.h" |
39 #include "cc/solid_color_draw_quad.h" | 39 #include "cc/solid_color_draw_quad.h" |
40 #include "cc/texture_uploader.h" | 40 #include "cc/texture_uploader.h" |
41 #include "cc/top_controls_manager.h" | 41 #include "cc/top_controls_manager.h" |
| 42 #include "cc/tree_synchronizer.h" |
42 #include "cc/util.h" | 43 #include "cc/util.h" |
43 #include "ui/gfx/size_conversions.h" | 44 #include "ui/gfx/size_conversions.h" |
44 #include "ui/gfx/vector2d_conversions.h" | 45 #include "ui/gfx/vector2d_conversions.h" |
45 | 46 |
46 namespace { | 47 namespace { |
47 | 48 |
48 void didVisibilityChange(cc::LayerTreeHostImpl* id, bool visible) | 49 void didVisibilityChange(cc::LayerTreeHostImpl* id, bool visible) |
49 { | 50 { |
50 if (visible) { | 51 if (visible) { |
51 TRACE_EVENT_ASYNC_BEGIN1("webkit", "LayerTreeHostImpl::setVisible", id,
"LayerTreeHostImpl", id); | 52 TRACE_EVENT_ASYNC_BEGIN1("webkit", "LayerTreeHostImpl::setVisible", id,
"LayerTreeHostImpl", id); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 LayerTreeHostImpl::~LayerTreeHostImpl() | 168 LayerTreeHostImpl::~LayerTreeHostImpl() |
168 { | 169 { |
169 DCHECK(m_proxy->isImplThread()); | 170 DCHECK(m_proxy->isImplThread()); |
170 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); | 171 TRACE_EVENT0("cc", "LayerTreeHostImpl::~LayerTreeHostImpl()"); |
171 | 172 |
172 if (rootLayer()) { | 173 if (rootLayer()) { |
173 clearRenderSurfaces(); | 174 clearRenderSurfaces(); |
174 // The layer trees must be destroyed before the layer tree host. We've | 175 // The layer trees must be destroyed before the layer tree host. We've |
175 // made a contract with our animation controllers that the registrar | 176 // made a contract with our animation controllers that the registrar |
176 // will outlive them, and we must make good. | 177 // will outlive them, and we must make good. |
| 178 m_recycleTree.reset(); |
| 179 m_pendingTree.reset(); |
177 m_activeTree.reset(); | 180 m_activeTree.reset(); |
178 m_pendingTree.reset(); | |
179 } | 181 } |
180 } | 182 } |
181 | 183 |
182 void LayerTreeHostImpl::beginCommit() | 184 void LayerTreeHostImpl::beginCommit() |
183 { | 185 { |
184 } | 186 } |
185 | 187 |
186 void LayerTreeHostImpl::commitComplete() | 188 void LayerTreeHostImpl::commitComplete() |
187 { | 189 { |
188 TRACE_EVENT0("cc", "LayerTreeHostImpl::commitComplete"); | 190 TRACE_EVENT0("cc", "LayerTreeHostImpl::commitComplete"); |
189 | 191 |
190 // Impl-side painting needs an update immediately post-commit to have the | 192 // Impl-side painting needs an update immediately post-commit to have the |
191 // opportunity to create tilings. Other paths can call updateDrawProperties | 193 // opportunity to create tilings. Other paths can call updateDrawProperties |
192 // more lazily when needed prior to drawing. | 194 // more lazily when needed prior to drawing. |
193 setNeedsUpdateDrawProperties(); | 195 setNeedsUpdateDrawProperties(); |
194 if (m_settings.implSidePainting) | 196 if (m_settings.implSidePainting) |
195 updateDrawProperties(); | 197 updateDrawProperties(); |
196 | 198 |
197 // Recompute max scroll position; must be after layer content bounds are | |
198 // updated. | |
199 updateMaxScrollOffset(); | |
200 m_client->sendManagedMemoryStats(); | 199 m_client->sendManagedMemoryStats(); |
201 } | 200 } |
202 | 201 |
203 bool LayerTreeHostImpl::canDraw() | 202 bool LayerTreeHostImpl::canDraw() |
204 { | 203 { |
205 // Note: If you are changing this function or any other function that might | 204 // Note: If you are changing this function or any other function that might |
206 // affect the result of canDraw, make sure to call m_client->onCanDrawStateC
hanged | 205 // affect the result of canDraw, make sure to call m_client->onCanDrawStateC
hanged |
207 // in the proper places and update the notifyIfCanDrawChanged test. | 206 // in the proper places and update the notifyIfCanDrawChanged test. |
208 | 207 |
209 if (!rootLayer()) { | 208 if (!rootLayer()) { |
(...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
925 | 924 |
926 if (layerImpl->drawsContent() && layerImpl->parent() && layerImpl->parent()-
>scrollable()) | 925 if (layerImpl->drawsContent() && layerImpl->parent() && layerImpl->parent()-
>scrollable()) |
927 return layerImpl->parent(); | 926 return layerImpl->parent(); |
928 | 927 |
929 return 0; | 928 return 0; |
930 } | 929 } |
931 | 930 |
932 void LayerTreeHostImpl::createPendingTree() | 931 void LayerTreeHostImpl::createPendingTree() |
933 { | 932 { |
934 CHECK(!m_pendingTree); | 933 CHECK(!m_pendingTree); |
935 m_pendingTree = LayerTreeImpl::create(this); | 934 if (m_recycleTree) |
| 935 m_recycleTree.swap(m_pendingTree); |
| 936 else |
| 937 m_pendingTree = LayerTreeImpl::create(this); |
936 m_client->onCanDrawStateChanged(canDraw()); | 938 m_client->onCanDrawStateChanged(canDraw()); |
937 m_client->onHasPendingTreeStateChanged(pendingTree()); | 939 m_client->onHasPendingTreeStateChanged(pendingTree()); |
938 } | 940 } |
939 | 941 |
940 void LayerTreeHostImpl::checkForCompletedTileUploads() | 942 void LayerTreeHostImpl::checkForCompletedTileUploads() |
941 { | 943 { |
942 DCHECK(!m_client->isInsideDraw()) << "Checking for completed uploads within
a draw may trigger spurious redraws."; | 944 DCHECK(!m_client->isInsideDraw()) << "Checking for completed uploads within
a draw may trigger spurious redraws."; |
943 if (m_tileManager) | 945 if (m_tileManager) |
944 m_tileManager->CheckForCompletedTileUploads(); | 946 m_tileManager->CheckForCompletedTileUploads(); |
945 } | 947 } |
(...skipping 10 matching lines...) Expand all Loading... |
956 return; | 958 return; |
957 | 959 |
958 activatePendingTree(); | 960 activatePendingTree(); |
959 } | 961 } |
960 | 962 |
961 void LayerTreeHostImpl::activatePendingTree() | 963 void LayerTreeHostImpl::activatePendingTree() |
962 { | 964 { |
963 CHECK(m_pendingTree); | 965 CHECK(m_pendingTree); |
964 | 966 |
965 m_activeTree->PushPersistedState(m_pendingTree.get()); | 967 m_activeTree->PushPersistedState(m_pendingTree.get()); |
966 m_activeTree.swap(m_pendingTree); | 968 m_activeTree->SetRootLayer(TreeSynchronizer::synchronizeTrees(m_pendingTree-
>RootLayer(), m_activeTree->DetachLayerTree(), m_activeTree.get())); |
967 // TODO(enne): consider recycling this tree to prevent layer churn | 969 TreeSynchronizer::pushProperties(m_pendingTree->RootLayer(), m_activeTree->R
ootLayer()); |
968 m_pendingTree.reset(); | 970 DCHECK(!m_recycleTree); |
| 971 |
| 972 // This should match the property synchronization in |
| 973 // LayerTreeHost::finishCommitOnImplThread(). |
| 974 m_activeTree->set_source_frame_number(m_pendingTree->source_frame_number()); |
| 975 m_activeTree->set_background_color(m_pendingTree->background_color()); |
| 976 m_activeTree->set_has_transparent_background(m_pendingTree->has_transparent_
background()); |
| 977 if (m_pendingTree->ContentsTexturesPurged()) |
| 978 m_activeTree->SetContentsTexturesPurged(); |
| 979 else |
| 980 m_activeTree->ResetContentsTexturesPurged(); |
| 981 |
| 982 // Now that we've synced everything from the pending tree to the active |
| 983 // tree, rename the pending tree the recycle tree so we can reuse it on the |
| 984 // next sync. |
| 985 m_pendingTree.swap(m_recycleTree); |
| 986 m_recycleTree->ClearRenderSurfaces(); |
| 987 |
969 m_activeTree->DidBecomeActive(); | 988 m_activeTree->DidBecomeActive(); |
970 | 989 |
971 m_client->onCanDrawStateChanged(canDraw()); | 990 m_client->onCanDrawStateChanged(canDraw()); |
972 m_client->onHasPendingTreeStateChanged(pendingTree()); | 991 m_client->onHasPendingTreeStateChanged(pendingTree()); |
973 m_client->setNeedsRedrawOnImplThread(); | 992 m_client->setNeedsRedrawOnImplThread(); |
974 m_client->renewTreePriority(); | 993 m_client->renewTreePriority(); |
975 } | 994 } |
976 | 995 |
977 void LayerTreeHostImpl::setVisible(bool visible) | 996 void LayerTreeHostImpl::setVisible(bool visible) |
978 { | 997 { |
(...skipping 17 matching lines...) Expand all Loading... |
996 { | 1015 { |
997 // Since we will create a new resource provider, we cannot continue to use | 1016 // Since we will create a new resource provider, we cannot continue to use |
998 // the old resources (i.e. renderSurfaces and texture IDs). Clear them | 1017 // the old resources (i.e. renderSurfaces and texture IDs). Clear them |
999 // before we destroy the old resource provider. | 1018 // before we destroy the old resource provider. |
1000 if (rootLayer()) | 1019 if (rootLayer()) |
1001 clearRenderSurfaces(); | 1020 clearRenderSurfaces(); |
1002 if (activeTree()->RootLayer()) | 1021 if (activeTree()->RootLayer()) |
1003 sendDidLoseOutputSurfaceRecursive(activeTree()->RootLayer()); | 1022 sendDidLoseOutputSurfaceRecursive(activeTree()->RootLayer()); |
1004 if (pendingTree() && pendingTree()->RootLayer()) | 1023 if (pendingTree() && pendingTree()->RootLayer()) |
1005 sendDidLoseOutputSurfaceRecursive(pendingTree()->RootLayer()); | 1024 sendDidLoseOutputSurfaceRecursive(pendingTree()->RootLayer()); |
| 1025 if (m_recycleTree && m_recycleTree->RootLayer()) |
| 1026 sendDidLoseOutputSurfaceRecursive(m_recycleTree->RootLayer()); |
1006 | 1027 |
1007 // Note: order is important here. | 1028 // Note: order is important here. |
1008 m_renderer.reset(); | 1029 m_renderer.reset(); |
1009 m_tileManager.reset(); | 1030 m_tileManager.reset(); |
1010 m_resourceProvider.reset(); | 1031 m_resourceProvider.reset(); |
1011 m_outputSurface.reset(); | 1032 m_outputSurface.reset(); |
1012 | 1033 |
1013 if (!outputSurface->BindToClient(this)) | 1034 if (!outputSurface->BindToClient(this)) |
1014 return false; | 1035 return false; |
1015 | 1036 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1110 void LayerTreeHostImpl::setPageScaleDelta(float delta) | 1131 void LayerTreeHostImpl::setPageScaleDelta(float delta) |
1111 { | 1132 { |
1112 m_pinchZoomViewport.set_page_scale_delta(delta); | 1133 m_pinchZoomViewport.set_page_scale_delta(delta); |
1113 | 1134 |
1114 updateMaxScrollOffset(); | 1135 updateMaxScrollOffset(); |
1115 } | 1136 } |
1116 | 1137 |
1117 void LayerTreeHostImpl::updateMaxScrollOffset() | 1138 void LayerTreeHostImpl::updateMaxScrollOffset() |
1118 { | 1139 { |
1119 activeTree()->UpdateMaxScrollOffset(); | 1140 activeTree()->UpdateMaxScrollOffset(); |
1120 if (pendingTree()) | |
1121 pendingTree()->UpdateMaxScrollOffset(); | |
1122 } | 1141 } |
1123 | 1142 |
1124 void LayerTreeHostImpl::setNeedsUpdateDrawProperties() | 1143 void LayerTreeHostImpl::setNeedsUpdateDrawProperties() |
1125 { | 1144 { |
1126 m_needsUpdateDrawProperties = true; | 1145 m_needsUpdateDrawProperties = true; |
1127 } | 1146 } |
1128 | 1147 |
1129 void LayerTreeHostImpl::setNeedsRedraw() | 1148 void LayerTreeHostImpl::setNeedsRedraw() |
1130 { | 1149 { |
1131 m_client->setNeedsRedrawOnImplThread(); | 1150 m_client->setNeedsRedrawOnImplThread(); |
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1694 LayerImpl* layer = getNonCompositedContentLayerRecursive(tree->RootLayer()); | 1713 LayerImpl* layer = getNonCompositedContentLayerRecursive(tree->RootLayer()); |
1695 return layer ? layer->getPicture() : skia::RefPtr<SkPicture>(); | 1714 return layer ? layer->getPicture() : skia::RefPtr<SkPicture>(); |
1696 } | 1715 } |
1697 | 1716 |
1698 void LayerTreeHostImpl::savePaintTime(const base::TimeDelta& totalPaintTime) | 1717 void LayerTreeHostImpl::savePaintTime(const base::TimeDelta& totalPaintTime) |
1699 { | 1718 { |
1700 m_paintTimeCounter->SavePaintTime(totalPaintTime); | 1719 m_paintTimeCounter->SavePaintTime(totalPaintTime); |
1701 } | 1720 } |
1702 | 1721 |
1703 } // namespace cc | 1722 } // namespace cc |
OLD | NEW |