Skip to content

Commit 2a0f228

Browse files
author
Romain Guy
committed
Invalidate display lists immediately when views are removed/added quickly
The deferred invalidation of display list could cause problems with view like TextureView who destroy resources when detached from the window but only recreate them later at draw time. This would cause temporary flashes or other visual glitches on screen. Change-Id: I018488ba09743df21c6434ea610813014fb80a85
1 parent c2182c6 commit 2a0f228

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

core/java/android/view/View.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11077,22 +11077,30 @@ protected void onAttachedToWindow() {
1107711077
if ((mPrivateFlags & REQUEST_TRANSPARENT_REGIONS) != 0) {
1107811078
mParent.requestTransparentRegion(this);
1107911079
}
11080+
1108011081
if ((mPrivateFlags & AWAKEN_SCROLL_BARS_ON_ATTACH) != 0) {
1108111082
initialAwakenScrollBars();
1108211083
mPrivateFlags &= ~AWAKEN_SCROLL_BARS_ON_ATTACH;
1108311084
}
11085+
1108411086
jumpDrawablesToCurrentState();
11087+
1108511088
// Order is important here: LayoutDirection MUST be resolved before Padding
1108611089
// and TextDirection
1108711090
resolveLayoutDirection();
1108811091
resolvePadding();
1108911092
resolveTextDirection();
1109011093
resolveTextAlignment();
11094+
1109111095
clearAccessibilityFocus();
1109211096
if (isFocused()) {
1109311097
InputMethodManager imm = InputMethodManager.peekInstance();
1109411098
imm.focusIn(this);
1109511099
}
11100+
11101+
if (mAttachInfo != null && mDisplayList != null) {
11102+
mAttachInfo.mViewRootImpl.dequeueDisplayList(mDisplayList);
11103+
}
1109611104
}
1109711105

1109811106
/**
@@ -11313,7 +11321,7 @@ protected void onDetachedFromWindow() {
1131311321

1131411322
if (mAttachInfo != null) {
1131511323
if (mDisplayList != null) {
11316-
mAttachInfo.mViewRootImpl.invalidateDisplayList(mDisplayList);
11324+
mAttachInfo.mViewRootImpl.enqueueDisplayList(mDisplayList);
1131711325
}
1131811326
mAttachInfo.mViewRootImpl.cancelInvalidate(this);
1131911327
} else {
@@ -12007,7 +12015,6 @@ private DisplayList getDisplayList(DisplayList displayList, boolean isLayer) {
1200712015

1200812016
boolean caching = false;
1200912017
final HardwareCanvas canvas = displayList.start();
12010-
int restoreCount = 0;
1201112018
int width = mRight - mLeft;
1201212019
int height = mBottom - mTop;
1201312020

@@ -12640,10 +12647,6 @@ private boolean drawAnimation(ViewGroup parent, long drawingTime,
1264012647
return more;
1264112648
}
1264212649

12643-
void setDisplayListProperties() {
12644-
setDisplayListProperties(mDisplayList);
12645-
}
12646-
1264712650
/**
1264812651
* This method is called by getDisplayList() when a display list is created or re-rendered.
1264912652
* It sets or resets the current value of all properties on that display list (resetting is

core/java/android/view/ViewRootImpl.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4412,14 +4412,23 @@ public void dispatchInvalidateRectOnAnimation(AttachInfo.InvalidateInfo info) {
44124412
mInvalidateOnAnimationRunnable.addViewRect(info);
44134413
}
44144414

4415-
public void invalidateDisplayList(DisplayList displayList) {
4415+
public void enqueueDisplayList(DisplayList displayList) {
44164416
mDisplayLists.add(displayList);
44174417

44184418
mHandler.removeMessages(MSG_INVALIDATE_DISPLAY_LIST);
44194419
Message msg = mHandler.obtainMessage(MSG_INVALIDATE_DISPLAY_LIST);
44204420
mHandler.sendMessage(msg);
44214421
}
4422-
4422+
4423+
public void dequeueDisplayList(DisplayList displayList) {
4424+
if (mDisplayLists.remove(displayList)) {
4425+
displayList.invalidate();
4426+
if (mDisplayLists.size() == 0) {
4427+
mHandler.removeMessages(MSG_INVALIDATE_DISPLAY_LIST);
4428+
}
4429+
}
4430+
}
4431+
44234432
public void cancelInvalidate(View view) {
44244433
mHandler.removeMessages(MSG_INVALIDATE, view);
44254434
// fixme: might leak the AttachInfo.InvalidateInfo objects instead of returning

0 commit comments

Comments
 (0)