blob: 39ea53b6e3b32b140024364b4a2d282310d416fd [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"
Stan Iliev021693b2016-10-17 16:26:15 -040038#include "pipeline/skia/SkiaDisplayList.h"
Stan Iliev500a0c32016-10-26 10:30:09 -040039#include "pipeline/skia/SkiaLayer.h"
John Reck113e0822014-03-18 09:22:59 -070040
John Reck272a6852015-07-29 16:48:58 -070041#include <vector>
42
John Reck113e0822014-03-18 09:22:59 -070043class SkBitmap;
44class SkPaint;
45class SkPath;
46class SkRegion;
Derek Sollenberger0df62092016-09-27 16:04:42 -040047class SkSurface;
John Reck113e0822014-03-18 09:22:59 -070048
49namespace android {
50namespace uirenderer {
51
Chris Craikb565df12015-10-05 13:00:52 -070052class CanvasState;
Chris Craik5e00c7c2016-07-06 16:10:09 -070053class Rect;
54class SkiaShader;
Chris Craik8d1f2122015-11-24 16:40:09 -080055struct RenderNodeOp;
Chris Craik0b7e8242015-10-28 16:50:44 -070056
Tom Hudson2dc236b2014-10-15 15:46:42 -040057class TreeInfo;
John Reck44b49f02016-03-25 14:29:48 -070058class TreeObserver;
John Reck113e0822014-03-18 09:22:59 -070059
John Recke248bd12015-08-05 13:53:53 -070060namespace proto {
61class RenderNode;
62}
63
John Reck113e0822014-03-18 09:22:59 -070064/**
John Reck1bcacfd2017-11-03 10:12:19 -070065 * Primary class for storing recorded canvas commands, as well as per-View/ViewGroup display
66 * properties.
John Reck113e0822014-03-18 09:22:59 -070067 *
68 * Recording of canvas commands is somewhat similar to SkPicture, except the canvas-recording
Chris Craik5e00c7c2016-07-06 16:10:09 -070069 * 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 Reck113e0822014-03-18 09:22:59 -070071 *
Chris Craik003cc3d2015-10-16 10:24:55 -070072 * 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 Reck113e0822014-03-18 09:22:59 -070074 * attached.
75 */
John Reck087bc0c2014-04-04 16:20:08 -070076class RenderNode : public VirtualLightRefBase {
John Reck1bcacfd2017-11-03 10:12:19 -070077 friend class TestUtils; // allow TestUtils to access syncDisplayList / syncProperties
John Reck1bcacfd2017-11-03 10:12:19 -070078
John Reck113e0822014-03-18 09:22:59 -070079public:
John Reckff941dc2014-05-14 16:34:14 -070080 enum DirtyPropertyMask {
John Reck1bcacfd2017-11-03 10:12:19 -070081 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 Reckff941dc2014-05-14 16:34:14 -070095 };
96
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -050097 RenderNode();
98 virtual ~RenderNode();
John Reck113e0822014-03-18 09:22:59 -070099
100 // See flags defined in DisplayList.java
John Reck1bcacfd2017-11-03 10:12:19 -0700101 enum ReplayFlag { kReplayFlag_ClipChildren = 0x1 };
John Reck113e0822014-03-18 09:22:59 -0700102
John Reckbe671952021-01-13 22:39:32 -0500103 void setStagingDisplayList(DisplayList&& newData);
John Reckdc1a6962021-01-12 13:56:07 -0500104 void discardStagingDisplayList();
John Reck113e0822014-03-18 09:22:59 -0700105
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500106 void output();
107 int getUsageSize();
108 int getAllocatedSize();
John Reck113e0822014-03-18 09:22:59 -0700109
John Reckbe671952021-01-13 22:39:32 -0500110 bool isRenderable() const { return mDisplayList.hasContent(); }
John Reck113e0822014-03-18 09:22:59 -0700111
John Recka447d292014-06-11 18:39:44 -0700112 bool hasProjectionReceiver() const {
John Reckbe671952021-01-13 22:39:32 -0500113 return mDisplayList.containsProjectionReceiver();
John Recka447d292014-06-11 18:39:44 -0700114 }
115
John Reck1bcacfd2017-11-03 10:12:19 -0700116 const char* getName() const { return mName.string(); }
Chris Craikdefb7f32014-04-08 18:17:07 -0700117
John Reck113e0822014-03-18 09:22:59 -0700118 void setName(const char* name) {
119 if (name) {
Dan Austin71831a62016-03-24 12:03:42 -0700120 const char* lastPeriod = strrchr(name, '.');
John Reck113e0822014-03-18 09:22:59 -0700121 if (lastPeriod) {
122 mName.setTo(lastPeriod + 1);
123 } else {
124 mName.setTo(name);
125 }
126 }
127 }
128
John Reck1bcacfd2017-11-03 10:12:19 -0700129 VirtualLightRefBase* getUserContext() const { return mUserContext.get(); }
John Reck44b49f02016-03-25 14:29:48 -0700130
John Reck1bcacfd2017-11-03 10:12:19 -0700131 void setUserContext(VirtualLightRefBase* context) { mUserContext = context; }
John Reck44b49f02016-03-25 14:29:48 -0700132
John Reckff941dc2014-05-14 16:34:14 -0700133 bool isPropertyFieldDirty(DirtyPropertyMask field) const {
134 return mDirtyPropertyFields & field;
135 }
136
John Reck1bcacfd2017-11-03 10:12:19 -0700137 void setPropertyFieldsDirty(uint32_t fields) { mDirtyPropertyFields |= fields; }
John Reckff941dc2014-05-14 16:34:14 -0700138
John Reck1bcacfd2017-11-03 10:12:19 -0700139 const RenderProperties& properties() const { return mProperties; }
John Reck113e0822014-03-18 09:22:59 -0700140
John Reck1bcacfd2017-11-03 10:12:19 -0700141 RenderProperties& animatorProperties() { return mProperties; }
John Reck52244ff2014-05-01 21:27:37 -0700142
John Reck1bcacfd2017-11-03 10:12:19 -0700143 const RenderProperties& stagingProperties() { return mStagingProperties; }
John Reckd0a0b2a2014-03-20 16:28:56 -0700144
John Reck1bcacfd2017-11-03 10:12:19 -0700145 RenderProperties& mutateStagingProperties() { return mStagingProperties; }
John Reckd0a0b2a2014-03-20 16:28:56 -0700146
John Reck1bcacfd2017-11-03 10:12:19 -0700147 bool isValid() { return mValid; }
John Reck2de950d2017-01-25 10:58:30 -0800148
John Reck1bcacfd2017-11-03 10:12:19 -0700149 int getWidth() const { return properties().getWidth(); }
John Reck113e0822014-03-18 09:22:59 -0700150
John Reck1bcacfd2017-11-03 10:12:19 -0700151 int getHeight() const { return properties().getHeight(); }
John Reck113e0822014-03-18 09:22:59 -0700152
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500153 virtual void prepareTree(TreeInfo& info);
John Reck2de950d2017-01-25 10:58:30 -0800154 void destroyHardwareResources(TreeInfo* info = nullptr);
155 void destroyLayers();
John Recke45b1fd2014-04-15 09:50:16 -0700156
157 // UI thread only!
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500158 void addAnimator(const sp<BaseRenderNodeAnimator>& animator);
Doris Liu8b083202016-02-19 21:46:06 +0000159 void removeAnimator(const sp<BaseRenderNodeAnimator>& animator);
160
161 // This can only happen during pushStaging()
162 void onAnimatorTargetChanged(BaseRenderNodeAnimator* animator) {
163 mAnimatorManager.onAnimatorTargetChanged(animator);
164 }
John Reck668f0e32014-03-26 15:10:40 -0700165
John Reck119907c2014-08-14 09:02:01 -0700166 AnimatorManager& animators() { return mAnimatorManager; }
167
Chris Craik69e5adf2014-08-14 13:34:01 -0700168 void applyViewPropertyTransforms(mat4& matrix, bool true3dTransform = false) const;
169
Chris Craikb565df12015-10-05 13:00:52 -0700170 bool nothingToDraw() const {
171 const Outline& outline = properties().getOutline();
John Reckbe671952021-01-13 22:39:32 -0500172 return !mDisplayList.isValid() || properties().getAlpha() <= 0 ||
John Reck1bcacfd2017-11-03 10:12:19 -0700173 (outline.getShouldClip() && outline.isEmpty()) || properties().getScaleX() == 0 ||
174 properties().getScaleY() == 0;
Chris Craikb565df12015-10-05 13:00:52 -0700175 }
176
John Reckbe671952021-01-13 22:39:32 -0500177 const DisplayList& getDisplayList() const { return mDisplayList; }
178 // TODO: can this be cleaned up?
179 DisplayList& getDisplayList() { return mDisplayList; }
Chris Craikb565df12015-10-05 13:00:52 -0700180
John Reckaa6e84f2016-06-16 15:36:13 -0700181 // Note: The position callbacks are relying on the listener using
182 // the frameNumber to appropriately batch/synchronize these transactions.
183 // There is no other filtering/batching to ensure that only the "final"
184 // state called once per frame.
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500185 class PositionListener : public VirtualLightRefBase {
John Reckf6481082016-02-02 15:18:23 -0800186 public:
187 virtual ~PositionListener() {}
John Reckaa6e84f2016-06-16 15:36:13 -0700188 // Called when the RenderNode's position changes
John Reckf6481082016-02-02 15:18:23 -0800189 virtual void onPositionUpdated(RenderNode& node, const TreeInfo& info) = 0;
John Reckaa6e84f2016-06-16 15:36:13 -0700190 // Called when the RenderNode no longer has a position. As in, it's
191 // no longer being drawn.
192 // Note, tree info might be null
193 virtual void onPositionLost(RenderNode& node, const TreeInfo* info) = 0;
John Reckf6481082016-02-02 15:18:23 -0800194 };
195
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500196 void setPositionListener(PositionListener* listener) {
John Reck097e1d32019-06-12 15:01:51 -0700197 mStagingPositionListener = listener;
198 mPositionListenerDirty = true;
John Reckf6481082016-02-02 15:18:23 -0800199 }
200
John Reck44b49f02016-03-25 14:29:48 -0700201 // This is only modified in MODE_FULL, so it can be safely accessed
202 // on the UI thread.
Derek Sollenberger3fedf5a2020-02-21 13:07:28 -0500203 bool hasParents() { return mParentCount; }
John Reck44b49f02016-03-25 14:29:48 -0700204
John Reck2de950d2017-01-25 10:58:30 -0800205 void onRemovedFromTree(TreeInfo* info);
206
207 // Called by CanvasContext to promote a RenderNode to be a root node
John Reck1bcacfd2017-11-03 10:12:19 -0700208 void makeRoot() { incParentRefCount(); }
John Reck2de950d2017-01-25 10:58:30 -0800209
210 // Called by CanvasContext when it drops a RenderNode from being a root node
211 void clearRoot();
212
Stan Ilievd2172372017-02-09 16:59:27 -0500213 void output(std::ostream& output, uint32_t level);
214
John Reck8f45d4a2018-08-15 10:17:12 -0700215 void setUsageHint(UsageHint usageHint) { mUsageHint = usageHint; }
John Reck9ce2bf72018-07-02 18:33:32 -0700216
John Reck8f45d4a2018-08-15 10:17:12 -0700217 UsageHint usageHint() const { return mUsageHint; }
John Reck9ce2bf72018-07-02 18:33:32 -0700218
John Reckf96b2842018-11-29 09:44:10 -0800219 int64_t uniqueId() const { return mUniqueId; }
220
221 void markDrawStart(SkCanvas& canvas);
222 void markDrawEnd(SkCanvas& canvas);
223
John Reck113e0822014-03-18 09:22:59 -0700224private:
Chris Craik5e00c7c2016-07-06 16:10:09 -0700225 void computeOrderingImpl(RenderNodeOp* opState,
John Reck1bcacfd2017-11-03 10:12:19 -0700226 std::vector<RenderNodeOp*>* compositedChildrenOfProjectionSurface,
227 const mat4* transformFromProjectionSurface);
John Reck113e0822014-03-18 09:22:59 -0700228
Chris Craikb565df12015-10-05 13:00:52 -0700229 void syncProperties();
John Reck2de950d2017-01-25 10:58:30 -0800230 void syncDisplayList(TreeObserver& observer, TreeInfo* info);
John Reck3b4510cd2018-09-27 17:39:45 -0700231 void handleForceDark(TreeInfo* info);
Chris Craikb565df12015-10-05 13:00:52 -0700232
John Reck2de950d2017-01-25 10:58:30 -0800233 void prepareTreeImpl(TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer);
John Reck25fbb3f2014-06-12 13:46:45 -0700234 void pushStagingPropertiesChanges(TreeInfo& info);
John Reck2de950d2017-01-25 10:58:30 -0800235 void pushStagingDisplayListChanges(TreeObserver& observer, TreeInfo& info);
John Recka7c2ea22014-08-08 13:21:00 -0700236 void prepareLayer(TreeInfo& info, uint32_t dirtyMask);
John Reck25fbb3f2014-06-12 13:46:45 -0700237 void pushLayerUpdate(TreeInfo& info);
John Reck2de950d2017-01-25 10:58:30 -0800238 void deleteDisplayList(TreeObserver& observer, TreeInfo* info = nullptr);
John Reck0a973302014-07-16 13:29:45 -0700239 void damageSelf(TreeInfo& info);
John Reckdcba6722014-07-08 13:59:49 -0700240
241 void incParentRefCount() { mParentCount++; }
John Reck2de950d2017-01-25 10:58:30 -0800242 void decParentRefCount(TreeObserver& observer, TreeInfo* info = nullptr);
John Reck8de65a82014-04-09 15:23:38 -0700243
John Reckf96b2842018-11-29 09:44:10 -0800244 const int64_t mUniqueId;
John Reck113e0822014-03-18 09:22:59 -0700245 String8 mName;
John Reck44b49f02016-03-25 14:29:48 -0700246 sp<VirtualLightRefBase> mUserContext;
John Reck113e0822014-03-18 09:22:59 -0700247
John Reckff941dc2014-05-14 16:34:14 -0700248 uint32_t mDirtyPropertyFields;
John Reck113e0822014-03-18 09:22:59 -0700249 RenderProperties mProperties;
John Reckd0a0b2a2014-03-20 16:28:56 -0700250 RenderProperties mStagingProperties;
251
John Reck2de950d2017-01-25 10:58:30 -0800252 // Owned by UI. Set when DL is set, cleared when DL cleared or when node detached
253 // (likely by parent re-record/removal)
254 bool mValid = false;
255
Chris Craik003cc3d2015-10-16 10:24:55 -0700256 bool mNeedsDisplayListSync;
257 // WARNING: Do not delete this directly, you must go through deleteDisplayList()!
John Reckbe671952021-01-13 22:39:32 -0500258 DisplayList mDisplayList;
259 DisplayList mStagingDisplayList;
John Reck113e0822014-03-18 09:22:59 -0700260
John Reckf1aa7909e2019-03-07 17:01:08 -0800261 int64_t mDamageGenerationId;
262
John Reck68bfe0a2014-06-24 15:34:58 -0700263 friend class AnimatorManager;
264 AnimatorManager mAnimatorManager;
John Recke45b1fd2014-04-15 09:50:16 -0700265
John Reck113e0822014-03-18 09:22:59 -0700266 /**
267 * Draw time state - these properties are only set and used during rendering
268 */
269
270 // for projection surfaces, contains a list of all children items
Chris Craik5e00c7c2016-07-06 16:10:09 -0700271 std::vector<RenderNodeOp*> mProjectedNodes;
John Reckdcba6722014-07-08 13:59:49 -0700272
273 // How many references our parent(s) have to us. Typically this should alternate
274 // between 2 and 1 (when a staging push happens we inc first then dec)
275 // When this hits 0 we are no longer in the tree, so any hardware resources
276 // (specifically Layers) should be released.
277 // This is *NOT* thread-safe, and should therefore only be tracking
Chris Craik003cc3d2015-10-16 10:24:55 -0700278 // mDisplayList, not mStagingDisplayList.
John Reckdcba6722014-07-08 13:59:49 -0700279 uint32_t mParentCount;
John Reckf6481082016-02-02 15:18:23 -0800280
John Reck097e1d32019-06-12 15:01:51 -0700281 bool mPositionListenerDirty = false;
282 sp<PositionListener> mStagingPositionListener;
John Reck7b570de2016-06-27 13:27:23 -0700283 sp<PositionListener> mPositionListener;
Derek Sollenberger0df62092016-09-27 16:04:42 -0400284
John Reck9ce2bf72018-07-02 18:33:32 -0700285 UsageHint mUsageHint = UsageHint::Unknown;
286
John Reck1bcacfd2017-11-03 10:12:19 -0700287 // METHODS & FIELDS ONLY USED BY THE SKIA RENDERER
Derek Sollenberger0df62092016-09-27 16:04:42 -0400288public:
289 /**
290 * Detach and transfer ownership of an already allocated displayList for use
291 * in recording updated content for this renderNode
292 */
Stan Iliev021693b2016-10-17 16:26:15 -0400293 std::unique_ptr<skiapipeline::SkiaDisplayList> detachAvailableList() {
Derek Sollenberger0df62092016-09-27 16:04:42 -0400294 return std::move(mAvailableDisplayList);
295 }
296
297 /**
298 * Attach unused displayList to this node for potential future reuse.
299 */
Stan Iliev021693b2016-10-17 16:26:15 -0400300 void attachAvailableList(skiapipeline::SkiaDisplayList* skiaDisplayList) {
Derek Sollenberger0df62092016-09-27 16:04:42 -0400301 mAvailableDisplayList.reset(skiaDisplayList);
302 }
303
304 /**
305 * Returns true if an offscreen layer from any renderPipeline is attached
306 * to this node.
307 */
John Recke4c1e6c2018-05-24 16:27:35 -0700308 bool hasLayer() const { return mSkiaLayer.get(); }
Derek Sollenberger0df62092016-09-27 16:04:42 -0400309
310 /**
311 * Used by the RenderPipeline to attach an offscreen surface to the RenderNode.
312 * The surface is then will be used to store the contents of a layer.
313 */
Stan Iliev500a0c32016-10-26 10:30:09 -0400314 void setLayerSurface(sk_sp<SkSurface> layer) {
315 if (layer.get()) {
316 if (!mSkiaLayer.get()) {
317 mSkiaLayer = std::make_unique<skiapipeline::SkiaLayer>();
318 }
319 mSkiaLayer->layerSurface = std::move(layer);
320 mSkiaLayer->inverseTransformInWindow.loadIdentity();
321 } else {
322 mSkiaLayer.reset();
323 }
324 }
Derek Sollenberger0df62092016-09-27 16:04:42 -0400325
326 /**
327 * If the RenderNode is of type LayerType::RenderLayer then this method will
328 * return the an offscreen rendering surface that is used to both render into
329 * the layer and composite the layer into its parent. If the type is not
330 * LayerType::RenderLayer then it will return a nullptr.
331 *
332 * NOTE: this function is only guaranteed to return accurate results after
333 * prepareTree has been run for this RenderNode
334 */
Stan Iliev500a0c32016-10-26 10:30:09 -0400335 SkSurface* getLayerSurface() const {
336 return mSkiaLayer.get() ? mSkiaLayer->layerSurface.get() : nullptr;
337 }
338
John Reck1bcacfd2017-11-03 10:12:19 -0700339 skiapipeline::SkiaLayer* getSkiaLayer() const { return mSkiaLayer.get(); }
Derek Sollenberger0df62092016-09-27 16:04:42 -0400340
Derek Sollenberger579317d42017-08-29 16:33:49 -0400341 /**
342 * Returns the path that represents the outline of RenderNode intersected with
343 * the provided rect. This call will internally cache the resulting path in
344 * order to potentially return that path for subsequent calls to this method.
345 * By reusing the same path we get better performance on the GPU backends since
346 * those resources are cached in the hardware based on the path's genID.
347 *
348 * The returned path is only guaranteed to be valid until this function is called
349 * again or the RenderNode's outline is mutated.
350 */
351 const SkPath* getClippedOutline(const SkRect& clipRect) const;
John Reck1bcacfd2017-11-03 10:12:19 -0700352
Derek Sollenberger0df62092016-09-27 16:04:42 -0400353private:
354 /**
355 * If this RenderNode has been used in a previous frame then the SkiaDisplayList
356 * from that frame is cached here until one of the following conditions is met:
357 * 1) The RenderNode is deleted (causing this to be deleted)
358 * 2) It is replaced with the displayList from the next completed frame
359 * 3) It is detached and used to to record a new displayList for a later frame
360 */
Stan Iliev021693b2016-10-17 16:26:15 -0400361 std::unique_ptr<skiapipeline::SkiaDisplayList> mAvailableDisplayList;
Derek Sollenberger0df62092016-09-27 16:04:42 -0400362
363 /**
364 * An offscreen rendering target used to contain the contents this RenderNode
365 * when it has been set to draw as a LayerType::RenderLayer.
366 */
Stan Iliev500a0c32016-10-26 10:30:09 -0400367 std::unique_ptr<skiapipeline::SkiaLayer> mSkiaLayer;
Derek Sollenberger579317d42017-08-29 16:33:49 -0400368
369 struct ClippedOutlineCache {
370 // keys
371 uint32_t outlineID = 0;
372 SkRect clipRect;
373
374 // value
375 SkPath clippedOutline;
376 };
377 mutable ClippedOutlineCache mClippedOutlineCache;
John Reck1bcacfd2017-11-03 10:12:19 -0700378}; // class RenderNode
John Reck113e0822014-03-18 09:22:59 -0700379
John Reck2de950d2017-01-25 10:58:30 -0800380class MarkAndSweepRemoved : public TreeObserver {
John Reck1bcacfd2017-11-03 10:12:19 -0700381 PREVENT_COPY_AND_ASSIGN(MarkAndSweepRemoved);
John Reck2de950d2017-01-25 10:58:30 -0800382
383public:
384 explicit MarkAndSweepRemoved(TreeInfo* info) : mTreeInfo(info) {}
385
John Reck1bcacfd2017-11-03 10:12:19 -0700386 void onMaybeRemovedFromTree(RenderNode* node) override { mMarked.emplace_back(node); }
John Reck2de950d2017-01-25 10:58:30 -0800387
388 ~MarkAndSweepRemoved() {
389 for (auto& node : mMarked) {
390 if (!node->hasParents()) {
391 node->onRemovedFromTree(mTreeInfo);
392 }
393 }
394 }
395
396private:
397 FatVector<sp<RenderNode>, 10> mMarked;
398 TreeInfo* mTreeInfo;
399};
400
John Reck113e0822014-03-18 09:22:59 -0700401} /* namespace uirenderer */
402} /* namespace android */