blob: 9575391a8b3ff6579505d1b7779ff26c04416c8f [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);
John Reck1bcacfd2017-11-03 10:12:19 -070037
John Reck68bfe0a2014-06-24 15:34:58 -070038public:
Chih-Hung Hsiehfaecb782016-07-21 11:23:06 -070039 explicit AnimatorManager(RenderNode& parent);
John Reck68bfe0a2014-06-24 15:34:58 -070040 ~AnimatorManager();
41
42 void addAnimator(const sp<BaseRenderNodeAnimator>& animator);
Doris Liu8b083202016-02-19 21:46:06 +000043 void removeAnimator(const sp<BaseRenderNodeAnimator>& animator);
John Reck68bfe0a2014-06-24 15:34:58 -070044
John Reck119907c2014-08-14 09:02:01 -070045 void setAnimationHandle(AnimationHandle* handle);
46 bool hasAnimationHandle() { return mAnimationHandle; }
47
48 void pushStaging();
Doris Liu8b083202016-02-19 21:46:06 +000049 void onAnimatorTargetChanged(BaseRenderNodeAnimator* animator);
John Reck119907c2014-08-14 09:02:01 -070050
John Recka7c2ea22014-08-08 13:21:00 -070051 // Returns the combined dirty mask of all animators run
52 uint32_t animate(TreeInfo& info);
John Reck68bfe0a2014-06-24 15:34:58 -070053
John Reck119907c2014-08-14 09:02:01 -070054 void animateNoDamage(TreeInfo& info);
55
John Recke2478d42014-09-03 16:46:05 -070056 // Hard-ends all animators. May only be called on the UI thread.
57 ANDROID_API void endAllStagingAnimators();
58
59 // Hard-ends all animators that have been pushed. Used for cleanup if
60 // the ActivityContext is being destroyed
61 void endAllActiveAnimators();
John Reck119907c2014-08-14 09:02:01 -070062
63 bool hasAnimators() { return mAnimators.size(); }
64
John Reck68bfe0a2014-06-24 15:34:58 -070065private:
John Reck119907c2014-08-14 09:02:01 -070066 uint32_t animateCommon(TreeInfo& info);
67
John Reck68bfe0a2014-06-24 15:34:58 -070068 RenderNode& mParent;
John Reck119907c2014-08-14 09:02:01 -070069 AnimationHandle* mAnimationHandle;
John Reck68bfe0a2014-06-24 15:34:58 -070070
71 // To improve the efficiency of resizing & removing from the vector
John Reck1bcacfd2017-11-03 10:12:19 -070072 std::vector<sp<BaseRenderNodeAnimator> > mNewAnimators;
73 std::vector<sp<BaseRenderNodeAnimator> > mAnimators;
John Reck68bfe0a2014-06-24 15:34:58 -070074};
75
76} /* namespace uirenderer */
77} /* namespace android */
78
79#endif /* ANIMATORMANAGER_H */