blob: ea25f68d71706064d6c8d8294b43144eae9591e0 [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
John Recke45b1fd2014-04-15 09:50:16 -070019#include <utils/Timers.h>
John Recke45b1fd2014-04-15 09:50:16 -070020
Ady Abrahame088dcd2023-08-10 11:45:58 -070021#include <optional>
Chris Craik0b7e8242015-10-28 16:50:44 -070022#include <string>
John Recke4267ea2014-06-03 15:53:15 -070023
Ady Abrahame088dcd2023-08-10 11:45:58 -070024#include "Properties.h"
25#include "SkSize.h"
26#include "SkippedFrameInfo.h"
27#include "utils/Macros.h"
28
John Recke45b1fd2014-04-15 09:50:16 -070029namespace android {
30namespace uirenderer {
31
John Reck998a6d82014-08-28 15:35:53 -070032namespace renderthread {
33class CanvasContext;
34}
35
Tom Hudson2dc236b2014-10-15 15:46:42 -040036class DamageAccumulator;
Chris Craik0b7e8242015-10-28 16:50:44 -070037class LayerUpdateQueue;
John Reck44b49f02016-03-25 14:29:48 -070038class RenderNode;
John Reck3b202512014-06-23 13:13:08 -070039class RenderState;
John Recke45b1fd2014-04-15 09:50:16 -070040
John Reckc25e5062014-06-18 14:21:29 -070041class ErrorHandler {
42public:
43 virtual void onError(const std::string& message) = 0;
John Reck1bcacfd2017-11-03 10:12:19 -070044
John Reckbb3a3582018-09-26 11:21:08 -070045 virtual ~ErrorHandler() = default;
John Reckc25e5062014-06-18 14:21:29 -070046};
47
John Reck44b49f02016-03-25 14:29:48 -070048class TreeObserver {
49public:
50 // Called when a RenderNode's parent count hits 0.
51 // Due to the unordered nature of tree pushes, once prepareTree
52 // is finished it is possible that the node was "resurrected" and has
53 // a non-zero parent count.
John Reck2de950d2017-01-25 10:58:30 -080054 virtual void onMaybeRemovedFromTree(RenderNode* node) = 0;
John Reck1bcacfd2017-11-03 10:12:19 -070055
John Reck44b49f02016-03-25 14:29:48 -070056protected:
John Reckbb3a3582018-09-26 11:21:08 -070057 virtual ~TreeObserver() = default;
John Reck44b49f02016-03-25 14:29:48 -070058};
59
John Recke4267ea2014-06-03 15:53:15 -070060// This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN
61class TreeInfo {
62 PREVENT_COPY_AND_ASSIGN(TreeInfo);
John Reck1bcacfd2017-11-03 10:12:19 -070063
John Recke4267ea2014-06-03 15:53:15 -070064public:
65 enum TraversalMode {
66 // The full monty - sync, push, run animators, etc... Used by DrawFrameTask
67 // May only be used if both the UI thread and RT thread are blocked on the
68 // prepare
69 MODE_FULL,
70 // Run only what can be done safely on RT thread. Currently this only means
71 // animators, but potentially things like SurfaceTexture updates
72 // could be handled by this as well if there are no listeners
73 MODE_RT_ONLY,
John Recke4267ea2014-06-03 15:53:15 -070074 };
75
John Reckbb3a3582018-09-26 11:21:08 -070076 TreeInfo(TraversalMode mode, renderthread::CanvasContext& canvasContext);
John Reck68bfe0a2014-06-24 15:34:58 -070077
Skuhneea7a7fb2015-08-28 07:10:31 -070078 TraversalMode mode;
John Recke4267ea2014-06-03 15:53:15 -070079 // TODO: Remove this? Currently this is used to signal to stop preparing
80 // textures if we run out of cache space.
John Recke45b1fd2014-04-15 09:50:16 -070081 bool prepareTextures;
Chris Craike2e53a72015-10-28 15:55:40 -070082 renderthread::CanvasContext& canvasContext;
John Reck9eb9f6f2014-08-21 11:23:05 -070083 // TODO: buildLayer uses this to suppress running any animations, but this
84 // should probably be refactored somehow. The reason this is done is
85 // because buildLayer is not setup for injecting the animationHook, as well
86 // as this being otherwise wasted work as all the animators will be
87 // re-evaluated when the frame is actually drawn
Chris Craike2e53a72015-10-28 15:55:40 -070088 bool runAnimations = true;
Chris Craik69e5adf2014-08-14 13:34:01 -070089
90 // Must not be null during actual usage
Chris Craike2e53a72015-10-28 15:55:40 -070091 DamageAccumulator* damageAccumulator = nullptr;
John Reckf1aa7909e2019-03-07 17:01:08 -080092 int64_t damageGenerationId = 0;
Chris Craik0b7e8242015-10-28 16:50:44 -070093
Chris Craik0b7e8242015-10-28 16:50:44 -070094 LayerUpdateQueue* layerUpdateQueue = nullptr;
Chris Craike2e53a72015-10-28 15:55:40 -070095 ErrorHandler* errorHandler = nullptr;
John Reckf9be7792014-05-02 18:21:16 -070096
John Reckf6481082016-02-02 15:18:23 -080097 bool updateWindowPositions = false;
98
John Reckbb3a3582018-09-26 11:21:08 -070099 int disableForceDark;
John Reck1423e132018-09-21 14:30:19 -0700100
Leon Scroggins III6c5864c2019-04-03 15:09:25 -0400101 const SkISize screenSize;
102
John Reck5d53a752021-02-08 19:22:59 -0500103 int stretchEffectCount = 0;
104
chaviwadba0b12022-03-18 17:42:15 -0500105 bool forceDrawFrame = false;
106
John Reckf9be7792014-05-02 18:21:16 -0700107 struct Out {
Chris Craike2e53a72015-10-28 15:55:40 -0700108 bool hasFunctors = false;
John Reckf9be7792014-05-02 18:21:16 -0700109 // This is only updated if evaluateAnimations is true
Chris Craike2e53a72015-10-28 15:55:40 -0700110 bool hasAnimations = false;
John Reckf9be7792014-05-02 18:21:16 -0700111 // 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
Chris Craike2e53a72015-10-28 15:55:40 -0700114 bool requiresUiRedraw = false;
Ady Abrahame088dcd2023-08-10 11:45:58 -0700115 // This is set to nullopt if draw() can be called this frame
116 // A value means that we must delay until the next vsync pulse as frame
John Recka5dda642014-05-22 15:43:54 -0700117 // production is outrunning consumption
Ady Abrahame088dcd2023-08-10 11:45:58 -0700118 // NOTE that if this has a value CanvasContext will set either requiresUiRedraw
John Recka5dda642014-05-22 15:43:54 -0700119 // *OR* will post itself for the next vsync automatically, use this
120 // only to avoid calling draw()
Ady Abrahame088dcd2023-08-10 11:45:58 -0700121 std::optional<SkippedFrameReason> skippedFrameReason;
Leon Scroggins III4afdd1c2018-05-14 14:59:30 -0400122 // Sentinel for animatedImageDelay meaning there is no need to post such
123 // a message.
124 static constexpr nsecs_t kNoAnimatedImageDelay = -1;
125 // This is used to post a message to redraw when it is time to draw the
126 // next frame of an AnimatedImageDrawable.
127 nsecs_t animatedImageDelay = kNoAnimatedImageDelay;
Ady Abrahamcab4afe2023-05-09 11:25:22 -0700128 // This is used to determine if there were only TextureView updates in this frame.
129 // This info is passed to SurfaceFlinger to determine whether it should use vsyncIds
130 // for refresh rate selection.
131 bool solelyTextureViewUpdates = true;
John Reckf9be7792014-05-02 18:21:16 -0700132 } out;
John Recke45b1fd2014-04-15 09:50:16 -0700133
Stan Ilievdb45a4b2016-11-08 14:18:31 -0500134 // This flag helps to disable projection for receiver nodes that do not have any backward
135 // projected children.
136 bool hasBackwardProjectedNodes = false;
John Recke45b1fd2014-04-15 09:50:16 -0700137 // TODO: Damage calculations
138};
139
140} /* namespace uirenderer */
141} /* namespace android */