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" |
10 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
11 #include "cc/font_atlas.h" | 12 #include "cc/font_atlas.h" |
12 #include "cc/heads_up_display_layer.h" | 13 #include "cc/heads_up_display_layer.h" |
13 #include "cc/heads_up_display_layer_impl.h" | 14 #include "cc/heads_up_display_layer_impl.h" |
14 #include "cc/layer.h" | 15 #include "cc/layer.h" |
15 #include "cc/layer_animation_controller.h" | 16 #include "cc/layer_animation_controller.h" |
16 #include "cc/layer_iterator.h" | 17 #include "cc/layer_iterator.h" |
17 #include "cc/layer_tree_host_client.h" | 18 #include "cc/layer_tree_host_client.h" |
18 #include "cc/layer_tree_host_common.h" | 19 #include "cc/layer_tree_host_common.h" |
19 #include "cc/layer_tree_host_impl.h" | 20 #include "cc/layer_tree_host_impl.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 scoped_ptr<LayerTreeHost> LayerTreeHost::create(LayerTreeHostClient* client, con
st LayerTreeSettings& settings, scoped_ptr<Thread> implThread) | 171 scoped_ptr<LayerTreeHost> LayerTreeHost::create(LayerTreeHostClient* client, con
st LayerTreeSettings& settings, scoped_ptr<Thread> implThread) |
171 { | 172 { |
172 scoped_ptr<LayerTreeHost> layerTreeHost(new LayerTreeHost(client, settings))
; | 173 scoped_ptr<LayerTreeHost> layerTreeHost(new LayerTreeHost(client, settings))
; |
173 if (!layerTreeHost->initialize(implThread.Pass())) | 174 if (!layerTreeHost->initialize(implThread.Pass())) |
174 return scoped_ptr<LayerTreeHost>(); | 175 return scoped_ptr<LayerTreeHost>(); |
175 return layerTreeHost.Pass(); | 176 return layerTreeHost.Pass(); |
176 } | 177 } |
177 | 178 |
178 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting
s& settings) | 179 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting
s& settings) |
179 : m_animating(false) | 180 : 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; |
238 } | 241 } |
239 | 242 |
240 void LayerTreeHost::setSurfaceReady() | 243 void LayerTreeHost::setSurfaceReady() |
241 { | 244 { |
242 m_proxy->setSurfaceReady(); | 245 m_proxy->setSurfaceReady(); |
243 } | 246 } |
244 | 247 |
245 void LayerTreeHost::initializeRenderer() | 248 void LayerTreeHost::initializeRenderer() |
246 { | 249 { |
247 TRACE_EVENT0("cc", "LayerTreeHost::initializeRenderer"); | 250 TRACE_EVENT0("cc", "LayerTreeHost::initializeRenderer"); |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 TRACE_EVENT0("cc", "LayerTreeHost::pushPropertiesRecursive"); | 383 TRACE_EVENT0("cc", "LayerTreeHost::pushPropertiesRecursive"); |
381 pushPropertiesRecursive(rootLayer(), hostImpl->rootLayer()); | 384 pushPropertiesRecursive(rootLayer(), hostImpl->rootLayer()); |
382 } | 385 } |
383 m_needsFullTreeSync = false; | 386 m_needsFullTreeSync = false; |
384 | 387 |
385 if (m_rootLayer && m_hudLayer) | 388 if (m_rootLayer && m_hudLayer) |
386 hostImpl->activeTree()->set_hud_layer(static_cast<HeadsUpDisplayLayerImp
l*>(LayerTreeHostCommon::findLayerInSubtree(hostImpl->rootLayer(), m_hudLayer->i
d()))); | 389 hostImpl->activeTree()->set_hud_layer(static_cast<HeadsUpDisplayLayerImp
l*>(LayerTreeHostCommon::findLayerInSubtree(hostImpl->rootLayer(), m_hudLayer->i
d()))); |
387 else | 390 else |
388 hostImpl->activeTree()->set_hud_layer(0); | 391 hostImpl->activeTree()->set_hud_layer(0); |
389 | 392 |
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 | |
395 hostImpl->activeTree()->set_source_frame_number(commitNumber()); | 393 hostImpl->activeTree()->set_source_frame_number(commitNumber()); |
396 hostImpl->setViewportSize(layoutViewportSize(), deviceViewportSize()); | 394 hostImpl->setViewportSize(layoutViewportSize(), deviceViewportSize()); |
397 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); | 395 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); |
398 hostImpl->setPageScaleFactorAndLimits(m_pageScaleFactor, m_minPageScaleFacto
r, m_maxPageScaleFactor); | 396 hostImpl->setPageScaleFactorAndLimits(m_pageScaleFactor, m_minPageScaleFacto
r, m_maxPageScaleFactor); |
399 hostImpl->setBackgroundColor(m_backgroundColor); | 397 hostImpl->setBackgroundColor(m_backgroundColor); |
400 hostImpl->setHasTransparentBackground(m_hasTransparentBackground); | 398 hostImpl->setHasTransparentBackground(m_hasTransparentBackground); |
401 hostImpl->setDebugState(m_debugState); | 399 hostImpl->setDebugState(m_debugState); |
402 | 400 |
403 m_commitNumber++; | 401 m_commitNumber++; |
404 } | 402 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 { | 516 { |
519 return m_proxy->commitRequested(); | 517 return m_proxy->commitRequested(); |
520 } | 518 } |
521 | 519 |
522 void LayerTreeHost::setAnimationEvents(scoped_ptr<AnimationEventsVector> events,
base::Time wallClockTime) | 520 void LayerTreeHost::setAnimationEvents(scoped_ptr<AnimationEventsVector> events,
base::Time wallClockTime) |
523 { | 521 { |
524 DCHECK(m_proxy->isMainThread()); | 522 DCHECK(m_proxy->isMainThread()); |
525 setAnimationEventsRecursive(*events.get(), m_rootLayer.get(), wallClockTime)
; | 523 setAnimationEventsRecursive(*events.get(), m_rootLayer.get(), wallClockTime)
; |
526 } | 524 } |
527 | 525 |
528 void LayerTreeHost::didAddAnimation() | |
529 { | |
530 m_needsAnimateLayers = true; | |
531 m_proxy->didAddAnimation(); | |
532 } | |
533 | |
534 void LayerTreeHost::setRootLayer(scoped_refptr<Layer> rootLayer) | 526 void LayerTreeHost::setRootLayer(scoped_refptr<Layer> rootLayer) |
535 { | 527 { |
536 if (m_rootLayer == rootLayer) | 528 if (m_rootLayer == rootLayer) |
537 return; | 529 return; |
538 | 530 |
539 if (m_rootLayer) | 531 if (m_rootLayer) |
540 m_rootLayer->setLayerTreeHost(0); | 532 m_rootLayer->setLayerTreeHost(0); |
541 m_rootLayer = rootLayer; | 533 m_rootLayer = rootLayer; |
542 if (m_rootLayer) | 534 if (m_rootLayer) |
543 m_rootLayer->setLayerTreeHost(this); | 535 m_rootLayer->setLayerTreeHost(this); |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
926 { | 918 { |
927 if (deviceScaleFactor == m_deviceScaleFactor) | 919 if (deviceScaleFactor == m_deviceScaleFactor) |
928 return; | 920 return; |
929 m_deviceScaleFactor = deviceScaleFactor; | 921 m_deviceScaleFactor = deviceScaleFactor; |
930 | 922 |
931 setNeedsCommit(); | 923 setNeedsCommit(); |
932 } | 924 } |
933 | 925 |
934 void LayerTreeHost::animateLayers(base::TimeTicks time) | 926 void LayerTreeHost::animateLayers(base::TimeTicks time) |
935 { | 927 { |
936 if (!m_settings.acceleratedAnimationEnabled || !m_needsAnimateLayers) | 928 if (!m_settings.acceleratedAnimationEnabled || m_activeAnimationControllers.
empty()) |
937 return; | 929 return; |
938 | 930 |
939 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); | 931 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); |
940 m_needsAnimateLayers = animateLayersRecursive(m_rootLayer.get(), time); | |
941 } | |
942 | 932 |
943 bool LayerTreeHost::animateLayersRecursive(Layer* current, base::TimeTicks time) | 933 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); |
944 { | |
945 if (!current) | |
946 return false; | |
947 | 934 |
948 bool subtreeNeedsAnimateLayers = false; | 935 AnimationControllerSet copy = m_activeAnimationControllers; |
949 LayerAnimationController* currentController = current->layerAnimationControl
ler(); | 936 for (AnimationControllerSet::iterator iter = copy.begin(); iter != copy.end(
); ++iter) |
950 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); | 937 (*iter)->animate(monotonicTime, 0); |
951 currentController->animate(monotonicTime, 0); | |
952 | |
953 // If the current controller still has an active animation, we must continue
animating layers. | |
954 if (currentController->hasActiveAnimation()) | |
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; | |
963 } | 938 } |
964 | 939 |
965 void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& eve
nts, Layer* layer, base::Time wallClockTime) | 940 void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& eve
nts, Layer* layer, base::Time wallClockTime) |
966 { | 941 { |
967 if (!layer) | 942 if (!layer) |
968 return; | 943 return; |
969 | 944 |
970 for (size_t eventIndex = 0; eventIndex < events.size(); ++eventIndex) { | 945 for (size_t eventIndex = 0; eventIndex < events.size(); ++eventIndex) { |
971 if (layer->id() == events[eventIndex].layerId) { | 946 if (layer->id() == events[eventIndex].layerId) { |
972 if (events[eventIndex].type == AnimationEvent::Started) | 947 if (events[eventIndex].type == AnimationEvent::Started) |
973 layer->notifyAnimationStarted(events[eventIndex], wallClockTime.
ToDoubleT()); | 948 layer->notifyAnimationStarted(events[eventIndex], wallClockTime.
ToDoubleT()); |
974 else | 949 else |
975 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); | 950 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); |
976 } | 951 } |
977 } | 952 } |
978 | 953 |
979 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn
dex) | 954 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn
dex) |
980 setAnimationEventsRecursive(events, layer->children()[childIndex].get(),
wallClockTime); | 955 setAnimationEventsRecursive(events, layer->children()[childIndex].get(),
wallClockTime); |
981 } | 956 } |
982 | 957 |
| 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 |
983 } // namespace cc | 984 } // namespace cc |
OLD | NEW |