summaryrefslogtreecommitdiffstats
path: root/cc
diff options
context:
space:
mode:
authorajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-18 00:32:26 +0000
committerajuma@chromium.org <ajuma@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-18 00:32:26 +0000
commite10cd0281560fa50d635688bf05a1fb315441de9 (patch)
treec7a68f3bd2e1e11ba70316d47b7fc2cc118542da /cc
parentdeb682b1faa01604703d9fd659f8469b092dfd9e (diff)
downloadchromium_src-e10cd0281560fa50d635688bf05a1fb315441de9.zip
chromium_src-e10cd0281560fa50d635688bf05a1fb315441de9.tar.gz
chromium_src-e10cd0281560fa50d635688bf05a1fb315441de9.tar.bz2
cc: Define LayerAnimationObserver and allow LayerAnimationObservers to be registered on a Layer
This makes Layers notify each of their LayerAnimationObservers whenever an animation is started on the impl thread. This functionality is needed for threading ui animations. BUG=164206 Review URL: https://chromiumcodereview.appspot.com/11605002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173597 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r--cc/cc.gyp1
-rw-r--r--cc/layer.cc20
-rw-r--r--cc/layer.h6
-rw-r--r--cc/layer_animation_controller.cc2
-rw-r--r--cc/layer_animation_controller.h5
-rw-r--r--cc/layer_animation_controller_unittest.cc6
-rw-r--r--cc/layer_animation_observer.h18
7 files changed, 51 insertions, 7 deletions
diff --git a/cc/cc.gyp b/cc/cc.gyp
index 4133762..041864d 100644
--- a/cc/cc.gyp
+++ b/cc/cc.gyp
@@ -86,6 +86,7 @@
'layer.h',
'layer_animation_controller.cc',
'layer_animation_controller.h',
+ 'layer_animation_observer.h',
'layer_impl.cc',
'layer_impl.h',
'layer_iterator.cc',
diff --git a/cc/layer.cc b/cc/layer.cc
index 3519f14..51f4a59 100644
--- a/cc/layer.cc
+++ b/cc/layer.cc
@@ -63,6 +63,8 @@ Layer::Layer()
s_nextLayerId = 1;
m_layerId = s_nextLayerId++;
}
+
+ addLayerAnimationObserver(m_layerAnimationController.get());
}
Layer::~Layer()
@@ -779,10 +781,14 @@ void Layer::resumeAnimations(double monotonicTime)
void Layer::setLayerAnimationController(scoped_ptr<LayerAnimationController> layerAnimationController)
{
+ if (m_layerAnimationController)
+ removeLayerAnimationObserver(m_layerAnimationController.get());
+
m_layerAnimationController = layerAnimationController.Pass();
if (m_layerAnimationController) {
m_layerAnimationController->setClient(this);
m_layerAnimationController->setForceSync();
+ addLayerAnimationObserver(m_layerAnimationController.get());
}
setNeedsCommit();
}
@@ -801,7 +807,8 @@ bool Layer::hasActiveAnimation() const
void Layer::notifyAnimationStarted(const AnimationEvent& event, double wallClockTime)
{
- m_layerAnimationController->notifyAnimationStarted(event);
+ FOR_EACH_OBSERVER(LayerAnimationObserver, m_layerAnimationObservers,
+ OnAnimationStarted(event));
if (m_layerAnimationDelegate)
m_layerAnimationDelegate->notifyAnimationStarted(wallClockTime);
}
@@ -812,6 +819,17 @@ void Layer::notifyAnimationFinished(double wallClockTime)
m_layerAnimationDelegate->notifyAnimationFinished(wallClockTime);
}
+void Layer::addLayerAnimationObserver(LayerAnimationObserver* animationObserver)
+{
+ if (!m_layerAnimationObservers.HasObserver(animationObserver))
+ m_layerAnimationObservers.AddObserver(animationObserver);
+}
+
+void Layer::removeLayerAnimationObserver(LayerAnimationObserver* animationObserver)
+{
+ m_layerAnimationObservers.RemoveObserver(animationObserver);
+}
+
Region Layer::visibleContentOpaqueRegion() const
{
if (contentsOpaque())
diff --git a/cc/layer.h b/cc/layer.h
index ede6120..adca3b2 100644
--- a/cc/layer.h
+++ b/cc/layer.h
@@ -10,9 +10,11 @@
#include <vector>
#include "base/memory/ref_counted.h"
+#include "base/observer_list.h"
#include "cc/cc_export.h"
#include "cc/draw_properties.h"
#include "cc/layer_animation_controller.h"
+#include "cc/layer_animation_observer.h"
#include "cc/occlusion_tracker.h"
#include "cc/region.h"
#include "cc/render_surface.h"
@@ -277,6 +279,9 @@ public:
virtual void notifyAnimationStarted(const AnimationEvent&, double wallClockTime);
virtual void notifyAnimationFinished(double wallClockTime);
+ void addLayerAnimationObserver(LayerAnimationObserver* animationObserver);
+ void removeLayerAnimationObserver(LayerAnimationObserver* animationObserver);
+
virtual Region visibleContentOpaqueRegion() const;
virtual ScrollbarLayer* toScrollbarLayer();
@@ -340,6 +345,7 @@ private:
LayerTreeHost* m_layerTreeHost;
scoped_ptr<LayerAnimationController> m_layerAnimationController;
+ ObserverList<LayerAnimationObserver> m_layerAnimationObservers;
// Layer properties.
gfx::Size m_bounds;
diff --git a/cc/layer_animation_controller.cc b/cc/layer_animation_controller.cc
index 805f8fc..a45bb43 100644
--- a/cc/layer_animation_controller.cc
+++ b/cc/layer_animation_controller.cc
@@ -143,7 +143,7 @@ bool LayerAnimationController::isAnimatingProperty(ActiveAnimation::TargetProper
return false;
}
-void LayerAnimationController::notifyAnimationStarted(const AnimationEvent& event)
+void LayerAnimationController::OnAnimationStarted(const AnimationEvent& event)
{
for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
if (m_activeAnimations[i]->group() == event.groupId && m_activeAnimations[i]->targetProperty() == event.targetProperty && m_activeAnimations[i]->needsSynchronizedStartTime()) {
diff --git a/cc/layer_animation_controller.h b/cc/layer_animation_controller.h
index be55afe..e7a01e0 100644
--- a/cc/layer_animation_controller.h
+++ b/cc/layer_animation_controller.h
@@ -10,6 +10,7 @@
#include "base/memory/scoped_ptr.h"
#include "cc/animation_events.h"
#include "cc/cc_export.h"
+#include "cc/layer_animation_observer.h"
#include "cc/scoped_ptr_vector.h"
namespace gfx {
@@ -32,7 +33,7 @@ public:
virtual const gfx::Transform& transform() const = 0;
};
-class CC_EXPORT LayerAnimationController {
+class CC_EXPORT LayerAnimationController : public LayerAnimationObserver {
public:
static scoped_ptr<LayerAnimationController> create(LayerAnimationControllerClient*);
@@ -69,7 +70,7 @@ public:
// This is called in response to an animation being started on the impl thread. This
// function updates the corresponding main thread animation's start time.
- void notifyAnimationStarted(const AnimationEvent&);
+ virtual void OnAnimationStarted(const AnimationEvent&) OVERRIDE;
// If a sync is forced, then the next time animation updates are pushed to the impl
// thread, all animations will be transferred.
diff --git a/cc/layer_animation_controller_unittest.cc b/cc/layer_animation_controller_unittest.cc
index 4b2afa8..698fe77 100644
--- a/cc/layer_animation_controller_unittest.cc
+++ b/cc/layer_animation_controller_unittest.cc
@@ -64,7 +64,7 @@ TEST(LayerAnimationControllerTest, doNotClobberStartTimes)
// Synchronize the start times.
EXPECT_EQ(1u, events.size());
- controller->notifyAnimationStarted(events[0]);
+ controller->OnAnimationStarted(events[0]);
EXPECT_EQ(controller->getActiveAnimation(0, ActiveAnimation::Opacity)->startTime(), controllerImpl->getActiveAnimation(0, ActiveAnimation::Opacity)->startTime());
// Start the animation on the main thread. Should not affect the start time.
@@ -130,7 +130,7 @@ TEST(LayerAnimationControllerTest, doNotSyncFinishedAnimation)
// Notify main thread controller that the animation has started.
AnimationEvent animationStartedEvent(AnimationEvent::Started, 0, 0, ActiveAnimation::Opacity, 0);
- controller->notifyAnimationStarted(animationStartedEvent);
+ controller->OnAnimationStarted(animationStartedEvent);
// Force animation to complete on impl thread.
controllerImpl->removeAnimation(animationId);
@@ -186,7 +186,7 @@ TEST(LayerAnimationControllerTest, AnimationsWaitingForStartTimeDoNotFinishIfThe
EXPECT_EQ(0, dummy.opacity());
// Send the synchronized start time.
- controller->notifyAnimationStarted(AnimationEvent(AnimationEvent::Started, 0, 1, ActiveAnimation::Opacity, 2));
+ controller->OnAnimationStarted(AnimationEvent(AnimationEvent::Started, 0, 1, ActiveAnimation::Opacity, 2));
controller->animate(5, events.get());
EXPECT_EQ(1, dummy.opacity());
EXPECT_FALSE(controller->hasActiveAnimation());
diff --git a/cc/layer_animation_observer.h b/cc/layer_animation_observer.h
new file mode 100644
index 0000000..16a10b9
--- /dev/null
+++ b/cc/layer_animation_observer.h
@@ -0,0 +1,18 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CC_LAYER_ANIMATION_OBSERVER_H_
+#define CC_LAYER_ANIMATION_OBSERVER_H_
+
+namespace cc {
+
+class CC_EXPORT LayerAnimationObserver {
+ public:
+ virtual void OnAnimationStarted(const AnimationEvent& event) = 0;
+};
+
+} // namespace cc
+
+#endif // CC_LAYER_ANIMATION_OBSERVER_H_
+