12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright 2012 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CC_ANIMATION_ANIMATION_REGISTRAR_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CC_ANIMATION_ANIMATION_REGISTRAR_H_ 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "base/containers/hash_tables.h" 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/ref_counted.h" 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/scoped_ptr.h" 112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "cc/base/cc_export.h" 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace cc { 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class LayerAnimationController; 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class CC_EXPORT AnimationRegistrar { 182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) public: 192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) typedef base::hash_map<int, LayerAnimationController*> AnimationControllerMap; 202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static scoped_ptr<AnimationRegistrar> Create() { 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return make_scoped_ptr(new AnimationRegistrar()); 232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~AnimationRegistrar(); 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // If an animation has been registered for the given id, return it. Otherwise 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // creates a new one and returns a scoped_refptr to it. 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) scoped_refptr<LayerAnimationController> GetAnimationControllerForId(int id); 302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Registers the given animation controller as active. An active animation 322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // controller is one that has a running animation that needs to be ticked. 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void DidActivateAnimationController(LayerAnimationController* controller); 342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Unregisters the given animation controller. When this happens, the 362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // animation controller will no longer be ticked (since it's not active). It 372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // is not an error to call this function with a deactivated controller. 382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void DidDeactivateAnimationController(LayerAnimationController* controller); 392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Registers the given controller as alive. 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void RegisterAnimationController(LayerAnimationController* controller); 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Unregisters the given controller as alive. 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void UnregisterAnimationController(LayerAnimationController* controller); 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const AnimationControllerMap& active_animation_controllers() const { 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return active_animation_controllers_; 482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const AnimationControllerMap& all_animation_controllers() const { 512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return all_animation_controllers_; 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 54116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch void set_supports_scroll_animations(bool supports_scroll_animations) { 55116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch supports_scroll_animations_ = supports_scroll_animations; 56116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 57116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 58116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool supports_scroll_animations() { return supports_scroll_animations_; } 59116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AnimationRegistrar(); 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AnimationControllerMap active_animation_controllers_; 642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AnimationControllerMap all_animation_controllers_; 652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 66116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch bool supports_scroll_animations_; 67116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(AnimationRegistrar); 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}; 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace cc 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // CC_ANIMATION_ANIMATION_REGISTRAR_H_ 74