diff options
-rw-r--r-- | cc/animation_registrar.cc | 7 | ||||
-rw-r--r-- | cc/layer.cc | 16 | ||||
-rw-r--r-- | cc/layer_animation_controller.h | 1 | ||||
-rw-r--r-- | cc/layer_tree_host.cc | 3 | ||||
-rw-r--r-- | cc/layer_unittest.cc | 38 | ||||
-rw-r--r-- | content/renderer/gpu/render_widget_compositor.cc | 6 | ||||
-rw-r--r-- | content/renderer/gpu/render_widget_compositor.h | 1 |
7 files changed, 40 insertions, 32 deletions
diff --git a/cc/animation_registrar.cc b/cc/animation_registrar.cc index 5eb7a81..13b6a21 100644 --- a/cc/animation_registrar.cc +++ b/cc/animation_registrar.cc @@ -9,7 +9,12 @@ namespace cc { AnimationRegistrar::AnimationRegistrar() { } -AnimationRegistrar::~AnimationRegistrar() { } +AnimationRegistrar::~AnimationRegistrar() +{ + AnimationControllerMap copy = all_animation_controllers_; + for (AnimationControllerMap::iterator iter = copy.begin(); iter != copy.end(); ++iter) + (*iter).second->setAnimationRegistrar(NULL); +} scoped_refptr<LayerAnimationController> AnimationRegistrar::GetAnimationControllerForId(int id) diff --git a/cc/layer.cc b/cc/layer.cc index b08bbcd..d129817 100644 --- a/cc/layer.cc +++ b/cc/layer.cc @@ -790,22 +790,9 @@ bool Layer::IsActive() const bool Layer::addAnimation(scoped_ptr <Animation> animation) { - // WebCore currently assumes that accelerated animations will start soon - // after the animation is added. However we cannot guarantee that if we do - // not have a layerTreeHost that will setNeedsCommit(). - // Unfortunately, the fix below to guarantee correctness causes performance - // regressions on Android, since Android has shipped for a long time - // with all animations accelerated. For this reason, we will live with - // this bug only on Android until the bug is fixed. - // http://crbug.com/129683 -#if !defined(OS_ANDROID) - if (!m_layerTreeHost) + if (!m_layerAnimationController->animationRegistrar()) return false; - if (!m_layerTreeHost->settings().acceleratedAnimationEnabled) - return false; -#endif - m_layerAnimationController->addAnimation(animation.Pass()); setNeedsCommit(); return true; @@ -852,6 +839,7 @@ scoped_refptr<LayerAnimationController> Layer::releaseLayerAnimationController() scoped_refptr<LayerAnimationController> toReturn = m_layerAnimationController; m_layerAnimationController = LayerAnimationController::create(id()); m_layerAnimationController->addObserver(this); + m_layerAnimationController->setAnimationRegistrar(toReturn->animationRegistrar()); return toReturn; } diff --git a/cc/layer_animation_controller.h b/cc/layer_animation_controller.h index aa91b25..464be36 100644 --- a/cc/layer_animation_controller.h +++ b/cc/layer_animation_controller.h @@ -79,6 +79,7 @@ public: void setForceSync() { m_forceSync = true; } void setAnimationRegistrar(AnimationRegistrar*); + AnimationRegistrar* animationRegistrar() { return m_registrar; } void addObserver(LayerAnimationValueObserver*); void removeObserver(LayerAnimationValueObserver*); diff --git a/cc/layer_tree_host.cc b/cc/layer_tree_host.cc index 4d935df..3c6ead4 100644 --- a/cc/layer_tree_host.cc +++ b/cc/layer_tree_host.cc @@ -90,8 +90,9 @@ LayerTreeHost::LayerTreeHost(LayerTreeHostClient* client, const LayerTreeSetting , m_backgroundColor(SK_ColorWHITE) , m_hasTransparentBackground(false) , m_partialTextureUpdateRequests(0) - , m_animationRegistrar(AnimationRegistrar::create()) { + if (m_settings.acceleratedAnimationEnabled) + m_animationRegistrar = AnimationRegistrar::create(); numLayerTreeInstances++; } diff --git a/cc/layer_unittest.cc b/cc/layer_unittest.cc index 5eb9e2e..6fdf2bc 100644 --- a/cc/layer_unittest.cc +++ b/cc/layer_unittest.cc @@ -689,6 +689,13 @@ public: return host.Pass(); } + static scoped_ptr<FakeLayerImplTreeHost> create(LayerTreeSettings settings) + { + scoped_ptr<FakeLayerImplTreeHost> host(new FakeLayerImplTreeHost(settings)); + host->initialize(scoped_ptr<Thread>(NULL)); + return host.Pass(); + } + private: FakeLayerImplTreeHost(const LayerTreeSettings& settings) : LayerTreeHost(&m_client, settings) @@ -883,31 +890,30 @@ static bool addTestAnimation(Layer* layer) return layer->addAnimation(animation.Pass()); } -TEST(LayerLayerTreeHostTest, shouldNotAddAnimationWithoutLayerTreeHost) +TEST(LayerLayerTreeHostTest, shouldNotAddAnimationWithoutAnimationRegistrar) { - // Currently, WebCore assumes that animations will be started immediately / very soon - // if a composited layer's addAnimation() returns true. However, without a layerTreeHost, - // layers cannot actually animate yet. So, to prevent violating this WebCore assumption, - // the animation should not be accepted if the layer doesn't already have a layerTreeHost. - scoped_refptr<Layer> layer = Layer::create(); - // Case 1: without a layerTreeHost, the animation should not be accepted. -#if defined(OS_ANDROID) - // All animations are enabled on Android to avoid performance regressions. - // Other platforms will be enabled with http://crbug.com/129683 - EXPECT_TRUE(addTestAnimation(layer.get())); -#else + // Case 1: without a LayerTreeHost and without an AnimationRegistrar, the + // animation should not be accepted. EXPECT_FALSE(addTestAnimation(layer.get())); -#endif - scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::create()); + scoped_ptr<AnimationRegistrar> registrar = AnimationRegistrar::create(); + layer->layerAnimationController()->setAnimationRegistrar(registrar.get()); + + // Case 2: with an AnimationRegistrar, the animation should be accepted. + EXPECT_TRUE(addTestAnimation(layer.get())); + + LayerTreeSettings settings; + settings.acceleratedAnimationEnabled = false; + scoped_ptr<FakeLayerImplTreeHost> layerTreeHost(FakeLayerImplTreeHost::create(settings)); layerTreeHost->setRootLayer(layer.get()); layer->setLayerTreeHost(layerTreeHost.get()); assertLayerTreeHostMatchesForSubtree(layer.get(), layerTreeHost.get()); - // Case 2: with a layerTreeHost, the animation should be accepted. - EXPECT_TRUE(addTestAnimation(layer.get())); + // Case 3: with a LayerTreeHost where accelerated animation is disabled, the + // animation should be rejected. + EXPECT_FALSE(addTestAnimation(layer.get())); } } // namespace diff --git a/content/renderer/gpu/render_widget_compositor.cc b/content/renderer/gpu/render_widget_compositor.cc index 35bf2e8..04b2c09 100644 --- a/content/renderer/gpu/render_widget_compositor.cc +++ b/content/renderer/gpu/render_widget_compositor.cc @@ -390,6 +390,12 @@ void RenderWidgetCompositor::didStopFlinging() { layer_tree_host_->didStopFlinging(); } +void RenderWidgetCompositor::registerForAnimations(WebKit::WebLayer* layer) { + cc::Layer* cc_layer = static_cast<WebKit::WebLayerImpl*>(layer)->layer(); + cc_layer->layerAnimationController()->setAnimationRegistrar( + layer_tree_host_->animationRegistrar()); +} + bool RenderWidgetCompositor::compositeAndReadback(void *pixels, const WebRect& rect) { return layer_tree_host_->compositeAndReadback(pixels, rect); diff --git a/content/renderer/gpu/render_widget_compositor.h b/content/renderer/gpu/render_widget_compositor.h index 9f53fb1..c047082 100644 --- a/content/renderer/gpu/render_widget_compositor.h +++ b/content/renderer/gpu/render_widget_compositor.h @@ -69,6 +69,7 @@ class RenderWidgetCompositor : public WebKit::WebLayerTreeView, virtual bool compositeAndReadback(void *pixels, const WebKit::WebRect& rect); virtual void finishAllRendering(); virtual void setDeferCommits(bool defer_commits); + virtual void registerForAnimations(WebKit::WebLayer* layer); virtual void renderingStats(WebKit::WebRenderingStats& stats) const {} virtual void setShowFPSCounter(bool show); virtual void setShowPaintRects(bool show); |