blob: ae6ea94740697d532ef36efbcd24ba35d3f5c624 [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 Reck998a6d82014-08-28 15:35:53 -070029namespace renderthread {
30class CanvasContext;
31}
32
John Reck25fbb3f2014-06-12 13:46:45 -070033class OpenGLRenderer;
John Reck3b202512014-06-23 13:13:08 -070034class RenderState;
John Recke45b1fd2014-04-15 09:50:16 -070035
John Reckc25e5062014-06-18 14:21:29 -070036class ErrorHandler {
37public:
38 virtual void onError(const std::string& message) = 0;
39protected:
40 ~ErrorHandler() {}
41};
42
John Recke4267ea2014-06-03 15:53:15 -070043// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN
44class TreeInfo {
45 PREVENT_COPY_AND_ASSIGN(TreeInfo);
46public:
47 enum TraversalMode {
48 // The full monty - sync, push, run animators, etc... Used by DrawFrameTask
49 // May only be used if both the UI thread and RT thread are blocked on the
50 // prepare
51 MODE_FULL,
52 // Run only what can be done safely on RT thread. Currently this only means
53 // animators, but potentially things like SurfaceTexture updates
54 // could be handled by this as well if there are no listeners
55 MODE_RT_ONLY,
John Recke4267ea2014-06-03 15:53:15 -070056 };
57
John Reck3b202512014-06-23 13:13:08 -070058 explicit TreeInfo(TraversalMode mode, RenderState& renderState)
John Recke4267ea2014-06-03 15:53:15 -070059 : mode(mode)
John Recke4267ea2014-06-03 15:53:15 -070060 , prepareTextures(mode == MODE_FULL)
John Reck9eb9f6f2014-08-21 11:23:05 -070061 , runAnimations(true)
Chris Craik69e5adf2014-08-14 13:34:01 -070062 , damageAccumulator(NULL)
John Reck3b202512014-06-23 13:13:08 -070063 , renderState(renderState)
64 , renderer(NULL)
65 , errorHandler(NULL)
John Reck998a6d82014-08-28 15:35:53 -070066 , canvasContext(NULL)
John Recke45b1fd2014-04-15 09:50:16 -070067 {}
68
John Reck68bfe0a2014-06-24 15:34:58 -070069 explicit TreeInfo(TraversalMode mode, const TreeInfo& clone)
70 : mode(mode)
John Reck68bfe0a2014-06-24 15:34:58 -070071 , prepareTextures(mode == MODE_FULL)
John Reck9eb9f6f2014-08-21 11:23:05 -070072 , runAnimations(clone.runAnimations)
John Reck68bfe0a2014-06-24 15:34:58 -070073 , damageAccumulator(clone.damageAccumulator)
74 , renderState(clone.renderState)
75 , renderer(clone.renderer)
76 , errorHandler(clone.errorHandler)
John Reck998a6d82014-08-28 15:35:53 -070077 , canvasContext(clone.canvasContext)
John Reck68bfe0a2014-06-24 15:34:58 -070078 {}
79
John Recke4267ea2014-06-03 15:53:15 -070080 const TraversalMode mode;
John Recke4267ea2014-06-03 15:53:15 -070081 // TODO: Remove this? Currently this is used to signal to stop preparing
82 // textures if we run out of cache space.
John Recke45b1fd2014-04-15 09:50:16 -070083 bool prepareTextures;
John Reck9eb9f6f2014-08-21 11:23:05 -070084 // TODO: buildLayer uses this to suppress running any animations, but this
85 // should probably be refactored somehow. The reason this is done is
86 // because buildLayer is not setup for injecting the animationHook, as well
87 // as this being otherwise wasted work as all the animators will be
88 // re-evaluated when the frame is actually drawn
89 bool runAnimations;
Chris Craik69e5adf2014-08-14 13:34:01 -070090
91 // Must not be null during actual usage
92 DamageAccumulator* damageAccumulator;
John Reck3b202512014-06-23 13:13:08 -070093 RenderState& renderState;
John Reck25fbb3f2014-06-12 13:46:45 -070094 // The renderer that will be drawing the next frame. Use this to push any
95 // layer updates or similar. May be NULL.
96 OpenGLRenderer* renderer;
John Reckc25e5062014-06-18 14:21:29 -070097 ErrorHandler* errorHandler;
John Reck998a6d82014-08-28 15:35:53 -070098 // TODO: Remove this? May be NULL
99 renderthread::CanvasContext* canvasContext;
John Reckf9be7792014-05-02 18:21:16 -0700100
101 struct Out {
102 Out()
103 : hasFunctors(false)
104 , hasAnimations(false)
105 , requiresUiRedraw(false)
John Recka5dda642014-05-22 15:43:54 -0700106 , canDrawThisFrame(true)
John Reckf9be7792014-05-02 18:21:16 -0700107 {}
108 bool hasFunctors;
109 // This is only updated if evaluateAnimations is true
110 bool hasAnimations;
111 // This is set to true if there is an animation that RenderThread cannot
112 // animate itself, such as if hasFunctors is true
113 // This is only set if hasAnimations is true
114 bool requiresUiRedraw;
John Recka5dda642014-05-22 15:43:54 -0700115 // This is set to true if draw() can be called this frame
116 // false means that we must delay until the next vsync pulse as frame
117 // production is outrunning consumption
118 // NOTE that if this is false CanvasContext will set either requiresUiRedraw
119 // *OR* will post itself for the next vsync automatically, use this
120 // only to avoid calling draw()
121 bool canDrawThisFrame;
John Reckf9be7792014-05-02 18:21:16 -0700122 } out;
John Recke45b1fd2014-04-15 09:50:16 -0700123
124 // TODO: Damage calculations
125};
126
127} /* namespace uirenderer */
128} /* namespace android */
129
130#endif /* TREEINFO_H */