blob: 2096f98e0c0068d565b80da93f31ff1d22d8732a [file] [log] [blame]
John Recke45b1fd2014-04-15 09:50:16 -07001/*
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
John Recke45b1fd2014-04-15 09:50:16 -070019#include <utils/Timers.h>
John Recke45b1fd2014-04-15 09:50:16 -070020
John Recke4267ea2014-06-03 15:53:15 -070021#include "utils/Macros.h"
22
John Recke45b1fd2014-04-15 09:50:16 -070023namespace android {
24namespace uirenderer {
25
John Reckff941dc2014-05-14 16:34:14 -070026class BaseRenderNodeAnimator;
John Reck52244ff2014-05-01 21:27:37 -070027class AnimationListener;
John Recke4267ea2014-06-03 15:53:15 -070028class DamageAccumulator;
John Recke45b1fd2014-04-15 09:50:16 -070029
John Reck52244ff2014-05-01 21:27:37 -070030class AnimationHook {
John Recke45b1fd2014-04-15 09:50:16 -070031public:
John Reckff941dc2014-05-14 16:34:14 -070032 virtual void callOnFinished(BaseRenderNodeAnimator* animator, AnimationListener* listener) = 0;
John Recke45b1fd2014-04-15 09:50:16 -070033protected:
John Reck52244ff2014-05-01 21:27:37 -070034 ~AnimationHook() {}
John Recke45b1fd2014-04-15 09:50:16 -070035};
36
John Recke4267ea2014-06-03 15:53:15 -070037// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN
38class TreeInfo {
39 PREVENT_COPY_AND_ASSIGN(TreeInfo);
40public:
41 enum TraversalMode {
42 // The full monty - sync, push, run animators, etc... Used by DrawFrameTask
43 // May only be used if both the UI thread and RT thread are blocked on the
44 // prepare
45 MODE_FULL,
46 // Run only what can be done safely on RT thread. Currently this only means
47 // animators, but potentially things like SurfaceTexture updates
48 // could be handled by this as well if there are no listeners
49 MODE_RT_ONLY,
50 // The subtree is being detached. Maybe. If the RenderNode is present
51 // in both the old and new display list's children then it will get a
52 // MODE_MAYBE_DETACHING followed shortly by a MODE_FULL.
53 // Push any pending display list changes in case it is detached,
54 // but don't evaluate animators and such as if it isn't detached as a
55 // MODE_FULL will follow shortly.
56 MODE_MAYBE_DETACHING,
57 // TODO: TRIM_MEMORY?
58 };
59
60 explicit TreeInfo(TraversalMode mode)
61 : mode(mode)
62 , frameTimeMs(0)
John Reckf9be7792014-05-02 18:21:16 -070063 , animationHook(NULL)
John Recke4267ea2014-06-03 15:53:15 -070064 , prepareTextures(mode == MODE_FULL)
65 , damageAccumulator(0)
John Recke45b1fd2014-04-15 09:50:16 -070066 {}
67
John Recke4267ea2014-06-03 15:53:15 -070068 const TraversalMode mode;
John Reckf9be7792014-05-02 18:21:16 -070069 nsecs_t frameTimeMs;
70 AnimationHook* animationHook;
John Recke4267ea2014-06-03 15:53:15 -070071 // TODO: Remove this? Currently this is used to signal to stop preparing
72 // textures if we run out of cache space.
John Recke45b1fd2014-04-15 09:50:16 -070073 bool prepareTextures;
John Recke4267ea2014-06-03 15:53:15 -070074 DamageAccumulator* damageAccumulator;
John Reckf9be7792014-05-02 18:21:16 -070075
76 struct Out {
77 Out()
78 : hasFunctors(false)
79 , hasAnimations(false)
80 , requiresUiRedraw(false)
John Recka5dda642014-05-22 15:43:54 -070081 , canDrawThisFrame(true)
John Reckf9be7792014-05-02 18:21:16 -070082 {}
83 bool hasFunctors;
84 // This is only updated if evaluateAnimations is true
85 bool hasAnimations;
86 // This is set to true if there is an animation that RenderThread cannot
87 // animate itself, such as if hasFunctors is true
88 // This is only set if hasAnimations is true
89 bool requiresUiRedraw;
John Recka5dda642014-05-22 15:43:54 -070090 // This is set to true if draw() can be called this frame
91 // false means that we must delay until the next vsync pulse as frame
92 // production is outrunning consumption
93 // NOTE that if this is false CanvasContext will set either requiresUiRedraw
94 // *OR* will post itself for the next vsync automatically, use this
95 // only to avoid calling draw()
96 bool canDrawThisFrame;
John Reckf9be7792014-05-02 18:21:16 -070097 } out;
John Recke45b1fd2014-04-15 09:50:16 -070098
99 // TODO: Damage calculations
100};
101
102} /* namespace uirenderer */
103} /* namespace android */
104
105#endif /* TREEINFO_H */