TreeInfo.h revision 5e00c7ce063116c11315639f0035aca8ad73e8cc
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 */
165e00c7ce063116c11315639f0035aca8ad73e8ccChris Craik
175e00c7ce063116c11315639f0035aca8ad73e8ccChris Craik#pragma once
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;
3444b49f070aafe8ad44efae87341121cce49ff11cJohn Reckclass RenderNode;
353b20251a355c88193c439f928a84ae69483fb488John Reckclass RenderState;
36e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
37c25e506f7fc08790c0532f927f31310a2ca778b7John Reckclass ErrorHandler {
38c25e506f7fc08790c0532f927f31310a2ca778b7John Reckpublic:
39c25e506f7fc08790c0532f927f31310a2ca778b7John Reck    virtual void onError(const std::string& message) = 0;
40c25e506f7fc08790c0532f927f31310a2ca778b7John Reckprotected:
41c25e506f7fc08790c0532f927f31310a2ca778b7John Reck    ~ErrorHandler() {}
42c25e506f7fc08790c0532f927f31310a2ca778b7John Reck};
43c25e506f7fc08790c0532f927f31310a2ca778b7John Reck
4444b49f070aafe8ad44efae87341121cce49ff11cJohn Reckclass TreeObserver {
4544b49f070aafe8ad44efae87341121cce49ff11cJohn Reckpublic:
4644b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    // Called when a RenderNode's parent count hits 0.
4744b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    // Due to the unordered nature of tree pushes, once prepareTree
4844b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    // is finished it is possible that the node was "resurrected" and has
4944b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    // a non-zero parent count.
5044b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    virtual void onMaybeRemovedFromTree(RenderNode* node) {}
5144b49f070aafe8ad44efae87341121cce49ff11cJohn Reckprotected:
5244b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    ~TreeObserver() {}
5344b49f070aafe8ad44efae87341121cce49ff11cJohn Reck};
5444b49f070aafe8ad44efae87341121cce49ff11cJohn Reck
55e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN
56e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reckclass TreeInfo {
57e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    PREVENT_COPY_AND_ASSIGN(TreeInfo);
58e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reckpublic:
59e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    enum TraversalMode {
60e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // The full monty - sync, push, run animators, etc... Used by DrawFrameTask
61e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // May only be used if both the UI thread and RT thread are blocked on the
62e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // prepare
63e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        MODE_FULL,
64e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // Run only what can be done safely on RT thread. Currently this only means
65e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // animators, but potentially things like SurfaceTexture updates
66e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // could be handled by this as well if there are no listeners
67e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        MODE_RT_ONLY,
68e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    };
69e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck
70e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik    TreeInfo(TraversalMode mode, renderthread::CanvasContext& canvasContext)
71e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik            : mode(mode)
72e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik            , prepareTextures(mode == MODE_FULL)
73e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik            , canvasContext(canvasContext)
7468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    {}
7568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
76ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne    TraversalMode mode;
77e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    // TODO: Remove this? Currently this is used to signal to stop preparing
78e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    // textures if we run out of cache space.
79e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    bool prepareTextures;
80e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik    renderthread::CanvasContext& canvasContext;
819eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    // TODO: buildLayer uses this to suppress running any animations, but this
829eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    // should probably be refactored somehow. The reason this is done is
839eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    // because buildLayer is not setup for injecting the animationHook, as well
849eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    // as this being otherwise wasted work as all the animators will be
859eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    // re-evaluated when the frame is actually drawn
86e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik    bool runAnimations = true;
8769e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik
8869e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik    // Must not be null during actual usage
89e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik    DamageAccumulator* damageAccumulator = nullptr;
900b7e8245db728d127ada698be63d78b33fc6e4daChris Craik
910b7e8245db728d127ada698be63d78b33fc6e4daChris Craik    LayerUpdateQueue* layerUpdateQueue = nullptr;
92e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik    ErrorHandler* errorHandler = nullptr;
93f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck
9444b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    // Optional, may be nullptr. Used to allow things to observe interesting
9544b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    // tree state changes
9644b49f070aafe8ad44efae87341121cce49ff11cJohn Reck    TreeObserver* observer = nullptr;
9744b49f070aafe8ad44efae87341121cce49ff11cJohn Reck
98f648108f83d4e74811919e9811efb8fcc184b8a3John Reck    int32_t windowInsetLeft = 0;
99f648108f83d4e74811919e9811efb8fcc184b8a3John Reck    int32_t windowInsetTop = 0;
100f648108f83d4e74811919e9811efb8fcc184b8a3John Reck    bool updateWindowPositions = false;
101f648108f83d4e74811919e9811efb8fcc184b8a3John Reck
102f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck    struct Out {
103e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik        bool hasFunctors = false;
104f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // This is only updated if evaluateAnimations is true
105e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik        bool hasAnimations = false;
106f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // This is set to true if there is an animation that RenderThread cannot
107f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // animate itself, such as if hasFunctors is true
108f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // This is only set if hasAnimations is true
109e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik        bool requiresUiRedraw = false;
110a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // This is set to true if draw() can be called this frame
111a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // false means that we must delay until the next vsync pulse as frame
112a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // production is outrunning consumption
113a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // NOTE that if this is false CanvasContext will set either requiresUiRedraw
114a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // *OR* will post itself for the next vsync automatically, use this
115a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // only to avoid calling draw()
116e2e53a7079733694bd52dbce665e9ceff21e9727Chris Craik        bool canDrawThisFrame = true;
117f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck    } out;
118e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
119e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    // TODO: Damage calculations
120e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck};
121e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
122e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} /* namespace uirenderer */
123e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} /* namespace android */
124