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.h" | 5 #include "cc/layer_tree_host.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/stl_util.h" | |
11 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
12 #include "cc/font_atlas.h" | 11 #include "cc/font_atlas.h" |
13 #include "cc/heads_up_display_layer.h" | 12 #include "cc/heads_up_display_layer.h" |
14 #include "cc/heads_up_display_layer_impl.h" | 13 #include "cc/heads_up_display_layer_impl.h" |
15 #include "cc/layer.h" | 14 #include "cc/layer.h" |
16 #include "cc/layer_animation_controller.h" | 15 #include "cc/layer_animation_controller.h" |
17 #include "cc/layer_iterator.h" | 16 #include "cc/layer_iterator.h" |
18 #include "cc/layer_tree_host_client.h" | 17 #include "cc/layer_tree_host_client.h" |
19 #include "cc/layer_tree_host_common.h" | 18 #include "cc/layer_tree_host_common.h" |
20 #include "cc/layer_tree_host_impl.h" | 19 #include "cc/layer_tree_host_impl.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 scoped_ptr<LayerTreeHost> LayerTreeHost::create(LayerTreeHostClient* client, con
st LayerTreeSettings& settings, scoped_ptr<Thread> implThread) | 170 scoped_ptr<LayerTreeHost> LayerTreeHost::create(LayerTreeHostClient* client, con
st LayerTreeSettings& settings, scoped_ptr<Thread> implThread) |
172 { | 171 { |
173 scoped_ptr<LayerTreeHost> layerTreeHost(new LayerTreeHost(client, settings))
; | 172 scoped_ptr<LayerTreeHost> layerTreeHost(new LayerTreeHost(client, settings))
; |
174 if (!layerTreeHost->initialize(implThread.Pass())) | 173 if (!layerTreeHost->initialize(implThread.Pass())) |
175 return scoped_ptr<LayerTreeHost>(); | 174 return scoped_ptr<LayerTreeHost>(); |
176 return layerTreeHost.Pass(); | 175 return layerTreeHost.Pass(); |
177 } | 176 } |
178 | 177 |
179 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting
s& settings) | 178 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting
s& settings) |
180 : m_animating(false) | 179 : m_animating(false) |
| 180 , m_needsAnimateLayers(false) |
181 , m_needsFullTreeSync(true) | 181 , m_needsFullTreeSync(true) |
182 , m_client(client) | 182 , m_client(client) |
183 , m_commitNumber(0) | 183 , m_commitNumber(0) |
184 , m_renderingStats() | 184 , m_renderingStats() |
185 , m_rendererInitialized(false) | 185 , m_rendererInitialized(false) |
186 , m_outputSurfaceLost(false) | 186 , m_outputSurfaceLost(false) |
187 , m_numTimesRecreateShouldFail(0) | 187 , m_numTimesRecreateShouldFail(0) |
188 , m_numFailedRecreateAttempts(0) | 188 , m_numFailedRecreateAttempts(0) |
189 , m_settings(settings) | 189 , m_settings(settings) |
190 , m_debugState(settings.initialDebugState) | 190 , m_debugState(settings.initialDebugState) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 if (m_rootLayer) | 228 if (m_rootLayer) |
229 m_rootLayer->setLayerTreeHost(0); | 229 m_rootLayer->setLayerTreeHost(0); |
230 DCHECK(m_proxy); | 230 DCHECK(m_proxy); |
231 DCHECK(m_proxy->isMainThread()); | 231 DCHECK(m_proxy->isMainThread()); |
232 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); | 232 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); |
233 m_proxy->stop(); | 233 m_proxy->stop(); |
234 numLayerTreeInstances--; | 234 numLayerTreeInstances--; |
235 RateLimiterMap::iterator it = m_rateLimiters.begin(); | 235 RateLimiterMap::iterator it = m_rateLimiters.begin(); |
236 if (it != m_rateLimiters.end()) | 236 if (it != m_rateLimiters.end()) |
237 it->second->stop(); | 237 it->second->stop(); |
238 | |
239 if (m_rootLayer) | |
240 m_rootLayer = 0; | |
241 } | 238 } |
242 | 239 |
243 void LayerTreeHost::setSurfaceReady() | 240 void LayerTreeHost::setSurfaceReady() |
244 { | 241 { |
245 m_proxy->setSurfaceReady(); | 242 m_proxy->setSurfaceReady(); |
246 } | 243 } |
247 | 244 |
248 void LayerTreeHost::initializeRenderer() | 245 void LayerTreeHost::initializeRenderer() |
249 { | 246 { |
250 TRACE_EVENT0("cc", "LayerTreeHost::initializeRenderer"); | 247 TRACE_EVENT0("cc", "LayerTreeHost::initializeRenderer"); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 TRACE_EVENT0("cc", "LayerTreeHost::pushPropertiesRecursive"); | 380 TRACE_EVENT0("cc", "LayerTreeHost::pushPropertiesRecursive"); |
384 pushPropertiesRecursive(rootLayer(), hostImpl->rootLayer()); | 381 pushPropertiesRecursive(rootLayer(), hostImpl->rootLayer()); |
385 } | 382 } |
386 m_needsFullTreeSync = false; | 383 m_needsFullTreeSync = false; |
387 | 384 |
388 if (m_rootLayer && m_hudLayer) | 385 if (m_rootLayer && m_hudLayer) |
389 hostImpl->activeTree()->set_hud_layer(static_cast<HeadsUpDisplayLayerImp
l*>(LayerTreeHostCommon::findLayerInSubtree(hostImpl->rootLayer(), m_hudLayer->i
d()))); | 386 hostImpl->activeTree()->set_hud_layer(static_cast<HeadsUpDisplayLayerImp
l*>(LayerTreeHostCommon::findLayerInSubtree(hostImpl->rootLayer(), m_hudLayer->i
d()))); |
390 else | 387 else |
391 hostImpl->activeTree()->set_hud_layer(0); | 388 hostImpl->activeTree()->set_hud_layer(0); |
392 | 389 |
| 390 // We may have added an animation during the tree sync. This will cause both
layer tree hosts |
| 391 // to visit their controllers. |
| 392 if (rootLayer() && m_needsAnimateLayers) |
| 393 hostImpl->setNeedsAnimateLayers(); |
| 394 |
393 hostImpl->activeTree()->set_source_frame_number(commitNumber()); | 395 hostImpl->activeTree()->set_source_frame_number(commitNumber()); |
394 hostImpl->setViewportSize(layoutViewportSize(), deviceViewportSize()); | 396 hostImpl->setViewportSize(layoutViewportSize(), deviceViewportSize()); |
395 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); | 397 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); |
396 hostImpl->setPageScaleFactorAndLimits(m_pageScaleFactor, m_minPageScaleFacto
r, m_maxPageScaleFactor); | 398 hostImpl->setPageScaleFactorAndLimits(m_pageScaleFactor, m_minPageScaleFacto
r, m_maxPageScaleFactor); |
397 hostImpl->setBackgroundColor(m_backgroundColor); | 399 hostImpl->setBackgroundColor(m_backgroundColor); |
398 hostImpl->setHasTransparentBackground(m_hasTransparentBackground); | 400 hostImpl->setHasTransparentBackground(m_hasTransparentBackground); |
399 hostImpl->setDebugState(m_debugState); | 401 hostImpl->setDebugState(m_debugState); |
400 | 402 |
401 m_commitNumber++; | 403 m_commitNumber++; |
402 } | 404 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 { | 518 { |
517 return m_proxy->commitRequested(); | 519 return m_proxy->commitRequested(); |
518 } | 520 } |
519 | 521 |
520 void LayerTreeHost::setAnimationEvents(scoped_ptr<AnimationEventsVector> events,
base::Time wallClockTime) | 522 void LayerTreeHost::setAnimationEvents(scoped_ptr<AnimationEventsVector> events,
base::Time wallClockTime) |
521 { | 523 { |
522 DCHECK(m_proxy->isMainThread()); | 524 DCHECK(m_proxy->isMainThread()); |
523 setAnimationEventsRecursive(*events.get(), m_rootLayer.get(), wallClockTime)
; | 525 setAnimationEventsRecursive(*events.get(), m_rootLayer.get(), wallClockTime)
; |
524 } | 526 } |
525 | 527 |
| 528 void LayerTreeHost::didAddAnimation() |
| 529 { |
| 530 m_needsAnimateLayers = true; |
| 531 m_proxy->didAddAnimation(); |
| 532 } |
| 533 |
526 void LayerTreeHost::setRootLayer(scoped_refptr<Layer> rootLayer) | 534 void LayerTreeHost::setRootLayer(scoped_refptr<Layer> rootLayer) |
527 { | 535 { |
528 if (m_rootLayer == rootLayer) | 536 if (m_rootLayer == rootLayer) |
529 return; | 537 return; |
530 | 538 |
531 if (m_rootLayer) | 539 if (m_rootLayer) |
532 m_rootLayer->setLayerTreeHost(0); | 540 m_rootLayer->setLayerTreeHost(0); |
533 m_rootLayer = rootLayer; | 541 m_rootLayer = rootLayer; |
534 if (m_rootLayer) | 542 if (m_rootLayer) |
535 m_rootLayer->setLayerTreeHost(this); | 543 m_rootLayer->setLayerTreeHost(this); |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
918 { | 926 { |
919 if (deviceScaleFactor == m_deviceScaleFactor) | 927 if (deviceScaleFactor == m_deviceScaleFactor) |
920 return; | 928 return; |
921 m_deviceScaleFactor = deviceScaleFactor; | 929 m_deviceScaleFactor = deviceScaleFactor; |
922 | 930 |
923 setNeedsCommit(); | 931 setNeedsCommit(); |
924 } | 932 } |
925 | 933 |
926 void LayerTreeHost::animateLayers(base::TimeTicks time) | 934 void LayerTreeHost::animateLayers(base::TimeTicks time) |
927 { | 935 { |
928 if (!m_settings.acceleratedAnimationEnabled || m_activeAnimationControllers.
empty()) | 936 if (!m_settings.acceleratedAnimationEnabled || !m_needsAnimateLayers) |
929 return; | 937 return; |
930 | 938 |
931 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); | 939 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); |
| 940 m_needsAnimateLayers = animateLayersRecursive(m_rootLayer.get(), time); |
| 941 } |
932 | 942 |
| 943 bool LayerTreeHost::animateLayersRecursive(Layer* current, base::TimeTicks time) |
| 944 { |
| 945 if (!current) |
| 946 return false; |
| 947 |
| 948 bool subtreeNeedsAnimateLayers = false; |
| 949 LayerAnimationController* currentController = current->layerAnimationControl
ler(); |
933 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); | 950 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); |
| 951 currentController->animate(monotonicTime, 0); |
934 | 952 |
935 AnimationControllerSet copy = m_activeAnimationControllers; | 953 // If the current controller still has an active animation, we must continue
animating layers. |
936 for (AnimationControllerSet::iterator iter = copy.begin(); iter != copy.end(
); ++iter) | 954 if (currentController->hasActiveAnimation()) |
937 (*iter)->animate(monotonicTime, 0); | 955 subtreeNeedsAnimateLayers = true; |
| 956 |
| 957 for (size_t i = 0; i < current->children().size(); ++i) { |
| 958 if (animateLayersRecursive(current->children()[i].get(), time)) |
| 959 subtreeNeedsAnimateLayers = true; |
| 960 } |
| 961 |
| 962 return subtreeNeedsAnimateLayers; |
938 } | 963 } |
939 | 964 |
940 void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& eve
nts, Layer* layer, base::Time wallClockTime) | 965 void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& eve
nts, Layer* layer, base::Time wallClockTime) |
941 { | 966 { |
942 if (!layer) | 967 if (!layer) |
943 return; | 968 return; |
944 | 969 |
945 for (size_t eventIndex = 0; eventIndex < events.size(); ++eventIndex) { | 970 for (size_t eventIndex = 0; eventIndex < events.size(); ++eventIndex) { |
946 if (layer->id() == events[eventIndex].layerId) { | 971 if (layer->id() == events[eventIndex].layerId) { |
947 if (events[eventIndex].type == AnimationEvent::Started) | 972 if (events[eventIndex].type == AnimationEvent::Started) |
948 layer->notifyAnimationStarted(events[eventIndex], wallClockTime.
ToDoubleT()); | 973 layer->notifyAnimationStarted(events[eventIndex], wallClockTime.
ToDoubleT()); |
949 else | 974 else |
950 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); | 975 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); |
951 } | 976 } |
952 } | 977 } |
953 | 978 |
954 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn
dex) | 979 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn
dex) |
955 setAnimationEventsRecursive(events, layer->children()[childIndex].get(),
wallClockTime); | 980 setAnimationEventsRecursive(events, layer->children()[childIndex].get(),
wallClockTime); |
956 } | 981 } |
957 | 982 |
958 void LayerTreeHost::DidActivateAnimationController(LayerAnimationController* con
troller) { | |
959 // Controllers register themselves when they have new animations. We need | |
960 // to commit in this case. | |
961 setNeedsCommit(); | |
962 m_activeAnimationControllers.insert(controller); | |
963 } | |
964 | |
965 void LayerTreeHost::DidDeactivateAnimationController(LayerAnimationController* c
ontroller) { | |
966 if (ContainsKey(m_activeAnimationControllers, controller)) | |
967 m_activeAnimationControllers.erase(controller); | |
968 } | |
969 | |
970 void LayerTreeHost::RegisterAnimationController(LayerAnimationController* contro
ller) { | |
971 #if !defined(NDEBUG) | |
972 m_allAnimationControllers.insert(controller); | |
973 #endif | |
974 } | |
975 | |
976 void LayerTreeHost::UnregisterAnimationController(LayerAnimationController* cont
roller) { | |
977 #if !defined(NDEBUG) | |
978 if (ContainsKey(m_allAnimationControllers, controller)) | |
979 m_allAnimationControllers.erase(controller); | |
980 #endif | |
981 DidDeactivateAnimationController(controller); | |
982 } | |
983 | |
984 } // namespace cc | 983 } // namespace cc |
OLD | NEW |