Merge "[Magnifier-38] Avoid deadlock causing ANR" into pi-dev
am: 285797a45a
Change-Id: I81474f04a8d33d2cf063aa0d89b7abca255d3864
This commit is contained in:
@@ -393,6 +393,12 @@ public final class Magnifier {
|
|||||||
private int mWindowPositionY;
|
private int mWindowPositionY;
|
||||||
private boolean mPendingWindowPositionUpdate;
|
private boolean mPendingWindowPositionUpdate;
|
||||||
|
|
||||||
|
// The lock used to synchronize the UI and render threads when a #destroy
|
||||||
|
// is performed on the UI thread and a frame callback on the render thread.
|
||||||
|
// When both mLock and mDestroyLock need to be held at the same time,
|
||||||
|
// mDestroyLock should be acquired before mLock in order to avoid deadlocks.
|
||||||
|
private final Object mDestroyLock = new Object();
|
||||||
|
|
||||||
InternalPopupWindow(final Context context, final Display display,
|
InternalPopupWindow(final Context context, final Display display,
|
||||||
final Surface parentSurface,
|
final Surface parentSurface,
|
||||||
final int width, final int height, final float elevation, final float cornerRadius,
|
final int width, final int height, final float elevation, final float cornerRadius,
|
||||||
@@ -517,9 +523,11 @@ public final class Magnifier {
|
|||||||
* Destroys this instance.
|
* Destroys this instance.
|
||||||
*/
|
*/
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
|
synchronized (mDestroyLock) {
|
||||||
|
mSurface.destroy();
|
||||||
|
}
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
mRenderer.destroy();
|
mRenderer.destroy();
|
||||||
mSurface.destroy();
|
|
||||||
mSurfaceControl.destroy();
|
mSurfaceControl.destroy();
|
||||||
mSurfaceSession.kill();
|
mSurfaceSession.kill();
|
||||||
mBitmapRenderNode.destroy();
|
mBitmapRenderNode.destroy();
|
||||||
@@ -567,10 +575,11 @@ public final class Magnifier {
|
|||||||
final int pendingY = mWindowPositionY;
|
final int pendingY = mWindowPositionY;
|
||||||
|
|
||||||
callback = frame -> {
|
callback = frame -> {
|
||||||
synchronized (mLock) {
|
synchronized (mDestroyLock) {
|
||||||
if (!mSurface.isValid()) {
|
if (!mSurface.isValid()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
synchronized (mLock) {
|
||||||
mRenderer.setLightCenter(mDisplay, pendingX, pendingY);
|
mRenderer.setLightCenter(mDisplay, pendingX, pendingY);
|
||||||
// Show or move the window at the content draw frame.
|
// Show or move the window at the content draw frame.
|
||||||
SurfaceControl.openTransaction();
|
SurfaceControl.openTransaction();
|
||||||
@@ -583,6 +592,7 @@ public final class Magnifier {
|
|||||||
}
|
}
|
||||||
SurfaceControl.closeTransaction();
|
SurfaceControl.closeTransaction();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
callback = null;
|
callback = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user