Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(894)

Side by Side Diff: cc/layer_tree_host.cc

Issue 11348256: Use an auxiliary list of animation controllers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Unit tests pass! Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 scoped_ptr<LayerTreeHost> LayerTreeHost::create(LayerTreeHostClient* client, con st LayerTreeSettings& settings, scoped_ptr<Thread> implThread) 104 scoped_ptr<LayerTreeHost> LayerTreeHost::create(LayerTreeHostClient* client, con st LayerTreeSettings& settings, scoped_ptr<Thread> implThread)
104 { 105 {
105 scoped_ptr<LayerTreeHost> layerTreeHost(new LayerTreeHost(client, settings)) ; 106 scoped_ptr<LayerTreeHost> layerTreeHost(new LayerTreeHost(client, settings)) ;
106 if (!layerTreeHost->initialize(implThread.Pass())) 107 if (!layerTreeHost->initialize(implThread.Pass()))
107 return scoped_ptr<LayerTreeHost>(); 108 return scoped_ptr<LayerTreeHost>();
108 return layerTreeHost.Pass(); 109 return layerTreeHost.Pass();
109 } 110 }
110 111
111 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting s& settings) 112 LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting s& settings)
112 : m_animating(false) 113 : m_animating(false)
113 , m_needsAnimateLayers(false)
114 , m_client(client) 114 , m_client(client)
115 , m_commitNumber(0) 115 , m_commitNumber(0)
116 , m_renderingStats() 116 , m_renderingStats()
117 , m_rendererInitialized(false) 117 , m_rendererInitialized(false)
118 , m_contextLost(false) 118 , m_contextLost(false)
119 , m_numTimesRecreateShouldFail(0) 119 , m_numTimesRecreateShouldFail(0)
120 , m_numFailedRecreateAttempts(0) 120 , m_numFailedRecreateAttempts(0)
121 , m_settings(settings) 121 , m_settings(settings)
122 , m_deviceScaleFactor(1) 122 , m_deviceScaleFactor(1)
123 , m_visible(true) 123 , m_visible(true)
(...skipping 26 matching lines...) Expand all
150 if (m_rootLayer) 150 if (m_rootLayer)
151 m_rootLayer->setLayerTreeHost(0); 151 m_rootLayer->setLayerTreeHost(0);
152 DCHECK(m_proxy); 152 DCHECK(m_proxy);
153 DCHECK(m_proxy->isMainThread()); 153 DCHECK(m_proxy->isMainThread());
154 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost"); 154 TRACE_EVENT0("cc", "LayerTreeHost::~LayerTreeHost");
155 m_proxy->stop(); 155 m_proxy->stop();
156 numLayerTreeInstances--; 156 numLayerTreeInstances--;
157 RateLimiterMap::iterator it = m_rateLimiters.begin(); 157 RateLimiterMap::iterator it = m_rateLimiters.begin();
158 if (it != m_rateLimiters.end()) 158 if (it != m_rateLimiters.end())
159 it->second->stop(); 159 it->second->stop();
160
161 if (m_rootLayer)
162 m_rootLayer = 0;
160 } 163 }
161 164
162 void LayerTreeHost::setSurfaceReady() 165 void LayerTreeHost::setSurfaceReady()
163 { 166 {
164 m_proxy->setSurfaceReady(); 167 m_proxy->setSurfaceReady();
165 } 168 }
166 169
167 void LayerTreeHost::initializeRenderer() 170 void LayerTreeHost::initializeRenderer()
168 { 171 {
169 TRACE_EVENT0("cc", "LayerTreeHost::initializeRenderer"); 172 TRACE_EVENT0("cc", "LayerTreeHost::initializeRenderer");
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 m_contentsTextureManager->updateBackingsInDrawingImplTree(); 274 m_contentsTextureManager->updateBackingsInDrawingImplTree();
272 m_contentsTextureManager->reduceMemory(hostImpl->resourceProvider()); 275 m_contentsTextureManager->reduceMemory(hostImpl->resourceProvider());
273 276
274 hostImpl->setRootLayer(TreeSynchronizer::synchronizeTrees(rootLayer(), hostI mpl->detachLayerTree(), hostImpl)); 277 hostImpl->setRootLayer(TreeSynchronizer::synchronizeTrees(rootLayer(), hostI mpl->detachLayerTree(), hostImpl));
275 278
276 if (m_rootLayer && m_hudLayer) 279 if (m_rootLayer && m_hudLayer)
277 hostImpl->setHudLayer(static_cast<HeadsUpDisplayLayerImpl*>(LayerTreeHos tCommon::findLayerInSubtree(hostImpl->rootLayer(), m_hudLayer->id()))); 280 hostImpl->setHudLayer(static_cast<HeadsUpDisplayLayerImpl*>(LayerTreeHos tCommon::findLayerInSubtree(hostImpl->rootLayer(), m_hudLayer->id())));
278 else 281 else
279 hostImpl->setHudLayer(0); 282 hostImpl->setHudLayer(0);
280 283
281 // We may have added an animation during the tree sync. This will cause both layer tree hosts
282 // to visit their controllers.
283 if (rootLayer() && m_needsAnimateLayers)
284 hostImpl->setNeedsAnimateLayers();
285
286 hostImpl->setSourceFrameNumber(commitNumber()); 284 hostImpl->setSourceFrameNumber(commitNumber());
287 hostImpl->setViewportSize(layoutViewportSize(), deviceViewportSize()); 285 hostImpl->setViewportSize(layoutViewportSize(), deviceViewportSize());
288 hostImpl->setDeviceScaleFactor(deviceScaleFactor()); 286 hostImpl->setDeviceScaleFactor(deviceScaleFactor());
289 hostImpl->setPageScaleFactorAndLimits(m_pageScaleFactor, m_minPageScaleFacto r, m_maxPageScaleFactor); 287 hostImpl->setPageScaleFactorAndLimits(m_pageScaleFactor, m_minPageScaleFacto r, m_maxPageScaleFactor);
290 hostImpl->setBackgroundColor(m_backgroundColor); 288 hostImpl->setBackgroundColor(m_backgroundColor);
291 hostImpl->setHasTransparentBackground(m_hasTransparentBackground); 289 hostImpl->setHasTransparentBackground(m_hasTransparentBackground);
292 290
293 m_commitNumber++; 291 m_commitNumber++;
294 } 292 }
295 293
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 { 410 {
413 return m_proxy->commitRequested(); 411 return m_proxy->commitRequested();
414 } 412 }
415 413
416 void LayerTreeHost::setAnimationEvents(scoped_ptr<AnimationEventsVector> events, base::Time wallClockTime) 414 void LayerTreeHost::setAnimationEvents(scoped_ptr<AnimationEventsVector> events, base::Time wallClockTime)
417 { 415 {
418 DCHECK(m_proxy->isMainThread()); 416 DCHECK(m_proxy->isMainThread());
419 setAnimationEventsRecursive(*events.get(), m_rootLayer.get(), wallClockTime) ; 417 setAnimationEventsRecursive(*events.get(), m_rootLayer.get(), wallClockTime) ;
420 } 418 }
421 419
422 void LayerTreeHost::didAddAnimation()
423 {
424 m_needsAnimateLayers = true;
425 m_proxy->didAddAnimation();
426 }
427
428 void LayerTreeHost::setRootLayer(scoped_refptr<Layer> rootLayer) 420 void LayerTreeHost::setRootLayer(scoped_refptr<Layer> rootLayer)
429 { 421 {
430 if (m_rootLayer == rootLayer) 422 if (m_rootLayer == rootLayer)
431 return; 423 return;
432 424
433 if (m_rootLayer) 425 if (m_rootLayer)
434 m_rootLayer->setLayerTreeHost(0); 426 m_rootLayer->setLayerTreeHost(0);
435 m_rootLayer = rootLayer; 427 m_rootLayer = rootLayer;
436 if (m_rootLayer) 428 if (m_rootLayer)
437 m_rootLayer->setLayerTreeHost(this); 429 m_rootLayer->setLayerTreeHost(this);
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 { 801 {
810 if (deviceScaleFactor == m_deviceScaleFactor) 802 if (deviceScaleFactor == m_deviceScaleFactor)
811 return; 803 return;
812 m_deviceScaleFactor = deviceScaleFactor; 804 m_deviceScaleFactor = deviceScaleFactor;
813 805
814 setNeedsCommit(); 806 setNeedsCommit();
815 } 807 }
816 808
817 void LayerTreeHost::animateLayers(base::TimeTicks time) 809 void LayerTreeHost::animateLayers(base::TimeTicks time)
818 { 810 {
819 if (!m_settings.acceleratedAnimationEnabled || !m_needsAnimateLayers) 811 if (!m_settings.acceleratedAnimationEnabled || m_activeAnimationControllers. empty())
820 return; 812 return;
821 813
822 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers"); 814 TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers");
823 m_needsAnimateLayers = animateLayersRecursive(m_rootLayer.get(), time);
824 }
825 815
826 bool LayerTreeHost::animateLayersRecursive(Layer* current, base::TimeTicks time) 816 double monotonicTime = (time - base::TimeTicks()).InSecondsF();
827 {
828 if (!current)
829 return false;
830 817
831 bool subtreeNeedsAnimateLayers = false; 818 AnimationControllerSet copy = m_activeAnimationControllers;
832 LayerAnimationController* currentController = current->layerAnimationControl ler(); 819 for (AnimationControllerSet::iterator iter = copy.begin(); iter != copy.end( ); ++iter)
833 double monotonicTime = (time - base::TimeTicks()).InSecondsF(); 820 (*iter)->animate(monotonicTime, 0);
834 currentController->animate(monotonicTime, 0);
835
836 // If the current controller still has an active animation, we must continue animating layers.
837 if (currentController->hasActiveAnimation())
838 subtreeNeedsAnimateLayers = true;
839
840 for (size_t i = 0; i < current->children().size(); ++i) {
841 if (animateLayersRecursive(current->children()[i].get(), time))
842 subtreeNeedsAnimateLayers = true;
843 }
844
845 return subtreeNeedsAnimateLayers;
846 } 821 }
847 822
848 void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& eve nts, Layer* layer, base::Time wallClockTime) 823 void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& eve nts, Layer* layer, base::Time wallClockTime)
849 { 824 {
850 if (!layer) 825 if (!layer)
851 return; 826 return;
852 827
853 for (size_t eventIndex = 0; eventIndex < events.size(); ++eventIndex) { 828 for (size_t eventIndex = 0; eventIndex < events.size(); ++eventIndex) {
854 if (layer->id() == events[eventIndex].layerId) { 829 if (layer->id() == events[eventIndex].layerId) {
855 if (events[eventIndex].type == AnimationEvent::Started) 830 if (events[eventIndex].type == AnimationEvent::Started)
856 layer->notifyAnimationStarted(events[eventIndex], wallClockTime. ToDoubleT()); 831 layer->notifyAnimationStarted(events[eventIndex], wallClockTime. ToDoubleT());
857 else 832 else
858 layer->notifyAnimationFinished(wallClockTime.ToDoubleT()); 833 layer->notifyAnimationFinished(wallClockTime.ToDoubleT());
859 } 834 }
860 } 835 }
861 836
862 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex) 837 for (size_t childIndex = 0; childIndex < layer->children().size(); ++childIn dex)
863 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime); 838 setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime);
864 } 839 }
865 840
841 void LayerTreeHost::Register(LayerAnimationController* controller) {
842 // Controllers register themselves when they have new animations. We need
843 // to commit in this case.
844 setNeedsCommit();
845 m_activeAnimationControllers.insert(controller);
846 }
847
848 void LayerTreeHost::Unregister(LayerAnimationController* controller) {
849 if (ContainsKey(m_activeAnimationControllers, controller))
850 m_activeAnimationControllers.erase(controller);
851 }
852
866 } // namespace cc 853 } // namespace cc
OLDNEW
« cc/layer_tree_host.h ('K') | « cc/layer_tree_host.h ('k') | cc/layer_tree_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698