blob: 61f6179d217ca970088674eed0f5f93947d0884c [file] [log] [blame]
John Reck68bfe0a2014-06-24 15:34:58 -07001/*
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 <vector>
20
21#include <cutils/compiler.h>
22#include <utils/StrongPointer.h>
23
John Reck68bfe0a2014-06-24 15:34:58 -070024#include "utils/Macros.h"
25
26namespace android {
27namespace uirenderer {
28
John Reck119907c2014-08-14 09:02:01 -070029class AnimationHandle;
John Reck68bfe0a2014-06-24 15:34:58 -070030class BaseRenderNodeAnimator;
31class RenderNode;
Tom Hudson2dc236b2014-10-15 15:46:42 -040032class TreeInfo;
John Reck68bfe0a2014-06-24 15:34:58 -070033
34// Responsible for managing the animators for a single RenderNode
35class AnimatorManager {
36 PREVENT_COPY_AND_ASSIGN(AnimatorManager);
37public:
38 AnimatorManager(RenderNode& parent);
39 ~AnimatorManager();
40
41 void addAnimator(const sp<BaseRenderNodeAnimator>& animator);
Doris Liu8b083202016-02-19 21:46:06 +000042 void removeAnimator(const sp<BaseRenderNodeAnimator>& animator);
John Reck68bfe0a2014-06-24 15:34:58 -070043
John Reck119907c2014-08-14 09:02:01 -070044 void setAnimationHandle(AnimationHandle* handle);
45 bool hasAnimationHandle() { return mAnimationHandle; }
46
47 void pushStaging();
Doris Liu8b083202016-02-19 21:46:06 +000048 void onAnimatorTargetChanged(BaseRenderNodeAnimator* animator);
John Reck119907c2014-08-14 09:02:01 -070049
John Recka7c2ea22014-08-08 13:21:00 -070050 // Returns the combined dirty mask of all animators run
51 uint32_t animate(TreeInfo& info);
John Reck68bfe0a2014-06-24 15:34:58 -070052
John Reck119907c2014-08-14 09:02:01 -070053 void animateNoDamage(TreeInfo& info);
54
John Recke2478d42014-09-03 16:46:05 -070055 // Hard-ends all animators. May only be called on the UI thread.
56 ANDROID_API void endAllStagingAnimators();
57
58 // Hard-ends all animators that have been pushed. Used for cleanup if
59 // the ActivityContext is being destroyed
60 void endAllActiveAnimators();
John Reck119907c2014-08-14 09:02:01 -070061
62 bool hasAnimators() { return mAnimators.size(); }
63
John Reck68bfe0a2014-06-24 15:34:58 -070064private:
John Reck119907c2014-08-14 09:02:01 -070065 uint32_t animateCommon(TreeInfo& info);
66
John Reck68bfe0a2014-06-24 15:34:58 -070067 RenderNode& mParent;
John Reck119907c2014-08-14 09:02:01 -070068 AnimationHandle* mAnimationHandle;
John Reck68bfe0a2014-06-24 15:34:58 -070069
70 // To improve the efficiency of resizing & removing from the vector
Doris Liuc4bb1852016-02-19 21:39:21 +000071 std::vector< sp<BaseRenderNodeAnimator> > mNewAnimators;
72 std::vector< sp<BaseRenderNodeAnimator> > mAnimators;
John Reck68bfe0a2014-06-24 15:34:58 -070073};
74
75} /* namespace uirenderer */
76} /* namespace android */
77
78#endif /* ANIMATORMANAGER_H */