blob: 0fc0cef76fefdfb10b277246f2cd0c4711a3e5b1 [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 Recka447d292014-06-11 18:39:44 -070021#include "DamageAccumulator.h"
John Recke4267ea2014-06-03 15:53:15 -070022#include "utils/Macros.h"
23
John Recke45b1fd2014-04-15 09:50:16 -070024namespace android {
25namespace uirenderer {
26
John Reckff941dc2014-05-14 16:34:14 -070027class BaseRenderNodeAnimator;
John Reck52244ff2014-05-01 21:27:37 -070028class AnimationListener;
John Reck25fbb3f2014-06-12 13:46:45 -070029class OpenGLRenderer;
John Recke45b1fd2014-04-15 09:50:16 -070030
John Reck52244ff2014-05-01 21:27:37 -070031class AnimationHook {
John Recke45b1fd2014-04-15 09:50:16 -070032public:
John Reckff941dc2014-05-14 16:34:14 -070033 virtual void callOnFinished(BaseRenderNodeAnimator* animator, AnimationListener* listener) = 0;
John Recke45b1fd2014-04-15 09:50:16 -070034protected:
John Reck52244ff2014-05-01 21:27:37 -070035 ~AnimationHook() {}
John Recke45b1fd2014-04-15 09:50:16 -070036};
37
John Recke4267ea2014-06-03 15:53:15 -070038// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN
39class TreeInfo {
40 PREVENT_COPY_AND_ASSIGN(TreeInfo);
41public:
42 enum TraversalMode {
43 // The full monty - sync, push, run animators, etc... Used by DrawFrameTask
44 // May only be used if both the UI thread and RT thread are blocked on the
45 // prepare
46 MODE_FULL,
47 // Run only what can be done safely on RT thread. Currently this only means
48 // animators, but potentially things like SurfaceTexture updates
49 // could be handled by this as well if there are no listeners
50 MODE_RT_ONLY,
51 // The subtree is being detached. Maybe. If the RenderNode is present
52 // in both the old and new display list's children then it will get a
53 // MODE_MAYBE_DETACHING followed shortly by a MODE_FULL.
54 // Push any pending display list changes in case it is detached,
55 // but don't evaluate animators and such as if it isn't detached as a
56 // MODE_FULL will follow shortly.
57 MODE_MAYBE_DETACHING,
58 // TODO: TRIM_MEMORY?
59 };
60
61 explicit TreeInfo(TraversalMode mode)
62 : mode(mode)
63 , frameTimeMs(0)
John Reckf9be7792014-05-02 18:21:16 -070064 , animationHook(NULL)
John Recke4267ea2014-06-03 15:53:15 -070065 , prepareTextures(mode == MODE_FULL)
John Recka447d292014-06-11 18:39:44 -070066 , damageAccumulator(NullDamageAccumulator::instance())
John Reck25fbb3f2014-06-12 13:46:45 -070067 , renderer(0)
John Recke45b1fd2014-04-15 09:50:16 -070068 {}
69
John Recke4267ea2014-06-03 15:53:15 -070070 const TraversalMode mode;
John Reckf9be7792014-05-02 18:21:16 -070071 nsecs_t frameTimeMs;
72 AnimationHook* animationHook;
John Recke4267ea2014-06-03 15:53:15 -070073 // TODO: Remove this? Currently this is used to signal to stop preparing
74 // textures if we run out of cache space.
John Recke45b1fd2014-04-15 09:50:16 -070075 bool prepareTextures;
John Recka447d292014-06-11 18:39:44 -070076 // Must not be null
77 IDamageAccumulator* damageAccumulator;
John Reck25fbb3f2014-06-12 13:46:45 -070078 // The renderer that will be drawing the next frame. Use this to push any
79 // layer updates or similar. May be NULL.
80 OpenGLRenderer* renderer;
John Reckf9be7792014-05-02 18:21:16 -070081
82 struct Out {
83 Out()
84 : hasFunctors(false)
85 , hasAnimations(false)
86 , requiresUiRedraw(false)
John Recka5dda642014-05-22 15:43:54 -070087 , canDrawThisFrame(true)
John Reckf9be7792014-05-02 18:21:16 -070088 {}
89 bool hasFunctors;
90 // This is only updated if evaluateAnimations is true
91 bool hasAnimations;
92 // This is set to true if there is an animation that RenderThread cannot
93 // animate itself, such as if hasFunctors is true
94 // This is only set if hasAnimations is true
95 bool requiresUiRedraw;
John Recka5dda642014-05-22 15:43:54 -070096 // This is set to true if draw() can be called this frame
97 // false means that we must delay until the next vsync pulse as frame
98 // production is outrunning consumption
99 // NOTE that if this is false CanvasContext will set either requiresUiRedraw
100 // *OR* will post itself for the next vsync automatically, use this
101 // only to avoid calling draw()
102 bool canDrawThisFrame;
John Reckf9be7792014-05-02 18:21:16 -0700103 } out;
John Recke45b1fd2014-04-15 09:50:16 -0700104
105 // TODO: Damage calculations
106};
107
108} /* namespace uirenderer */
109} /* namespace android */
110
111#endif /* TREEINFO_H */