TreeInfo.h revision dcba6725e8b9d3eba9ad7a01258d6aa974feafba
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 TREEINFO_H
17#define TREEINFO_H
18
19#include <string>
20
21#include <utils/Timers.h>
22
23#include "DamageAccumulator.h"
24#include "utils/Macros.h"
25
26namespace android {
27namespace uirenderer {
28
29class BaseRenderNodeAnimator;
30class AnimationListener;
31class OpenGLRenderer;
32class RenderState;
33
34class AnimationHook {
35public:
36    virtual void callOnFinished(BaseRenderNodeAnimator* animator, AnimationListener* listener) = 0;
37protected:
38    ~AnimationHook() {}
39};
40
41class ErrorHandler {
42public:
43    virtual void onError(const std::string& message) = 0;
44protected:
45    ~ErrorHandler() {}
46};
47
48// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN
49class TreeInfo {
50    PREVENT_COPY_AND_ASSIGN(TreeInfo);
51public:
52    enum TraversalMode {
53        // The full monty - sync, push, run animators, etc... Used by DrawFrameTask
54        // May only be used if both the UI thread and RT thread are blocked on the
55        // prepare
56        MODE_FULL,
57        // Run only what can be done safely on RT thread. Currently this only means
58        // animators, but potentially things like SurfaceTexture updates
59        // could be handled by this as well if there are no listeners
60        MODE_RT_ONLY,
61    };
62
63    explicit TreeInfo(TraversalMode mode, RenderState& renderState)
64        : mode(mode)
65        , frameTimeMs(0)
66        , animationHook(NULL)
67        , prepareTextures(mode == MODE_FULL)
68        , damageAccumulator(NullDamageAccumulator::instance())
69        , renderState(renderState)
70        , renderer(NULL)
71        , errorHandler(NULL)
72    {}
73
74    explicit TreeInfo(TraversalMode mode, const TreeInfo& clone)
75        : mode(mode)
76        , frameTimeMs(clone.frameTimeMs)
77        , animationHook(clone.animationHook)
78        , prepareTextures(mode == MODE_FULL)
79        , damageAccumulator(clone.damageAccumulator)
80        , renderState(clone.renderState)
81        , renderer(clone.renderer)
82        , errorHandler(clone.errorHandler)
83    {}
84
85    const TraversalMode mode;
86    nsecs_t frameTimeMs;
87    AnimationHook* animationHook;
88    // TODO: Remove this? Currently this is used to signal to stop preparing
89    // textures if we run out of cache space.
90    bool prepareTextures;
91    // Must not be null
92    IDamageAccumulator* damageAccumulator;
93    RenderState& renderState;
94    // The renderer that will be drawing the next frame. Use this to push any
95    // layer updates or similar. May be NULL.
96    OpenGLRenderer* renderer;
97    ErrorHandler* errorHandler;
98
99    struct Out {
100        Out()
101            : hasFunctors(false)
102            , hasAnimations(false)
103            , requiresUiRedraw(false)
104            , canDrawThisFrame(true)
105        {}
106        bool hasFunctors;
107        // This is only updated if evaluateAnimations is true
108        bool hasAnimations;
109        // This is set to true if there is an animation that RenderThread cannot
110        // animate itself, such as if hasFunctors is true
111        // This is only set if hasAnimations is true
112        bool requiresUiRedraw;
113        // This is set to true if draw() can be called this frame
114        // false means that we must delay until the next vsync pulse as frame
115        // production is outrunning consumption
116        // NOTE that if this is false CanvasContext will set either requiresUiRedraw
117        // *OR* will post itself for the next vsync automatically, use this
118        // only to avoid calling draw()
119        bool canDrawThisFrame;
120    } out;
121
122    // TODO: Damage calculations
123};
124
125} /* namespace uirenderer */
126} /* namespace android */
127
128#endif /* TREEINFO_H */
129