blob: 331f1574ff178b436ad6e0ff6954f4c887834086 [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 Reckc25e5062014-06-18 14:21:29 -070019#include <string>
20
John Recke45b1fd2014-04-15 09:50:16 -070021#include <utils/Timers.h>
John Recke45b1fd2014-04-15 09:50:16 -070022
John Recka447d292014-06-11 18:39:44 -070023#include "DamageAccumulator.h"
John Recke4267ea2014-06-03 15:53:15 -070024#include "utils/Macros.h"
25
John Recke45b1fd2014-04-15 09:50:16 -070026namespace android {
27namespace uirenderer {
28
John Reckff941dc2014-05-14 16:34:14 -070029class BaseRenderNodeAnimator;
John Reck52244ff2014-05-01 21:27:37 -070030class AnimationListener;
John Reck25fbb3f2014-06-12 13:46:45 -070031class OpenGLRenderer;
John Reck3b202512014-06-23 13:13:08 -070032class RenderState;
John Recke45b1fd2014-04-15 09:50:16 -070033
John Reck52244ff2014-05-01 21:27:37 -070034class AnimationHook {
John Recke45b1fd2014-04-15 09:50:16 -070035public:
John Reckff941dc2014-05-14 16:34:14 -070036 virtual void callOnFinished(BaseRenderNodeAnimator* animator, AnimationListener* listener) = 0;
John Recke45b1fd2014-04-15 09:50:16 -070037protected:
John Reck52244ff2014-05-01 21:27:37 -070038 ~AnimationHook() {}
John Recke45b1fd2014-04-15 09:50:16 -070039};
40
John Reckc25e5062014-06-18 14:21:29 -070041class ErrorHandler {
42public:
43 virtual void onError(const std::string& message) = 0;
44protected:
45 ~ErrorHandler() {}
46};
47
John Recke4267ea2014-06-03 15:53:15 -070048// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN
49class TreeInfo {
50 PREVENT_COPY_AND_ASSIGN(TreeInfo);
51public:
52 enum TraversalMode {
53 // The full monty - sync, push, run animators, etc... Used by DrawFrameTask
54 // May only be used if both the UI thread and RT thread are blocked on the
55 // prepare
56 MODE_FULL,
57 // Run only what can be done safely on RT thread. Currently this only means
58 // animators, but potentially things like SurfaceTexture updates
59 // could be handled by this as well if there are no listeners
60 MODE_RT_ONLY,
John Recke4267ea2014-06-03 15:53:15 -070061 };
62
John Reck3b202512014-06-23 13:13:08 -070063 explicit TreeInfo(TraversalMode mode, RenderState& renderState)
John Recke4267ea2014-06-03 15:53:15 -070064 : mode(mode)
65 , frameTimeMs(0)
John Reckf9be7792014-05-02 18:21:16 -070066 , animationHook(NULL)
John Recke4267ea2014-06-03 15:53:15 -070067 , prepareTextures(mode == MODE_FULL)
Chris Craik69e5adf2014-08-14 13:34:01 -070068 , damageAccumulator(NULL)
John Reck3b202512014-06-23 13:13:08 -070069 , renderState(renderState)
70 , renderer(NULL)
71 , errorHandler(NULL)
John Recke45b1fd2014-04-15 09:50:16 -070072 {}
73
John Reck68bfe0a2014-06-24 15:34:58 -070074 explicit TreeInfo(TraversalMode mode, const TreeInfo& clone)
75 : mode(mode)
76 , frameTimeMs(clone.frameTimeMs)
77 , animationHook(clone.animationHook)
78 , prepareTextures(mode == MODE_FULL)
79 , damageAccumulator(clone.damageAccumulator)
80 , renderState(clone.renderState)
81 , renderer(clone.renderer)
82 , errorHandler(clone.errorHandler)
83 {}
84
John Recke4267ea2014-06-03 15:53:15 -070085 const TraversalMode mode;
John Reckf9be7792014-05-02 18:21:16 -070086 nsecs_t frameTimeMs;
87 AnimationHook* animationHook;
John Recke4267ea2014-06-03 15:53:15 -070088 // TODO: Remove this? Currently this is used to signal to stop preparing
89 // textures if we run out of cache space.
John Recke45b1fd2014-04-15 09:50:16 -070090 bool prepareTextures;
Chris Craik69e5adf2014-08-14 13:34:01 -070091
92 // Must not be null during actual usage
93 DamageAccumulator* damageAccumulator;
John Reck3b202512014-06-23 13:13:08 -070094 RenderState& renderState;
John Reck25fbb3f2014-06-12 13:46:45 -070095 // The renderer that will be drawing the next frame. Use this to push any
96 // layer updates or similar. May be NULL.
97 OpenGLRenderer* renderer;
John Reckc25e5062014-06-18 14:21:29 -070098 ErrorHandler* errorHandler;
John Reckf9be7792014-05-02 18:21:16 -070099
100 struct Out {
101 Out()
102 : hasFunctors(false)
103 , hasAnimations(false)
104 , requiresUiRedraw(false)
John Recka5dda642014-05-22 15:43:54 -0700105 , canDrawThisFrame(true)
John Reckf9be7792014-05-02 18:21:16 -0700106 {}
107 bool hasFunctors;
108 // This is only updated if evaluateAnimations is true
109 bool hasAnimations;
110 // This is set to true if there is an animation that RenderThread cannot
111 // animate itself, such as if hasFunctors is true
112 // This is only set if hasAnimations is true
113 bool requiresUiRedraw;
John Recka5dda642014-05-22 15:43:54 -0700114 // This is set to true if draw() can be called this frame
115 // false means that we must delay until the next vsync pulse as frame
116 // production is outrunning consumption
117 // NOTE that if this is false CanvasContext will set either requiresUiRedraw
118 // *OR* will post itself for the next vsync automatically, use this
119 // only to avoid calling draw()
120 bool canDrawThisFrame;
John Reckf9be7792014-05-02 18:21:16 -0700121 } out;
John Recke45b1fd2014-04-15 09:50:16 -0700122
123 // TODO: Damage calculations
124};
125
126} /* namespace uirenderer */
127} /* namespace android */
128
129#endif /* TREEINFO_H */