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