Fedor Kudasov | 34a2576 | 2019-06-28 21:53:56 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | |
| 17 | #pragma once |
| 18 | |
Fedor Kudasov | 34a2576 | 2019-06-28 21:53:56 +0100 | [diff] [blame] | 19 | #include <set> |
| 20 | #include <vector> |
| 21 | |
| 22 | #include "AnimationContext.h" |
| 23 | #include "Animator.h" |
Fedor Kudasov | bc409cf | 2019-07-03 13:56:56 +0100 | [diff] [blame] | 24 | #include <IContextFactory.h> |
Fedor Kudasov | 34a2576 | 2019-06-28 21:53:56 +0100 | [diff] [blame] | 25 | #include "PropertyValuesAnimatorSet.h" |
| 26 | #include "RenderNode.h" |
| 27 | |
| 28 | namespace android::uirenderer { |
| 29 | |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame^] | 30 | class RootRenderNode : public RenderNode { |
Fedor Kudasov | 34a2576 | 2019-06-28 21:53:56 +0100 | [diff] [blame] | 31 | public: |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame^] | 32 | explicit RootRenderNode(std::unique_ptr<ErrorHandler> errorHandler) |
Fedor Kudasov | 34a2576 | 2019-06-28 21:53:56 +0100 | [diff] [blame] | 33 | : RenderNode(), mErrorHandler(std::move(errorHandler)) {} |
| 34 | |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame^] | 35 | virtual ~RootRenderNode() {} |
Fedor Kudasov | 34a2576 | 2019-06-28 21:53:56 +0100 | [diff] [blame] | 36 | |
| 37 | virtual void prepareTree(TreeInfo& info) override; |
| 38 | |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame^] | 39 | void attachAnimatingNode(RenderNode* animatingNode); |
Fedor Kudasov | 34a2576 | 2019-06-28 21:53:56 +0100 | [diff] [blame] | 40 | |
| 41 | void attachPendingVectorDrawableAnimators(); |
| 42 | |
| 43 | void detachAnimators(); |
| 44 | |
| 45 | void pauseAnimators(); |
| 46 | |
| 47 | void doAttachAnimatingNodes(AnimationContext* context); |
| 48 | |
| 49 | // Run VectorDrawable animators after prepareTree. |
| 50 | void runVectorDrawableAnimators(AnimationContext* context, TreeInfo& info); |
| 51 | |
| 52 | void trimPausedVDAnimators(AnimationContext* context); |
| 53 | |
| 54 | void pushStagingVectorDrawableAnimators(AnimationContext* context); |
| 55 | |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame^] | 56 | void destroy(); |
Fedor Kudasov | 34a2576 | 2019-06-28 21:53:56 +0100 | [diff] [blame] | 57 | |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame^] | 58 | void addVectorDrawableAnimator(PropertyValuesAnimatorSet* anim); |
Fedor Kudasov | 34a2576 | 2019-06-28 21:53:56 +0100 | [diff] [blame] | 59 | |
| 60 | private: |
| 61 | const std::unique_ptr<ErrorHandler> mErrorHandler; |
| 62 | std::vector<sp<RenderNode> > mPendingAnimatingRenderNodes; |
| 63 | std::set<sp<PropertyValuesAnimatorSet> > mPendingVectorDrawableAnimators; |
| 64 | std::set<sp<PropertyValuesAnimatorSet> > mRunningVDAnimators; |
| 65 | // mPausedVDAnimators stores a list of animators that have not yet passed the finish time, but |
| 66 | // their VectorDrawable targets are no longer in the DisplayList. We skip these animators when |
| 67 | // render thread runs animators independent of UI thread (i.e. RT_ONLY mode). These animators |
| 68 | // need to be re-activated once their VD target is added back into DisplayList. Since that could |
| 69 | // only happen when we do a full sync, we need to make sure to pulse these paused animators at |
| 70 | // full sync. If any animator's VD target is found in DisplayList during a full sync, we move |
| 71 | // the animator back to the running list. |
| 72 | std::set<sp<PropertyValuesAnimatorSet> > mPausedVDAnimators; |
| 73 | |
| 74 | void detachVectorDrawableAnimator(PropertyValuesAnimatorSet* anim); |
| 75 | }; |
| 76 | |
Fedor Kudasov | 09cfce0 | 2019-07-04 09:41:13 +0100 | [diff] [blame] | 77 | #ifdef __ANDROID__ // Layoutlib does not support Animations |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame^] | 78 | class ContextFactoryImpl : public IContextFactory { |
Fedor Kudasov | 34a2576 | 2019-06-28 21:53:56 +0100 | [diff] [blame] | 79 | public: |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame^] | 80 | explicit ContextFactoryImpl(RootRenderNode* rootNode) : mRootNode(rootNode) {} |
Fedor Kudasov | 34a2576 | 2019-06-28 21:53:56 +0100 | [diff] [blame] | 81 | |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame^] | 82 | virtual AnimationContext* createAnimationContext(renderthread::TimeLord& clock) override; |
Fedor Kudasov | 34a2576 | 2019-06-28 21:53:56 +0100 | [diff] [blame] | 83 | |
| 84 | private: |
| 85 | RootRenderNode* mRootNode; |
| 86 | }; |
Fedor Kudasov | 09cfce0 | 2019-07-04 09:41:13 +0100 | [diff] [blame] | 87 | #endif |
Fedor Kudasov | 34a2576 | 2019-06-28 21:53:56 +0100 | [diff] [blame] | 88 | |
| 89 | } // namespace android::uirenderer |