blob: 1c3148726b6379e34284107406c5d75499994a60 [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 Recke4267ea2014-06-03 15:53:15 -070023#include "utils/Macros.h"
24
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;
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
Chris Craike2e53a72015-10-28 15:55:40 -070058 TreeInfo(TraversalMode mode, renderthread::CanvasContext& canvasContext)
59 : mode(mode)
60 , prepareTextures(mode == MODE_FULL)
61 , canvasContext(canvasContext)
John Reck68bfe0a2014-06-24 15:34:58 -070062 {}
63
Skuhneea7a7fb2015-08-28 07:10:31 -070064 TraversalMode mode;
John Recke4267ea2014-06-03 15:53:15 -070065 // TODO: Remove this? Currently this is used to signal to stop preparing
66 // textures if we run out of cache space.
John Recke45b1fd2014-04-15 09:50:16 -070067 bool prepareTextures;
Chris Craike2e53a72015-10-28 15:55:40 -070068 renderthread::CanvasContext& canvasContext;
John Reck9eb9f6f2014-08-21 11:23:05 -070069 // TODO: buildLayer uses this to suppress running any animations, but this
70 // should probably be refactored somehow. The reason this is done is
71 // because buildLayer is not setup for injecting the animationHook, as well
72 // as this being otherwise wasted work as all the animators will be
73 // re-evaluated when the frame is actually drawn
Chris Craike2e53a72015-10-28 15:55:40 -070074 bool runAnimations = true;
Chris Craik69e5adf2014-08-14 13:34:01 -070075
76 // Must not be null during actual usage
Chris Craike2e53a72015-10-28 15:55:40 -070077 DamageAccumulator* damageAccumulator = nullptr;
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.
Chris Craike2e53a72015-10-28 15:55:40 -070080 OpenGLRenderer* renderer = nullptr;
81 ErrorHandler* errorHandler = nullptr;
John Reckf9be7792014-05-02 18:21:16 -070082
83 struct Out {
Chris Craike2e53a72015-10-28 15:55:40 -070084 bool hasFunctors = false;
John Reckf9be7792014-05-02 18:21:16 -070085 // This is only updated if evaluateAnimations is true
Chris Craike2e53a72015-10-28 15:55:40 -070086 bool hasAnimations = false;
John Reckf9be7792014-05-02 18:21:16 -070087 // This is set to true if there is an animation that RenderThread cannot
88 // animate itself, such as if hasFunctors is true
89 // This is only set if hasAnimations is true
Chris Craike2e53a72015-10-28 15:55:40 -070090 bool requiresUiRedraw = false;
John Recka5dda642014-05-22 15:43:54 -070091 // This is set to true if draw() can be called this frame
92 // false means that we must delay until the next vsync pulse as frame
93 // production is outrunning consumption
94 // NOTE that if this is false CanvasContext will set either requiresUiRedraw
95 // *OR* will post itself for the next vsync automatically, use this
96 // only to avoid calling draw()
Chris Craike2e53a72015-10-28 15:55:40 -070097 bool canDrawThisFrame = true;
John Reckf9be7792014-05-02 18:21:16 -070098 } out;
John Recke45b1fd2014-04-15 09:50:16 -070099
100 // TODO: Damage calculations
101};
102
103} /* namespace uirenderer */
104} /* namespace android */
105
106#endif /* TREEINFO_H */