• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef ANIMATORMANAGER_H
17 #define ANIMATORMANAGER_H
18 
19 #include <cutils/compiler.h>
20 #include <utils/StrongPointer.h>
21 
22 #include <vector>
23 
24 #include "utils/Macros.h"
25 
26 namespace android {
27 namespace uirenderer {
28 
29 class AnimationHandle;
30 class BaseRenderNodeAnimator;
31 class RenderNode;
32 class TreeInfo;
33 
34 // Responsible for managing the animators for a single RenderNode
35 class AnimatorManager {
36     PREVENT_COPY_AND_ASSIGN(AnimatorManager);
37 
38 public:
39     explicit AnimatorManager(RenderNode& parent);
40     ~AnimatorManager();
41 
42     void addAnimator(const sp<BaseRenderNodeAnimator>& animator);
43     void removeAnimator(const sp<BaseRenderNodeAnimator>& animator);
44 
45     void setAnimationHandle(AnimationHandle* handle);
hasAnimationHandle()46     bool hasAnimationHandle() { return mAnimationHandle; }
47 
48     void pushStaging();
49     void onAnimatorTargetChanged(BaseRenderNodeAnimator* animator);
50 
51     // Returns the combined dirty mask of all animators run
52     uint32_t animate(TreeInfo& info);
53 
54     void animateNoDamage(TreeInfo& info);
55 
56     // Hard-ends all animators. May only be called on the UI thread.
57     void endAllStagingAnimators();
58 
59     void forceEndAnimators();
60 
61     // Hard-ends all animators that have been pushed. Used for cleanup if
62     // the ActivityContext is being destroyed
63     void endAllActiveAnimators();
64 
hasAnimators()65     bool hasAnimators() { return mAnimators.size(); }
66 
67 private:
68     uint32_t animateCommon(TreeInfo& info);
69 
70     RenderNode& mParent;
71     AnimationHandle* mAnimationHandle;
72 
73     // To improve the efficiency of resizing & removing from the vector
74     std::vector<sp<BaseRenderNodeAnimator> > mNewAnimators;
75     std::vector<sp<BaseRenderNodeAnimator> > mAnimators;
76 
77     bool mCancelAllAnimators;
78 };
79 
80 } /* namespace uirenderer */
81 } /* namespace android */
82 
83 #endif /* ANIMATORMANAGER_H */
84