1e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck/*
2e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * Copyright (C) 2014 The Android Open Source Project
3e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck *
4e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * Licensed under the Apache License, Version 2.0 (the "License");
5e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * you may not use this file except in compliance with the License.
6e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * You may obtain a copy of the License at
7e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck *
8e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck *      http://www.apache.org/licenses/LICENSE-2.0
9e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck *
10e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * Unless required by applicable law or agreed to in writing, software
11e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * distributed under the License is distributed on an "AS IS" BASIS,
12e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * See the License for the specific language governing permissions and
14e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck * limitations under the License.
15e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck */
16e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#ifndef TREEINFO_H
17e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#define TREEINFO_H
18e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
190b7e8245db728d127ada698be63d78b33fc6e4daChris Craik#include "utils/Macros.h"
20c25e506f7fc08790c0532f927f31310a2ca778b7John Reck
21e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#include <utils/Timers.h>
22e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
230b7e8245db728d127ada698be63d78b33fc6e4daChris Craik#include <string>
24e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck
25e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Recknamespace android {
26e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Recknamespace uirenderer {
27e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
28998a6d81896df8b662cc10ddeb35087b78b38d72John Recknamespace renderthread {
29998a6d81896df8b662cc10ddeb35087b78b38d72John Reckclass CanvasContext;
30998a6d81896df8b662cc10ddeb35087b78b38d72John Reck}
31998a6d81896df8b662cc10ddeb35087b78b38d72John Reck
322dc236b2bae13b9a0ed9b3f7320502aecd7983b3Tom Hudsonclass DamageAccumulator;
330b7e8245db728d127ada698be63d78b33fc6e4daChris Craikclass LayerUpdateQueue;
3425fbb3fa1138675379102a44405852555cefccbdJohn Reckclass OpenGLRenderer;
3544b49f070aafe8ad44efae87341121cce49ff11cJohn Reckclass RenderNode;
363b20251a355c88193c439f928a84ae69483fb488John Reckclass RenderState;
37e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
38c25e506f7fc08790c0532f927f31310a2ca778b7John Reckclass ErrorHandler {
39c25e506f7fc08790c0532f927f31310a2ca778b7John Reckpublic:
40c25e506f7fc08790c0532f927f31310a2ca778b7John Reck    virtual void onError(const std::string& message) = 0;
41c25e506f7fc08790c0532f927f31310a2ca778b7John Reckprotected:
42c25e506f7fc08790c0532f927f31310a2ca778b7John Reck    ~ErrorHandler() {}
43c25e506f7fc08790c0532f927f31310a2ca778b7John Reck};
44c25e506f7fc08790c0532f927f31310a2ca778b7John Reck
4544b49f070aafe8ad44efae87341121cce49ff11cJohn Reckclass TreeObserver {
4644b49f070aafe8ad44efae87341121cce49ff11cJohn Reckpublic:
4744b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    // Called when a RenderNode's parent count hits 0.
4844b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    // Due to the unordered nature of tree pushes, once prepareTree
4944b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    // is finished it is possible that the node was "resurrected" and has
5044b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    // a non-zero parent count.
5144b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    virtual void onMaybeRemovedFromTree(RenderNode* node) {}
5244b49f070aafe8ad44efae87341121cce49ff11cJohn Reckprotected:
5344b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    ~TreeObserver() {}
5444b49f070aafe8ad44efae87341121cce49ff11cJohn Reck};
5544b49f070aafe8ad44efae87341121cce49ff11cJohn Reck
56e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN
57e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reckclass TreeInfo {
58e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    PREVENT_COPY_AND_ASSIGN(TreeInfo);
59e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reckpublic:
60e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    enum TraversalMode {
61e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // The full monty - sync, push, run animators, etc... Used by DrawFrameTask
62e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // May only be used if both the UI thread and RT thread are blocked on the
63e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // prepare
64e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        MODE_FULL,
65e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // Run only what can be done safely on RT thread. Currently this only means
66e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // animators, but potentially things like SurfaceTexture updates
67e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // could be handled by this as well if there are no listeners
68e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        MODE_RT_ONLY,
69e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    };
70e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck
71e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik    TreeInfo(TraversalMode mode, renderthread::CanvasContext& canvasContext)
72e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik            : mode(mode)
73e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik            , prepareTextures(mode == MODE_FULL)
74e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik            , canvasContext(canvasContext)
7568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    {}
7668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
77ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne    TraversalMode mode;
78e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    // TODO: Remove this? Currently this is used to signal to stop preparing
79e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    // textures if we run out of cache space.
80e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    bool prepareTextures;
81e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik    renderthread::CanvasContext& canvasContext;
829eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    // TODO: buildLayer uses this to suppress running any animations, but this
839eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    // should probably be refactored somehow. The reason this is done is
849eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    // because buildLayer is not setup for injecting the animationHook, as well
859eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    // as this being otherwise wasted work as all the animators will be
869eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    // re-evaluated when the frame is actually drawn
87e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik    bool runAnimations = true;
8869e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik
8969e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik    // Must not be null during actual usage
90e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik    DamageAccumulator* damageAccumulator = nullptr;
910b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
920b7e8245db728d127ada698be63d78b33fc6e4daChris Craik#if HWUI_NEW_OPS
930b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    LayerUpdateQueue* layerUpdateQueue = nullptr;
940b7e8245db728d127ada698be63d78b33fc6e4daChris Craik#else
9525fbb3fa1138675379102a44405852555cefccbdJohn Reck    // The renderer that will be drawing the next frame. Use this to push any
9625fbb3fa1138675379102a44405852555cefccbdJohn Reck    // layer updates or similar. May be NULL.
97e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik    OpenGLRenderer* renderer = nullptr;
980b7e8245db728d127ada698be63d78b33fc6e4daChris Craik#endif
99e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik    ErrorHandler* errorHandler = nullptr;
100f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck
10144b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    // Optional, may be nullptr. Used to allow things to observe interesting
10244b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    // tree state changes
10344b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    TreeObserver* observer = nullptr;
10444b49f070aafe8ad44efae87341121cce49ff11cJohn Reck
105f648108f83d4e74811919e9811efb8fcc184b8a3John Reck    int32_t windowInsetLeft = 0;
106f648108f83d4e74811919e9811efb8fcc184b8a3John Reck    int32_t windowInsetTop = 0;
107f648108f83d4e74811919e9811efb8fcc184b8a3John Reck    bool updateWindowPositions = false;
108f648108f83d4e74811919e9811efb8fcc184b8a3John Reck
109f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck    struct Out {
110e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik        bool hasFunctors = false;
111f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // This is only updated if evaluateAnimations is true
112e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik        bool hasAnimations = false;
113f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // This is set to true if there is an animation that RenderThread cannot
114f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // animate itself, such as if hasFunctors is true
115f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // This is only set if hasAnimations is true
116e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik        bool requiresUiRedraw = false;
117a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // This is set to true if draw() can be called this frame
118a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // false means that we must delay until the next vsync pulse as frame
119a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // production is outrunning consumption
120a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // NOTE that if this is false CanvasContext will set either requiresUiRedraw
121a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // *OR* will post itself for the next vsync automatically, use this
122a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // only to avoid calling draw()
123e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik        bool canDrawThisFrame = true;
124f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck    } out;
125e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
126e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    // TODO: Damage calculations
127e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck};
128e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
129e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} /* namespace uirenderer */
130e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} /* namespace android */
131e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
132e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#endif /* TREEINFO_H */
133