blob: a43e544b45075f8761c957b129d3421530e9085c [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
Chris Craik0b7e8242015-10-28 16:50:44 -070019#include "utils/Macros.h"
John Reckc25e5062014-06-18 14:21:29 -070020
John Recke45b1fd2014-04-15 09:50:16 -070021#include <utils/Timers.h>
John Recke45b1fd2014-04-15 09:50:16 -070022
Chris Craik0b7e8242015-10-28 16:50:44 -070023#include <string>
John Recke4267ea2014-06-03 15:53:15 -070024
John Recke45b1fd2014-04-15 09:50:16 -070025namespace android {
26namespace uirenderer {
27
John Reck998a6d82014-08-28 15:35:53 -070028namespace renderthread {
29class CanvasContext;
30}
31
Tom Hudson2dc236b2014-10-15 15:46:42 -040032class DamageAccumulator;
Chris Craik0b7e8242015-10-28 16:50:44 -070033class LayerUpdateQueue;
John Reck25fbb3f2014-06-12 13:46:45 -070034class OpenGLRenderer;
John Reck44b49f02016-03-25 14:29:48 -070035class RenderNode;
John Reck3b202512014-06-23 13:13:08 -070036class RenderState;
John Recke45b1fd2014-04-15 09:50:16 -070037
John Reckc25e5062014-06-18 14:21:29 -070038class ErrorHandler {
39public:
40 virtual void onError(const std::string& message) = 0;
41protected:
42 ~ErrorHandler() {}
43};
44
John Reck44b49f02016-03-25 14:29:48 -070045class TreeObserver {
46public:
47 // Called when a RenderNode's parent count hits 0.
48 // Due to the unordered nature of tree pushes, once prepareTree
49 // is finished it is possible that the node was "resurrected" and has
50 // a non-zero parent count.
51 virtual void onMaybeRemovedFromTree(RenderNode* node) {}
52protected:
53 ~TreeObserver() {}
54};
55
John Recke4267ea2014-06-03 15:53:15 -070056// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN
57class TreeInfo {
58 PREVENT_COPY_AND_ASSIGN(TreeInfo);
59public:
60 enum TraversalMode {
61 // The full monty - sync, push, run animators, etc... Used by DrawFrameTask
62 // May only be used if both the UI thread and RT thread are blocked on the
63 // prepare
64 MODE_FULL,
65 // Run only what can be done safely on RT thread. Currently this only means
66 // animators, but potentially things like SurfaceTexture updates
67 // could be handled by this as well if there are no listeners
68 MODE_RT_ONLY,
John Recke4267ea2014-06-03 15:53:15 -070069 };
70
Chris Craike2e53a72015-10-28 15:55:40 -070071 TreeInfo(TraversalMode mode, renderthread::CanvasContext& canvasContext)
72 : mode(mode)
73 , prepareTextures(mode == MODE_FULL)
74 , canvasContext(canvasContext)
John Reck68bfe0a2014-06-24 15:34:58 -070075 {}
76
Skuhneea7a7fb2015-08-28 07:10:31 -070077 TraversalMode mode;
John Recke4267ea2014-06-03 15:53:15 -070078 // TODO: Remove this? Currently this is used to signal to stop preparing
79 // textures if we run out of cache space.
John Recke45b1fd2014-04-15 09:50:16 -070080 bool prepareTextures;
Chris Craike2e53a72015-10-28 15:55:40 -070081 renderthread::CanvasContext& canvasContext;
John Reck9eb9f6f2014-08-21 11:23:05 -070082 // TODO: buildLayer uses this to suppress running any animations, but this
83 // should probably be refactored somehow. The reason this is done is
84 // because buildLayer is not setup for injecting the animationHook, as well
85 // as this being otherwise wasted work as all the animators will be
86 // re-evaluated when the frame is actually drawn
Chris Craike2e53a72015-10-28 15:55:40 -070087 bool runAnimations = true;
Chris Craik69e5adf2014-08-14 13:34:01 -070088
89 // Must not be null during actual usage
Chris Craike2e53a72015-10-28 15:55:40 -070090 DamageAccumulator* damageAccumulator = nullptr;
Chris Craik0b7e8242015-10-28 16:50:44 -070091
92#if HWUI_NEW_OPS
93 LayerUpdateQueue* layerUpdateQueue = nullptr;
94#else
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.
Chris Craike2e53a72015-10-28 15:55:40 -070097 OpenGLRenderer* renderer = nullptr;
Chris Craik0b7e8242015-10-28 16:50:44 -070098#endif
Chris Craike2e53a72015-10-28 15:55:40 -070099 ErrorHandler* errorHandler = nullptr;
John Reckf9be7792014-05-02 18:21:16 -0700100
John Reck44b49f02016-03-25 14:29:48 -0700101 // Optional, may be nullptr. Used to allow things to observe interesting
102 // tree state changes
103 TreeObserver* observer = nullptr;
104
John Reckf6481082016-02-02 15:18:23 -0800105 // Frame number for use with synchronized surfaceview position updating
106 int64_t frameNumber = -1;
107 int32_t windowInsetLeft = 0;
108 int32_t windowInsetTop = 0;
109 bool updateWindowPositions = false;
110
John Reckf9be7792014-05-02 18:21:16 -0700111 struct Out {
Chris Craike2e53a72015-10-28 15:55:40 -0700112 bool hasFunctors = false;
John Reckf9be7792014-05-02 18:21:16 -0700113 // This is only updated if evaluateAnimations is true
Chris Craike2e53a72015-10-28 15:55:40 -0700114 bool hasAnimations = false;
John Reckf9be7792014-05-02 18:21:16 -0700115 // This is set to true if there is an animation that RenderThread cannot
116 // animate itself, such as if hasFunctors is true
117 // This is only set if hasAnimations is true
Chris Craike2e53a72015-10-28 15:55:40 -0700118 bool requiresUiRedraw = false;
John Recka5dda642014-05-22 15:43:54 -0700119 // This is set to true if draw() can be called this frame
120 // false means that we must delay until the next vsync pulse as frame
121 // production is outrunning consumption
122 // NOTE that if this is false CanvasContext will set either requiresUiRedraw
123 // *OR* will post itself for the next vsync automatically, use this
124 // only to avoid calling draw()
Chris Craike2e53a72015-10-28 15:55:40 -0700125 bool canDrawThisFrame = true;
John Reckf9be7792014-05-02 18:21:16 -0700126 } out;
John Recke45b1fd2014-04-15 09:50:16 -0700127
128 // TODO: Damage calculations
129};
130
131} /* namespace uirenderer */
132} /* namespace android */
133
134#endif /* TREEINFO_H */