Chromium Code Reviews| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 scoped_ptr<LayerTreeHost> LayerTreeHost::create(LayerTreeHostClient* client, con st LayerTreeSettings& settings, scoped_ptr<Thread> implThread) | 64 scoped_ptr<LayerTreeHost> LayerTreeHost::create(LayerTreeHostClient* client, con st LayerTreeSettings& settings, scoped_ptr<Thread> implThread) |
| 64 { | 65 { |
| 65 scoped_ptr<LayerTreeHost> layerTreeHost(new LayerTreeHost(client, settings)) ; | 66 scoped_ptr<LayerTreeHost> layerTreeHost(new LayerTreeHost(client, settings)) ; |
| 66 if (!layerTreeHost->initialize(implThread.Pass())) | 67 if (!layerTreeHost->initialize(implThread.Pass())) |
| 67 return scoped_ptr<LayerTreeHost>(); | 68 return scoped_ptr<LayerTreeHost>(); |
| 68 return layerTreeHost.Pass(); | 69 return layerTreeHost.Pass(); |
| 69 } | 70 } |
| 70 | 71 |
| 71 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting s& settings) | 72 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting s& settings) |
| 72 : m_animating(false) | 73 : m_animating(false) |
| 73 , m_needsAnimateLayers(false) | |
| 74 , m_needsFullTreeSync(true) | 74 , m_needsFullTreeSync(true) |
| 75 , m_client(client) | 75 , m_client(client) |
| 76 , m_commitNumber(0) | 76 , m_commitNumber(0) |
| 77 , m_renderingStats() | 77 , m_renderingStats() |
| 78 , m_rendererInitialized(false) | 78 , m_rendererInitialized(false) |
| 79 , m_outputSurfaceLost(false) | 79 , m_outputSurfaceLost(false) |
| 80 , m_numTimesRecreateShouldFail(0) | 80 , m_numTimesRecreateShouldFail(0) |
| 81 , m_numFailedRecreateAttempts(0) | 81 , m_numFailedRecreateAttempts(0) |
| 82 , m_settings(settings) | 82 , m_settings(settings) |
| 83 , m_debugState(settings.initialDebugState) | 83 , m_debugState(settings.initialDebugState) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 if (m_rootLayer) | 121 if (m_rootLayer) |
| 122 m_rootLayer->setLayerTreeHost(0); | 122 m_rootLayer->setLayerTreeHost(0); |
| 123 DCHECK(m_proxy); | 123 DCHECK(m_proxy); |
| 124 DCHECK(m_proxy->isMainThread()); | 124 DCHECK(m_proxy->isMainThread()); |
| 125 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); | 125 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); |
| 126 m_proxy->stop(); | 126 m_proxy->stop(); |
| 127 numLayerTreeInstances--; | 127 numLayerTreeInstances--; |
| 128 RateLimiterMap::iterator it = m_rateLimiters.begin(); | 128 RateLimiterMap::iterator it = m_rateLimiters.begin(); |
| 129 if (it != m_rateLimiters.end()) | 129 if (it != m_rateLimiters.end()) |
| 130 it->second->stop(); | 130 it->second->stop(); |
| 131 | |
| 132 if (m_rootLayer) | |
| 133 m_rootLayer = 0; | |
|
enne (OOO)
2012/12/17 20:21:22
style nit: use NULL in Chromium-land.
Also, pleas
| |
| 131 } | 134 } |
| 132 | 135 |
| 133 void LayerTreeHost::setSurfaceReady() | 136 void LayerTreeHost::setSurfaceReady() |
| 134 { | 137 { |
| 135 m_proxy->setSurfaceReady(); | 138 m_proxy->setSurfaceReady(); |
| 136 } | 139 } |
| 137 | 140 |
| 138 void LayerTreeHost::initializeRenderer() | 141 void LayerTreeHost::initializeRenderer() |
| 139 { | 142 { |
| 140 TRACE_EVENT0("cc", "LayerTreeHost::initializeRenderer"); | 143 TRACE_EVENT0("cc", "LayerTreeHost::initializeRenderer"); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 TRACE_EVENT0("cc", "LayerTreeHost::pushPropertiesRecursive"); | 276 TRACE_EVENT0("cc", "LayerTreeHost::pushPropertiesRecursive"); |
| 274 pushPropertiesRecursive(rootLayer(), hostImpl->rootLayer()); | 277 pushPropertiesRecursive(rootLayer(), hostImpl->rootLayer()); |
| 275 } | 278 } |
| 276 m_needsFullTreeSync = false; | 279 m_needsFullTreeSync = false; |
| 277 | 280 |
| 278 if (m_rootLayer && m_hudLayer) | 281 if (m_rootLayer && m_hudLayer) |
| 279 hostImpl->activeTree()->set_hud_layer(static_cast<HeadsUpDisplayLayerImp l*>(LayerTreeHostCommon::findLayerInSubtree(hostImpl->rootLayer(), m_hudLayer->i d()))); | 282 hostImpl->activeTree()->set_hud_layer(static_cast<HeadsUpDisplayLayerImp l*>(LayerTreeHostCommon::findLayerInSubtree(hostImpl->rootLayer(), m_hudLayer->i d()))); |
| 280 else | 283 else |
| 281 hostImpl->activeTree()->set_hud_layer(0); | 284 hostImpl->activeTree()->set_hud_layer(0); |
| 282 | 285 |
| 283 // We may have added an animation during the tree sync. This will cause both layer tree hosts | |
| 284 // to visit their controllers. | |
| 285 if (rootLayer() && m_needsAnimateLayers) | |
| 286 hostImpl->setNeedsAnimateLayers(); | |
| 287 | |
| 288 hostImpl->activeTree()->set_source_frame_number(commitNumber()); | 286 hostImpl->activeTree()->set_source_frame_number(commitNumber()); |
| 289 hostImpl->setViewportSize(layoutViewportSize(), deviceViewportSize()); | 287 hostImpl->setViewportSize(layoutViewportSize(), deviceViewportSize()); |
| 290 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); | 288 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); |
| 291 hostImpl->setPageScaleFactorAndLimits(m_pageScaleFactor, m_minPageScaleFacto r, m_maxPageScaleFactor); | 289 hostImpl->setPageScaleFactorAndLimits(m_pageScaleFactor, m_minPageScaleFacto r, m_maxPageScaleFactor); |
| 292 hostImpl->setBackgroundColor(m_backgroundColor); | 290 hostImpl->setBackgroundColor(m_backgroundColor); |
| 293 hostImpl->setHasTransparentBackground(m_hasTransparentBackground); | 291 hostImpl->setHasTransparentBackground(m_hasTransparentBackground); |
| 294 hostImpl->setDebugState(m_debugState); | 292 hostImpl->setDebugState(m_debugState); |
| 295 | 293 |
| 296 m_commitNumber++; | 294 m_commitNumber++; |
| 297 } | 295 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 411 { | 409 { |
| 412 return m_proxy->commitRequested(); | 410 return m_proxy->commitRequested(); |
| 413 } | 411 } |
| 414 | 412 |
| 415 void LayerTreeHost::setAnimationEvents(scoped_ptr<AnimationEventsVector> events, base::Time wallClockTime) | 413 void LayerTreeHost::setAnimationEvents(scoped_ptr<AnimationEventsVector> events, base::Time wallClockTime) |
| 416 { | 414 { |
| 417 DCHECK(m_proxy->isMainThread()); | 415 DCHECK(m_proxy->isMainThread()); |
| 418 setAnimationEventsRecursive(*events.get(), m_rootLayer.get(), wallClockTime) ; | 416 setAnimationEventsRecursive(*events.get(), m_rootLayer.get(), wallClockTime) ; |
| 419 } | 417 } |
| 420 | 418 |
| 421 void LayerTreeHost::didAddAnimation() | |
| 422 { | |
| 423 m_needsAnimateLayers = true; | |
| 424 m_proxy->didAddAnimation(); | |
| 425 } | |
| 426 | |
| 427 void LayerTreeHost::setRootLayer(scoped_refptr<Layer> rootLayer) | 419 void LayerTreeHost::setRootLayer(scoped_refptr<Layer> rootLayer) |
| 428 { | 420 { |
| 429 if (m_rootLayer == rootLayer) | 421 if (m_rootLayer == rootLayer) |
| 430 return; | 422 return; |
| 431 | 423 |
| 432 if (m_rootLayer) | 424 if (m_rootLayer) |
| 433 m_rootLayer->setLayerTreeHost(0); | 425 m_rootLayer->setLayerTreeHost(0); |
| 434 m_rootLayer = rootLayer; | 426 m_rootLayer = rootLayer; |
| 435 if (m_rootLayer) | 427 if (m_rootLayer) |
| 436 m_rootLayer->setLayerTreeHost(this); | 428 m_rootLayer->setLayerTreeHost(this); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 { | 811 { |
| 820 if (deviceScaleFactor == m_deviceScaleFactor) | 812 if (deviceScaleFactor == m_deviceScaleFactor) |
| 821 return; | 813 return; |
| 822 m_deviceScaleFactor = deviceScaleFactor; | 814 m_deviceScaleFactor = deviceScaleFactor; |
| 823 | 815 |
| 824 setNeedsCommit(); | 816 setNeedsCommit(); |
| 825 } | 817 } |
| 826 | 818 |
| 827 void LayerTreeHost::animateLayers(base::TimeTicks time) | 819 void LayerTreeHost::animateLayers(base::TimeTicks time) |
| 828 { | 820 { |
| 829 if (!m_settings.acceleratedAnimationEnabled || !m_needsAnimateLayers) | 821 if (!m_settings.acceleratedAnimationEnabled || m_activeAnimationControllers. empty()) |
| 830 return; | 822 return; |
| 831 | 823 |
| 832 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); | 824 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); |
| 833 m_needsAnimateLayers = animateLayersRecursive(m_rootLayer.get(), time); | |
| 834 } | |
| 835 | 825 |
| 836 bool LayerTreeHost::animateLayersRecursive(Layer* current, base::TimeTicks time) | 826 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); |
| 837 { | |
| 838 if (!current) | |
| 839 return false; | |
| 840 | 827 |
| 841 bool subtreeNeedsAnimateLayers = false; | 828 AnimationControllerMap copy = m_activeAnimationControllers; |
| 842 LayerAnimationController* currentController = current->layerAnimationControl ler(); | 829 for (AnimationControllerMap::iterator iter = copy.begin(); iter != copy.end( ); ++iter) |
| 843 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); | 830 (*iter).second->animate(monotonicTime, 0); |
| 844 currentController->animate(monotonicTime, 0); | |
| 845 | |
| 846 // If the current controller still has an active animation, we must continue animating layers. | |
| 847 if (currentController->hasActiveAnimation()) | |
| 848 subtreeNeedsAnimateLayers = true; | |
| 849 | |
| 850 for (size_t i = 0; i < current->children().size(); ++i) { | |
| 851 if (animateLayersRecursive(current->children()[i].get(), time)) | |
| 852 subtreeNeedsAnimateLayers = true; | |
| 853 } | |
| 854 | |
| 855 return subtreeNeedsAnimateLayers; | |
| 856 } | 831 } |
| 857 | 832 |
| 858 void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& eve nts, Layer* layer, base::Time wallClockTime) | 833 void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& eve nts, Layer* layer, base::Time wallClockTime) |
| 859 { | 834 { |
| 860 if (!layer) | 835 if (!layer) |
| 861 return; | 836 return; |
| 862 | 837 |
| 863 for (size_t eventIndex = 0; eventIndex < events.size(); ++eventIndex) { | 838 for (size_t eventIndex = 0; eventIndex < events.size(); ++eventIndex) { |
| 864 if (layer->id() == events[eventIndex].layerId) { | 839 if (layer->id() == events[eventIndex].layerId) { |
| 865 if (events[eventIndex].type == AnimationEvent::Started) | 840 if (events[eventIndex].type == AnimationEvent::Started) |
| 866 layer->notifyAnimationStarted(events[eventIndex], wallClockTime. ToDoubleT()); | 841 layer->notifyAnimationStarted(events[eventIndex], wallClockTime. ToDoubleT()); |
| 867 else | 842 else |
| 868 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); | 843 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); |
| 869 } | 844 } |
| 870 } | 845 } |
| 871 | 846 |
| 872 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex) | 847 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex) |
| 873 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime); | 848 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime); |
| 874 } | 849 } |
| 875 | 850 |
| 851 scoped_refptr<LayerAnimationController> LayerTreeHost::GetAnimationControllerFor Id(int id) | |
| 852 { | |
| 853 // On the main thread, animation controllers are created by the layers. | |
| 854 NOTREACHED(); | |
| 855 return NULL; | |
| 856 } | |
| 857 | |
| 858 void LayerTreeHost::DidActivateAnimationController(LayerAnimationController* con troller) | |
| 859 { | |
| 860 // Controllers register themselves when they have new animations. We need | |
| 861 // to commit in this case. | |
| 862 setNeedsCommit(); | |
| 863 m_activeAnimationControllers[controller->id()] = controller; | |
| 864 } | |
| 865 | |
| 866 void LayerTreeHost::DidDeactivateAnimationController(LayerAnimationController* c ontroller) | |
| 867 { | |
| 868 if (ContainsKey(m_activeAnimationControllers, controller->id())) | |
| 869 m_activeAnimationControllers.erase(controller->id()); | |
| 870 } | |
| 871 | |
| 872 void LayerTreeHost::RegisterAnimationController(LayerAnimationController* contro ller) | |
| 873 { | |
| 874 m_allAnimationControllers[controller->id()] = controller; | |
| 875 } | |
| 876 | |
| 877 void LayerTreeHost::UnregisterAnimationController(LayerAnimationController* cont roller) | |
| 878 { | |
| 879 if (ContainsKey(m_allAnimationControllers, controller->id())) | |
| 880 m_allAnimationControllers.erase(controller->id()); | |
| 881 DidDeactivateAnimationController(controller); | |
| 882 } | |
| 883 | |
| 876 } // namespace cc | 884 } // namespace cc |
| OLD | NEW |