168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck/*
268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck * Copyright (C) 2014 The Android Open Source Project
368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck *
468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck * Licensed under the Apache License, Version 2.0 (the "License");
568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck * you may not use this file except in compliance with the License.
668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck * You may obtain a copy of the License at
768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck *
868bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck *      http://www.apache.org/licenses/LICENSE-2.0
968bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck *
1068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck * Unless required by applicable law or agreed to in writing, software
1168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck * distributed under the License is distributed on an "AS IS" BASIS,
1268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck * See the License for the specific language governing permissions and
1468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck * limitations under the License.
1568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck */
1668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck#ifndef ANIMATORMANAGER_H
1768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck#define ANIMATORMANAGER_H
1868bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
1968bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck#include <vector>
2068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
2168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck#include <cutils/compiler.h>
2268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck#include <utils/StrongPointer.h>
2368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
2468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck#include "utils/Macros.h"
2568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
2668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Recknamespace android {
2768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Recknamespace uirenderer {
2868bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
29119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reckclass AnimationHandle;
3068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reckclass BaseRenderNodeAnimator;
3168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reckclass RenderNode;
322dc236b2bae13b9a0ed9b3f7320502aecd7983b3Tom Hudsonclass TreeInfo;
3368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
3468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck// Responsible for managing the animators for a single RenderNode
3568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reckclass AnimatorManager {
3668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    PREVENT_COPY_AND_ASSIGN(AnimatorManager);
3768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reckpublic:
38faecb78a6b11c780db47bc940ca7662899ab5d5eChih-Hung Hsieh    explicit AnimatorManager(RenderNode& parent);
3968bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    ~AnimatorManager();
4068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
4168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    void addAnimator(const sp<BaseRenderNodeAnimator>& animator);
428b083206aef627b6445a8c6be8bf5bb1d778a7f8Doris Liu    void removeAnimator(const sp<BaseRenderNodeAnimator>& animator);
4368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
44119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck    void setAnimationHandle(AnimationHandle* handle);
45119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck    bool hasAnimationHandle() { return mAnimationHandle; }
46119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck
47119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck    void pushStaging();
488b083206aef627b6445a8c6be8bf5bb1d778a7f8Doris Liu    void onAnimatorTargetChanged(BaseRenderNodeAnimator* animator);
49119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck
50a7c2ea20c43ab797bef5801530687e22e83def8fJohn Reck    // Returns the combined dirty mask of all animators run
51a7c2ea20c43ab797bef5801530687e22e83def8fJohn Reck    uint32_t animate(TreeInfo& info);
5268bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
53119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck    void animateNoDamage(TreeInfo& info);
54119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck
55e2478d45ccbe5b6abb360ac9d44771b5f4a50bdeJohn Reck    // Hard-ends all animators. May only be called on the UI thread.
56e2478d45ccbe5b6abb360ac9d44771b5f4a50bdeJohn Reck    ANDROID_API void endAllStagingAnimators();
57e2478d45ccbe5b6abb360ac9d44771b5f4a50bdeJohn Reck
58e2478d45ccbe5b6abb360ac9d44771b5f4a50bdeJohn Reck    // Hard-ends all animators that have been pushed. Used for cleanup if
59e2478d45ccbe5b6abb360ac9d44771b5f4a50bdeJohn Reck    // the ActivityContext is being destroyed
60e2478d45ccbe5b6abb360ac9d44771b5f4a50bdeJohn Reck    void endAllActiveAnimators();
61119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck
62119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck    bool hasAnimators() { return mAnimators.size(); }
63119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck
6468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reckprivate:
65119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck    uint32_t animateCommon(TreeInfo& info);
66119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck
6768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    RenderNode& mParent;
68119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck    AnimationHandle* mAnimationHandle;
6968bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
7068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    // To improve the efficiency of resizing & removing from the vector
71c4bb185d41cfb960ed9a3178a4f8974c351abdb0Doris Liu    std::vector< sp<BaseRenderNodeAnimator> > mNewAnimators;
72c4bb185d41cfb960ed9a3178a4f8974c351abdb0Doris Liu    std::vector< sp<BaseRenderNodeAnimator> > mAnimators;
7368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck};
7468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
7568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck} /* namespace uirenderer */
7668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck} /* namespace android */
7768bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
7868bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck#endif /* ANIMATORMANAGER_H */
79