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