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