TreeInfo.h revision c25e506f7fc08790c0532f927f31310a2ca778b7
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
19c25e506f7fc08790c0532f927f31310a2ca778b7John Reck#include <string>
20c25e506f7fc08790c0532f927f31310a2ca778b7John Reck
21e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#include <utils/Timers.h>
22e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
23a447d29c65fb811cd184775a3476101a1cede929John Reck#include "DamageAccumulator.h"
24e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck#include "utils/Macros.h"
25e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck
26e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Recknamespace android {
27e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Recknamespace uirenderer {
28e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
29ff941dcd815021bb20d6504eb486acb1e50592c3John Reckclass BaseRenderNodeAnimator;
3052244fff29042926e21fa897ef5ab11148e35299John Reckclass AnimationListener;
3125fbb3fa1138675379102a44405852555cefccbdJohn Reckclass OpenGLRenderer;
32e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
3352244fff29042926e21fa897ef5ab11148e35299John Reckclass AnimationHook {
34e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reckpublic:
35ff941dcd815021bb20d6504eb486acb1e50592c3John Reck    virtual void callOnFinished(BaseRenderNodeAnimator* animator, AnimationListener* listener) = 0;
36e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reckprotected:
3752244fff29042926e21fa897ef5ab11148e35299John Reck    ~AnimationHook() {}
38e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck};
39e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
40c25e506f7fc08790c0532f927f31310a2ca778b7John Reckclass ErrorHandler {
41c25e506f7fc08790c0532f927f31310a2ca778b7John Reckpublic:
42c25e506f7fc08790c0532f927f31310a2ca778b7John Reck    virtual void onError(const std::string& message) = 0;
43c25e506f7fc08790c0532f927f31310a2ca778b7John Reckprotected:
44c25e506f7fc08790c0532f927f31310a2ca778b7John Reck    ~ErrorHandler() {}
45c25e506f7fc08790c0532f927f31310a2ca778b7John Reck};
46c25e506f7fc08790c0532f927f31310a2ca778b7John Reck
47e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN
48e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reckclass TreeInfo {
49e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    PREVENT_COPY_AND_ASSIGN(TreeInfo);
50e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reckpublic:
51e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    enum TraversalMode {
52e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // The full monty - sync, push, run animators, etc... Used by DrawFrameTask
53e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // May only be used if both the UI thread and RT thread are blocked on the
54e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // prepare
55e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        MODE_FULL,
56e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // Run only what can be done safely on RT thread. Currently this only means
57e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // animators, but potentially things like SurfaceTexture updates
58e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // could be handled by this as well if there are no listeners
59e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        MODE_RT_ONLY,
60e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // The subtree is being detached. Maybe. If the RenderNode is present
61e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // in both the old and new display list's children then it will get a
62e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // MODE_MAYBE_DETACHING followed shortly by a MODE_FULL.
63e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // Push any pending display list changes in case it is detached,
64e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // but don't evaluate animators and such as if it isn't detached as a
65e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // MODE_FULL will follow shortly.
66e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        MODE_MAYBE_DETACHING,
67e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // TODO: TRIM_MEMORY?
68e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    };
69e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck
70e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    explicit TreeInfo(TraversalMode mode)
71e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        : mode(mode)
72e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        , frameTimeMs(0)
73f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        , animationHook(NULL)
74e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        , prepareTextures(mode == MODE_FULL)
75a447d29c65fb811cd184775a3476101a1cede929John Reck        , damageAccumulator(NullDamageAccumulator::instance())
7625fbb3fa1138675379102a44405852555cefccbdJohn Reck        , renderer(0)
77c25e506f7fc08790c0532f927f31310a2ca778b7John Reck        , errorHandler(0)
78e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    {}
79e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
80e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    const TraversalMode mode;
81f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck    nsecs_t frameTimeMs;
82f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck    AnimationHook* animationHook;
83e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    // TODO: Remove this? Currently this is used to signal to stop preparing
84e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    // textures if we run out of cache space.
85e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    bool prepareTextures;
86a447d29c65fb811cd184775a3476101a1cede929John Reck    // Must not be null
87a447d29c65fb811cd184775a3476101a1cede929John Reck    IDamageAccumulator* damageAccumulator;
8825fbb3fa1138675379102a44405852555cefccbdJohn Reck    // The renderer that will be drawing the next frame. Use this to push any
8925fbb3fa1138675379102a44405852555cefccbdJohn Reck    // layer updates or similar. May be NULL.
9025fbb3fa1138675379102a44405852555cefccbdJohn Reck    OpenGLRenderer* renderer;
91c25e506f7fc08790c0532f927f31310a2ca778b7John Reck    ErrorHandler* errorHandler;
92f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck
93f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck    struct Out {
94f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        Out()
95f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck            : hasFunctors(false)
96f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck            , hasAnimations(false)
97f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck            , requiresUiRedraw(false)
98a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck            , canDrawThisFrame(true)
99f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        {}
100f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        bool hasFunctors;
101f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // This is only updated if evaluateAnimations is true
102f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        bool hasAnimations;
103f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // This is set to true if there is an animation that RenderThread cannot
104f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // animate itself, such as if hasFunctors is true
105f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // This is only set if hasAnimations is true
106f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        bool requiresUiRedraw;
107a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // This is set to true if draw() can be called this frame
108a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // false means that we must delay until the next vsync pulse as frame
109a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // production is outrunning consumption
110a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // NOTE that if this is false CanvasContext will set either requiresUiRedraw
111a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // *OR* will post itself for the next vsync automatically, use this
112a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // only to avoid calling draw()
113a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        bool canDrawThisFrame;
114f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck    } out;
115e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
116e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    // TODO: Damage calculations
117e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck};
118e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
119e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} /* namespace uirenderer */
120e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} /* namespace android */
121e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
122e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#endif /* TREEINFO_H */
123