blob: caa5762d174ae033d4d6125b76fd0461ed5a538f [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 */
Chris Craik5e00c7c2016-07-06 16:10:09 -070016
17#pragma once
John Recke45b1fd2014-04-15 09:50:16 -070018
Chris Craik0b7e8242015-10-28 16:50:44 -070019#include "utils/Macros.h"
John Reck1423e132018-09-21 14:30:19 -070020#include "Properties.h"
John Reckc25e5062014-06-18 14:21:29 -070021
John Recke45b1fd2014-04-15 09:50:16 -070022#include <utils/Timers.h>
John Recke45b1fd2014-04-15 09:50:16 -070023
Chris Craik0b7e8242015-10-28 16:50:44 -070024#include <string>
John Recke4267ea2014-06-03 15:53:15 -070025
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
Tom Hudson2dc236b2014-10-15 15:46:42 -040033class DamageAccumulator;
Chris Craik0b7e8242015-10-28 16:50:44 -070034class LayerUpdateQueue;
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;
John Reck1bcacfd2017-11-03 10:12:19 -070041
John Reckc25e5062014-06-18 14:21:29 -070042protected:
Greg Kaiser174b50f2018-08-23 17:02:39 -070043 virtual ~ErrorHandler() {}
John Reckc25e5062014-06-18 14:21:29 -070044};
45
John Reck44b49f02016-03-25 14:29:48 -070046class TreeObserver {
47public:
48 // Called when a RenderNode's parent count hits 0.
49 // Due to the unordered nature of tree pushes, once prepareTree
50 // is finished it is possible that the node was "resurrected" and has
51 // a non-zero parent count.
John Reck2de950d2017-01-25 10:58:30 -080052 virtual void onMaybeRemovedFromTree(RenderNode* node) = 0;
John Reck1bcacfd2017-11-03 10:12:19 -070053
John Reck44b49f02016-03-25 14:29:48 -070054protected:
John Reck2de950d2017-01-25 10:58:30 -080055 virtual ~TreeObserver() {}
John Reck44b49f02016-03-25 14:29:48 -070056};
57
John Recke4267ea2014-06-03 15:53:15 -070058// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN
59class TreeInfo {
60 PREVENT_COPY_AND_ASSIGN(TreeInfo);
John Reck1bcacfd2017-11-03 10:12:19 -070061
John Recke4267ea2014-06-03 15:53:15 -070062public:
63 enum TraversalMode {
64 // The full monty - sync, push, run animators, etc... Used by DrawFrameTask
65 // May only be used if both the UI thread and RT thread are blocked on the
66 // prepare
67 MODE_FULL,
68 // Run only what can be done safely on RT thread. Currently this only means
69 // animators, but potentially things like SurfaceTexture updates
70 // could be handled by this as well if there are no listeners
71 MODE_RT_ONLY,
John Recke4267ea2014-06-03 15:53:15 -070072 };
73
Chris Craike2e53a72015-10-28 15:55:40 -070074 TreeInfo(TraversalMode mode, renderthread::CanvasContext& canvasContext)
John Reck1bcacfd2017-11-03 10:12:19 -070075 : mode(mode), prepareTextures(mode == MODE_FULL), canvasContext(canvasContext) {}
John Reck68bfe0a2014-06-24 15:34:58 -070076
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
Chris Craik0b7e8242015-10-28 16:50:44 -070092 LayerUpdateQueue* layerUpdateQueue = nullptr;
Chris Craike2e53a72015-10-28 15:55:40 -070093 ErrorHandler* errorHandler = nullptr;
John Reckf9be7792014-05-02 18:21:16 -070094
John Reckf6481082016-02-02 15:18:23 -080095 bool updateWindowPositions = false;
96
John Reck1423e132018-09-21 14:30:19 -070097 int disableForceDark = Properties::forceDarkMode ? 0 : 1;
98
John Reckf9be7792014-05-02 18:21:16 -070099 struct Out {
Chris Craike2e53a72015-10-28 15:55:40 -0700100 bool hasFunctors = false;
John Reckf9be7792014-05-02 18:21:16 -0700101 // This is only updated if evaluateAnimations is true
Chris Craike2e53a72015-10-28 15:55:40 -0700102 bool hasAnimations = false;
John Reckf9be7792014-05-02 18:21:16 -0700103 // This is set to true if there is an animation that RenderThread cannot
104 // animate itself, such as if hasFunctors is true
105 // This is only set if hasAnimations is true
Chris Craike2e53a72015-10-28 15:55:40 -0700106 bool requiresUiRedraw = false;
John Recka5dda642014-05-22 15:43:54 -0700107 // This is set to true if draw() can be called this frame
108 // false means that we must delay until the next vsync pulse as frame
109 // production is outrunning consumption
110 // NOTE that if this is false CanvasContext will set either requiresUiRedraw
111 // *OR* will post itself for the next vsync automatically, use this
112 // only to avoid calling draw()
Chris Craike2e53a72015-10-28 15:55:40 -0700113 bool canDrawThisFrame = true;
Leon Scroggins III4afdd1c2018-05-14 14:59:30 -0400114 // Sentinel for animatedImageDelay meaning there is no need to post such
115 // a message.
116 static constexpr nsecs_t kNoAnimatedImageDelay = -1;
117 // This is used to post a message to redraw when it is time to draw the
118 // next frame of an AnimatedImageDrawable.
119 nsecs_t animatedImageDelay = kNoAnimatedImageDelay;
John Reckf9be7792014-05-02 18:21:16 -0700120 } out;
John Recke45b1fd2014-04-15 09:50:16 -0700121
Stan Ilievdb45a4b2016-11-08 14:18:31 -0500122 // This flag helps to disable projection for receiver nodes that do not have any backward
123 // projected children.
124 bool hasBackwardProjectedNodes = false;
John Recke45b1fd2014-04-15 09:50:16 -0700125 // TODO: Damage calculations
126};
127
128} /* namespace uirenderer */
129} /* namespace android */