John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 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 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 19 | #include <cutils/compiler.h> |
| 20 | #include <utils/StrongPointer.h> |
| 21 | |
Nader Jawad | 528b0d2 | 2022-05-10 13:58:36 -0700 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 24 | #include "utils/Macros.h" |
| 25 | |
| 26 | namespace android { |
| 27 | namespace uirenderer { |
| 28 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 29 | class AnimationHandle; |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 30 | class BaseRenderNodeAnimator; |
| 31 | class RenderNode; |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 32 | class TreeInfo; |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 33 | |
| 34 | // Responsible for managing the animators for a single RenderNode |
| 35 | class AnimatorManager { |
| 36 | PREVENT_COPY_AND_ASSIGN(AnimatorManager); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 37 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 38 | public: |
Chih-Hung Hsieh | faecb78 | 2016-07-21 11:23:06 -0700 | [diff] [blame] | 39 | explicit AnimatorManager(RenderNode& parent); |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 40 | ~AnimatorManager(); |
| 41 | |
| 42 | void addAnimator(const sp<BaseRenderNodeAnimator>& animator); |
Doris Liu | 8b08320 | 2016-02-19 21:46:06 +0000 | [diff] [blame] | 43 | void removeAnimator(const sp<BaseRenderNodeAnimator>& animator); |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 44 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 45 | void setAnimationHandle(AnimationHandle* handle); |
| 46 | bool hasAnimationHandle() { return mAnimationHandle; } |
| 47 | |
| 48 | void pushStaging(); |
Doris Liu | 8b08320 | 2016-02-19 21:46:06 +0000 | [diff] [blame] | 49 | void onAnimatorTargetChanged(BaseRenderNodeAnimator* animator); |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 50 | |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 51 | // Returns the combined dirty mask of all animators run |
| 52 | uint32_t animate(TreeInfo& info); |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 53 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 54 | void animateNoDamage(TreeInfo& info); |
| 55 | |
John Reck | e2478d4 | 2014-09-03 16:46:05 -0700 | [diff] [blame] | 56 | // Hard-ends all animators. May only be called on the UI thread. |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame] | 57 | void endAllStagingAnimators(); |
John Reck | e2478d4 | 2014-09-03 16:46:05 -0700 | [diff] [blame] | 58 | |
Nader Jawad | 528b0d2 | 2022-05-10 13:58:36 -0700 | [diff] [blame] | 59 | void forceEndAnimators(); |
| 60 | |
John Reck | e2478d4 | 2014-09-03 16:46:05 -0700 | [diff] [blame] | 61 | // Hard-ends all animators that have been pushed. Used for cleanup if |
| 62 | // the ActivityContext is being destroyed |
| 63 | void endAllActiveAnimators(); |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 64 | |
| 65 | bool hasAnimators() { return mAnimators.size(); } |
| 66 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 67 | private: |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 68 | uint32_t animateCommon(TreeInfo& info); |
| 69 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 70 | RenderNode& mParent; |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 71 | AnimationHandle* mAnimationHandle; |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 72 | |
| 73 | // To improve the efficiency of resizing & removing from the vector |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 74 | std::vector<sp<BaseRenderNodeAnimator> > mNewAnimators; |
| 75 | std::vector<sp<BaseRenderNodeAnimator> > mAnimators; |
Nader Jawad | 528b0d2 | 2022-05-10 13:58:36 -0700 | [diff] [blame] | 76 | |
| 77 | bool mCancelAllAnimators; |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } /* namespace uirenderer */ |
| 81 | } /* namespace android */ |
| 82 | |
| 83 | #endif /* ANIMATORMANAGER_H */ |