TreeInfo.h revision e2e53a7079733694bd52dbce665e9ceff21e9727
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 "utils/Macros.h"
24
25namespace android {
26namespace uirenderer {
27
28namespace renderthread {
29class CanvasContext;
30}
31
32class DamageAccumulator;
33class OpenGLRenderer;
34class RenderState;
35
36class ErrorHandler {
37public:
38    virtual void onError(const std::string& message) = 0;
39protected:
40    ~ErrorHandler() {}
41};
42
43// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN
44class TreeInfo {
45    PREVENT_COPY_AND_ASSIGN(TreeInfo);
46public:
47    enum TraversalMode {
48        // The full monty - sync, push, run animators, etc... Used by DrawFrameTask
49        // May only be used if both the UI thread and RT thread are blocked on the
50        // prepare
51        MODE_FULL,
52        // Run only what can be done safely on RT thread. Currently this only means
53        // animators, but potentially things like SurfaceTexture updates
54        // could be handled by this as well if there are no listeners
55        MODE_RT_ONLY,
56    };
57
58    TreeInfo(TraversalMode mode, renderthread::CanvasContext& canvasContext)
59            : mode(mode)
60            , prepareTextures(mode == MODE_FULL)
61            , canvasContext(canvasContext)
62    {}
63
64    TraversalMode mode;
65    // TODO: Remove this? Currently this is used to signal to stop preparing
66    // textures if we run out of cache space.
67    bool prepareTextures;
68    renderthread::CanvasContext& canvasContext;
69    // TODO: buildLayer uses this to suppress running any animations, but this
70    // should probably be refactored somehow. The reason this is done is
71    // because buildLayer is not setup for injecting the animationHook, as well
72    // as this being otherwise wasted work as all the animators will be
73    // re-evaluated when the frame is actually drawn
74    bool runAnimations = true;
75
76    // Must not be null during actual usage
77    DamageAccumulator* damageAccumulator = nullptr;
78    // The renderer that will be drawing the next frame. Use this to push any
79    // layer updates or similar. May be NULL.
80    OpenGLRenderer* renderer = nullptr;
81    ErrorHandler* errorHandler = nullptr;
82
83    struct Out {
84        bool hasFunctors = false;
85        // This is only updated if evaluateAnimations is true
86        bool hasAnimations = false;
87        // This is set to true if there is an animation that RenderThread cannot
88        // animate itself, such as if hasFunctors is true
89        // This is only set if hasAnimations is true
90        bool requiresUiRedraw = false;
91        // This is set to true if draw() can be called this frame
92        // false means that we must delay until the next vsync pulse as frame
93        // production is outrunning consumption
94        // NOTE that if this is false CanvasContext will set either requiresUiRedraw
95        // *OR* will post itself for the next vsync automatically, use this
96        // only to avoid calling draw()
97        bool canDrawThisFrame = true;
98    } out;
99
100    // TODO: Damage calculations
101};
102
103} /* namespace uirenderer */
104} /* namespace android */
105
106#endif /* TREEINFO_H */
107