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 | |
| 19 | #include <vector> |
| 20 | |
| 21 | #include <cutils/compiler.h> |
| 22 | #include <utils/StrongPointer.h> |
| 23 | |
| 24 | #include "TreeInfo.h" |
| 25 | #include "utils/Macros.h" |
| 26 | |
| 27 | namespace android { |
| 28 | namespace uirenderer { |
| 29 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 30 | class AnimationHandle; |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 31 | class BaseRenderNodeAnimator; |
| 32 | class RenderNode; |
| 33 | |
| 34 | // Responsible for managing the animators for a single RenderNode |
| 35 | class AnimatorManager { |
| 36 | PREVENT_COPY_AND_ASSIGN(AnimatorManager); |
| 37 | public: |
| 38 | AnimatorManager(RenderNode& parent); |
| 39 | ~AnimatorManager(); |
| 40 | |
| 41 | void addAnimator(const sp<BaseRenderNodeAnimator>& animator); |
| 42 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 43 | void setAnimationHandle(AnimationHandle* handle); |
| 44 | bool hasAnimationHandle() { return mAnimationHandle; } |
| 45 | |
| 46 | void pushStaging(); |
| 47 | |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 48 | // Returns the combined dirty mask of all animators run |
| 49 | uint32_t animate(TreeInfo& info); |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 50 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 51 | void animateNoDamage(TreeInfo& info); |
| 52 | |
John Reck | e2478d4 | 2014-09-03 16:46:05 -0700 | [diff] [blame] | 53 | // Hard-ends all animators. May only be called on the UI thread. |
| 54 | ANDROID_API void endAllStagingAnimators(); |
| 55 | |
| 56 | // Hard-ends all animators that have been pushed. Used for cleanup if |
| 57 | // the ActivityContext is being destroyed |
| 58 | void endAllActiveAnimators(); |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 59 | |
| 60 | bool hasAnimators() { return mAnimators.size(); } |
| 61 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 62 | private: |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 63 | uint32_t animateCommon(TreeInfo& info); |
| 64 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 65 | RenderNode& mParent; |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 66 | AnimationHandle* mAnimationHandle; |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 67 | |
| 68 | // To improve the efficiency of resizing & removing from the vector |
| 69 | // use manual ref counting instead of sp<>. |
| 70 | std::vector<BaseRenderNodeAnimator*> mNewAnimators; |
| 71 | std::vector<BaseRenderNodeAnimator*> mAnimators; |
| 72 | }; |
| 73 | |
| 74 | } /* namespace uirenderer */ |
| 75 | } /* namespace android */ |
| 76 | |
| 77 | #endif /* ANIMATORMANAGER_H */ |