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  */
16 
17 #include "RenderNode.h"
18 
19 #include "DamageAccumulator.h"
20 #include "Debug.h"
21 #include "Properties.h"
22 #include "TreeInfo.h"
23 #include "VectorDrawable.h"
24 #include "private/hwui/WebViewFunctor.h"
25 #ifdef __ANDROID__
26 #include "renderthread/CanvasContext.h"
27 #else
28 #include "DamageAccumulator.h"
29 #include "pipeline/skia/SkiaDisplayList.h"
30 #endif
31 #include <gui/TraceUtils.h>
32 #include "utils/MathUtils.h"
33 #include "utils/StringUtils.h"
34 
35 #include <SkPathOps.h>
36 #include <algorithm>
37 #include <atomic>
38 #include <sstream>
39 #include <string>
40 #include <ui/FatVector.h>
41 
42 namespace android {
43 namespace uirenderer {
44 
45 // Used for tree mutations that are purely destructive.
46 // Generic tree mutations should use MarkAndSweepObserver instead
47 class ImmediateRemoved : public TreeObserver {
48 public:
ImmediateRemoved(TreeInfo * info)49     explicit ImmediateRemoved(TreeInfo* info) : mTreeInfo(info) {}
50 
onMaybeRemovedFromTree(RenderNode * node)51     void onMaybeRemovedFromTree(RenderNode* node) override { node->onRemovedFromTree(mTreeInfo); }
52 
53 private:
54     TreeInfo* mTreeInfo;
55 };
56 
generateId()57 static int64_t generateId() {
58     static std::atomic<int64_t> sNextId{1};
59     return sNextId++;
60 }
61 
RenderNode()62 RenderNode::RenderNode()
63         : mUniqueId(generateId())
64         , mDirtyPropertyFields(0)
65         , mNeedsDisplayListSync(false)
66         , mDisplayList(nullptr)
67         , mStagingDisplayList(nullptr)
68         , mAnimatorManager(*this)
69         , mParentCount(0) {}
70 
~RenderNode()71 RenderNode::~RenderNode() {
72     ImmediateRemoved observer(nullptr);
73     deleteDisplayList(observer);
74     LOG_ALWAYS_FATAL_IF(hasLayer(), "layer missed detachment!");
75 }
76 
setStagingDisplayList(DisplayList && newData)77 void RenderNode::setStagingDisplayList(DisplayList&& newData) {
78     mValid = newData.isValid();
79     mNeedsDisplayListSync = true;
80     mStagingDisplayList = std::move(newData);
81 }
82 
discardStagingDisplayList()83 void RenderNode::discardStagingDisplayList() {
84     setStagingDisplayList(DisplayList());
85 }
86 
87 /**
88  * This function is a simplified version of replay(), where we simply retrieve and log the
89  * display list. This function should remain in sync with the replay() function.
90  */
output()91 void RenderNode::output() {
92     LogcatStream strout;
93     strout << "Root";
94     output(strout, 0);
95 }
96 
output(std::ostream & output,uint32_t level)97 void RenderNode::output(std::ostream& output, uint32_t level) {
98     output << "  (" << getName() << " " << this
99            << (MathUtils::isZero(properties().getAlpha()) ? ", zero alpha" : "")
100            << (properties().hasShadow() ? ", casting shadow" : "")
101            << (isRenderable() ? "" : ", empty")
102            << (properties().getProjectBackwards() ? ", projected" : "")
103            << (hasLayer() ? ", on HW Layer" : "") << ")" << std::endl;
104 
105     properties().debugOutputProperties(output, level + 1);
106 
107     mDisplayList.output(output, level);
108     output << std::string(level * 2, ' ') << "/RenderNode(" << getName() << " " << this << ")";
109     output << std::endl;
110 }
111 
getUsageSize()112 int RenderNode::getUsageSize() {
113     int size = sizeof(RenderNode);
114     size += mStagingDisplayList.getUsedSize();
115     size += mDisplayList.getUsedSize();
116     return size;
117 }
118 
getAllocatedSize()119 int RenderNode::getAllocatedSize() {
120     int size = sizeof(RenderNode);
121     size += mStagingDisplayList.getAllocatedSize();
122     size += mDisplayList.getAllocatedSize();
123     return size;
124 }
125 
126 
prepareTree(TreeInfo & info)127 void RenderNode::prepareTree(TreeInfo& info) {
128     ATRACE_CALL();
129     LOG_ALWAYS_FATAL_IF(!info.damageAccumulator, "DamageAccumulator missing");
130     MarkAndSweepRemoved observer(&info);
131 
132     const int before = info.disableForceDark;
133     prepareTreeImpl(observer, info, false);
134     LOG_ALWAYS_FATAL_IF(before != info.disableForceDark, "Mis-matched force dark");
135 }
136 
addAnimator(const sp<BaseRenderNodeAnimator> & animator)137 void RenderNode::addAnimator(const sp<BaseRenderNodeAnimator>& animator) {
138     mAnimatorManager.addAnimator(animator);
139 }
140 
removeAnimator(const sp<BaseRenderNodeAnimator> & animator)141 void RenderNode::removeAnimator(const sp<BaseRenderNodeAnimator>& animator) {
142     mAnimatorManager.removeAnimator(animator);
143 }
144 
damageSelf(TreeInfo & info)145 void RenderNode::damageSelf(TreeInfo& info) {
146     if (isRenderable()) {
147         mDamageGenerationId = info.damageGenerationId;
148         if (properties().getClipDamageToBounds()) {
149             info.damageAccumulator->dirty(0, 0, properties().getWidth(), properties().getHeight());
150         } else {
151             // Hope this is big enough?
152             // TODO: Get this from the display list ops or something
153             info.damageAccumulator->dirty(DIRTY_MIN, DIRTY_MIN, DIRTY_MAX, DIRTY_MAX);
154         }
155         if (!mIsTextureView) {
156             info.out.solelyTextureViewUpdates = false;
157         }
158     }
159 }
160 
prepareLayer(TreeInfo & info,uint32_t dirtyMask)161 void RenderNode::prepareLayer(TreeInfo& info, uint32_t dirtyMask) {
162     LayerType layerType = properties().effectiveLayerType();
163     if (CC_UNLIKELY(layerType == LayerType::RenderLayer)) {
164         // Damage applied so far needs to affect our parent, but does not require
165         // the layer to be updated. So we pop/push here to clear out the current
166         // damage and get a clean state for display list or children updates to
167         // affect, which will require the layer to be updated
168         info.damageAccumulator->popTransform();
169         info.damageAccumulator->pushTransform(this);
170         if (dirtyMask & DISPLAY_LIST) {
171             damageSelf(info);
172         }
173     }
174 }
175 
pushLayerUpdate(TreeInfo & info)176 void RenderNode::pushLayerUpdate(TreeInfo& info) {
177 #ifdef __ANDROID__ // Layoutlib does not support CanvasContext and Layers
178     LayerType layerType = properties().effectiveLayerType();
179     // If we are not a layer OR we cannot be rendered (eg, view was detached)
180     // we need to destroy any Layers we may have had previously
181     if (CC_LIKELY(layerType != LayerType::RenderLayer) || CC_UNLIKELY(!isRenderable()) ||
182         CC_UNLIKELY(properties().getWidth() == 0) || CC_UNLIKELY(properties().getHeight() == 0) ||
183         CC_UNLIKELY(!properties().fitsOnLayer())) {
184         if (CC_UNLIKELY(hasLayer())) {
185             this->setLayerSurface(nullptr);
186         }
187         return;
188     }
189 
190     if (info.canvasContext.createOrUpdateLayer(this, *info.damageAccumulator, info.errorHandler)) {
191         damageSelf(info);
192     }
193 
194     if (!hasLayer()) {
195         return;
196     }
197 
198     SkRect dirty;
199     info.damageAccumulator->peekAtDirty(&dirty);
200     info.layerUpdateQueue->enqueueLayerWithDamage(this, dirty);
201     if (!dirty.isEmpty()) {
202       mStretchMask.markDirty();
203     }
204 
205     // There might be prefetched layers that need to be accounted for.
206     // That might be us, so tell CanvasContext that this layer is in the
207     // tree and should not be destroyed.
208     info.canvasContext.markLayerInUse(this);
209 #endif
210 }
211 
212 /**
213  * Traverse down the the draw tree to prepare for a frame.
214  *
215  * MODE_FULL = UI Thread-driven (thus properties must be synced), otherwise RT driven
216  *
217  * While traversing down the tree, functorsNeedLayer flag is set to true if anything that uses the
218  * stencil buffer may be needed. Views that use a functor to draw will be forced onto a layer.
219  */
prepareTreeImpl(TreeObserver & observer,TreeInfo & info,bool functorsNeedLayer)220 void RenderNode::prepareTreeImpl(TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer) {
221     if (mDamageGenerationId == info.damageGenerationId) {
222         // We hit the same node a second time in the same tree. We don't know the minimal
223         // damage rect anymore, so just push the biggest we can onto our parent's transform
224         // We push directly onto parent in case we are clipped to bounds but have moved position.
225         info.damageAccumulator->dirty(DIRTY_MIN, DIRTY_MIN, DIRTY_MAX, DIRTY_MAX);
226     }
227     info.damageAccumulator->pushTransform(this);
228 
229     if (info.mode == TreeInfo::MODE_FULL) {
230         pushStagingPropertiesChanges(info);
231     }
232 
233     if (!mProperties.getAllowForceDark()) {
234         info.disableForceDark++;
235     }
236     if (!mProperties.layerProperties().getStretchEffect().isEmpty()) {
237         info.stretchEffectCount++;
238     }
239 
240     uint32_t animatorDirtyMask = 0;
241     if (CC_LIKELY(info.runAnimations)) {
242         animatorDirtyMask = mAnimatorManager.animate(info);
243     }
244 
245     bool willHaveFunctor = false;
246     if (info.mode == TreeInfo::MODE_FULL && mStagingDisplayList) {
247         willHaveFunctor = mStagingDisplayList.hasFunctor();
248     } else if (mDisplayList) {
249         willHaveFunctor = mDisplayList.hasFunctor();
250     }
251     bool childFunctorsNeedLayer =
252             mProperties.prepareForFunctorPresence(willHaveFunctor, functorsNeedLayer);
253 
254     if (CC_UNLIKELY(mPositionListener.get())) {
255         mPositionListener->onPositionUpdated(*this, info);
256     }
257 
258     prepareLayer(info, animatorDirtyMask);
259     if (info.mode == TreeInfo::MODE_FULL) {
260         pushStagingDisplayListChanges(observer, info);
261     }
262 
263     if (mDisplayList) {
264         info.out.hasFunctors |= mDisplayList.hasFunctor();
265         mHasHolePunches = mDisplayList.hasHolePunches();
266         bool isDirty = mDisplayList.prepareListAndChildren(
267                 observer, info, childFunctorsNeedLayer,
268                 [this](RenderNode* child, TreeObserver& observer, TreeInfo& info,
269                        bool functorsNeedLayer) {
270                     child->prepareTreeImpl(observer, info, functorsNeedLayer);
271                     mHasHolePunches |= child->hasHolePunches();
272                 });
273         if (isDirty) {
274             damageSelf(info);
275         }
276     } else {
277         mHasHolePunches = false;
278     }
279     pushLayerUpdate(info);
280 
281     if (!mProperties.getAllowForceDark()) {
282         info.disableForceDark--;
283     }
284     if (!mProperties.layerProperties().getStretchEffect().isEmpty()) {
285         info.stretchEffectCount--;
286     }
287     info.damageAccumulator->popTransform();
288 }
289 
syncProperties()290 void RenderNode::syncProperties() {
291     mProperties = mStagingProperties;
292 }
293 
pushStagingPropertiesChanges(TreeInfo & info)294 void RenderNode::pushStagingPropertiesChanges(TreeInfo& info) {
295     if (mPositionListenerDirty) {
296         mPositionListener = std::move(mStagingPositionListener);
297         mStagingPositionListener = nullptr;
298         mPositionListenerDirty = false;
299     }
300 
301     // Push the animators first so that setupStartValueIfNecessary() is called
302     // before properties() is trampled by stagingProperties(), as they are
303     // required by some animators.
304     if (CC_LIKELY(info.runAnimations)) {
305         mAnimatorManager.pushStaging();
306     }
307     if (mDirtyPropertyFields) {
308         mDirtyPropertyFields = 0;
309         damageSelf(info);
310         info.damageAccumulator->popTransform();
311         syncProperties();
312 
313         auto& layerProperties = mProperties.layerProperties();
314         const StretchEffect& stagingStretch = layerProperties.getStretchEffect();
315         if (stagingStretch.isEmpty()) {
316             mStretchMask.clear();
317         }
318 
319         if (layerProperties.getImageFilter() == nullptr) {
320             mSnapshotResult.snapshot = nullptr;
321             mTargetImageFilter = nullptr;
322         }
323 
324         // We could try to be clever and only re-damage if the matrix changed.
325         // However, we don't need to worry about that. The cost of over-damaging
326         // here is only going to be a single additional map rect of this node
327         // plus a rect join(). The parent's transform (and up) will only be
328         // performed once.
329         info.damageAccumulator->pushTransform(this);
330         damageSelf(info);
331     }
332 }
333 
updateSnapshotIfRequired(GrRecordingContext * context,const SkImageFilter * imageFilter,const SkIRect & clipBounds)334 std::optional<RenderNode::SnapshotResult> RenderNode::updateSnapshotIfRequired(
335     GrRecordingContext* context,
336     const SkImageFilter* imageFilter,
337     const SkIRect& clipBounds
338 ) {
339     auto* layerSurface = getLayerSurface();
340     if (layerSurface == nullptr) {
341         return std::nullopt;
342     }
343 
344     sk_sp<SkImage> snapshot = layerSurface->makeImageSnapshot();
345     const auto subset = SkIRect::MakeWH(properties().getWidth(),
346                                         properties().getHeight());
347     uint32_t layerSurfaceGenerationId = layerSurface->generationID();
348     // If we don't have an ImageFilter just return the snapshot
349     if (imageFilter == nullptr) {
350         mSnapshotResult.snapshot = snapshot;
351         mSnapshotResult.outSubset = subset;
352         mSnapshotResult.outOffset = SkIPoint::Make(0.0f, 0.0f);
353         mImageFilterClipBounds = clipBounds;
354         mTargetImageFilter = nullptr;
355         mTargetImageFilterLayerSurfaceGenerationId = 0;
356     } else if (mSnapshotResult.snapshot == nullptr || imageFilter != mTargetImageFilter.get() ||
357                mImageFilterClipBounds != clipBounds ||
358                mTargetImageFilterLayerSurfaceGenerationId != layerSurfaceGenerationId) {
359         // Otherwise create a new snapshot with the given filter and snapshot
360         mSnapshotResult.snapshot =
361                 snapshot->makeWithFilter(context,
362                                          imageFilter,
363                                          subset,
364                                          clipBounds,
365                                          &mSnapshotResult.outSubset,
366                                          &mSnapshotResult.outOffset);
367         mTargetImageFilter = sk_ref_sp(imageFilter);
368         mImageFilterClipBounds = clipBounds;
369         mTargetImageFilterLayerSurfaceGenerationId = layerSurfaceGenerationId;
370     }
371 
372     return mSnapshotResult;
373 }
374 
syncDisplayList(TreeObserver & observer,TreeInfo * info)375 void RenderNode::syncDisplayList(TreeObserver& observer, TreeInfo* info) {
376     // Make sure we inc first so that we don't fluctuate between 0 and 1,
377     // which would thrash the layer cache
378     if (mStagingDisplayList) {
379         mStagingDisplayList.updateChildren([](RenderNode* child) { child->incParentRefCount(); });
380     }
381     deleteDisplayList(observer, info);
382     mDisplayList = std::move(mStagingDisplayList);
383     if (mDisplayList) {
384         WebViewSyncData syncData {
385             .applyForceDark = info && !info->disableForceDark
386         };
387         mDisplayList.syncContents(syncData);
388         handleForceDark(info);
389     }
390 }
391 
handleForceDark(android::uirenderer::TreeInfo * info)392 void RenderNode::handleForceDark(android::uirenderer::TreeInfo *info) {
393     if (CC_LIKELY(!info || info->disableForceDark)) {
394         return;
395     }
396     auto usage = usageHint();
397     FatVector<RenderNode*, 6> children;
398     mDisplayList.updateChildren([&children](RenderNode* node) {
399         children.push_back(node);
400     });
401     if (mDisplayList.hasText()) {
402         usage = UsageHint::Foreground;
403     }
404     if (usage == UsageHint::Unknown) {
405         if (children.size() > 1) {
406             usage = UsageHint::Background;
407         } else if (children.size() == 1 &&
408                 children.front()->usageHint() !=
409                         UsageHint::Background) {
410             usage = UsageHint::Background;
411         }
412     }
413     if (children.size() > 1) {
414         // Crude overlap check
415         SkRect drawn = SkRect::MakeEmpty();
416         for (auto iter = children.rbegin(); iter != children.rend(); ++iter) {
417             const auto& child = *iter;
418             // We use stagingProperties here because we haven't yet sync'd the children
419             SkRect bounds = SkRect::MakeXYWH(child->stagingProperties().getX(), child->stagingProperties().getY(),
420                     child->stagingProperties().getWidth(), child->stagingProperties().getHeight());
421             if (bounds.contains(drawn)) {
422                 // This contains everything drawn after it, so make it a background
423                 child->setUsageHint(UsageHint::Background);
424             }
425             drawn.join(bounds);
426         }
427     }
428     mDisplayList.applyColorTransform(
429             usage == UsageHint::Background ? ColorTransform::Dark : ColorTransform::Light);
430 }
431 
pushStagingDisplayListChanges(TreeObserver & observer,TreeInfo & info)432 void RenderNode::pushStagingDisplayListChanges(TreeObserver& observer, TreeInfo& info) {
433     if (mNeedsDisplayListSync) {
434         mNeedsDisplayListSync = false;
435         // Damage with the old display list first then the new one to catch any
436         // changes in isRenderable or, in the future, bounds
437         damageSelf(info);
438         syncDisplayList(observer, &info);
439         damageSelf(info);
440     }
441 }
442 
deleteDisplayList(TreeObserver & observer,TreeInfo * info)443 void RenderNode::deleteDisplayList(TreeObserver& observer, TreeInfo* info) {
444     if (mDisplayList) {
445         mDisplayList.updateChildren(
446                 [&observer, info](RenderNode* child) { child->decParentRefCount(observer, info); });
447         mDisplayList.clear(this);
448     }
449 }
450 
destroyHardwareResources(TreeInfo * info)451 void RenderNode::destroyHardwareResources(TreeInfo* info) {
452     if (hasLayer()) {
453         this->setLayerSurface(nullptr);
454     }
455     discardStagingDisplayList();
456 
457     ImmediateRemoved observer(info);
458     deleteDisplayList(observer, info);
459 }
460 
destroyLayers()461 void RenderNode::destroyLayers() {
462     if (hasLayer()) {
463         this->setLayerSurface(nullptr);
464     }
465 
466     if (mDisplayList) {
467         mDisplayList.updateChildren([](RenderNode* child) { child->destroyLayers(); });
468     }
469 }
470 
decParentRefCount(TreeObserver & observer,TreeInfo * info)471 void RenderNode::decParentRefCount(TreeObserver& observer, TreeInfo* info) {
472     LOG_ALWAYS_FATAL_IF(!mParentCount, "already 0!");
473     mParentCount--;
474     if (!mParentCount) {
475         observer.onMaybeRemovedFromTree(this);
476         if (CC_UNLIKELY(mPositionListener.get())) {
477             mPositionListener->onPositionLost(*this, info);
478         }
479     }
480 }
481 
onRemovedFromTree(TreeInfo * info)482 void RenderNode::onRemovedFromTree(TreeInfo* info) {
483     if (Properties::enableWebViewOverlays && mDisplayList) {
484         mDisplayList.onRemovedFromTree();
485     }
486     destroyHardwareResources(info);
487 }
488 
clearRoot()489 void RenderNode::clearRoot() {
490     ImmediateRemoved observer(nullptr);
491     decParentRefCount(observer);
492 }
493 
494 /**
495  * Apply property-based transformations to input matrix
496  *
497  * If true3dTransform is set to true, the transform applied to the input matrix will use true 4x4
498  * matrix computation instead of the Skia 3x3 matrix + camera hackery.
499  */
applyViewPropertyTransforms(mat4 & matrix,bool true3dTransform) const500 void RenderNode::applyViewPropertyTransforms(mat4& matrix, bool true3dTransform) const {
501     if (properties().getLeft() != 0 || properties().getTop() != 0) {
502         matrix.translate(properties().getLeft(), properties().getTop());
503     }
504     if (properties().getStaticMatrix()) {
505         mat4 stat(*properties().getStaticMatrix());
506         matrix.multiply(stat);
507     } else if (properties().getAnimationMatrix()) {
508         mat4 anim(*properties().getAnimationMatrix());
509         matrix.multiply(anim);
510     }
511 
512     bool applyTranslationZ = true3dTransform && !MathUtils::isZero(properties().getZ());
513     if (properties().hasTransformMatrix() || applyTranslationZ) {
514         if (properties().isTransformTranslateOnly()) {
515             matrix.translate(properties().getTranslationX(), properties().getTranslationY(),
516                              true3dTransform ? properties().getZ() : 0.0f);
517         } else {
518             if (!true3dTransform) {
519                 matrix.multiply(*properties().getTransformMatrix());
520             } else {
521                 mat4 true3dMat;
522                 true3dMat.loadTranslate(properties().getPivotX() + properties().getTranslationX(),
523                                         properties().getPivotY() + properties().getTranslationY(),
524                                         properties().getZ());
525                 true3dMat.rotate(properties().getRotationX(), 1, 0, 0);
526                 true3dMat.rotate(properties().getRotationY(), 0, 1, 0);
527                 true3dMat.rotate(properties().getRotation(), 0, 0, 1);
528                 true3dMat.scale(properties().getScaleX(), properties().getScaleY(), 1);
529                 true3dMat.translate(-properties().getPivotX(), -properties().getPivotY());
530 
531                 matrix.multiply(true3dMat);
532             }
533         }
534     }
535 
536     if (Properties::getStretchEffectBehavior() == StretchEffectBehavior::UniformScale) {
537         const StretchEffect& stretch = properties().layerProperties().getStretchEffect();
538         if (!stretch.isEmpty()) {
539             matrix.multiply(
540                     stretch.makeLinearStretch(properties().getWidth(), properties().getHeight()));
541         }
542     }
543 }
544 
getClippedOutline(const SkRect & clipRect) const545 const SkPath* RenderNode::getClippedOutline(const SkRect& clipRect) const {
546     const SkPath* outlinePath = properties().getOutline().getPath();
547     const uint32_t outlineID = outlinePath->getGenerationID();
548 
549     if (outlineID != mClippedOutlineCache.outlineID || clipRect != mClippedOutlineCache.clipRect) {
550         // update the cache keys
551         mClippedOutlineCache.outlineID = outlineID;
552         mClippedOutlineCache.clipRect = clipRect;
553 
554         // update the cache value by recomputing a new path
555         SkPath clipPath;
556         clipPath.addRect(clipRect);
557         Op(*outlinePath, clipPath, kIntersect_SkPathOp, &mClippedOutlineCache.clippedOutline);
558     }
559     return &mClippedOutlineCache.clippedOutline;
560 }
561 
562 using StringBuffer = FatVector<char, 128>;
563 
564 template <typename... T>
565 // TODO:__printflike(2, 3)
566 // Doesn't work because the warning doesn't understand string_view and doesn't like that
567 // it's not a C-style variadic function.
format(StringBuffer & buffer,const std::string_view & format,T...args)568 static void format(StringBuffer& buffer, const std::string_view& format, T... args) {
569     buffer.resize(buffer.capacity());
570     while (1) {
571         int needed = snprintf(buffer.data(), buffer.size(),
572                 format.data(), std::forward<T>(args)...);
573         if (needed < 0) {
574             buffer[0] = '\0';
575             buffer.resize(1);
576             return;
577         }
578         if (needed < buffer.size()) {
579             buffer.resize(needed + 1);
580             return;
581         }
582         // If we're doing a heap alloc anyway might as well give it some slop
583         buffer.resize(needed + 100);
584     }
585 }
586 
markDrawStart(SkCanvas & canvas)587 void RenderNode::markDrawStart(SkCanvas& canvas) {
588     StringBuffer buffer;
589     format(buffer, "RenderNode(id=%" PRId64 ", name='%s')", uniqueId(), getName());
590     canvas.drawAnnotation(SkRect::MakeWH(getWidth(), getHeight()), buffer.data(), nullptr);
591 }
592 
markDrawEnd(SkCanvas & canvas)593 void RenderNode::markDrawEnd(SkCanvas& canvas) {
594     StringBuffer buffer;
595     format(buffer, "/RenderNode(id=%" PRId64 ", name='%s')", uniqueId(), getName());
596     canvas.drawAnnotation(SkRect::MakeWH(getWidth(), getHeight()), buffer.data(), nullptr);
597 }
598 
599 } /* namespace uirenderer */
600 } /* namespace android */
601