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