TreeInfo.h revision 2dc236b2bae13b9a0ed9b3f7320502aecd7983b3
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
23e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck#include "utils/Macros.h"
24e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck
25e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Recknamespace android {
26e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Recknamespace uirenderer {
27e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
28998a6d81896df8b662cc10ddeb35087b78b38d72John Recknamespace renderthread {
29998a6d81896df8b662cc10ddeb35087b78b38d72John Reckclass CanvasContext;
30998a6d81896df8b662cc10ddeb35087b78b38d72John Reck}
31998a6d81896df8b662cc10ddeb35087b78b38d72John Reck
322dc236b2bae13b9a0ed9b3f7320502aecd7983b3Tom Hudsonclass DamageAccumulator;
3325fbb3fa1138675379102a44405852555cefccbdJohn Reckclass OpenGLRenderer;
343b20251a355c88193c439f928a84ae69483fb488John Reckclass RenderState;
35e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
36c25e506f7fc08790c0532f927f31310a2ca778b7John Reckclass ErrorHandler {
37c25e506f7fc08790c0532f927f31310a2ca778b7John Reckpublic:
38c25e506f7fc08790c0532f927f31310a2ca778b7John Reck    virtual void onError(const std::string& message) = 0;
39c25e506f7fc08790c0532f927f31310a2ca778b7John Reckprotected:
40c25e506f7fc08790c0532f927f31310a2ca778b7John Reck    ~ErrorHandler() {}
41c25e506f7fc08790c0532f927f31310a2ca778b7John Reck};
42c25e506f7fc08790c0532f927f31310a2ca778b7John Reck
43e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN
44e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reckclass TreeInfo {
45e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    PREVENT_COPY_AND_ASSIGN(TreeInfo);
46e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reckpublic:
47e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    enum TraversalMode {
48e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // The full monty - sync, push, run animators, etc... Used by DrawFrameTask
49e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // May only be used if both the UI thread and RT thread are blocked on the
50e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // prepare
51e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        MODE_FULL,
52e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // Run only what can be done safely on RT thread. Currently this only means
53e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // animators, but potentially things like SurfaceTexture updates
54e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        // could be handled by this as well if there are no listeners
55e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        MODE_RT_ONLY,
56e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    };
57e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck
583b20251a355c88193c439f928a84ae69483fb488John Reck    explicit TreeInfo(TraversalMode mode, RenderState& renderState)
59e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        : mode(mode)
60e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck        , prepareTextures(mode == MODE_FULL)
619eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck        , runAnimations(true)
6269e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik        , damageAccumulator(NULL)
633b20251a355c88193c439f928a84ae69483fb488John Reck        , renderState(renderState)
643b20251a355c88193c439f928a84ae69483fb488John Reck        , renderer(NULL)
653b20251a355c88193c439f928a84ae69483fb488John Reck        , errorHandler(NULL)
66998a6d81896df8b662cc10ddeb35087b78b38d72John Reck        , canvasContext(NULL)
67e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    {}
68e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
6968bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    explicit TreeInfo(TraversalMode mode, const TreeInfo& clone)
7068bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        : mode(mode)
7168bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        , prepareTextures(mode == MODE_FULL)
729eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck        , runAnimations(clone.runAnimations)
7368bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        , damageAccumulator(clone.damageAccumulator)
7468bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        , renderState(clone.renderState)
7568bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        , renderer(clone.renderer)
7668bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck        , errorHandler(clone.errorHandler)
77998a6d81896df8b662cc10ddeb35087b78b38d72John Reck        , canvasContext(clone.canvasContext)
7868bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck    {}
7968bfe0a37a0dcef52abd81688d8520c5d16e1a85John Reck
80e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    const TraversalMode mode;
81e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    // TODO: Remove this? Currently this is used to signal to stop preparing
82e4267ea4f20740c37c01bfb6aefcf61fddc4566aJohn Reck    // textures if we run out of cache space.
83e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    bool prepareTextures;
849eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    // TODO: buildLayer uses this to suppress running any animations, but this
859eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    // should probably be refactored somehow. The reason this is done is
869eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    // because buildLayer is not setup for injecting the animationHook, as well
879eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    // as this being otherwise wasted work as all the animators will be
889eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    // re-evaluated when the frame is actually drawn
899eb9f6f8cbbbd87d45da8071aa54cb066a797723John Reck    bool runAnimations;
9069e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik
9169e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik    // Must not be null during actual usage
9269e5adffb19135d51bde8e458f4907d7265f3e23Chris Craik    DamageAccumulator* damageAccumulator;
933b20251a355c88193c439f928a84ae69483fb488John Reck    RenderState& renderState;
9425fbb3fa1138675379102a44405852555cefccbdJohn Reck    // The renderer that will be drawing the next frame. Use this to push any
9525fbb3fa1138675379102a44405852555cefccbdJohn Reck    // layer updates or similar. May be NULL.
9625fbb3fa1138675379102a44405852555cefccbdJohn Reck    OpenGLRenderer* renderer;
97c25e506f7fc08790c0532f927f31310a2ca778b7John Reck    ErrorHandler* errorHandler;
98998a6d81896df8b662cc10ddeb35087b78b38d72John Reck    // TODO: Remove this? May be NULL
99998a6d81896df8b662cc10ddeb35087b78b38d72John Reck    renderthread::CanvasContext* canvasContext;
100f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck
101f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck    struct Out {
102f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        Out()
103f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck            : hasFunctors(false)
104f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck            , hasAnimations(false)
105f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck            , requiresUiRedraw(false)
106a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck            , canDrawThisFrame(true)
107f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        {}
108f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        bool hasFunctors;
109f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // This is only updated if evaluateAnimations is true
110f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        bool hasAnimations;
111f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // This is set to true if there is an animation that RenderThread cannot
112f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // animate itself, such as if hasFunctors is true
113f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        // This is only set if hasAnimations is true
114f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck        bool requiresUiRedraw;
115a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // This is set to true if draw() can be called this frame
116a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // false means that we must delay until the next vsync pulse as frame
117a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // production is outrunning consumption
118a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // NOTE that if this is false CanvasContext will set either requiresUiRedraw
119a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // *OR* will post itself for the next vsync automatically, use this
120a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        // only to avoid calling draw()
121a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck        bool canDrawThisFrame;
122f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck    } out;
123e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
124e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck    // TODO: Damage calculations
125e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck};
126e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
127e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} /* namespace uirenderer */
128e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck} /* namespace android */
129e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck
130e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck#endif /* TREEINFO_H */
131