Fix damage tracking for RenderNode drawn twice
Bug: 127866048
Test: CustomRenderer demo
Change-Id: I431a7284b1d0a026e06500a78f41830a268235a5
diff --git a/libs/hwui/RenderNode.cpp b/libs/hwui/RenderNode.cpp
index 1ff7ffe..e0ed3e4 100644
--- a/libs/hwui/RenderNode.cpp
+++ b/libs/hwui/RenderNode.cpp
@@ -134,6 +134,7 @@
void RenderNode::damageSelf(TreeInfo& info) {
if (isRenderable()) {
+ mDamageGenerationId = info.damageGenerationId;
if (properties().getClipDamageToBounds()) {
info.damageAccumulator->dirty(0, 0, properties().getWidth(), properties().getHeight());
} else {
@@ -199,6 +200,12 @@
* stencil buffer may be needed. Views that use a functor to draw will be forced onto a layer.
*/
void RenderNode::prepareTreeImpl(TreeObserver& observer, TreeInfo& info, bool functorsNeedLayer) {
+ if (mDamageGenerationId == info.damageGenerationId) {
+ // We hit the same node a second time in the same tree. We don't know the minimal
+ // damage rect anymore, so just push the biggest we can onto our parent's transform
+ // We push directly onto parent in case we are clipped to bounds but have moved position.
+ info.damageAccumulator->dirty(DIRTY_MIN, DIRTY_MIN, DIRTY_MAX, DIRTY_MAX);
+ }
info.damageAccumulator->pushTransform(this);
if (info.mode == TreeInfo::MODE_FULL) {
diff --git a/libs/hwui/RenderNode.h b/libs/hwui/RenderNode.h
index 6060123..23e7a0e 100644
--- a/libs/hwui/RenderNode.h
+++ b/libs/hwui/RenderNode.h
@@ -255,6 +255,8 @@
DisplayList* mDisplayList;
DisplayList* mStagingDisplayList;
+ int64_t mDamageGenerationId;
+
friend class AnimatorManager;
AnimatorManager mAnimatorManager;
diff --git a/libs/hwui/TreeInfo.cpp b/libs/hwui/TreeInfo.cpp
index 808a12a..cdad20e 100644
--- a/libs/hwui/TreeInfo.cpp
+++ b/libs/hwui/TreeInfo.cpp
@@ -24,6 +24,7 @@
: mode(mode)
, prepareTextures(mode == MODE_FULL)
, canvasContext(canvasContext)
+ , damageGenerationId(canvasContext.getFrameNumber())
, disableForceDark(canvasContext.useForceDark() ? 0 : 1) {}
} // namespace android::uirenderer
diff --git a/libs/hwui/TreeInfo.h b/libs/hwui/TreeInfo.h
index a0d9605..04eabac 100644
--- a/libs/hwui/TreeInfo.h
+++ b/libs/hwui/TreeInfo.h
@@ -87,6 +87,7 @@
// Must not be null during actual usage
DamageAccumulator* damageAccumulator = nullptr;
+ int64_t damageGenerationId = 0;
LayerUpdateQueue* layerUpdateQueue = nullptr;
ErrorHandler* errorHandler = nullptr;