John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 1 | /* |
| 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 Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 16 | |
| 17 | #pragma once |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 18 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 19 | #include <utils/Timers.h> |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 20 | |
Ady Abraham | e088dcd | 2023-08-10 11:45:58 -0700 | [diff] [blame] | 21 | #include <optional> |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 22 | #include <string> |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 23 | |
Ady Abraham | e088dcd | 2023-08-10 11:45:58 -0700 | [diff] [blame] | 24 | #include "Properties.h" |
| 25 | #include "SkSize.h" |
| 26 | #include "SkippedFrameInfo.h" |
Tyler Freeman | 3356774 | 2023-10-31 01:55:51 +0000 | [diff] [blame] | 27 | #include "utils/ForceDark.h" |
Ady Abraham | e088dcd | 2023-08-10 11:45:58 -0700 | [diff] [blame] | 28 | #include "utils/Macros.h" |
| 29 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 30 | namespace android { |
| 31 | namespace uirenderer { |
| 32 | |
John Reck | 998a6d8 | 2014-08-28 15:35:53 -0700 | [diff] [blame] | 33 | namespace renderthread { |
| 34 | class CanvasContext; |
| 35 | } |
| 36 | |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 37 | class DamageAccumulator; |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 38 | class LayerUpdateQueue; |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 39 | class RenderNode; |
John Reck | 3b20251 | 2014-06-23 13:13:08 -0700 | [diff] [blame] | 40 | class RenderState; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 41 | |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 42 | class ErrorHandler { |
| 43 | public: |
| 44 | virtual void onError(const std::string& message) = 0; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 45 | |
John Reck | bb3a358 | 2018-09-26 11:21:08 -0700 | [diff] [blame] | 46 | virtual ~ErrorHandler() = default; |
John Reck | c25e506 | 2014-06-18 14:21:29 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 49 | class TreeObserver { |
| 50 | public: |
| 51 | // Called when a RenderNode's parent count hits 0. |
| 52 | // Due to the unordered nature of tree pushes, once prepareTree |
| 53 | // is finished it is possible that the node was "resurrected" and has |
| 54 | // a non-zero parent count. |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 55 | virtual void onMaybeRemovedFromTree(RenderNode* node) = 0; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 56 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 57 | protected: |
John Reck | bb3a358 | 2018-09-26 11:21:08 -0700 | [diff] [blame] | 58 | virtual ~TreeObserver() = default; |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 59 | }; |
| 60 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 61 | // This would be a struct, but we want to PREVENT_COPY_AND_ASSIGN |
| 62 | class TreeInfo { |
| 63 | PREVENT_COPY_AND_ASSIGN(TreeInfo); |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 64 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 65 | public: |
| 66 | enum TraversalMode { |
| 67 | // The full monty - sync, push, run animators, etc... Used by DrawFrameTask |
| 68 | // May only be used if both the UI thread and RT thread are blocked on the |
| 69 | // prepare |
| 70 | MODE_FULL, |
| 71 | // Run only what can be done safely on RT thread. Currently this only means |
| 72 | // animators, but potentially things like SurfaceTexture updates |
| 73 | // could be handled by this as well if there are no listeners |
| 74 | MODE_RT_ONLY, |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
John Reck | bb3a358 | 2018-09-26 11:21:08 -0700 | [diff] [blame] | 77 | TreeInfo(TraversalMode mode, renderthread::CanvasContext& canvasContext); |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 78 | |
Skuhne | ea7a7fb | 2015-08-28 07:10:31 -0700 | [diff] [blame] | 79 | TraversalMode mode; |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 80 | // TODO: Remove this? Currently this is used to signal to stop preparing |
| 81 | // textures if we run out of cache space. |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 82 | bool prepareTextures; |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 83 | renderthread::CanvasContext& canvasContext; |
John Reck | 9eb9f6f | 2014-08-21 11:23:05 -0700 | [diff] [blame] | 84 | // 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 |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 89 | bool runAnimations = true; |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 90 | |
| 91 | // Must not be null during actual usage |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 92 | DamageAccumulator* damageAccumulator = nullptr; |
John Reck | f1aa7909e | 2019-03-07 17:01:08 -0800 | [diff] [blame] | 93 | int64_t damageGenerationId = 0; |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 94 | |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 95 | LayerUpdateQueue* layerUpdateQueue = nullptr; |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 96 | ErrorHandler* errorHandler = nullptr; |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 97 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 98 | bool updateWindowPositions = false; |
| 99 | |
John Reck | bb3a358 | 2018-09-26 11:21:08 -0700 | [diff] [blame] | 100 | int disableForceDark; |
Tyler Freeman | 3356774 | 2023-10-31 01:55:51 +0000 | [diff] [blame] | 101 | ForceDarkType forceDarkType = ForceDarkType::NONE; |
John Reck | 1423e13 | 2018-09-21 14:30:19 -0700 | [diff] [blame] | 102 | |
Leon Scroggins III | 6c5864c | 2019-04-03 15:09:25 -0400 | [diff] [blame] | 103 | const SkISize screenSize; |
| 104 | |
John Reck | 5d53a75 | 2021-02-08 19:22:59 -0500 | [diff] [blame] | 105 | int stretchEffectCount = 0; |
| 106 | |
chaviw | adba0b1 | 2022-03-18 17:42:15 -0500 | [diff] [blame] | 107 | bool forceDrawFrame = false; |
| 108 | |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 109 | struct Out { |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 110 | bool hasFunctors = false; |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 111 | // This is only updated if evaluateAnimations is true |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 112 | bool hasAnimations = false; |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 113 | // This is set to true if there is an animation that RenderThread cannot |
| 114 | // animate itself, such as if hasFunctors is true |
| 115 | // This is only set if hasAnimations is true |
Chris Craik | e2e53a7 | 2015-10-28 15:55:40 -0700 | [diff] [blame] | 116 | bool requiresUiRedraw = false; |
Ady Abraham | e088dcd | 2023-08-10 11:45:58 -0700 | [diff] [blame] | 117 | // This is set to nullopt if draw() can be called this frame |
| 118 | // A value means that we must delay until the next vsync pulse as frame |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 119 | // production is outrunning consumption |
Ady Abraham | e088dcd | 2023-08-10 11:45:58 -0700 | [diff] [blame] | 120 | // NOTE that if this has a value CanvasContext will set either requiresUiRedraw |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 121 | // *OR* will post itself for the next vsync automatically, use this |
| 122 | // only to avoid calling draw() |
Ady Abraham | e088dcd | 2023-08-10 11:45:58 -0700 | [diff] [blame] | 123 | std::optional<SkippedFrameReason> skippedFrameReason; |
Leon Scroggins III | 4afdd1c | 2018-05-14 14:59:30 -0400 | [diff] [blame] | 124 | // Sentinel for animatedImageDelay meaning there is no need to post such |
| 125 | // a message. |
| 126 | static constexpr nsecs_t kNoAnimatedImageDelay = -1; |
| 127 | // This is used to post a message to redraw when it is time to draw the |
| 128 | // next frame of an AnimatedImageDrawable. |
| 129 | nsecs_t animatedImageDelay = kNoAnimatedImageDelay; |
Ady Abraham | cab4afe | 2023-05-09 11:25:22 -0700 | [diff] [blame] | 130 | // This is used to determine if there were only TextureView updates in this frame. |
| 131 | // This info is passed to SurfaceFlinger to determine whether it should use vsyncIds |
| 132 | // for refresh rate selection. |
| 133 | bool solelyTextureViewUpdates = true; |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 134 | } out; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 135 | |
Stan Iliev | db45a4b | 2016-11-08 14:18:31 -0500 | [diff] [blame] | 136 | // This flag helps to disable projection for receiver nodes that do not have any backward |
| 137 | // projected children. |
| 138 | bool hasBackwardProjectedNodes = false; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 139 | // TODO: Damage calculations |
| 140 | }; |
| 141 | |
| 142 | } /* namespace uirenderer */ |
| 143 | } /* namespace android */ |