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

Unified Diff: cc/layer_tree_host.cc

Issue 11598005: Ref count layer animation controllers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . 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 side-by-side diff with in-line comments
Download patch
Index: cc/layer_tree_host.cc
diff --git a/cc/layer_tree_host.cc b/cc/layer_tree_host.cc
index 9d7b6f3ebda97b76bfe5ab607216cfe5c0a42425..955580a433ff58cd85e8892a3b8f83cefd4346bf 100644
--- a/cc/layer_tree_host.cc
+++ b/cc/layer_tree_host.cc
@@ -7,6 +7,7 @@
#include "base/command_line.h"
#include "base/debug/trace_event.h"
#include "base/message_loop.h"
+#include "base/stl_util.h"
#include "base/string_number_conversions.h"
#include "cc/font_atlas.h"
#include "cc/heads_up_display_layer.h"
@@ -70,7 +71,6 @@ scoped_ptr<LayerTreeHost> LayerTreeHost::create(LayerTreeHostClient* client, con
LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSettings& settings)
: m_animating(false)
- , m_needsAnimateLayers(false)
, m_needsFullTreeSync(true)
, m_client(client)
, m_commitNumber(0)
@@ -128,6 +128,9 @@ LayerTreeHost::~LayerTreeHost()
RateLimiterMap::iterator it = m_rateLimiters.begin();
if (it != m_rateLimiters.end())
it->second->stop();
+
+ if (m_rootLayer)
+ m_rootLayer = 0;
enne (OOO) 2012/12/17 20:21:22 style nit: use NULL in Chromium-land. Also, pleas
}
void LayerTreeHost::setSurfaceReady()
@@ -280,11 +283,6 @@ void LayerTreeHost::finishCommitOnImplThread(LayerTreeHostImpl* hostImpl)
else
hostImpl->activeTree()->set_hud_layer(0);
- // We may have added an animation during the tree sync. This will cause both layer tree hosts
- // to visit their controllers.
- if (rootLayer() && m_needsAnimateLayers)
- hostImpl->setNeedsAnimateLayers();
-
hostImpl->activeTree()->set_source_frame_number(commitNumber());
hostImpl->setViewportSize(layoutViewportSize(), deviceViewportSize());
hostImpl->setDeviceScaleFactor(deviceScaleFactor());
@@ -418,12 +416,6 @@ void LayerTreeHost::setAnimationEvents(scoped_ptr<AnimationEventsVector> events,
setAnimationEventsRecursive(*events.get(), m_rootLayer.get(), wallClockTime);
}
-void LayerTreeHost::didAddAnimation()
-{
- m_needsAnimateLayers = true;
- m_proxy->didAddAnimation();
-}
-
void LayerTreeHost::setRootLayer(scoped_refptr<Layer> rootLayer)
{
if (m_rootLayer == rootLayer)
@@ -826,33 +818,16 @@ void LayerTreeHost::setDeviceScaleFactor(float deviceScaleFactor)
void LayerTreeHost::animateLayers(base::TimeTicks time)
{
- if (!m_settings.acceleratedAnimationEnabled || !m_needsAnimateLayers)
+ if (!m_settings.acceleratedAnimationEnabled || m_activeAnimationControllers.empty())
return;
TRACE_EVENT0("cc", "LayerTreeHostImpl::animateLayers");
- m_needsAnimateLayers = animateLayersRecursive(m_rootLayer.get(), time);
-}
-bool LayerTreeHost::animateLayersRecursive(Layer* current, base::TimeTicks time)
-{
- if (!current)
- return false;
-
- bool subtreeNeedsAnimateLayers = false;
- LayerAnimationController* currentController = current->layerAnimationController();
double monotonicTime = (time - base::TimeTicks()).InSecondsF();
- currentController->animate(monotonicTime, 0);
- // If the current controller still has an active animation, we must continue animating layers.
- if (currentController->hasActiveAnimation())
- subtreeNeedsAnimateLayers = true;
-
- for (size_t i = 0; i < current->children().size(); ++i) {
- if (animateLayersRecursive(current->children()[i].get(), time))
- subtreeNeedsAnimateLayers = true;
- }
-
- return subtreeNeedsAnimateLayers;
+ AnimationControllerMap copy = m_activeAnimationControllers;
+ for (AnimationControllerMap::iterator iter = copy.begin(); iter != copy.end(); ++iter)
+ (*iter).second->animate(monotonicTime, 0);
}
void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& events, Layer* layer, base::Time wallClockTime)
@@ -873,4 +848,37 @@ void LayerTreeHost::setAnimationEventsRecursive(const AnimationEventsVector& eve
setAnimationEventsRecursive(events, layer->children()[childIndex].get(), wallClockTime);
}
+scoped_refptr<LayerAnimationController> LayerTreeHost::GetAnimationControllerForId(int id)
+{
+ // On the main thread, animation controllers are created by the layers.
+ NOTREACHED();
+ return NULL;
+}
+
+void LayerTreeHost::DidActivateAnimationController(LayerAnimationController* controller)
+{
+ // Controllers register themselves when they have new animations. We need
+ // to commit in this case.
+ setNeedsCommit();
+ m_activeAnimationControllers[controller->id()] = controller;
+}
+
+void LayerTreeHost::DidDeactivateAnimationController(LayerAnimationController* controller)
+{
+ if (ContainsKey(m_activeAnimationControllers, controller->id()))
+ m_activeAnimationControllers.erase(controller->id());
+}
+
+void LayerTreeHost::RegisterAnimationController(LayerAnimationController* controller)
+{
+ m_allAnimationControllers[controller->id()] = controller;
+}
+
+void LayerTreeHost::UnregisterAnimationController(LayerAnimationController* controller)
+{
+ if (ContainsKey(m_allAnimationControllers, controller->id()))
+ m_allAnimationControllers.erase(controller->id());
+ DidDeactivateAnimationController(controller);
+}
+
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698