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 <SkCamera.h> |
| 20 | #include <SkMatrix.h> |
| 21 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 22 | #include <utils/LinearAllocator.h> |
| 23 | #include <utils/RefBase.h> |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 24 | #include <utils/String8.h> |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 25 | |
| 26 | #include <cutils/compiler.h> |
| 27 | |
| 28 | #include <androidfw/ResourceTypes.h> |
| 29 | |
Jagadeesh Pakaravoor | b624af3 | 2020-05-01 00:01:40 +0000 | [diff] [blame] | 30 | #include <ui/FatVector.h> |
| 31 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 32 | #include "AnimatorManager.h" |
John Reck | 9ce2bf7 | 2018-07-02 18:33:32 -0700 | [diff] [blame] | 33 | #include "CanvasTransform.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 34 | #include "Debug.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 35 | #include "DisplayList.h" |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 36 | #include "Matrix.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 37 | #include "RenderProperties.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> |
| 42 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 43 | class SkBitmap; |
| 44 | class SkPaint; |
| 45 | class SkPath; |
| 46 | class SkRegion; |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 47 | class SkSurface; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 48 | |
| 49 | namespace android { |
| 50 | namespace uirenderer { |
| 51 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 52 | class CanvasState; |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 53 | class Rect; |
| 54 | class SkiaShader; |
Chris Craik | 8d1f212 | 2015-11-24 16:40:09 -0800 | [diff] [blame] | 55 | struct RenderNodeOp; |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 56 | |
Tom Hudson | 2dc236b | 2014-10-15 15:46:42 -0400 | [diff] [blame] | 57 | class TreeInfo; |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 58 | class TreeObserver; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 59 | |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 60 | namespace proto { |
| 61 | class RenderNode; |
| 62 | } |
| 63 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 64 | /** |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 65 | * Primary class for storing recorded canvas commands, as well as per-View/ViewGroup display |
| 66 | * properties. |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 67 | * |
| 68 | * 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] | 69 | * functionality is split between RecordingCanvas (which manages the recording), DisplayList |
| 70 | * (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] | 71 | * |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 72 | * Note that DisplayList is swapped out from beneath an individual RenderNode when a view's |
| 73 | * 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] | 74 | * attached. |
| 75 | */ |
John Reck | 087bc0c | 2014-04-04 16:20:08 -0700 | [diff] [blame] | 76 | class RenderNode : public VirtualLightRefBase { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 77 | friend class TestUtils; // allow TestUtils to access syncDisplayList / syncProperties |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 78 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 79 | public: |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 80 | enum DirtyPropertyMask { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 81 | GENERIC = 1 << 1, |
| 82 | TRANSLATION_X = 1 << 2, |
| 83 | TRANSLATION_Y = 1 << 3, |
| 84 | TRANSLATION_Z = 1 << 4, |
| 85 | SCALE_X = 1 << 5, |
| 86 | SCALE_Y = 1 << 6, |
| 87 | ROTATION = 1 << 7, |
| 88 | ROTATION_X = 1 << 8, |
| 89 | ROTATION_Y = 1 << 9, |
| 90 | X = 1 << 10, |
| 91 | Y = 1 << 11, |
| 92 | Z = 1 << 12, |
| 93 | ALPHA = 1 << 13, |
| 94 | DISPLAY_LIST = 1 << 14, |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 95 | }; |
| 96 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 97 | ANDROID_API RenderNode(); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 98 | ANDROID_API virtual ~RenderNode(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 99 | |
| 100 | // See flags defined in DisplayList.java |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 101 | enum ReplayFlag { kReplayFlag_ClipChildren = 0x1 }; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 102 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 103 | ANDROID_API void setStagingDisplayList(DisplayList* newData); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 104 | |
sergeyv | c3849aa | 2016-08-08 13:22:06 -0700 | [diff] [blame] | 105 | ANDROID_API void output(); |
John Reck | 183e138 | 2019-10-09 13:41:18 -0700 | [diff] [blame] | 106 | ANDROID_API int getUsageSize(); |
| 107 | ANDROID_API int getAllocatedSize(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 108 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 109 | bool isRenderable() const { return mDisplayList && !mDisplayList->isEmpty(); } |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 110 | |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 111 | bool hasProjectionReceiver() const { |
John Reck | f3c724f | 2018-09-20 13:00:04 -0700 | [diff] [blame] | 112 | return mDisplayList && mDisplayList->containsProjectionReceiver(); |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 113 | } |
| 114 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 115 | const char* getName() const { return mName.string(); } |
Chris Craik | defb7f3 | 2014-04-08 18:17:07 -0700 | [diff] [blame] | 116 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 117 | void setName(const char* name) { |
| 118 | if (name) { |
Dan Austin | 71831a6 | 2016-03-24 12:03:42 -0700 | [diff] [blame] | 119 | const char* lastPeriod = strrchr(name, '.'); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 120 | if (lastPeriod) { |
| 121 | mName.setTo(lastPeriod + 1); |
| 122 | } else { |
| 123 | mName.setTo(name); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 128 | VirtualLightRefBase* getUserContext() const { return mUserContext.get(); } |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 129 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 130 | void setUserContext(VirtualLightRefBase* context) { mUserContext = context; } |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 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 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 152 | ANDROID_API 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! |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 157 | ANDROID_API 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 | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 171 | return mDisplayList == nullptr || properties().getAlpha() <= 0 || |
| 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 | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 176 | const DisplayList* getDisplayList() const { return mDisplayList; } |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 177 | |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 178 | // Note: The position callbacks are relying on the listener using |
| 179 | // the frameNumber to appropriately batch/synchronize these transactions. |
| 180 | // There is no other filtering/batching to ensure that only the "final" |
| 181 | // state called once per frame. |
John Reck | 7b570de | 2016-06-27 13:27:23 -0700 | [diff] [blame] | 182 | class ANDROID_API PositionListener : public VirtualLightRefBase { |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 183 | public: |
| 184 | virtual ~PositionListener() {} |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 185 | // Called when the RenderNode's position changes |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 186 | virtual void onPositionUpdated(RenderNode& node, const TreeInfo& info) = 0; |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 187 | // Called when the RenderNode no longer has a position. As in, it's |
| 188 | // no longer being drawn. |
| 189 | // Note, tree info might be null |
| 190 | virtual void onPositionLost(RenderNode& node, const TreeInfo* info) = 0; |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 191 | }; |
| 192 | |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 193 | ANDROID_API void setPositionListener(PositionListener* listener) { |
John Reck | 097e1d3 | 2019-06-12 15:01:51 -0700 | [diff] [blame] | 194 | mStagingPositionListener = listener; |
| 195 | mPositionListenerDirty = true; |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 196 | } |
| 197 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 198 | // This is only modified in MODE_FULL, so it can be safely accessed |
| 199 | // on the UI thread. |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 200 | ANDROID_API bool hasParents() { return mParentCount; } |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 201 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 202 | void onRemovedFromTree(TreeInfo* info); |
| 203 | |
| 204 | // Called by CanvasContext to promote a RenderNode to be a root node |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 205 | void makeRoot() { incParentRefCount(); } |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 206 | |
| 207 | // Called by CanvasContext when it drops a RenderNode from being a root node |
| 208 | void clearRoot(); |
| 209 | |
Stan Iliev | d217237 | 2017-02-09 16:59:27 -0500 | [diff] [blame] | 210 | void output(std::ostream& output, uint32_t level); |
| 211 | |
John Reck | 8f45d4a | 2018-08-15 10:17:12 -0700 | [diff] [blame] | 212 | void setUsageHint(UsageHint usageHint) { mUsageHint = usageHint; } |
John Reck | 9ce2bf7 | 2018-07-02 18:33:32 -0700 | [diff] [blame] | 213 | |
John Reck | 8f45d4a | 2018-08-15 10:17:12 -0700 | [diff] [blame] | 214 | UsageHint usageHint() const { return mUsageHint; } |
John Reck | 9ce2bf7 | 2018-07-02 18:33:32 -0700 | [diff] [blame] | 215 | |
John Reck | f96b284 | 2018-11-29 09:44:10 -0800 | [diff] [blame] | 216 | int64_t uniqueId() const { return mUniqueId; } |
| 217 | |
| 218 | void markDrawStart(SkCanvas& canvas); |
| 219 | void markDrawEnd(SkCanvas& canvas); |
| 220 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 221 | private: |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 222 | void computeOrderingImpl(RenderNodeOp* opState, |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 223 | std::vector<RenderNodeOp*>* compositedChildrenOfProjectionSurface, |
| 224 | const mat4* transformFromProjectionSurface); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 225 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 226 | void syncProperties(); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 227 | void syncDisplayList(TreeObserver& observer, TreeInfo* info); |
John Reck | 3b4510cd | 2018-09-27 17:39:45 -0700 | [diff] [blame] | 228 | void handleForceDark(TreeInfo* info); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 229 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 230 | void prepareTreeImpl(TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 231 | void pushStagingPropertiesChanges(TreeInfo& info); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 232 | void pushStagingDisplayListChanges(TreeObserver& observer, TreeInfo& info); |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 233 | void prepareLayer(TreeInfo& info, uint32_t dirtyMask); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 234 | void pushLayerUpdate(TreeInfo& info); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 235 | void deleteDisplayList(TreeObserver& observer, TreeInfo* info = nullptr); |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 236 | void damageSelf(TreeInfo& info); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 237 | |
| 238 | void incParentRefCount() { mParentCount++; } |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 239 | void decParentRefCount(TreeObserver& observer, TreeInfo* info = nullptr); |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 240 | |
John Reck | f96b284 | 2018-11-29 09:44:10 -0800 | [diff] [blame] | 241 | const int64_t mUniqueId; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 242 | String8 mName; |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 243 | sp<VirtualLightRefBase> mUserContext; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 244 | |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 245 | uint32_t mDirtyPropertyFields; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 246 | RenderProperties mProperties; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 247 | RenderProperties mStagingProperties; |
| 248 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 249 | // Owned by UI. Set when DL is set, cleared when DL cleared or when node detached |
| 250 | // (likely by parent re-record/removal) |
| 251 | bool mValid = false; |
| 252 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 253 | bool mNeedsDisplayListSync; |
| 254 | // WARNING: Do not delete this directly, you must go through deleteDisplayList()! |
| 255 | DisplayList* mDisplayList; |
| 256 | DisplayList* mStagingDisplayList; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 257 | |
John Reck | f1aa7909e | 2019-03-07 17:01:08 -0800 | [diff] [blame] | 258 | int64_t mDamageGenerationId; |
| 259 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 260 | friend class AnimatorManager; |
| 261 | AnimatorManager mAnimatorManager; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 262 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 263 | /** |
| 264 | * Draw time state - these properties are only set and used during rendering |
| 265 | */ |
| 266 | |
| 267 | // for projection surfaces, contains a list of all children items |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 268 | std::vector<RenderNodeOp*> mProjectedNodes; |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 269 | |
| 270 | // How many references our parent(s) have to us. Typically this should alternate |
| 271 | // between 2 and 1 (when a staging push happens we inc first then dec) |
| 272 | // When this hits 0 we are no longer in the tree, so any hardware resources |
| 273 | // (specifically Layers) should be released. |
| 274 | // This is *NOT* thread-safe, and should therefore only be tracking |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 275 | // mDisplayList, not mStagingDisplayList. |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 276 | uint32_t mParentCount; |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 277 | |
John Reck | 097e1d3 | 2019-06-12 15:01:51 -0700 | [diff] [blame] | 278 | bool mPositionListenerDirty = false; |
| 279 | sp<PositionListener> mStagingPositionListener; |
John Reck | 7b570de | 2016-06-27 13:27:23 -0700 | [diff] [blame] | 280 | sp<PositionListener> mPositionListener; |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 281 | |
John Reck | 9ce2bf7 | 2018-07-02 18:33:32 -0700 | [diff] [blame] | 282 | UsageHint mUsageHint = UsageHint::Unknown; |
| 283 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 284 | // METHODS & FIELDS ONLY USED BY THE SKIA RENDERER |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 285 | public: |
| 286 | /** |
| 287 | * Detach and transfer ownership of an already allocated displayList for use |
| 288 | * in recording updated content for this renderNode |
| 289 | */ |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 290 | std::unique_ptr<skiapipeline::SkiaDisplayList> detachAvailableList() { |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 291 | return std::move(mAvailableDisplayList); |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * Attach unused displayList to this node for potential future reuse. |
| 296 | */ |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 297 | void attachAvailableList(skiapipeline::SkiaDisplayList* skiaDisplayList) { |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 298 | mAvailableDisplayList.reset(skiaDisplayList); |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Returns true if an offscreen layer from any renderPipeline is attached |
| 303 | * to this node. |
| 304 | */ |
John Reck | e4c1e6c | 2018-05-24 16:27:35 -0700 | [diff] [blame] | 305 | bool hasLayer() const { return mSkiaLayer.get(); } |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 306 | |
| 307 | /** |
| 308 | * Used by the RenderPipeline to attach an offscreen surface to the RenderNode. |
| 309 | * The surface is then will be used to store the contents of a layer. |
| 310 | */ |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 311 | void setLayerSurface(sk_sp<SkSurface> layer) { |
| 312 | if (layer.get()) { |
| 313 | if (!mSkiaLayer.get()) { |
| 314 | mSkiaLayer = std::make_unique<skiapipeline::SkiaLayer>(); |
| 315 | } |
| 316 | mSkiaLayer->layerSurface = std::move(layer); |
| 317 | mSkiaLayer->inverseTransformInWindow.loadIdentity(); |
| 318 | } else { |
| 319 | mSkiaLayer.reset(); |
| 320 | } |
| 321 | } |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 322 | |
| 323 | /** |
| 324 | * If the RenderNode is of type LayerType::RenderLayer then this method will |
| 325 | * return the an offscreen rendering surface that is used to both render into |
| 326 | * the layer and composite the layer into its parent. If the type is not |
| 327 | * LayerType::RenderLayer then it will return a nullptr. |
| 328 | * |
| 329 | * NOTE: this function is only guaranteed to return accurate results after |
| 330 | * prepareTree has been run for this RenderNode |
| 331 | */ |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 332 | SkSurface* getLayerSurface() const { |
| 333 | return mSkiaLayer.get() ? mSkiaLayer->layerSurface.get() : nullptr; |
| 334 | } |
| 335 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 336 | skiapipeline::SkiaLayer* getSkiaLayer() const { return mSkiaLayer.get(); } |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 337 | |
Derek Sollenberger | 579317d | 2017-08-29 16:33:49 -0400 | [diff] [blame] | 338 | /** |
| 339 | * Returns the path that represents the outline of RenderNode intersected with |
| 340 | * the provided rect. This call will internally cache the resulting path in |
| 341 | * order to potentially return that path for subsequent calls to this method. |
| 342 | * By reusing the same path we get better performance on the GPU backends since |
| 343 | * those resources are cached in the hardware based on the path's genID. |
| 344 | * |
| 345 | * The returned path is only guaranteed to be valid until this function is called |
| 346 | * again or the RenderNode's outline is mutated. |
| 347 | */ |
| 348 | const SkPath* getClippedOutline(const SkRect& clipRect) const; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 349 | |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 350 | private: |
| 351 | /** |
| 352 | * If this RenderNode has been used in a previous frame then the SkiaDisplayList |
| 353 | * from that frame is cached here until one of the following conditions is met: |
| 354 | * 1) The RenderNode is deleted (causing this to be deleted) |
| 355 | * 2) It is replaced with the displayList from the next completed frame |
| 356 | * 3) It is detached and used to to record a new displayList for a later frame |
| 357 | */ |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 358 | std::unique_ptr<skiapipeline::SkiaDisplayList> mAvailableDisplayList; |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 359 | |
| 360 | /** |
| 361 | * An offscreen rendering target used to contain the contents this RenderNode |
| 362 | * when it has been set to draw as a LayerType::RenderLayer. |
| 363 | */ |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 364 | std::unique_ptr<skiapipeline::SkiaLayer> mSkiaLayer; |
Derek Sollenberger | 579317d | 2017-08-29 16:33:49 -0400 | [diff] [blame] | 365 | |
| 366 | struct ClippedOutlineCache { |
| 367 | // keys |
| 368 | uint32_t outlineID = 0; |
| 369 | SkRect clipRect; |
| 370 | |
| 371 | // value |
| 372 | SkPath clippedOutline; |
| 373 | }; |
| 374 | mutable ClippedOutlineCache mClippedOutlineCache; |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 375 | }; // class RenderNode |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 376 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 377 | class MarkAndSweepRemoved : public TreeObserver { |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 378 | PREVENT_COPY_AND_ASSIGN(MarkAndSweepRemoved); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 379 | |
| 380 | public: |
| 381 | explicit MarkAndSweepRemoved(TreeInfo* info) : mTreeInfo(info) {} |
| 382 | |
John Reck | 1bcacfd | 2017-11-03 10:12:19 -0700 | [diff] [blame] | 383 | void onMaybeRemovedFromTree(RenderNode* node) override { mMarked.emplace_back(node); } |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame] | 384 | |
| 385 | ~MarkAndSweepRemoved() { |
| 386 | for (auto& node : mMarked) { |
| 387 | if (!node->hasParents()) { |
| 388 | node->onRemovedFromTree(mTreeInfo); |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | private: |
| 394 | FatVector<sp<RenderNode>, 10> mMarked; |
| 395 | TreeInfo* mTreeInfo; |
| 396 | }; |
| 397 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 398 | } /* namespace uirenderer */ |
| 399 | } /* namespace android */ |