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 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 30 | #include "AnimatorManager.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 31 | #include "Debug.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 32 | #include "DisplayList.h" |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 33 | #include "Matrix.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 34 | #include "RenderProperties.h" |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 35 | #include "pipeline/skia/SkiaDisplayList.h" |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 36 | #include "pipeline/skia/SkiaLayer.h" |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame^] | 37 | #include "utils/FatVector.h" |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 38 | |
John Reck | 272a685 | 2015-07-29 16:48:58 -0700 | [diff] [blame] | 39 | #include <vector> |
| 40 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 41 | class SkBitmap; |
| 42 | class SkPaint; |
| 43 | class SkPath; |
| 44 | class SkRegion; |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 45 | class SkSurface; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 46 | |
| 47 | namespace android { |
| 48 | namespace uirenderer { |
| 49 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 50 | class CanvasState; |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 51 | class DisplayListOp; |
Chris Craik | f158b49 | 2016-01-12 14:45:08 -0800 | [diff] [blame] | 52 | class FrameBuilder; |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 53 | class OffscreenBuffer; |
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 | /** |
| 66 | * Primary class for storing recorded canvas commands, as well as per-View/ViewGroup display properties. |
| 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 { |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 77 | friend class TestUtils; // allow TestUtils to access syncDisplayList / syncProperties |
Chris Craik | f158b49 | 2016-01-12 14:45:08 -0800 | [diff] [blame] | 78 | friend class FrameBuilder; |
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 { |
| 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, |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 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 |
| 101 | enum ReplayFlag { |
| 102 | kReplayFlag_ClipChildren = 0x1 |
| 103 | }; |
| 104 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame^] | 105 | ANDROID_API void setStagingDisplayList(DisplayList* newData); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 106 | |
| 107 | void computeOrdering(); |
Chris Craik | b265e2c | 2014-03-27 15:50:09 -0700 | [diff] [blame] | 108 | |
sergeyv | c3849aa | 2016-08-08 13:22:06 -0700 | [diff] [blame] | 109 | ANDROID_API void output(); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame] | 110 | ANDROID_API int getDebugSize(); |
John Reck | e248bd1 | 2015-08-05 13:53:53 -0700 | [diff] [blame] | 111 | void copyTo(proto::RenderNode* node); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 112 | |
| 113 | bool isRenderable() const { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 114 | return mDisplayList && !mDisplayList->isEmpty(); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 115 | } |
| 116 | |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 117 | bool hasProjectionReceiver() const { |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 118 | return mDisplayList && mDisplayList->projectionReceiveIndex >= 0; |
John Reck | a447d29 | 2014-06-11 18:39:44 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Chris Craik | defb7f3 | 2014-04-08 18:17:07 -0700 | [diff] [blame] | 121 | const char* getName() const { |
| 122 | return mName.string(); |
| 123 | } |
| 124 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 125 | void setName(const char* name) { |
| 126 | if (name) { |
Dan Austin | 71831a6 | 2016-03-24 12:03:42 -0700 | [diff] [blame] | 127 | const char* lastPeriod = strrchr(name, '.'); |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 128 | if (lastPeriod) { |
| 129 | mName.setTo(lastPeriod + 1); |
| 130 | } else { |
| 131 | mName.setTo(name); |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 136 | VirtualLightRefBase* getUserContext() const { |
| 137 | return mUserContext.get(); |
| 138 | } |
| 139 | |
| 140 | void setUserContext(VirtualLightRefBase* context) { |
| 141 | mUserContext = context; |
| 142 | } |
| 143 | |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 144 | bool isPropertyFieldDirty(DirtyPropertyMask field) const { |
| 145 | return mDirtyPropertyFields & field; |
| 146 | } |
| 147 | |
| 148 | void setPropertyFieldsDirty(uint32_t fields) { |
| 149 | mDirtyPropertyFields |= fields; |
| 150 | } |
| 151 | |
John Reck | e4267ea | 2014-06-03 15:53:15 -0700 | [diff] [blame] | 152 | const RenderProperties& properties() const { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 153 | return mProperties; |
| 154 | } |
| 155 | |
John Reck | 52244ff | 2014-05-01 21:27:37 -0700 | [diff] [blame] | 156 | RenderProperties& animatorProperties() { |
| 157 | return mProperties; |
| 158 | } |
| 159 | |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 160 | const RenderProperties& stagingProperties() { |
| 161 | return mStagingProperties; |
| 162 | } |
| 163 | |
| 164 | RenderProperties& mutateStagingProperties() { |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 165 | return mStagingProperties; |
| 166 | } |
| 167 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame^] | 168 | bool isValid() { |
| 169 | return mValid; |
| 170 | } |
| 171 | |
Chris Craik | 76caecf | 2015-11-02 19:17:45 -0800 | [diff] [blame] | 172 | int getWidth() const { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 173 | return properties().getWidth(); |
| 174 | } |
| 175 | |
Chris Craik | 76caecf | 2015-11-02 19:17:45 -0800 | [diff] [blame] | 176 | int getHeight() const { |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 177 | return properties().getHeight(); |
| 178 | } |
| 179 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 180 | ANDROID_API virtual void prepareTree(TreeInfo& info); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame^] | 181 | void destroyHardwareResources(TreeInfo* info = nullptr); |
| 182 | void destroyLayers(); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 183 | |
| 184 | // UI thread only! |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 185 | ANDROID_API void addAnimator(const sp<BaseRenderNodeAnimator>& animator); |
Doris Liu | 8b08320 | 2016-02-19 21:46:06 +0000 | [diff] [blame] | 186 | void removeAnimator(const sp<BaseRenderNodeAnimator>& animator); |
| 187 | |
| 188 | // This can only happen during pushStaging() |
| 189 | void onAnimatorTargetChanged(BaseRenderNodeAnimator* animator) { |
| 190 | mAnimatorManager.onAnimatorTargetChanged(animator); |
| 191 | } |
John Reck | 668f0e3 | 2014-03-26 15:10:40 -0700 | [diff] [blame] | 192 | |
John Reck | 119907c | 2014-08-14 09:02:01 -0700 | [diff] [blame] | 193 | AnimatorManager& animators() { return mAnimatorManager; } |
| 194 | |
Chris Craik | 69e5adf | 2014-08-14 13:34:01 -0700 | [diff] [blame] | 195 | void applyViewPropertyTransforms(mat4& matrix, bool true3dTransform = false) const; |
| 196 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 197 | bool nothingToDraw() const { |
| 198 | const Outline& outline = properties().getOutline(); |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 199 | return mDisplayList == nullptr |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 200 | || properties().getAlpha() <= 0 |
| 201 | || (outline.getShouldClip() && outline.isEmpty()) |
| 202 | || properties().getScaleX() == 0 |
| 203 | || properties().getScaleY() == 0; |
| 204 | } |
| 205 | |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 206 | const DisplayList* getDisplayList() const { |
| 207 | return mDisplayList; |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 208 | } |
Chris Craik | 0b7e824 | 2015-10-28 16:50:44 -0700 | [diff] [blame] | 209 | OffscreenBuffer* getLayer() const { return mLayer; } |
| 210 | OffscreenBuffer** getLayerHandle() { return &mLayer; } // ugh... |
Derek Sollenberger | 6a21ca5 | 2016-09-28 13:39:55 -0400 | [diff] [blame] | 211 | void setLayer(OffscreenBuffer* layer) { mLayer = layer; } |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 212 | |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 213 | // Note: The position callbacks are relying on the listener using |
| 214 | // the frameNumber to appropriately batch/synchronize these transactions. |
| 215 | // There is no other filtering/batching to ensure that only the "final" |
| 216 | // state called once per frame. |
John Reck | 7b570de | 2016-06-27 13:27:23 -0700 | [diff] [blame] | 217 | class ANDROID_API PositionListener : public VirtualLightRefBase { |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 218 | public: |
| 219 | virtual ~PositionListener() {} |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 220 | // Called when the RenderNode's position changes |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 221 | virtual void onPositionUpdated(RenderNode& node, const TreeInfo& info) = 0; |
John Reck | aa6e84f | 2016-06-16 15:36:13 -0700 | [diff] [blame] | 222 | // Called when the RenderNode no longer has a position. As in, it's |
| 223 | // no longer being drawn. |
| 224 | // Note, tree info might be null |
| 225 | virtual void onPositionLost(RenderNode& node, const TreeInfo* info) = 0; |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 226 | }; |
| 227 | |
| 228 | // Note this is not thread safe, this needs to be called |
| 229 | // before the RenderNode is used for drawing. |
| 230 | // RenderNode takes ownership of the pointer |
| 231 | ANDROID_API void setPositionListener(PositionListener* listener) { |
John Reck | 7b570de | 2016-06-27 13:27:23 -0700 | [diff] [blame] | 232 | mPositionListener = listener; |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 233 | } |
| 234 | |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 235 | // This is only modified in MODE_FULL, so it can be safely accessed |
| 236 | // on the UI thread. |
| 237 | ANDROID_API bool hasParents() { |
| 238 | return mParentCount; |
| 239 | } |
| 240 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame^] | 241 | void onRemovedFromTree(TreeInfo* info); |
| 242 | |
| 243 | // Called by CanvasContext to promote a RenderNode to be a root node |
| 244 | void makeRoot() { |
| 245 | incParentRefCount(); |
| 246 | } |
| 247 | |
| 248 | // Called by CanvasContext when it drops a RenderNode from being a root node |
| 249 | void clearRoot(); |
| 250 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 251 | private: |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 252 | void computeOrderingImpl(RenderNodeOp* opState, |
| 253 | std::vector<RenderNodeOp*>* compositedChildrenOfProjectionSurface, |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 254 | const mat4* transformFromProjectionSurface); |
| 255 | |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 256 | void syncProperties(); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame^] | 257 | void syncDisplayList(TreeObserver& observer, TreeInfo* info); |
Chris Craik | b565df1 | 2015-10-05 13:00:52 -0700 | [diff] [blame] | 258 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame^] | 259 | void prepareTreeImpl(TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 260 | void pushStagingPropertiesChanges(TreeInfo& info); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame^] | 261 | void pushStagingDisplayListChanges(TreeObserver& observer, TreeInfo& info); |
John Reck | a7c2ea2 | 2014-08-08 13:21:00 -0700 | [diff] [blame] | 262 | void prepareLayer(TreeInfo& info, uint32_t dirtyMask); |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 263 | void pushLayerUpdate(TreeInfo& info); |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame^] | 264 | void deleteDisplayList(TreeObserver& observer, TreeInfo* info = nullptr); |
| 265 | void destroyHardwareResourcesImpl(TreeObserver& observer, TreeInfo* info = nullptr); |
John Reck | 0a97330 | 2014-07-16 13:29:45 -0700 | [diff] [blame] | 266 | void damageSelf(TreeInfo& info); |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 267 | |
| 268 | void incParentRefCount() { mParentCount++; } |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame^] | 269 | void decParentRefCount(TreeObserver& observer, TreeInfo* info = nullptr); |
sergeyv | c3849aa | 2016-08-08 13:22:06 -0700 | [diff] [blame] | 270 | void output(std::ostream& output, uint32_t level); |
John Reck | 8de65a8 | 2014-04-09 15:23:38 -0700 | [diff] [blame] | 271 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 272 | String8 mName; |
John Reck | 44b49f0 | 2016-03-25 14:29:48 -0700 | [diff] [blame] | 273 | sp<VirtualLightRefBase> mUserContext; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 274 | |
John Reck | ff941dc | 2014-05-14 16:34:14 -0700 | [diff] [blame] | 275 | uint32_t mDirtyPropertyFields; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 276 | RenderProperties mProperties; |
John Reck | d0a0b2a | 2014-03-20 16:28:56 -0700 | [diff] [blame] | 277 | RenderProperties mStagingProperties; |
| 278 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame^] | 279 | // Owned by UI. Set when DL is set, cleared when DL cleared or when node detached |
| 280 | // (likely by parent re-record/removal) |
| 281 | bool mValid = false; |
| 282 | |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 283 | bool mNeedsDisplayListSync; |
| 284 | // WARNING: Do not delete this directly, you must go through deleteDisplayList()! |
| 285 | DisplayList* mDisplayList; |
| 286 | DisplayList* mStagingDisplayList; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 287 | |
John Reck | 68bfe0a | 2014-06-24 15:34:58 -0700 | [diff] [blame] | 288 | friend class AnimatorManager; |
| 289 | AnimatorManager mAnimatorManager; |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 290 | |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 291 | // Owned by RT. Lifecycle is managed by prepareTree(), with the exception |
| 292 | // being in ~RenderNode() which may happen on any thread. |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 293 | OffscreenBuffer* mLayer = nullptr; |
John Reck | 25fbb3f | 2014-06-12 13:46:45 -0700 | [diff] [blame] | 294 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 295 | /** |
| 296 | * Draw time state - these properties are only set and used during rendering |
| 297 | */ |
| 298 | |
| 299 | // for projection surfaces, contains a list of all children items |
Chris Craik | 5e00c7c | 2016-07-06 16:10:09 -0700 | [diff] [blame] | 300 | std::vector<RenderNodeOp*> mProjectedNodes; |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 301 | |
| 302 | // How many references our parent(s) have to us. Typically this should alternate |
| 303 | // between 2 and 1 (when a staging push happens we inc first then dec) |
| 304 | // When this hits 0 we are no longer in the tree, so any hardware resources |
| 305 | // (specifically Layers) should be released. |
| 306 | // This is *NOT* thread-safe, and should therefore only be tracking |
Chris Craik | 003cc3d | 2015-10-16 10:24:55 -0700 | [diff] [blame] | 307 | // mDisplayList, not mStagingDisplayList. |
John Reck | dcba672 | 2014-07-08 13:59:49 -0700 | [diff] [blame] | 308 | uint32_t mParentCount; |
John Reck | f648108 | 2016-02-02 15:18:23 -0800 | [diff] [blame] | 309 | |
John Reck | 7b570de | 2016-06-27 13:27:23 -0700 | [diff] [blame] | 310 | sp<PositionListener> mPositionListener; |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 311 | |
| 312 | // METHODS & FIELDS ONLY USED BY THE SKIA RENDERER |
| 313 | public: |
| 314 | /** |
| 315 | * Detach and transfer ownership of an already allocated displayList for use |
| 316 | * in recording updated content for this renderNode |
| 317 | */ |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 318 | std::unique_ptr<skiapipeline::SkiaDisplayList> detachAvailableList() { |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 319 | return std::move(mAvailableDisplayList); |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Attach unused displayList to this node for potential future reuse. |
| 324 | */ |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 325 | void attachAvailableList(skiapipeline::SkiaDisplayList* skiaDisplayList) { |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 326 | mAvailableDisplayList.reset(skiaDisplayList); |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * Returns true if an offscreen layer from any renderPipeline is attached |
| 331 | * to this node. |
| 332 | */ |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 333 | bool hasLayer() const { return mLayer || mSkiaLayer.get(); } |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 334 | |
| 335 | /** |
| 336 | * Used by the RenderPipeline to attach an offscreen surface to the RenderNode. |
| 337 | * The surface is then will be used to store the contents of a layer. |
| 338 | */ |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 339 | void setLayerSurface(sk_sp<SkSurface> layer) { |
| 340 | if (layer.get()) { |
| 341 | if (!mSkiaLayer.get()) { |
| 342 | mSkiaLayer = std::make_unique<skiapipeline::SkiaLayer>(); |
| 343 | } |
| 344 | mSkiaLayer->layerSurface = std::move(layer); |
| 345 | mSkiaLayer->inverseTransformInWindow.loadIdentity(); |
| 346 | } else { |
| 347 | mSkiaLayer.reset(); |
| 348 | } |
| 349 | } |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 350 | |
| 351 | /** |
| 352 | * If the RenderNode is of type LayerType::RenderLayer then this method will |
| 353 | * return the an offscreen rendering surface that is used to both render into |
| 354 | * the layer and composite the layer into its parent. If the type is not |
| 355 | * LayerType::RenderLayer then it will return a nullptr. |
| 356 | * |
| 357 | * NOTE: this function is only guaranteed to return accurate results after |
| 358 | * prepareTree has been run for this RenderNode |
| 359 | */ |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 360 | SkSurface* getLayerSurface() const { |
| 361 | return mSkiaLayer.get() ? mSkiaLayer->layerSurface.get() : nullptr; |
| 362 | } |
| 363 | |
| 364 | skiapipeline::SkiaLayer* getSkiaLayer() const { |
| 365 | return mSkiaLayer.get(); |
| 366 | } |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 367 | |
| 368 | private: |
| 369 | /** |
| 370 | * If this RenderNode has been used in a previous frame then the SkiaDisplayList |
| 371 | * from that frame is cached here until one of the following conditions is met: |
| 372 | * 1) The RenderNode is deleted (causing this to be deleted) |
| 373 | * 2) It is replaced with the displayList from the next completed frame |
| 374 | * 3) It is detached and used to to record a new displayList for a later frame |
| 375 | */ |
Stan Iliev | 021693b | 2016-10-17 16:26:15 -0400 | [diff] [blame] | 376 | std::unique_ptr<skiapipeline::SkiaDisplayList> mAvailableDisplayList; |
Derek Sollenberger | 0df6209 | 2016-09-27 16:04:42 -0400 | [diff] [blame] | 377 | |
| 378 | /** |
| 379 | * An offscreen rendering target used to contain the contents this RenderNode |
| 380 | * when it has been set to draw as a LayerType::RenderLayer. |
| 381 | */ |
Stan Iliev | 500a0c3 | 2016-10-26 10:30:09 -0400 | [diff] [blame] | 382 | std::unique_ptr<skiapipeline::SkiaLayer> mSkiaLayer; |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 383 | }; // class RenderNode |
| 384 | |
John Reck | 2de950d | 2017-01-25 10:58:30 -0800 | [diff] [blame^] | 385 | class MarkAndSweepRemoved : public TreeObserver { |
| 386 | PREVENT_COPY_AND_ASSIGN(MarkAndSweepRemoved); |
| 387 | |
| 388 | public: |
| 389 | explicit MarkAndSweepRemoved(TreeInfo* info) : mTreeInfo(info) {} |
| 390 | |
| 391 | void onMaybeRemovedFromTree(RenderNode* node) override { |
| 392 | mMarked.emplace_back(node); |
| 393 | } |
| 394 | |
| 395 | ~MarkAndSweepRemoved() { |
| 396 | for (auto& node : mMarked) { |
| 397 | if (!node->hasParents()) { |
| 398 | node->onRemovedFromTree(mTreeInfo); |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | private: |
| 404 | FatVector<sp<RenderNode>, 10> mMarked; |
| 405 | TreeInfo* mTreeInfo; |
| 406 | }; |
| 407 | |
John Reck | 113e082 | 2014-03-18 09:22:59 -0700 | [diff] [blame] | 408 | } /* namespace uirenderer */ |
| 409 | } /* namespace android */ |