Merge "Force disconnect when the surface is about to be saved." into nyc-dev

This commit is contained in:
Chong Zhang
2016-03-02 20:10:09 +00:00
committed by Android (Google) Code Review
4 changed files with 39 additions and 0 deletions

View File

@@ -36,6 +36,7 @@ public class SurfaceControl {
throws OutOfResourcesException;
private static native void nativeRelease(long nativeObject);
private static native void nativeDestroy(long nativeObject);
private static native void nativeDisconnect(long nativeObject);
private static native Bitmap nativeScreenshot(IBinder displayToken,
Rect sourceCrop, int width, int height, int minLayer, int maxLayer,
@@ -341,6 +342,15 @@ public class SurfaceControl {
mCloseGuard.close();
}
/**
* Disconnect any client still connected to the surface.
*/
public void disconnect() {
if (mNativeObject != 0) {
nativeDisconnect(mNativeObject);
}
}
private void checkNotReleased() {
if (mNativeObject == 0) throw new NullPointerException(
"mNativeObject is null. Have you called release() already?");

View File

@@ -110,6 +110,13 @@ static void nativeDestroy(JNIEnv* env, jclass clazz, jlong nativeObject) {
ctrl->decStrong((void *)nativeCreate);
}
static void nativeDisconnect(JNIEnv* env, jclass clazz, jlong nativeObject) {
SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
if (ctrl != NULL) {
ctrl->disconnect();
}
}
static jobject nativeScreenshotBitmap(JNIEnv* env, jclass clazz,
jobject displayTokenObj, jobject sourceCropObj, jint width, jint height,
jint minLayer, jint maxLayer, bool allLayers, bool useIdentityTransform,
@@ -595,6 +602,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
(void*)nativeRelease },
{"nativeDestroy", "(J)V",
(void*)nativeDestroy },
{"nativeDisconnect", "(J)V",
(void*)nativeDisconnect },
{"nativeScreenshot", "(Landroid/os/IBinder;Landroid/graphics/Rect;IIIIZZI)Landroid/graphics/Bitmap;",
(void*)nativeScreenshotBitmap },
{"nativeScreenshot", "(Landroid/os/IBinder;Landroid/view/Surface;Landroid/graphics/Rect;IIIIZZ)V",

View File

@@ -1902,6 +1902,12 @@ final class WindowState implements WindowManagerPolicy.WindowState {
mWinAnimator.hide("saved surface");
mWinAnimator.mDrawState = WindowStateAnimator.NO_SURFACE;
setHasSurface(false);
// The client should have disconnected at this point, but if it doesn't,
// we need to make sure it's disconnected. Otherwise when we reuse the surface
// the client can't reconnect to the buffer queue, and rendering will fail.
if (mWinAnimator.mSurfaceController != null) {
mWinAnimator.mSurfaceController.disconnectInTransaction();
}
} else {
mWinAnimator.destroySurfaceLocked();
}

View File

@@ -152,6 +152,20 @@ class WindowSurfaceController {
}
}
void disconnectInTransaction() {
if (SHOW_TRANSACTIONS || SHOW_SURFACE_ALLOC) {
Slog.i(TAG, "Disconnecting client: " + this);
}
try {
if (mSurfaceControl != null) {
mSurfaceControl.disconnect();
}
} catch (RuntimeException e) {
Slog.w(TAG, "Error disconnecting surface in: " + this, e);
}
}
void setCropInTransaction(Rect clipRect, boolean recoveringMemory) {
if (SHOW_TRANSACTIONS) logSurface(
"CROP " + clipRect.toShortString(), null);