| 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 "cc/font_atlas.h" | 11 #include "cc/font_atlas.h" |
| 11 #include "cc/graphics_context.h" | 12 #include "cc/graphics_context.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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 scoped_ptr<LayerTreeHost> LayerTreeHost::create(LayerTreeHostClient* client, con
st LayerTreeSettings& settings, scoped_ptr<Thread> implThread) | 154 scoped_ptr<LayerTreeHost> LayerTreeHost::create(LayerTreeHostClient* client, con
st LayerTreeSettings& settings, scoped_ptr<Thread> implThread) |
| 154 { | 155 { |
| 155 scoped_ptr<LayerTreeHost> layerTreeHost(new LayerTreeHost(client, settings))
; | 156 scoped_ptr<LayerTreeHost> layerTreeHost(new LayerTreeHost(client, settings))
; |
| 156 if (!layerTreeHost->initialize(implThread.Pass())) | 157 if (!layerTreeHost->initialize(implThread.Pass())) |
| 157 return scoped_ptr<LayerTreeHost>(); | 158 return scoped_ptr<LayerTreeHost>(); |
| 158 return layerTreeHost.Pass(); | 159 return layerTreeHost.Pass(); |
| 159 } | 160 } |
| 160 | 161 |
| 161 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting
s& settings) | 162 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting
s& settings) |
| 162 : m_animating(false) | 163 : m_animating(false) |
| 163 , m_needsAnimateLayers(false) | |
| 164 , m_needsFullTreeSync(true) | 164 , m_needsFullTreeSync(true) |
| 165 , m_client(client) | 165 , m_client(client) |
| 166 , m_commitNumber(0) | 166 , m_commitNumber(0) |
| 167 , m_renderingStats() | 167 , m_renderingStats() |
| 168 , m_rendererInitialized(false) | 168 , m_rendererInitialized(false) |
| 169 , m_contextLost(false) | 169 , m_contextLost(false) |
| 170 , m_numTimesRecreateShouldFail(0) | 170 , m_numTimesRecreateShouldFail(0) |
| 171 , m_numFailedRecreateAttempts(0) | 171 , m_numFailedRecreateAttempts(0) |
| 172 , m_settings(settings) | 172 , m_settings(settings) |
| 173 , m_debugState(settings.initialDebugState) | 173 , m_debugState(settings.initialDebugState) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 202 if (m_rootLayer) | 202 if (m_rootLayer) |
| 203 m_rootLayer->setLayerTreeHost(0); | 203 m_rootLayer->setLayerTreeHost(0); |
| 204 DCHECK(m_proxy); | 204 DCHECK(m_proxy); |
| 205 DCHECK(m_proxy->isMainThread()); | 205 DCHECK(m_proxy->isMainThread()); |
| 206 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); | 206 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); |
| 207 m_proxy->stop(); | 207 m_proxy->stop(); |
| 208 numLayerTreeInstances--; | 208 numLayerTreeInstances--; |
| 209 RateLimiterMap::iterator it = m_rateLimiters.begin(); | 209 RateLimiterMap::iterator it = m_rateLimiters.begin(); |
| 210 if (it != m_rateLimiters.end()) | 210 if (it != m_rateLimiters.end()) |
| 211 it->second->stop(); | 211 it->second->stop(); |
| 212 |
| 213 if (m_rootLayer) |
| 214 m_rootLayer = 0; |
| 212 } | 215 } |
| 213 | 216 |
| 214 void LayerTreeHost::setSurfaceReady() | 217 void LayerTreeHost::setSurfaceReady() |
| 215 { | 218 { |
| 216 m_proxy->setSurfaceReady(); | 219 m_proxy->setSurfaceReady(); |
| 217 } | 220 } |
| 218 | 221 |
| 219 void LayerTreeHost::initializeRenderer() | 222 void LayerTreeHost::initializeRenderer() |
| 220 { | 223 { |
| 221 TRACE_EVENT0("cc", "LayerTreeHost::initializeRenderer"); | 224 TRACE_EVENT0("cc", "LayerTreeHost::initializeRenderer"); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 TRACE_EVENT0("cc", "LayerTreeHost::pushPropertiesRecursive"); | 354 TRACE_EVENT0("cc", "LayerTreeHost::pushPropertiesRecursive"); |
| 352 pushPropertiesRecursive(rootLayer(), hostImpl->rootLayer()); | 355 pushPropertiesRecursive(rootLayer(), hostImpl->rootLayer()); |
| 353 } | 356 } |
| 354 m_needsFullTreeSync = false; | 357 m_needsFullTreeSync = false; |
| 355 | 358 |
| 356 if (m_rootLayer && m_hudLayer) | 359 if (m_rootLayer && m_hudLayer) |
| 357 hostImpl->setHudLayer(static_cast<HeadsUpDisplayLayerImpl*>(LayerTreeHos
tCommon::findLayerInSubtree(hostImpl->rootLayer(), m_hudLayer->id()))); | 360 hostImpl->setHudLayer(static_cast<HeadsUpDisplayLayerImpl*>(LayerTreeHos
tCommon::findLayerInSubtree(hostImpl->rootLayer(), m_hudLayer->id()))); |
| 358 else | 361 else |
| 359 hostImpl->setHudLayer(0); | 362 hostImpl->setHudLayer(0); |
| 360 | 363 |
| 361 // We may have added an animation during the tree sync. This will cause both
layer tree hosts | |
| 362 // to visit their controllers. | |
| 363 if (rootLayer() && m_needsAnimateLayers) | |
| 364 hostImpl->setNeedsAnimateLayers(); | |
| 365 | |
| 366 hostImpl->setSourceFrameNumber(commitNumber()); | 364 hostImpl->setSourceFrameNumber(commitNumber()); |
| 367 hostImpl->setViewportSize(layoutViewportSize(), deviceViewportSize()); | 365 hostImpl->setViewportSize(layoutViewportSize(), deviceViewportSize()); |
| 368 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); | 366 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); |
| 369 hostImpl->setPageScaleFactorAndLimits(m_pageScaleFactor, m_minPageScaleFacto
r, m_maxPageScaleFactor); | 367 hostImpl->setPageScaleFactorAndLimits(m_pageScaleFactor, m_minPageScaleFacto
r, m_maxPageScaleFactor); |
| 370 hostImpl->setBackgroundColor(m_backgroundColor); | 368 hostImpl->setBackgroundColor(m_backgroundColor); |
| 371 hostImpl->setHasTransparentBackground(m_hasTransparentBackground); | 369 hostImpl->setHasTransparentBackground(m_hasTransparentBackground); |
| 372 hostImpl->setDebugState(m_debugState); | 370 hostImpl->setDebugState(m_debugState); |
| 373 | 371 |
| 374 m_commitNumber++; | 372 m_commitNumber++; |
| 375 } | 373 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 { | 487 { |
| 490 return m_proxy->commitRequested(); | 488 return m_proxy->commitRequested(); |
| 491 } | 489 } |
| 492 | 490 |
| 493 void LayerTreeHost::setAnimationEvents(scoped_ptr<AnimationEventsVector> events,
base::Time wallClockTime) | 491 void LayerTreeHost::setAnimationEvents(scoped_ptr<AnimationEventsVector> events,
base::Time wallClockTime) |
| 494 { | 492 { |
| 495 DCHECK(m_proxy->isMainThread()); | 493 DCHECK(m_proxy->isMainThread()); |
| 496 setAnimationEventsRecursive(*events.get(), m_rootLayer.get(), wallClockTime)
; | 494 setAnimationEventsRecursive(*events.get(), m_rootLayer.get(), wallClockTime)
; |
| 497 } | 495 } |
| 498 | 496 |
| 499 void LayerTreeHost::didAddAnimation() | |
| 500 { | |
| 501 m_needsAnimateLayers = true; | |
| 502 m_proxy->didAddAnimation(); | |
| 503 } | |
| 504 | |
| 505 void LayerTreeHost::setRootLayer(scoped_refptr<Layer> rootLayer) | 497 void LayerTreeHost::setRootLayer(scoped_refptr<Layer> rootLayer) |
| 506 { | 498 { |
| 507 if (m_rootLayer == rootLayer) | 499 if (m_rootLayer == rootLayer) |
| 508 return; | 500 return; |
| 509 | 501 |
| 510 if (m_rootLayer) | 502 if (m_rootLayer) |
| 511 m_rootLayer->setLayerTreeHost(0); | 503 m_rootLayer->setLayerTreeHost(0); |
| 512 m_rootLayer = rootLayer; | 504 m_rootLayer = rootLayer; |
| 513 if (m_rootLayer) | 505 if (m_rootLayer) |
| 514 m_rootLayer->setLayerTreeHost(this); | 506 m_rootLayer->setLayerTreeHost(this); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 { | 889 { |
| 898 if (deviceScaleFactor == m_deviceScaleFactor) | 890 if (deviceScaleFactor == m_deviceScaleFactor) |
| 899 return; | 891 return; |
| 900 m_deviceScaleFactor = deviceScaleFactor; | 892 m_deviceScaleFactor = deviceScaleFactor; |
| 901 | 893 |
| 902 setNeedsCommit(); | 894 setNeedsCommit(); |
| 903 } | 895 } |
| 904 | 896 |
| 905 void LayerTreeHost::animateLayers(base::TimeTicks time) | 897 void LayerTreeHost::animateLayers(base::TimeTicks time) |
| 906 { | 898 { |
| 907 if (!m_settings.acceleratedAnimationEnabled || !m_needsAnimateLayers) | 899 if (!m_settings.acceleratedAnimationEnabled || m_activeAnimationControllers.
empty()) |
| 908 return; | 900 return; |
| 909 | 901 |
| 910 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); | 902 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); |
| 911 m_needsAnimateLayers = animateLayersRecursive(m_rootLayer.get(), time); | |
| 912 } | |
| 913 | 903 |
| 914 bool LayerTreeHost::animateLayersRecursive(Layer* current, base::TimeTicks time) | 904 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); |
| 915 { | |
| 916 if (!current) | |
| 917 return false; | |
| 918 | 905 |
| 919 bool subtreeNeedsAnimateLayers = false; | 906 AnimationControllerSet copy = m_activeAnimationControllers; |
| 920 LayerAnimationController* currentController = current->layerAnimationControl
ler(); | 907 for (AnimationControllerSet::iterator iter = copy.begin(); iter != copy.end(
); ++iter) |
| 921 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); | 908 (*iter)->animate(monotonicTime, 0); |
| 922 currentController->animate(monotonicTime, 0); | |
| 923 | |
| 924 // If the current controller still has an active animation, we must continue
animating layers. | |
| 925 if (currentController->hasActiveAnimation()) | |
| 926 subtreeNeedsAnimateLayers = true; | |
| 927 | |
| 928 for (size_t i = 0; i < current->children().size(); ++i) { | |
| 929 if (animateLayersRecursive(current->children()[i].get(), time)) | |
| 930 subtreeNeedsAnimateLayers = true; | |
| 931 } | |
| 932 | |
| 933 return subtreeNeedsAnimateLayers; | |
| 934 } | 909 } |
| 935 | 910 |
| 936 void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& eve
nts, Layer* layer, base::Time wallClockTime) | 911 void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& eve
nts, Layer* layer, base::Time wallClockTime) |
| 937 { | 912 { |
| 938 if (!layer) | 913 if (!layer) |
| 939 return; | 914 return; |
| 940 | 915 |
| 941 for (size_t eventIndex = 0; eventIndex < events.size(); ++eventIndex) { | 916 for (size_t eventIndex = 0; eventIndex < events.size(); ++eventIndex) { |
| 942 if (layer->id() == events[eventIndex].layerId) { | 917 if (layer->id() == events[eventIndex].layerId) { |
| 943 if (events[eventIndex].type == AnimationEvent::Started) | 918 if (events[eventIndex].type == AnimationEvent::Started) |
| 944 layer->notifyAnimationStarted(events[eventIndex], wallClockTime.
ToDoubleT()); | 919 layer->notifyAnimationStarted(events[eventIndex], wallClockTime.
ToDoubleT()); |
| 945 else | 920 else |
| 946 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); | 921 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); |
| 947 } | 922 } |
| 948 } | 923 } |
| 949 | 924 |
| 950 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn
dex) | 925 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn
dex) |
| 951 setAnimationEventsRecursive(events, layer->children()[childIndex].get(),
wallClockTime); | 926 setAnimationEventsRecursive(events, layer->children()[childIndex].get(),
wallClockTime); |
| 952 } | 927 } |
| 953 | 928 |
| 929 void LayerTreeHost::ActivateAnimationController(LayerAnimationController* contro
ller) { |
| 930 // Controllers register themselves when they have new animations. We need |
| 931 // to commit in this case. |
| 932 setNeedsCommit(); |
| 933 m_activeAnimationControllers.insert(controller); |
| 934 } |
| 935 |
| 936 void LayerTreeHost::DeactivateAnimationController(LayerAnimationController* cont
roller) { |
| 937 if (ContainsKey(m_activeAnimationControllers, controller)) |
| 938 m_activeAnimationControllers.erase(controller); |
| 939 } |
| 940 |
| 941 void LayerTreeHost::RegisterAnimationController(LayerAnimationController* contro
ller) { |
| 942 #if !defined(NDEBUG) |
| 943 m_allAnimationControllers.insert(controller); |
| 944 #endif |
| 945 } |
| 946 |
| 947 void LayerTreeHost::UnregisterAnimationController(LayerAnimationController* cont
roller) { |
| 948 #if !defined(NDEBUG) |
| 949 if (ContainsKey(m_allAnimationControllers, controller)) |
| 950 m_allAnimationControllers.erase(controller); |
| 951 #endif |
| 952 DeactivateAnimationController(controller); |
| 953 } |
| 954 |
| 954 } // namespace cc | 955 } // namespace cc |
| OLD | NEW |