blob: 8595b6e5f78ae61227a5bf16dc118556b3453ce2 [file] [log] [blame]
John Reck113e0822014-03-18 09:22:59 -07001/*
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 Craik5e00c7c2016-07-06 16:10:09 -070016
17#pragma once
John Reck113e0822014-03-18 09:22:59 -070018
John Reck113e0822014-03-18 09:22:59 -070019#include <SkCamera.h>
20#include <SkMatrix.h>
21
John Reck113e0822014-03-18 09:22:59 -070022#include <utils/LinearAllocator.h>
23#include <utils/RefBase.h>
John Reck113e0822014-03-18 09:22:59 -070024#include <utils/String8.h>
John Reck113e0822014-03-18 09:22:59 -070025
26#include <cutils/compiler.h>
27
28#include <androidfw/ResourceTypes.h>
29
Jagadeesh Pakaravoorb624af32020-05-01 00:01:40 +000030#include <ui/FatVector.h>
31
John Reck68bfe0a2014-06-24 15:34:58 -070032#include "AnimatorManager.h"
John Reck9ce2bf72018-07-02 18:33:32 -070033#include "CanvasTransform.h"
John Reck113e0822014-03-18 09:22:59 -070034#include "Debug.h"
John Reck113e0822014-03-18 09:22:59 -070035#include "DisplayList.h"
Chris Craikb565df12015-10-05 13:00:52 -070036#include "Matrix.h"
John Reck113e0822014-03-18 09:22:59 -070037#include "RenderProperties.h"
Nader Jawad2dc632a2021-03-29 18:51:29 -070038#include "pipeline/skia/HolePunch.h"
Stan Iliev021693b2016-10-17 16:26:15 -040039#include "pipeline/skia/SkiaDisplayList.h"
Stan Iliev500a0c32016-10-26 10:30:09 -040040#include "pipeline/skia/SkiaLayer.h"
John Reck113e0822014-03-18 09:22:59 -070041
John Reck272a6852015-07-29 16:48:58 -070042#include <vector>
Nader Jawad197743f2021-04-19 19:45:13 -070043#include <pipeline/skia/StretchMask.h>
John Reck272a6852015-07-29 16:48:58 -070044
John Reck113e0822014-03-18 09:22:59 -070045class SkBitmap;
46class SkPaint;
47class SkPath;
48class SkRegion;
Derek Sollenberger0df62092016-09-27 16:04:42 -040049class SkSurface;
John Reck113e0822014-03-18 09:22:59 -070050
51namespace android {
52namespace uirenderer {
53
Chris Craikb565df12015-10-05 13:00:52 -070054class CanvasState;
Chris Craik5e00c7c2016-07-06 16:10:09 -070055class Rect;
56class SkiaShader;
Chris Craik8d1f2122015-11-24 16:40:09 -080057struct RenderNodeOp;
Chris Craik0b7e8242015-10-28 16:50:44 -070058
Tom Hudson2dc236b2014-10-15 15:46:42 -040059class TreeInfo;
John Reck44b49f02016-03-25 14:29:48 -070060class TreeObserver;
John Reck113e0822014-03-18 09:22:59 -070061
John Recke248bd12015-08-05 13:53:53 -070062namespace proto {
63class RenderNode;
64}
65
John Reck113e0822014-03-18 09:22:59 -070066/**
John Reck1bcacfd2017-11-03 10:12:19 -070067 * Primary class for storing recorded canvas commands, as well as per-View/ViewGroup display
68 * properties.
John Reck113e0822014-03-18 09:22:59 -070069 *
70 * Recording of canvas commands is somewhat similar to SkPicture, except the canvas-recording
Chris Craik5e00c7c2016-07-06 16:10:09 -070071 * functionality is split between RecordingCanvas (which manages the recording), DisplayList
72 * (which holds the actual data), and RenderNode (which holds properties used for render playback).
John Reck113e0822014-03-18 09:22:59 -070073 *
Chris Craik003cc3d2015-10-16 10:24:55 -070074 * Note that DisplayList is swapped out from beneath an individual RenderNode when a view's
75 * recorded stream of canvas operations is refreshed. The RenderNode (and its properties) stay
John Reck113e0822014-03-18 09:22:59 -070076 * attached.
77 */
John Reck087bc0c2014-04-04 16:20:08 -070078class RenderNode : public VirtualLightRefBase {
John Reck1bcacfd2017-11-03 10:12:19 -070079 friend class TestUtils; // allow TestUtils to access syncDisplayList / syncProperties
John Reck1bcacfd2017-11-03 10:12:19 -070080
John Reck113e0822014-03-18 09:22:59 -070081public:
John Reckff941dc2014-05-14 16:34:14 -070082 enum DirtyPropertyMask {
John Reck1bcacfd2017-11-03 10:12:19 -070083 GENERIC = 1 << 1,
84 TRANSLATION_X = 1 << 2,
85 TRANSLATION_Y = 1 << 3,
86 TRANSLATION_Z = 1 << 4,
87 SCALE_X = 1 << 5,
88 SCALE_Y = 1 << 6,
89 ROTATION = 1 << 7,
90 ROTATION_X = 1 << 8,
91 ROTATION_Y = 1 << 9,
92 X = 1 << 10,
93 Y = 1 << 11,
94 Z = 1 << 12,
95 ALPHA = 1 << 13,
96 DISPLAY_LIST = 1 << 14,
John Reckff941dc2014-05-14 16:34:14 -070097 };
98
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050099 RenderNode();
100 virtual ~RenderNode();
John Reck113e0822014-03-18 09:22:59 -0700101
102 // See flags defined in DisplayList.java
John Reck1bcacfd2017-11-03 10:12:19 -0700103 enum ReplayFlag { kReplayFlag_ClipChildren = 0x1 };
John Reck113e0822014-03-18 09:22:59 -0700104
John Reckbe671952021-01-13 22:39:32 -0500105 void setStagingDisplayList(DisplayList&& newData);
John Reckdc1a6962021-01-12 13:56:07 -0500106 void discardStagingDisplayList();
John Reck113e0822014-03-18 09:22:59 -0700107
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500108 void output();
109 int getUsageSize();
110 int getAllocatedSize();
John Reck113e0822014-03-18 09:22:59 -0700111
John Reckbe671952021-01-13 22:39:32 -0500112 bool isRenderable() const { return mDisplayList.hasContent(); }
John Reck113e0822014-03-18 09:22:59 -0700113
John Recka447d292014-06-11 18:39:44 -0700114 bool hasProjectionReceiver() const {
John Reckbe671952021-01-13 22:39:32 -0500115 return mDisplayList.containsProjectionReceiver();
John Recka447d292014-06-11 18:39:44 -0700116 }
117
John Reck1bcacfd2017-11-03 10:12:19 -0700118 const char* getName() const { return mName.string(); }
Chris Craikdefb7f32014-04-08 18:17:07 -0700119
John Reck113e0822014-03-18 09:22:59 -0700120 void setName(const char* name) {
121 if (name) {
Dan Austin71831a62016-03-24 12:03:42 -0700122 const char* lastPeriod = strrchr(name, '.');
John Reck113e0822014-03-18 09:22:59 -0700123 if (lastPeriod) {
124 mName.setTo(lastPeriod + 1);
125 } else {
126 mName.setTo(name);
127 }
128 }
129 }
130
Nader Jawad197743f2021-04-19 19:45:13 -0700131 StretchMask& getStretchMask() { return mStretchMask; }
132
John Reck1bcacfd2017-11-03 10:12:19 -0700133 VirtualLightRefBase* getUserContext() const { return mUserContext.get(); }
John Reck44b49f02016-03-25 14:29:48 -0700134
John Reck1bcacfd2017-11-03 10:12:19 -0700135 void setUserContext(VirtualLightRefBase* context) { mUserContext = context; }
John Reck44b49f02016-03-25 14:29:48 -0700136
John Reckff941dc2014-05-14 16:34:14 -0700137 bool isPropertyFieldDirty(DirtyPropertyMask field) const {
138 return mDirtyPropertyFields & field;
139 }
140
John Reck1bcacfd2017-11-03 10:12:19 -0700141 void setPropertyFieldsDirty(uint32_t fields) { mDirtyPropertyFields |= fields; }
John Reckff941dc2014-05-14 16:34:14 -0700142
John Reck1bcacfd2017-11-03 10:12:19 -0700143 const RenderProperties& properties() const { return mProperties; }
John Reck113e0822014-03-18 09:22:59 -0700144
John Reck1bcacfd2017-11-03 10:12:19 -0700145 RenderProperties& animatorProperties() { return mProperties; }
John Reck52244ff2014-05-01 21:27:37 -0700146
John Reck1bcacfd2017-11-03 10:12:19 -0700147 const RenderProperties& stagingProperties() { return mStagingProperties; }
John Reckd0a0b2a2014-03-20 16:28:56 -0700148
John Reck1bcacfd2017-11-03 10:12:19 -0700149 RenderProperties& mutateStagingProperties() { return mStagingProperties; }
John Reckd0a0b2a2014-03-20 16:28:56 -0700150
John Reck1bcacfd2017-11-03 10:12:19 -0700151 bool isValid() { return mValid; }
John Reck2de950d2017-01-25 10:58:30 -0800152
John Reck1bcacfd2017-11-03 10:12:19 -0700153 int getWidth() const { return properties().getWidth(); }
John Reck113e0822014-03-18 09:22:59 -0700154
John Reck1bcacfd2017-11-03 10:12:19 -0700155 int getHeight() const { return properties().getHeight(); }
John Reck113e0822014-03-18 09:22:59 -0700156
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500157 virtual void prepareTree(TreeInfo& info);
John Reck2de950d2017-01-25 10:58:30 -0800158 void destroyHardwareResources(TreeInfo* info = nullptr);
159 void destroyLayers();
John Recke45b1fd2014-04-15 09:50:16 -0700160
161 // UI thread only!
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500162 void addAnimator(const sp<BaseRenderNodeAnimator>& animator);
Doris Liu8b083202016-02-19 21:46:06 +0000163 void removeAnimator(const sp<BaseRenderNodeAnimator>& animator);
164
165 // This can only happen during pushStaging()
166 void onAnimatorTargetChanged(BaseRenderNodeAnimator* animator) {
167 mAnimatorManager.onAnimatorTargetChanged(animator);
168 }
John Reck668f0e32014-03-26 15:10:40 -0700169
John Reck119907c2014-08-14 09:02:01 -0700170 AnimatorManager& animators() { return mAnimatorManager; }
171
Chris Craik69e5adf2014-08-14 13:34:01 -0700172 void applyViewPropertyTransforms(mat4& matrix, bool true3dTransform = false) const;
173
Chris Craikb565df12015-10-05 13:00:52 -0700174 bool nothingToDraw() const {
175 const Outline& outline = properties().getOutline();
John Reckbe671952021-01-13 22:39:32 -0500176 return !mDisplayList.isValid() || properties().getAlpha() <= 0 ||
John Reck1bcacfd2017-11-03 10:12:19 -0700177 (outline.getShouldClip() && outline.isEmpty()) || properties().getScaleX() == 0 ||
178 properties().getScaleY() == 0;
Chris Craikb565df12015-10-05 13:00:52 -0700179 }
180
John Reckbe671952021-01-13 22:39:32 -0500181 const DisplayList& getDisplayList() const { return mDisplayList; }
182 // TODO: can this be cleaned up?
183 DisplayList& getDisplayList() { return mDisplayList; }
Chris Craikb565df12015-10-05 13:00:52 -0700184
John Reckaa6e84f2016-06-16 15:36:13 -0700185 // Note: The position callbacks are relying on the listener using
186 // the frameNumber to appropriately batch/synchronize these transactions.
187 // There is no other filtering/batching to ensure that only the "final"
188 // state called once per frame.
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500189 class PositionListener : public VirtualLightRefBase {
John Reckf6481082016-02-02 15:18:23 -0800190 public:
191 virtual ~PositionListener() {}
John Reckaa6e84f2016-06-16 15:36:13 -0700192 // Called when the RenderNode's position changes
John Reckf6481082016-02-02 15:18:23 -0800193 virtual void onPositionUpdated(RenderNode& node, const TreeInfo& info) = 0;
John Reckaa6e84f2016-06-16 15:36:13 -0700194 // Called when the RenderNode no longer has a position. As in, it's
195 // no longer being drawn.
196 // Note, tree info might be null
197 virtual void onPositionLost(RenderNode& node, const TreeInfo* info) = 0;
John Reckf6481082016-02-02 15:18:23 -0800198 };
199
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500200 void setPositionListener(PositionListener* listener) {
John Reck097e1d32019-06-12 15:01:51 -0700201 mStagingPositionListener = listener;
202 mPositionListenerDirty = true;
John Reckf6481082016-02-02 15:18:23 -0800203 }
204
John Reck44b49f02016-03-25 14:29:48 -0700205 // This is only modified in MODE_FULL, so it can be safely accessed
206 // on the UI thread.
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500207 bool hasParents() { return mParentCount; }
John Reck44b49f02016-03-25 14:29:48 -0700208
John Reck2de950d2017-01-25 10:58:30 -0800209 void onRemovedFromTree(TreeInfo* info);
210
211 // Called by CanvasContext to promote a RenderNode to be a root node
John Reck1bcacfd2017-11-03 10:12:19 -0700212 void makeRoot() { incParentRefCount(); }
John Reck2de950d2017-01-25 10:58:30 -0800213
214 // Called by CanvasContext when it drops a RenderNode from being a root node
215 void clearRoot();
216
Stan Ilievd2172372017-02-09 16:59:27 -0500217 void output(std::ostream& output, uint32_t level);
218
John Reck8f45d4a2018-08-15 10:17:12 -0700219 void setUsageHint(UsageHint usageHint) { mUsageHint = usageHint; }
John Reck9ce2bf72018-07-02 18:33:32 -0700220
John Reck8f45d4a2018-08-15 10:17:12 -0700221 UsageHint usageHint() const { return mUsageHint; }
John Reck9ce2bf72018-07-02 18:33:32 -0700222
John Reckf96b2842018-11-29 09:44:10 -0800223 int64_t uniqueId() const { return mUniqueId; }
224
225 void markDrawStart(SkCanvas& canvas);
226 void markDrawEnd(SkCanvas& canvas);
227
John Reck113e0822014-03-18 09:22:59 -0700228private:
Chris Craik5e00c7c2016-07-06 16:10:09 -0700229 void computeOrderingImpl(RenderNodeOp* opState,
John Reck1bcacfd2017-11-03 10:12:19 -0700230 std::vector<RenderNodeOp*>* compositedChildrenOfProjectionSurface,
231 const mat4* transformFromProjectionSurface);
John Reck113e0822014-03-18 09:22:59 -0700232
Chris Craikb565df12015-10-05 13:00:52 -0700233 void syncProperties();
John Reck2de950d2017-01-25 10:58:30 -0800234 void syncDisplayList(TreeObserver& observer, TreeInfo* info);
John Reck3b4510cd2018-09-27 17:39:45 -0700235 void handleForceDark(TreeInfo* info);
Chris Craikb565df12015-10-05 13:00:52 -0700236
John Reck2de950d2017-01-25 10:58:30 -0800237 void prepareTreeImpl(TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer);
John Reck25fbb3f2014-06-12 13:46:45 -0700238 void pushStagingPropertiesChanges(TreeInfo& info);
John Reck2de950d2017-01-25 10:58:30 -0800239 void pushStagingDisplayListChanges(TreeObserver& observer, TreeInfo& info);
John Recka7c2ea22014-08-08 13:21:00 -0700240 void prepareLayer(TreeInfo& info, uint32_t dirtyMask);
John Reck25fbb3f2014-06-12 13:46:45 -0700241 void pushLayerUpdate(TreeInfo& info);
John Reck2de950d2017-01-25 10:58:30 -0800242 void deleteDisplayList(TreeObserver& observer, TreeInfo* info = nullptr);
John Reck0a973302014-07-16 13:29:45 -0700243 void damageSelf(TreeInfo& info);
John Reckdcba6722014-07-08 13:59:49 -0700244
245 void incParentRefCount() { mParentCount++; }
John Reck2de950d2017-01-25 10:58:30 -0800246 void decParentRefCount(TreeObserver& observer, TreeInfo* info = nullptr);
John Reck8de65a82014-04-09 15:23:38 -0700247
John Reckf96b2842018-11-29 09:44:10 -0800248 const int64_t mUniqueId;
John Reck113e0822014-03-18 09:22:59 -0700249 String8 mName;
John Reck44b49f02016-03-25 14:29:48 -0700250 sp<VirtualLightRefBase> mUserContext;
John Reck113e0822014-03-18 09:22:59 -0700251
John Reckff941dc2014-05-14 16:34:14 -0700252 uint32_t mDirtyPropertyFields;
John Reck113e0822014-03-18 09:22:59 -0700253 RenderProperties mProperties;
John Reckd0a0b2a2014-03-20 16:28:56 -0700254 RenderProperties mStagingProperties;
255
John Reck2de950d2017-01-25 10:58:30 -0800256 // Owned by UI. Set when DL is set, cleared when DL cleared or when node detached
257 // (likely by parent re-record/removal)
258 bool mValid = false;
259
Chris Craik003cc3d2015-10-16 10:24:55 -0700260 bool mNeedsDisplayListSync;
261 // WARNING: Do not delete this directly, you must go through deleteDisplayList()!
John Reckbe671952021-01-13 22:39:32 -0500262 DisplayList mDisplayList;
263 DisplayList mStagingDisplayList;
John Reck113e0822014-03-18 09:22:59 -0700264
John Reckf1aa7909e2019-03-07 17:01:08 -0800265 int64_t mDamageGenerationId;
266
John Reck68bfe0a2014-06-24 15:34:58 -0700267 friend class AnimatorManager;
268 AnimatorManager mAnimatorManager;
John Recke45b1fd2014-04-15 09:50:16 -0700269
John Reck113e0822014-03-18 09:22:59 -0700270 /**
271 * Draw time state - these properties are only set and used during rendering
272 */
273
274 // for projection surfaces, contains a list of all children items
Chris Craik5e00c7c2016-07-06 16:10:09 -0700275 std::vector<RenderNodeOp*> mProjectedNodes;
John Reckdcba6722014-07-08 13:59:49 -0700276
277 // How many references our parent(s) have to us. Typically this should alternate
278 // between 2 and 1 (when a staging push happens we inc first then dec)
279 // When this hits 0 we are no longer in the tree, so any hardware resources
280 // (specifically Layers) should be released.
281 // This is *NOT* thread-safe, and should therefore only be tracking
Chris Craik003cc3d2015-10-16 10:24:55 -0700282 // mDisplayList, not mStagingDisplayList.
John Reckdcba6722014-07-08 13:59:49 -0700283 uint32_t mParentCount;
John Reckf6481082016-02-02 15:18:23 -0800284
John Reck097e1d32019-06-12 15:01:51 -0700285 bool mPositionListenerDirty = false;
286 sp<PositionListener> mStagingPositionListener;
John Reck7b570de2016-06-27 13:27:23 -0700287 sp<PositionListener> mPositionListener;
Derek Sollenberger0df62092016-09-27 16:04:42 -0400288
John Reck9ce2bf72018-07-02 18:33:32 -0700289 UsageHint mUsageHint = UsageHint::Unknown;
290
Nader Jawad2dc632a2021-03-29 18:51:29 -0700291 bool mHasHolePunches;
Nader Jawad197743f2021-04-19 19:45:13 -0700292 StretchMask mStretchMask;
Nader Jawad2dc632a2021-03-29 18:51:29 -0700293
John Reck1bcacfd2017-11-03 10:12:19 -0700294 // METHODS & FIELDS ONLY USED BY THE SKIA RENDERER
Derek Sollenberger0df62092016-09-27 16:04:42 -0400295public:
296 /**
297 * Detach and transfer ownership of an already allocated displayList for use
298 * in recording updated content for this renderNode
299 */
Stan Iliev021693b2016-10-17 16:26:15 -0400300 std::unique_ptr<skiapipeline::SkiaDisplayList> detachAvailableList() {
Derek Sollenberger0df62092016-09-27 16:04:42 -0400301 return std::move(mAvailableDisplayList);
302 }
303
Nader Jawad2dc632a2021-03-29 18:51:29 -0700304 bool hasHolePunches() { return mHasHolePunches; }
305
Derek Sollenberger0df62092016-09-27 16:04:42 -0400306 /**
307 * Attach unused displayList to this node for potential future reuse.
308 */
Stan Iliev021693b2016-10-17 16:26:15 -0400309 void attachAvailableList(skiapipeline::SkiaDisplayList* skiaDisplayList) {
Derek Sollenberger0df62092016-09-27 16:04:42 -0400310 mAvailableDisplayList.reset(skiaDisplayList);
311 }
312
313 /**
314 * Returns true if an offscreen layer from any renderPipeline is attached
315 * to this node.
316 */
John Recke4c1e6c2018-05-24 16:27:35 -0700317 bool hasLayer() const { return mSkiaLayer.get(); }
Derek Sollenberger0df62092016-09-27 16:04:42 -0400318
319 /**
320 * Used by the RenderPipeline to attach an offscreen surface to the RenderNode.
321 * The surface is then will be used to store the contents of a layer.
322 */
Stan Iliev500a0c32016-10-26 10:30:09 -0400323 void setLayerSurface(sk_sp<SkSurface> layer) {
324 if (layer.get()) {
325 if (!mSkiaLayer.get()) {
326 mSkiaLayer = std::make_unique<skiapipeline::SkiaLayer>();
327 }
328 mSkiaLayer->layerSurface = std::move(layer);
329 mSkiaLayer->inverseTransformInWindow.loadIdentity();
330 } else {
331 mSkiaLayer.reset();
332 }
333 }
Derek Sollenberger0df62092016-09-27 16:04:42 -0400334
335 /**
336 * If the RenderNode is of type LayerType::RenderLayer then this method will
337 * return the an offscreen rendering surface that is used to both render into
338 * the layer and composite the layer into its parent. If the type is not
339 * LayerType::RenderLayer then it will return a nullptr.
340 *
341 * NOTE: this function is only guaranteed to return accurate results after
342 * prepareTree has been run for this RenderNode
343 */
Stan Iliev500a0c32016-10-26 10:30:09 -0400344 SkSurface* getLayerSurface() const {
345 return mSkiaLayer.get() ? mSkiaLayer->layerSurface.get() : nullptr;
346 }
347
Nader Jawad6aff4812021-06-09 10:14:43 -0700348 struct SnapshotResult {
349 sk_sp<SkImage> snapshot;
350 SkIRect outSubset;
351 SkIPoint outOffset;
352 };
353
354 std::optional<SnapshotResult> updateSnapshotIfRequired(GrRecordingContext* context,
355 const SkImageFilter* imageFilter,
356 const SkIRect& clipBounds);
357
John Reck1bcacfd2017-11-03 10:12:19 -0700358 skiapipeline::SkiaLayer* getSkiaLayer() const { return mSkiaLayer.get(); }
Derek Sollenberger0df62092016-09-27 16:04:42 -0400359
Derek Sollenberger579317d42017-08-29 16:33:49 -0400360 /**
361 * Returns the path that represents the outline of RenderNode intersected with
362 * the provided rect. This call will internally cache the resulting path in
363 * order to potentially return that path for subsequent calls to this method.
364 * By reusing the same path we get better performance on the GPU backends since
365 * those resources are cached in the hardware based on the path's genID.
366 *
367 * The returned path is only guaranteed to be valid until this function is called
368 * again or the RenderNode's outline is mutated.
369 */
370 const SkPath* getClippedOutline(const SkRect& clipRect) const;
John Reck1bcacfd2017-11-03 10:12:19 -0700371
Derek Sollenberger0df62092016-09-27 16:04:42 -0400372private:
373 /**
374 * If this RenderNode has been used in a previous frame then the SkiaDisplayList
375 * from that frame is cached here until one of the following conditions is met:
376 * 1) The RenderNode is deleted (causing this to be deleted)
377 * 2) It is replaced with the displayList from the next completed frame
378 * 3) It is detached and used to to record a new displayList for a later frame
379 */
Stan Iliev021693b2016-10-17 16:26:15 -0400380 std::unique_ptr<skiapipeline::SkiaDisplayList> mAvailableDisplayList;
Derek Sollenberger0df62092016-09-27 16:04:42 -0400381
382 /**
383 * An offscreen rendering target used to contain the contents this RenderNode
384 * when it has been set to draw as a LayerType::RenderLayer.
385 */
Stan Iliev500a0c32016-10-26 10:30:09 -0400386 std::unique_ptr<skiapipeline::SkiaLayer> mSkiaLayer;
Derek Sollenberger579317d42017-08-29 16:33:49 -0400387
Nader Jawad6aff4812021-06-09 10:14:43 -0700388 /**
389 * SkImageFilter used to create the mSnapshotResult
390 */
391 sk_sp<SkImageFilter> mTargetImageFilter;
392
393 /**
394 * Clip bounds used to create the mSnapshotResult
395 */
396 SkIRect mImageFilterClipBounds;
397
398 /**
399 * Result of the most recent snapshot with additional metadata used to
400 * determine how to draw the contents
401 */
402 SnapshotResult mSnapshotResult;
403
Derek Sollenberger579317d42017-08-29 16:33:49 -0400404 struct ClippedOutlineCache {
405 // keys
406 uint32_t outlineID = 0;
407 SkRect clipRect;
408
409 // value
410 SkPath clippedOutline;
411 };
412 mutable ClippedOutlineCache mClippedOutlineCache;
John Reck1bcacfd2017-11-03 10:12:19 -0700413}; // class RenderNode
John Reck113e0822014-03-18 09:22:59 -0700414
John Reck2de950d2017-01-25 10:58:30 -0800415class MarkAndSweepRemoved : public TreeObserver {
John Reck1bcacfd2017-11-03 10:12:19 -0700416 PREVENT_COPY_AND_ASSIGN(MarkAndSweepRemoved);
John Reck2de950d2017-01-25 10:58:30 -0800417
418public:
419 explicit MarkAndSweepRemoved(TreeInfo* info) : mTreeInfo(info) {}
420
John Reck1bcacfd2017-11-03 10:12:19 -0700421 void onMaybeRemovedFromTree(RenderNode* node) override { mMarked.emplace_back(node); }
John Reck2de950d2017-01-25 10:58:30 -0800422
423 ~MarkAndSweepRemoved() {
424 for (auto& node : mMarked) {
425 if (!node->hasParents()) {
426 node->onRemovedFromTree(mTreeInfo);
427 }
428 }
429 }
430
431private:
432 FatVector<sp<RenderNode>, 10> mMarked;
433 TreeInfo* mTreeInfo;
434};
435
John Reck113e0822014-03-18 09:22:59 -0700436} /* namespace uirenderer */
437} /* namespace android */