blob: d55e5b0ce836701939a57f3b0f3d993dce0aa831 [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
John Reck68bfe0a2014-06-24 15:34:58 -070030#include "AnimatorManager.h"
John Reck9ce2bf72018-07-02 18:33:32 -070031#include "CanvasTransform.h"
John Reck113e0822014-03-18 09:22:59 -070032#include "Debug.h"
John Reck113e0822014-03-18 09:22:59 -070033#include "DisplayList.h"
Chris Craikb565df12015-10-05 13:00:52 -070034#include "Matrix.h"
John Reck113e0822014-03-18 09:22:59 -070035#include "RenderProperties.h"
Stan Iliev021693b2016-10-17 16:26:15 -040036#include "pipeline/skia/SkiaDisplayList.h"
Stan Iliev500a0c32016-10-26 10:30:09 -040037#include "pipeline/skia/SkiaLayer.h"
Tim Murray894f1322020-02-24 21:30:20 +000038#include "utils/FatVector.h"
John Reck113e0822014-03-18 09:22:59 -070039
John Reck272a6852015-07-29 16:48:58 -070040#include <vector>
41
John Reck113e0822014-03-18 09:22:59 -070042class SkBitmap;
43class SkPaint;
44class SkPath;
45class SkRegion;
Derek Sollenberger0df62092016-09-27 16:04:42 -040046class SkSurface;
John Reck113e0822014-03-18 09:22:59 -070047
48namespace android {
49namespace uirenderer {
50
Chris Craikb565df12015-10-05 13:00:52 -070051class CanvasState;
Chris Craik5e00c7c2016-07-06 16:10:09 -070052class Rect;
53class SkiaShader;
Chris Craik8d1f2122015-11-24 16:40:09 -080054struct RenderNodeOp;
Chris Craik0b7e8242015-10-28 16:50:44 -070055
Tom Hudson2dc236b2014-10-15 15:46:42 -040056class TreeInfo;
John Reck44b49f02016-03-25 14:29:48 -070057class TreeObserver;
John Reck113e0822014-03-18 09:22:59 -070058
John Recke248bd12015-08-05 13:53:53 -070059namespace proto {
60class RenderNode;
61}
62
John Reck113e0822014-03-18 09:22:59 -070063/**
John Reck1bcacfd2017-11-03 10:12:19 -070064 * Primary class for storing recorded canvas commands, as well as per-View/ViewGroup display
65 * properties.
John Reck113e0822014-03-18 09:22:59 -070066 *
67 * Recording of canvas commands is somewhat similar to SkPicture, except the canvas-recording
Chris Craik5e00c7c2016-07-06 16:10:09 -070068 * 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 Reck113e0822014-03-18 09:22:59 -070070 *
Chris Craik003cc3d2015-10-16 10:24:55 -070071 * 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 Reck113e0822014-03-18 09:22:59 -070073 * attached.
74 */
John Reck087bc0c2014-04-04 16:20:08 -070075class RenderNode : public VirtualLightRefBase {
John Reck1bcacfd2017-11-03 10:12:19 -070076 friend class TestUtils; // allow TestUtils to access syncDisplayList / syncProperties
John Reck1bcacfd2017-11-03 10:12:19 -070077
John Reck113e0822014-03-18 09:22:59 -070078public:
John Reckff941dc2014-05-14 16:34:14 -070079 enum DirtyPropertyMask {
John Reck1bcacfd2017-11-03 10:12:19 -070080 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,
93 DISPLAY_LIST = 1 << 14,
John Reckff941dc2014-05-14 16:34:14 -070094 };
95
John Reck113e0822014-03-18 09:22:59 -070096 ANDROID_API RenderNode();
John Recke45b1fd2014-04-15 09:50:16 -070097 ANDROID_API virtual ~RenderNode();
John Reck113e0822014-03-18 09:22:59 -070098
99 // See flags defined in DisplayList.java
John Reck1bcacfd2017-11-03 10:12:19 -0700100 enum ReplayFlag { kReplayFlag_ClipChildren = 0x1 };
John Reck113e0822014-03-18 09:22:59 -0700101
John Reck2de950d2017-01-25 10:58:30 -0800102 ANDROID_API void setStagingDisplayList(DisplayList* newData);
John Reck113e0822014-03-18 09:22:59 -0700103
sergeyvc3849aa2016-08-08 13:22:06 -0700104 ANDROID_API void output();
John Reck183e1382019-10-09 13:41:18 -0700105 ANDROID_API int getUsageSize();
106 ANDROID_API int getAllocatedSize();
John Reck113e0822014-03-18 09:22:59 -0700107
John Reck1bcacfd2017-11-03 10:12:19 -0700108 bool isRenderable() const { return mDisplayList && !mDisplayList->isEmpty(); }
John Reck113e0822014-03-18 09:22:59 -0700109
John Recka447d292014-06-11 18:39:44 -0700110 bool hasProjectionReceiver() const {
John Reckf3c724f2018-09-20 13:00:04 -0700111 return mDisplayList && mDisplayList->containsProjectionReceiver();
John Recka447d292014-06-11 18:39:44 -0700112 }
113
John Reck1bcacfd2017-11-03 10:12:19 -0700114 const char* getName() const { return mName.string(); }
Chris Craikdefb7f32014-04-08 18:17:07 -0700115
John Reck113e0822014-03-18 09:22:59 -0700116 void setName(const char* name) {
117 if (name) {
Dan Austin71831a62016-03-24 12:03:42 -0700118 const char* lastPeriod = strrchr(name, '.');
John Reck113e0822014-03-18 09:22:59 -0700119 if (lastPeriod) {
120 mName.setTo(lastPeriod + 1);
121 } else {
122 mName.setTo(name);
123 }
124 }
125 }
126
John Reck1bcacfd2017-11-03 10:12:19 -0700127 VirtualLightRefBase* getUserContext() const { return mUserContext.get(); }
John Reck44b49f02016-03-25 14:29:48 -0700128
John Reck1bcacfd2017-11-03 10:12:19 -0700129 void setUserContext(VirtualLightRefBase* context) { mUserContext = context; }
John Reck44b49f02016-03-25 14:29:48 -0700130
John Reckff941dc2014-05-14 16:34:14 -0700131 bool isPropertyFieldDirty(DirtyPropertyMask field) const {
132 return mDirtyPropertyFields & field;
133 }
134
John Reck1bcacfd2017-11-03 10:12:19 -0700135 void setPropertyFieldsDirty(uint32_t fields) { mDirtyPropertyFields |= fields; }
John Reckff941dc2014-05-14 16:34:14 -0700136
John Reck1bcacfd2017-11-03 10:12:19 -0700137 const RenderProperties& properties() const { return mProperties; }
John Reck113e0822014-03-18 09:22:59 -0700138
John Reck1bcacfd2017-11-03 10:12:19 -0700139 RenderProperties& animatorProperties() { return mProperties; }
John Reck52244ff2014-05-01 21:27:37 -0700140
John Reck1bcacfd2017-11-03 10:12:19 -0700141 const RenderProperties& stagingProperties() { return mStagingProperties; }
John Reckd0a0b2a2014-03-20 16:28:56 -0700142
John Reck1bcacfd2017-11-03 10:12:19 -0700143 RenderProperties& mutateStagingProperties() { return mStagingProperties; }
John Reckd0a0b2a2014-03-20 16:28:56 -0700144
John Reck1bcacfd2017-11-03 10:12:19 -0700145 bool isValid() { return mValid; }
John Reck2de950d2017-01-25 10:58:30 -0800146
John Reck1bcacfd2017-11-03 10:12:19 -0700147 int getWidth() const { return properties().getWidth(); }
John Reck113e0822014-03-18 09:22:59 -0700148
John Reck1bcacfd2017-11-03 10:12:19 -0700149 int getHeight() const { return properties().getHeight(); }
John Reck113e0822014-03-18 09:22:59 -0700150
John Recke45b1fd2014-04-15 09:50:16 -0700151 ANDROID_API virtual void prepareTree(TreeInfo& info);
John Reck2de950d2017-01-25 10:58:30 -0800152 void destroyHardwareResources(TreeInfo* info = nullptr);
153 void destroyLayers();
John Recke45b1fd2014-04-15 09:50:16 -0700154
155 // UI thread only!
John Reck68bfe0a2014-06-24 15:34:58 -0700156 ANDROID_API void addAnimator(const sp<BaseRenderNodeAnimator>& animator);
Doris Liu8b083202016-02-19 21:46:06 +0000157 void removeAnimator(const sp<BaseRenderNodeAnimator>& animator);
158
159 // This can only happen during pushStaging()
160 void onAnimatorTargetChanged(BaseRenderNodeAnimator* animator) {
161 mAnimatorManager.onAnimatorTargetChanged(animator);
162 }
John Reck668f0e32014-03-26 15:10:40 -0700163
John Reck119907c2014-08-14 09:02:01 -0700164 AnimatorManager& animators() { return mAnimatorManager; }
165
Chris Craik69e5adf2014-08-14 13:34:01 -0700166 void applyViewPropertyTransforms(mat4& matrix, bool true3dTransform = false) const;
167
Chris Craikb565df12015-10-05 13:00:52 -0700168 bool nothingToDraw() const {
169 const Outline& outline = properties().getOutline();
John Reck1bcacfd2017-11-03 10:12:19 -0700170 return mDisplayList == nullptr || properties().getAlpha() <= 0 ||
171 (outline.getShouldClip() && outline.isEmpty()) || properties().getScaleX() == 0 ||
172 properties().getScaleY() == 0;
Chris Craikb565df12015-10-05 13:00:52 -0700173 }
174
John Reck1bcacfd2017-11-03 10:12:19 -0700175 const DisplayList* getDisplayList() const { return mDisplayList; }
Chris Craikb565df12015-10-05 13:00:52 -0700176
John Reckaa6e84f2016-06-16 15:36:13 -0700177 // Note: The position callbacks are relying on the listener using
178 // the frameNumber to appropriately batch/synchronize these transactions.
179 // There is no other filtering/batching to ensure that only the "final"
180 // state called once per frame.
John Reck7b570de2016-06-27 13:27:23 -0700181 class ANDROID_API PositionListener : public VirtualLightRefBase {
John Reckf6481082016-02-02 15:18:23 -0800182 public:
183 virtual ~PositionListener() {}
John Reckaa6e84f2016-06-16 15:36:13 -0700184 // Called when the RenderNode's position changes
John Reckf6481082016-02-02 15:18:23 -0800185 virtual void onPositionUpdated(RenderNode& node, const TreeInfo& info) = 0;
John Reckaa6e84f2016-06-16 15:36:13 -0700186 // Called when the RenderNode no longer has a position. As in, it's
187 // no longer being drawn.
188 // Note, tree info might be null
189 virtual void onPositionLost(RenderNode& node, const TreeInfo* info) = 0;
John Reckf6481082016-02-02 15:18:23 -0800190 };
191
John Reckf6481082016-02-02 15:18:23 -0800192 ANDROID_API void setPositionListener(PositionListener* listener) {
John Reck097e1d32019-06-12 15:01:51 -0700193 mStagingPositionListener = listener;
194 mPositionListenerDirty = true;
John Reckf6481082016-02-02 15:18:23 -0800195 }
196
John Reck44b49f02016-03-25 14:29:48 -0700197 // This is only modified in MODE_FULL, so it can be safely accessed
198 // on the UI thread.
John Reck1bcacfd2017-11-03 10:12:19 -0700199 ANDROID_API bool hasParents() { return mParentCount; }
John Reck44b49f02016-03-25 14:29:48 -0700200
John Reck2de950d2017-01-25 10:58:30 -0800201 void onRemovedFromTree(TreeInfo* info);
202
203 // Called by CanvasContext to promote a RenderNode to be a root node
John Reck1bcacfd2017-11-03 10:12:19 -0700204 void makeRoot() { incParentRefCount(); }
John Reck2de950d2017-01-25 10:58:30 -0800205
206 // Called by CanvasContext when it drops a RenderNode from being a root node
207 void clearRoot();
208
Stan Ilievd2172372017-02-09 16:59:27 -0500209 void output(std::ostream& output, uint32_t level);
210
John Reck8f45d4a2018-08-15 10:17:12 -0700211 void setUsageHint(UsageHint usageHint) { mUsageHint = usageHint; }
John Reck9ce2bf72018-07-02 18:33:32 -0700212
John Reck8f45d4a2018-08-15 10:17:12 -0700213 UsageHint usageHint() const { return mUsageHint; }
John Reck9ce2bf72018-07-02 18:33:32 -0700214
John Reckf96b2842018-11-29 09:44:10 -0800215 int64_t uniqueId() const { return mUniqueId; }
216
217 void markDrawStart(SkCanvas& canvas);
218 void markDrawEnd(SkCanvas& canvas);
219
John Reck113e0822014-03-18 09:22:59 -0700220private:
Chris Craik5e00c7c2016-07-06 16:10:09 -0700221 void computeOrderingImpl(RenderNodeOp* opState,
John Reck1bcacfd2017-11-03 10:12:19 -0700222 std::vector<RenderNodeOp*>* compositedChildrenOfProjectionSurface,
223 const mat4* transformFromProjectionSurface);
John Reck113e0822014-03-18 09:22:59 -0700224
Chris Craikb565df12015-10-05 13:00:52 -0700225 void syncProperties();
John Reck2de950d2017-01-25 10:58:30 -0800226 void syncDisplayList(TreeObserver& observer, TreeInfo* info);
John Reck3b4510cd2018-09-27 17:39:45 -0700227 void handleForceDark(TreeInfo* info);
Chris Craikb565df12015-10-05 13:00:52 -0700228
John Reck2de950d2017-01-25 10:58:30 -0800229 void prepareTreeImpl(TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer);
John Reck25fbb3f2014-06-12 13:46:45 -0700230 void pushStagingPropertiesChanges(TreeInfo& info);
John Reck2de950d2017-01-25 10:58:30 -0800231 void pushStagingDisplayListChanges(TreeObserver& observer, TreeInfo& info);
John Recka7c2ea22014-08-08 13:21:00 -0700232 void prepareLayer(TreeInfo& info, uint32_t dirtyMask);
John Reck25fbb3f2014-06-12 13:46:45 -0700233 void pushLayerUpdate(TreeInfo& info);
John Reck2de950d2017-01-25 10:58:30 -0800234 void deleteDisplayList(TreeObserver& observer, TreeInfo* info = nullptr);
John Reck0a973302014-07-16 13:29:45 -0700235 void damageSelf(TreeInfo& info);
John Reckdcba6722014-07-08 13:59:49 -0700236
237 void incParentRefCount() { mParentCount++; }
John Reck2de950d2017-01-25 10:58:30 -0800238 void decParentRefCount(TreeObserver& observer, TreeInfo* info = nullptr);
John Reck8de65a82014-04-09 15:23:38 -0700239
John Reckf96b2842018-11-29 09:44:10 -0800240 const int64_t mUniqueId;
John Reck113e0822014-03-18 09:22:59 -0700241 String8 mName;
John Reck44b49f02016-03-25 14:29:48 -0700242 sp<VirtualLightRefBase> mUserContext;
John Reck113e0822014-03-18 09:22:59 -0700243
John Reckff941dc2014-05-14 16:34:14 -0700244 uint32_t mDirtyPropertyFields;
John Reck113e0822014-03-18 09:22:59 -0700245 RenderProperties mProperties;
John Reckd0a0b2a2014-03-20 16:28:56 -0700246 RenderProperties mStagingProperties;
247
John Reck2de950d2017-01-25 10:58:30 -0800248 // Owned by UI. Set when DL is set, cleared when DL cleared or when node detached
249 // (likely by parent re-record/removal)
250 bool mValid = false;
251
Chris Craik003cc3d2015-10-16 10:24:55 -0700252 bool mNeedsDisplayListSync;
253 // WARNING: Do not delete this directly, you must go through deleteDisplayList()!
254 DisplayList* mDisplayList;
255 DisplayList* mStagingDisplayList;
John Reck113e0822014-03-18 09:22:59 -0700256
John Reckf1aa7909e2019-03-07 17:01:08 -0800257 int64_t mDamageGenerationId;
258
John Reck68bfe0a2014-06-24 15:34:58 -0700259 friend class AnimatorManager;
260 AnimatorManager mAnimatorManager;
John Recke45b1fd2014-04-15 09:50:16 -0700261
John Reck113e0822014-03-18 09:22:59 -0700262 /**
263 * Draw time state - these properties are only set and used during rendering
264 */
265
266 // for projection surfaces, contains a list of all children items
Chris Craik5e00c7c2016-07-06 16:10:09 -0700267 std::vector<RenderNodeOp*> mProjectedNodes;
John Reckdcba6722014-07-08 13:59:49 -0700268
269 // How many references our parent(s) have to us. Typically this should alternate
270 // between 2 and 1 (when a staging push happens we inc first then dec)
271 // When this hits 0 we are no longer in the tree, so any hardware resources
272 // (specifically Layers) should be released.
273 // This is *NOT* thread-safe, and should therefore only be tracking
Chris Craik003cc3d2015-10-16 10:24:55 -0700274 // mDisplayList, not mStagingDisplayList.
John Reckdcba6722014-07-08 13:59:49 -0700275 uint32_t mParentCount;
John Reckf6481082016-02-02 15:18:23 -0800276
John Reck097e1d32019-06-12 15:01:51 -0700277 bool mPositionListenerDirty = false;
278 sp<PositionListener> mStagingPositionListener;
John Reck7b570de2016-06-27 13:27:23 -0700279 sp<PositionListener> mPositionListener;
Derek Sollenberger0df62092016-09-27 16:04:42 -0400280
John Reck9ce2bf72018-07-02 18:33:32 -0700281 UsageHint mUsageHint = UsageHint::Unknown;
282
John Reck1bcacfd2017-11-03 10:12:19 -0700283 // METHODS & FIELDS ONLY USED BY THE SKIA RENDERER
Derek Sollenberger0df62092016-09-27 16:04:42 -0400284public:
285 /**
286 * Detach and transfer ownership of an already allocated displayList for use
287 * in recording updated content for this renderNode
288 */
Stan Iliev021693b2016-10-17 16:26:15 -0400289 std::unique_ptr<skiapipeline::SkiaDisplayList> detachAvailableList() {
Derek Sollenberger0df62092016-09-27 16:04:42 -0400290 return std::move(mAvailableDisplayList);
291 }
292
293 /**
294 * Attach unused displayList to this node for potential future reuse.
295 */
Stan Iliev021693b2016-10-17 16:26:15 -0400296 void attachAvailableList(skiapipeline::SkiaDisplayList* skiaDisplayList) {
Derek Sollenberger0df62092016-09-27 16:04:42 -0400297 mAvailableDisplayList.reset(skiaDisplayList);
298 }
299
300 /**
301 * Returns true if an offscreen layer from any renderPipeline is attached
302 * to this node.
303 */
John Recke4c1e6c2018-05-24 16:27:35 -0700304 bool hasLayer() const { return mSkiaLayer.get(); }
Derek Sollenberger0df62092016-09-27 16:04:42 -0400305
306 /**
307 * Used by the RenderPipeline to attach an offscreen surface to the RenderNode.
308 * The surface is then will be used to store the contents of a layer.
309 */
Stan Iliev500a0c32016-10-26 10:30:09 -0400310 void setLayerSurface(sk_sp<SkSurface> layer) {
311 if (layer.get()) {
312 if (!mSkiaLayer.get()) {
313 mSkiaLayer = std::make_unique<skiapipeline::SkiaLayer>();
314 }
315 mSkiaLayer->layerSurface = std::move(layer);
316 mSkiaLayer->inverseTransformInWindow.loadIdentity();
317 } else {
318 mSkiaLayer.reset();
319 }
320 }
Derek Sollenberger0df62092016-09-27 16:04:42 -0400321
322 /**
323 * If the RenderNode is of type LayerType::RenderLayer then this method will
324 * return the an offscreen rendering surface that is used to both render into
325 * the layer and composite the layer into its parent. If the type is not
326 * LayerType::RenderLayer then it will return a nullptr.
327 *
328 * NOTE: this function is only guaranteed to return accurate results after
329 * prepareTree has been run for this RenderNode
330 */
Stan Iliev500a0c32016-10-26 10:30:09 -0400331 SkSurface* getLayerSurface() const {
332 return mSkiaLayer.get() ? mSkiaLayer->layerSurface.get() : nullptr;
333 }
334
John Reck1bcacfd2017-11-03 10:12:19 -0700335 skiapipeline::SkiaLayer* getSkiaLayer() const { return mSkiaLayer.get(); }
Derek Sollenberger0df62092016-09-27 16:04:42 -0400336
Derek Sollenberger579317d2017-08-29 16:33:49 -0400337 /**
338 * Returns the path that represents the outline of RenderNode intersected with
339 * the provided rect. This call will internally cache the resulting path in
340 * order to potentially return that path for subsequent calls to this method.
341 * By reusing the same path we get better performance on the GPU backends since
342 * those resources are cached in the hardware based on the path's genID.
343 *
344 * The returned path is only guaranteed to be valid until this function is called
345 * again or the RenderNode's outline is mutated.
346 */
347 const SkPath* getClippedOutline(const SkRect& clipRect) const;
John Reck1bcacfd2017-11-03 10:12:19 -0700348
Derek Sollenberger0df62092016-09-27 16:04:42 -0400349private:
350 /**
351 * If this RenderNode has been used in a previous frame then the SkiaDisplayList
352 * from that frame is cached here until one of the following conditions is met:
353 * 1) The RenderNode is deleted (causing this to be deleted)
354 * 2) It is replaced with the displayList from the next completed frame
355 * 3) It is detached and used to to record a new displayList for a later frame
356 */
Stan Iliev021693b2016-10-17 16:26:15 -0400357 std::unique_ptr<skiapipeline::SkiaDisplayList> mAvailableDisplayList;
Derek Sollenberger0df62092016-09-27 16:04:42 -0400358
359 /**
360 * An offscreen rendering target used to contain the contents this RenderNode
361 * when it has been set to draw as a LayerType::RenderLayer.
362 */
Stan Iliev500a0c32016-10-26 10:30:09 -0400363 std::unique_ptr<skiapipeline::SkiaLayer> mSkiaLayer;
Derek Sollenberger579317d2017-08-29 16:33:49 -0400364
365 struct ClippedOutlineCache {
366 // keys
367 uint32_t outlineID = 0;
368 SkRect clipRect;
369
370 // value
371 SkPath clippedOutline;
372 };
373 mutable ClippedOutlineCache mClippedOutlineCache;
John Reck1bcacfd2017-11-03 10:12:19 -0700374}; // class RenderNode
John Reck113e0822014-03-18 09:22:59 -0700375
John Reck2de950d2017-01-25 10:58:30 -0800376class MarkAndSweepRemoved : public TreeObserver {
John Reck1bcacfd2017-11-03 10:12:19 -0700377 PREVENT_COPY_AND_ASSIGN(MarkAndSweepRemoved);
John Reck2de950d2017-01-25 10:58:30 -0800378
379public:
380 explicit MarkAndSweepRemoved(TreeInfo* info) : mTreeInfo(info) {}
381
John Reck1bcacfd2017-11-03 10:12:19 -0700382 void onMaybeRemovedFromTree(RenderNode* node) override { mMarked.emplace_back(node); }
John Reck2de950d2017-01-25 10:58:30 -0800383
384 ~MarkAndSweepRemoved() {
385 for (auto& node : mMarked) {
386 if (!node->hasParents()) {
387 node->onRemovedFromTree(mTreeInfo);
388 }
389 }
390 }
391
392private:
393 FatVector<sp<RenderNode>, 10> mMarked;
394 TreeInfo* mTreeInfo;
395};
396
John Reck113e0822014-03-18 09:22:59 -0700397} /* namespace uirenderer */
398} /* namespace android */