John Reck | 113e082 | 2014-03-18 09:22:59 -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 | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 18 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 19 | #include <SkMatrix.h> |
| 20 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 21 | #include <utils/LinearAllocator.h> |
| 22 | #include <utils/RefBase.h> |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 23 | #include <utils/String8.h> |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 24 | |
| 25 | #include <cutils/compiler.h> |
| 26 | |
| 27 | #include <androidfw/ResourceTypes.h> |
| 28 | |
Jagadeesh Pakaravoor | b624af3 | 2020-05-01 00:01:40 +0000 | [diff] [blame] | 29 | #include <ui/FatVector.h> |
| 30 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 31 | #include "AnimatorManager.h" |
John Reck | 9ce2bf7 | 2018-07-02 18:33:32 -0700 | [diff] [blame] | 32 | #include "CanvasTransform.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 33 | #include "Debug.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 34 | #include "DisplayList.h" |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 35 | #include "Matrix.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 36 | #include "RenderProperties.h" |
Nader Jawad | 2dc632a | 2021-03-29 18:51:29 -0700 | [diff] [blame] | 37 | #include "pipeline/skia/HolePunch.h" |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 38 | #include "pipeline/skia/SkiaDisplayList.h" |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 39 | #include "pipeline/skia/SkiaLayer.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 40 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 41 | #include <vector> |
Nader Jawad | 197743f | 2021-04-19 19:45:13 -0700 | [diff] [blame] | 42 | #include <pipeline/skia/StretchMask.h> |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 43 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 44 | class SkBitmap; |
| 45 | class SkPaint; |
| 46 | class SkPath; |
| 47 | class SkRegion; |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 48 | class SkSurface; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 49 | |
| 50 | namespace android { |
| 51 | namespace uirenderer { |
| 52 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 53 | class CanvasState; |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 54 | class Rect; |
| 55 | class SkiaShader; |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 56 | struct RenderNodeOp; |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 57 | |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 58 | class TreeInfo; |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 59 | class TreeObserver; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 60 | |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 61 | namespace proto { |
| 62 | class RenderNode; |
| 63 | } |
| 64 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 65 | /** |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 66 | * Primary class for storing recorded canvas commands, as well as per-View/ViewGroup display |
| 67 | * properties. |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 68 | * |
| 69 | * Recording of canvas commands is somewhat similar to SkPicture, except the canvas-recording |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 70 | * functionality is split between RecordingCanvas (which manages the recording), DisplayList |
| 71 | * (which holds the actual data), and RenderNode (which holds properties used for render playback). |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 72 | * |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 73 | * Note that DisplayList is swapped out from beneath an individual RenderNode when a view's |
| 74 | * recorded stream of canvas operations is refreshed. The RenderNode (and its properties) stay |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 75 | * attached. |
| 76 | */ |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 77 | class RenderNode : public VirtualLightRefBase { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 78 | friend class TestUtils; // allow TestUtils to access syncDisplayList / syncProperties |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 79 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 80 | public: |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 81 | enum DirtyPropertyMask { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 82 | GENERIC = 1 << 1, |
| 83 | TRANSLATION_X = 1 << 2, |
| 84 | TRANSLATION_Y = 1 << 3, |
| 85 | TRANSLATION_Z = 1 << 4, |
| 86 | SCALE_X = 1 << 5, |
| 87 | SCALE_Y = 1 << 6, |
| 88 | ROTATION = 1 << 7, |
| 89 | ROTATION_X = 1 << 8, |
| 90 | ROTATION_Y = 1 << 9, |
| 91 | X = 1 << 10, |
| 92 | Y = 1 << 11, |
| 93 | Z = 1 << 12, |
| 94 | ALPHA = 1 << 13, |
| 95 | DISPLAY_LIST = 1 << 14, |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame] | 98 | RenderNode(); |
| 99 | virtual ~RenderNode(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 100 | |
| 101 | // See flags defined in DisplayList.java |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 102 | enum ReplayFlag { kReplayFlag_ClipChildren = 0x1 }; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 103 | |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 104 | void setStagingDisplayList(DisplayList&& newData); |
John Reck | dc1a696 | 2021-01-12 13:56:07 -0500 | [diff] [blame] | 105 | void discardStagingDisplayList(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 106 | |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame] | 107 | void output(); |
| 108 | int getUsageSize(); |
| 109 | int getAllocatedSize(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 110 | |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 111 | bool isRenderable() const { return mDisplayList.hasContent(); } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 112 | |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 113 | bool hasProjectionReceiver() const { |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 114 | return mDisplayList.containsProjectionReceiver(); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Tomasz Wasilczyk | 3f9f863 | 2023-08-10 23:54:44 +0000 | [diff] [blame] | 117 | const char* getName() const { return mName.c_str(); } |
Chris Craik | defb7f3 | 2014-04-08 18:17:07 -0700 | [diff] [blame] | 118 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 119 | void setName(const char* name) { |
| 120 | if (name) { |
Dan Austin | 71831a6 | 2016-03-24 12:03:42 -0700 | [diff] [blame] | 121 | const char* lastPeriod = strrchr(name, '.'); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 122 | if (lastPeriod) { |
Tomasz Wasilczyk | 31eb3c89 | 2023-08-23 22:12:33 +0000 | [diff] [blame] | 123 | mName = (lastPeriod + 1); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 124 | } else { |
Tomasz Wasilczyk | 31eb3c89 | 2023-08-23 22:12:33 +0000 | [diff] [blame] | 125 | mName = name; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
Nader Jawad | 197743f | 2021-04-19 19:45:13 -0700 | [diff] [blame] | 130 | StretchMask& getStretchMask() { return mStretchMask; } |
| 131 | |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 132 | bool isPropertyFieldDirty(DirtyPropertyMask field) const { |
| 133 | return mDirtyPropertyFields & field; |
| 134 | } |
| 135 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 136 | void setPropertyFieldsDirty(uint32_t fields) { mDirtyPropertyFields |= fields; } |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 137 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 138 | const RenderProperties& properties() const { return mProperties; } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 139 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 140 | RenderProperties& animatorProperties() { return mProperties; } |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 141 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 142 | const RenderProperties& stagingProperties() { return mStagingProperties; } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 143 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 144 | RenderProperties& mutateStagingProperties() { return mStagingProperties; } |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 145 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 146 | bool isValid() { return mValid; } |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 147 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 148 | int getWidth() const { return properties().getWidth(); } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 149 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 150 | int getHeight() const { return properties().getHeight(); } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 151 | |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame] | 152 | virtual void prepareTree(TreeInfo& info); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 153 | void destroyHardwareResources(TreeInfo* info = nullptr); |
| 154 | void destroyLayers(); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 155 | |
| 156 | // UI thread only! |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame] | 157 | void addAnimator(const sp<BaseRenderNodeAnimator>& animator); |
Doris Liu | 8b08320 | 2016-02-19 21:46:06 +0000 | [diff] [blame] | 158 | void removeAnimator(const sp<BaseRenderNodeAnimator>& animator); |
| 159 | |
| 160 | // This can only happen during pushStaging() |
| 161 | void onAnimatorTargetChanged(BaseRenderNodeAnimator* animator) { |
| 162 | mAnimatorManager.onAnimatorTargetChanged(animator); |
| 163 | } |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 164 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 165 | AnimatorManager& animators() { return mAnimatorManager; } |
| 166 | |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 167 | void applyViewPropertyTransforms(mat4& matrix, bool true3dTransform = false) const; |
| 168 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 169 | bool nothingToDraw() const { |
| 170 | const Outline& outline = properties().getOutline(); |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 171 | return !mDisplayList.isValid() || properties().getAlpha() <= 0 || |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 172 | (outline.getShouldClip() && outline.isEmpty()) || properties().getScaleX() == 0 || |
| 173 | properties().getScaleY() == 0; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 174 | } |
| 175 | |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 176 | const DisplayList& getDisplayList() const { return mDisplayList; } |
| 177 | // TODO: can this be cleaned up? |
| 178 | DisplayList& getDisplayList() { return mDisplayList; } |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 179 | |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 180 | // Note: The position callbacks are relying on the listener using |
| 181 | // the frameNumber to appropriately batch/synchronize these transactions. |
| 182 | // There is no other filtering/batching to ensure that only the "final" |
| 183 | // state called once per frame. |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame] | 184 | class PositionListener : public VirtualLightRefBase { |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 185 | public: |
| 186 | virtual ~PositionListener() {} |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 187 | // Called when the RenderNode's position changes |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 188 | virtual void onPositionUpdated(RenderNode& node, const TreeInfo& info) = 0; |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 189 | // Called when the RenderNode no longer has a position. As in, it's |
| 190 | // no longer being drawn. |
| 191 | // Note, tree info might be null |
| 192 | virtual void onPositionLost(RenderNode& node, const TreeInfo* info) = 0; |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 193 | }; |
| 194 | |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame] | 195 | void setPositionListener(PositionListener* listener) { |
John Reck | 097e1d3 | 2019-06-12 15:01:51 -0700 | [diff] [blame] | 196 | mStagingPositionListener = listener; |
| 197 | mPositionListenerDirty = true; |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 198 | } |
| 199 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 200 | // This is only modified in MODE_FULL, so it can be safely accessed |
| 201 | // on the UI thread. |
Derek Sollenberger | 3fedf5a | 2020-02-21 13:07:28 -0500 | [diff] [blame] | 202 | bool hasParents() { return mParentCount; } |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 203 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 204 | void onRemovedFromTree(TreeInfo* info); |
| 205 | |
| 206 | // Called by CanvasContext to promote a RenderNode to be a root node |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 207 | void makeRoot() { incParentRefCount(); } |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 208 | |
| 209 | // Called by CanvasContext when it drops a RenderNode from being a root node |
| 210 | void clearRoot(); |
| 211 | |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 212 | void output(std::ostream& output, uint32_t level); |
| 213 | |
John Reck | 07f3d91 | 2023-08-17 12:46:44 -0400 | [diff] [blame] | 214 | void visit(std::function<void(const RenderNode&)>) const; |
| 215 | |
John Reck | 8f45d4a | 2018-08-15 10:17:12 -0700 | [diff] [blame] | 216 | void setUsageHint(UsageHint usageHint) { mUsageHint = usageHint; } |
John Reck | 9ce2bf7 | 2018-07-02 18:33:32 -0700 | [diff] [blame] | 217 | |
John Reck | 8f45d4a | 2018-08-15 10:17:12 -0700 | [diff] [blame] | 218 | UsageHint usageHint() const { return mUsageHint; } |
John Reck | 9ce2bf7 | 2018-07-02 18:33:32 -0700 | [diff] [blame] | 219 | |
John Reck | f96b284 | 2018-11-29 09:44:10 -0800 | [diff] [blame] | 220 | int64_t uniqueId() const { return mUniqueId; } |
| 221 | |
Ady Abraham | cab4afe | 2023-05-09 11:25:22 -0700 | [diff] [blame] | 222 | void setIsTextureView() { mIsTextureView = true; } |
John Reck | 07f3d91 | 2023-08-17 12:46:44 -0400 | [diff] [blame] | 223 | bool isTextureView() const { return mIsTextureView; } |
Ady Abraham | cab4afe | 2023-05-09 11:25:22 -0700 | [diff] [blame] | 224 | |
John Reck | f96b284 | 2018-11-29 09:44:10 -0800 | [diff] [blame] | 225 | void markDrawStart(SkCanvas& canvas); |
| 226 | void markDrawEnd(SkCanvas& canvas); |
| 227 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 228 | private: |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 229 | void computeOrderingImpl(RenderNodeOp* opState, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 230 | std::vector<RenderNodeOp*>* compositedChildrenOfProjectionSurface, |
| 231 | const mat4* transformFromProjectionSurface); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 232 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 233 | void syncProperties(); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 234 | void syncDisplayList(TreeObserver& observer, TreeInfo* info); |
John Reck | 3b4510cd | 2018-09-27 17:39:45 -0700 | [diff] [blame] | 235 | void handleForceDark(TreeInfo* info); |
Tyler Freeman | 3356774 | 2023-10-31 01:55:51 +0000 | [diff] [blame] | 236 | bool shouldEnableForceDark(TreeInfo* info); |
Tyler Freeman | 3455a21 | 2024-09-03 18:01:08 +0000 | [diff] [blame] | 237 | bool isForceInvertDark(TreeInfo& info); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 238 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 239 | void prepareTreeImpl(TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 240 | void pushStagingPropertiesChanges(TreeInfo& info); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 241 | void pushStagingDisplayListChanges(TreeObserver& observer, TreeInfo& info); |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 242 | void prepareLayer(TreeInfo& info, uint32_t dirtyMask); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 243 | void pushLayerUpdate(TreeInfo& info); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 244 | void deleteDisplayList(TreeObserver& observer, TreeInfo* info = nullptr); |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 245 | void damageSelf(TreeInfo& info); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 246 | |
| 247 | void incParentRefCount() { mParentCount++; } |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 248 | void decParentRefCount(TreeObserver& observer, TreeInfo* info = nullptr); |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 249 | |
John Reck | f96b284 | 2018-11-29 09:44:10 -0800 | [diff] [blame] | 250 | const int64_t mUniqueId; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 251 | String8 mName; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 252 | |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 253 | uint32_t mDirtyPropertyFields; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 254 | RenderProperties mProperties; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 255 | RenderProperties mStagingProperties; |
| 256 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 257 | // Owned by UI. Set when DL is set, cleared when DL cleared or when node detached |
| 258 | // (likely by parent re-record/removal) |
| 259 | bool mValid = false; |
| 260 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 261 | bool mNeedsDisplayListSync; |
| 262 | // WARNING: Do not delete this directly, you must go through deleteDisplayList()! |
John Reck | be67195 | 2021-01-13 22:39:32 -0500 | [diff] [blame] | 263 | DisplayList mDisplayList; |
| 264 | DisplayList mStagingDisplayList; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 265 | |
qiubowen | 13d879b | 2024-01-22 19:46:22 +0800 | [diff] [blame] | 266 | int64_t mDamageGenerationId = 0; |
John Reck | f1aa7909e | 2019-03-07 17:01:08 -0800 | [diff] [blame] | 267 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 268 | friend class AnimatorManager; |
| 269 | AnimatorManager mAnimatorManager; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 270 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 271 | /** |
| 272 | * Draw time state - these properties are only set and used during rendering |
| 273 | */ |
| 274 | |
| 275 | // for projection surfaces, contains a list of all children items |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 276 | std::vector<RenderNodeOp*> mProjectedNodes; |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 277 | |
| 278 | // How many references our parent(s) have to us. Typically this should alternate |
| 279 | // between 2 and 1 (when a staging push happens we inc first then dec) |
| 280 | // When this hits 0 we are no longer in the tree, so any hardware resources |
| 281 | // (specifically Layers) should be released. |
| 282 | // This is *NOT* thread-safe, and should therefore only be tracking |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 283 | // mDisplayList, not mStagingDisplayList. |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 284 | uint32_t mParentCount; |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 285 | |
John Reck | 097e1d3 | 2019-06-12 15:01:51 -0700 | [diff] [blame] | 286 | bool mPositionListenerDirty = false; |
| 287 | sp<PositionListener> mStagingPositionListener; |
John Reck | 7b570de | 2016-06-27 13:27:23 -0700 | [diff] [blame] | 288 | sp<PositionListener> mPositionListener; |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 289 | |
John Reck | 9ce2bf7 | 2018-07-02 18:33:32 -0700 | [diff] [blame] | 290 | UsageHint mUsageHint = UsageHint::Unknown; |
| 291 | |
Nader Jawad | 2dc632a | 2021-03-29 18:51:29 -0700 | [diff] [blame] | 292 | bool mHasHolePunches; |
Nader Jawad | 197743f | 2021-04-19 19:45:13 -0700 | [diff] [blame] | 293 | StretchMask mStretchMask; |
Nader Jawad | 2dc632a | 2021-03-29 18:51:29 -0700 | [diff] [blame] | 294 | |
Ady Abraham | cab4afe | 2023-05-09 11:25:22 -0700 | [diff] [blame] | 295 | bool mIsTextureView = false; |
| 296 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 297 | // METHODS & FIELDS ONLY USED BY THE SKIA RENDERER |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 298 | public: |
| 299 | /** |
| 300 | * Detach and transfer ownership of an already allocated displayList for use |
| 301 | * in recording updated content for this renderNode |
| 302 | */ |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 303 | std::unique_ptr<skiapipeline::SkiaDisplayList> detachAvailableList() { |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 304 | return std::move(mAvailableDisplayList); |
| 305 | } |
| 306 | |
Nader Jawad | 2dc632a | 2021-03-29 18:51:29 -0700 | [diff] [blame] | 307 | bool hasHolePunches() { return mHasHolePunches; } |
| 308 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 309 | /** |
| 310 | * Attach unused displayList to this node for potential future reuse. |
| 311 | */ |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 312 | void attachAvailableList(skiapipeline::SkiaDisplayList* skiaDisplayList) { |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 313 | mAvailableDisplayList.reset(skiaDisplayList); |
| 314 | } |
| 315 | |
| 316 | /** |
| 317 | * Returns true if an offscreen layer from any renderPipeline is attached |
| 318 | * to this node. |
| 319 | */ |
John Reck | e4c1e6c | 2018-05-24 16:27:35 -0700 | [diff] [blame] | 320 | bool hasLayer() const { return mSkiaLayer.get(); } |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 321 | |
| 322 | /** |
| 323 | * Used by the RenderPipeline to attach an offscreen surface to the RenderNode. |
| 324 | * The surface is then will be used to store the contents of a layer. |
| 325 | */ |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 326 | void setLayerSurface(sk_sp<SkSurface> layer) { |
| 327 | if (layer.get()) { |
| 328 | if (!mSkiaLayer.get()) { |
| 329 | mSkiaLayer = std::make_unique<skiapipeline::SkiaLayer>(); |
| 330 | } |
| 331 | mSkiaLayer->layerSurface = std::move(layer); |
| 332 | mSkiaLayer->inverseTransformInWindow.loadIdentity(); |
| 333 | } else { |
| 334 | mSkiaLayer.reset(); |
| 335 | } |
Nader Jawad | b502ad7 | 2021-06-17 14:10:04 -0700 | [diff] [blame] | 336 | |
Nader Jawad | 3206cce | 2021-06-23 11:48:58 -0700 | [diff] [blame] | 337 | mProperties.mutateLayerProperties().mutableStretchEffect().clear(); |
| 338 | mStretchMask.clear(); |
Nader Jawad | b502ad7 | 2021-06-17 14:10:04 -0700 | [diff] [blame] | 339 | // Clear out the previous snapshot and the image filter the previous |
| 340 | // snapshot was created with whenever the layer changes. |
| 341 | mSnapshotResult.snapshot = nullptr; |
| 342 | mTargetImageFilter = nullptr; |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 343 | } |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 344 | |
| 345 | /** |
| 346 | * If the RenderNode is of type LayerType::RenderLayer then this method will |
| 347 | * return the an offscreen rendering surface that is used to both render into |
| 348 | * the layer and composite the layer into its parent. If the type is not |
| 349 | * LayerType::RenderLayer then it will return a nullptr. |
| 350 | * |
| 351 | * NOTE: this function is only guaranteed to return accurate results after |
| 352 | * prepareTree has been run for this RenderNode |
| 353 | */ |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 354 | SkSurface* getLayerSurface() const { |
| 355 | return mSkiaLayer.get() ? mSkiaLayer->layerSurface.get() : nullptr; |
| 356 | } |
| 357 | |
Nader Jawad | 6aff481 | 2021-06-09 10:14:43 -0700 | [diff] [blame] | 358 | struct SnapshotResult { |
| 359 | sk_sp<SkImage> snapshot; |
| 360 | SkIRect outSubset; |
| 361 | SkIPoint outOffset; |
| 362 | }; |
| 363 | |
| 364 | std::optional<SnapshotResult> updateSnapshotIfRequired(GrRecordingContext* context, |
| 365 | const SkImageFilter* imageFilter, |
| 366 | const SkIRect& clipBounds); |
| 367 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 368 | skiapipeline::SkiaLayer* getSkiaLayer() const { return mSkiaLayer.get(); } |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 369 | |
Derek Sollenberger | 579317d4 | 2017-08-29 16:33:49 -0400 | [diff] [blame] | 370 | /** |
| 371 | * Returns the path that represents the outline of RenderNode intersected with |
| 372 | * the provided rect. This call will internally cache the resulting path in |
| 373 | * order to potentially return that path for subsequent calls to this method. |
| 374 | * By reusing the same path we get better performance on the GPU backends since |
| 375 | * those resources are cached in the hardware based on the path's genID. |
| 376 | * |
| 377 | * The returned path is only guaranteed to be valid until this function is called |
| 378 | * again or the RenderNode's outline is mutated. |
| 379 | */ |
| 380 | const SkPath* getClippedOutline(const SkRect& clipRect) const; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 381 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 382 | private: |
| 383 | /** |
| 384 | * If this RenderNode has been used in a previous frame then the SkiaDisplayList |
| 385 | * from that frame is cached here until one of the following conditions is met: |
| 386 | * 1) The RenderNode is deleted (causing this to be deleted) |
| 387 | * 2) It is replaced with the displayList from the next completed frame |
| 388 | * 3) It is detached and used to to record a new displayList for a later frame |
| 389 | */ |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 390 | std::unique_ptr<skiapipeline::SkiaDisplayList> mAvailableDisplayList; |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 391 | |
| 392 | /** |
| 393 | * An offscreen rendering target used to contain the contents this RenderNode |
| 394 | * when it has been set to draw as a LayerType::RenderLayer. |
| 395 | */ |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 396 | std::unique_ptr<skiapipeline::SkiaLayer> mSkiaLayer; |
Derek Sollenberger | 579317d4 | 2017-08-29 16:33:49 -0400 | [diff] [blame] | 397 | |
Nader Jawad | 6aff481 | 2021-06-09 10:14:43 -0700 | [diff] [blame] | 398 | /** |
| 399 | * SkImageFilter used to create the mSnapshotResult |
| 400 | */ |
| 401 | sk_sp<SkImageFilter> mTargetImageFilter; |
Nader Jawad | f49068f | 2021-09-08 22:17:15 -0700 | [diff] [blame] | 402 | uint32_t mTargetImageFilterLayerSurfaceGenerationId = 0; |
Nader Jawad | 6aff481 | 2021-06-09 10:14:43 -0700 | [diff] [blame] | 403 | |
| 404 | /** |
| 405 | * Clip bounds used to create the mSnapshotResult |
| 406 | */ |
| 407 | SkIRect mImageFilterClipBounds; |
| 408 | |
| 409 | /** |
| 410 | * Result of the most recent snapshot with additional metadata used to |
| 411 | * determine how to draw the contents |
| 412 | */ |
| 413 | SnapshotResult mSnapshotResult; |
| 414 | |
Derek Sollenberger | 579317d4 | 2017-08-29 16:33:49 -0400 | [diff] [blame] | 415 | struct ClippedOutlineCache { |
| 416 | // keys |
| 417 | uint32_t outlineID = 0; |
| 418 | SkRect clipRect; |
| 419 | |
| 420 | // value |
| 421 | SkPath clippedOutline; |
| 422 | }; |
| 423 | mutable ClippedOutlineCache mClippedOutlineCache; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 424 | }; // class RenderNode |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 425 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 426 | class MarkAndSweepRemoved : public TreeObserver { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 427 | PREVENT_COPY_AND_ASSIGN(MarkAndSweepRemoved); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 428 | |
| 429 | public: |
| 430 | explicit MarkAndSweepRemoved(TreeInfo* info) : mTreeInfo(info) {} |
| 431 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 432 | void onMaybeRemovedFromTree(RenderNode* node) override { mMarked.emplace_back(node); } |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 433 | |
| 434 | ~MarkAndSweepRemoved() { |
| 435 | for (auto& node : mMarked) { |
| 436 | if (!node->hasParents()) { |
| 437 | node->onRemovedFromTree(mTreeInfo); |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | private: |
| 443 | FatVector<sp<RenderNode>, 10> mMarked; |
| 444 | TreeInfo* mTreeInfo; |
| 445 | }; |
| 446 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 447 | } /* namespace uirenderer */ |
| 448 | } /* namespace android */ |