diff options
| -rw-r--r-- | core/java/android/view/Surface.java | 28 | ||||
| -rw-r--r-- | core/jni/android_view_Surface.cpp | 7 | ||||
| -rw-r--r-- | services/java/com/android/server/power/ElectronBeam.java | 3 |
3 files changed, 18 insertions, 20 deletions
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java index 9955bc1..0492d29 100644 --- a/core/java/android/view/Surface.java +++ b/core/java/android/view/Surface.java @@ -39,7 +39,6 @@ public class Surface implements Parcelable { private native void nativeUnlockCanvasAndPost(int nativeObject, Canvas canvas); private static native void nativeRelease(int nativeObject); - private static native void nativeDestroy(int nativeObject); private static native boolean nativeIsValid(int nativeObject); private static native boolean nativeIsConsumerRunningBehind(int nativeObject); private static native int nativeCopyFrom(int nativeObject, int surfaceControlNativeObject); @@ -106,7 +105,6 @@ public class Surface implements Parcelable { * @hide */ public Surface() { - mCloseGuard.open("release"); } /** @@ -135,6 +133,7 @@ public class Surface implements Parcelable { mCloseGuard.open("release"); } + /* called from android_view_Surface_createFromIGraphicBufferProducer() */ private Surface(int nativeObject) { mNativeObject = nativeObject; mCloseGuard.open("release"); @@ -146,9 +145,7 @@ public class Surface implements Parcelable { if (mCloseGuard != null) { mCloseGuard.warnIfOpen(); } - if (mNativeObject != 0) { - nativeRelease(mNativeObject); - } + release(); } finally { super.finalize(); } @@ -175,12 +172,7 @@ public class Surface implements Parcelable { * @hide */ public void destroy() { - if (mNativeObject != 0) { - nativeDestroy(mNativeObject); - mNativeObject = 0; - mGenerationId++; - } - mCloseGuard.close(); + release(); } /** @@ -287,6 +279,10 @@ public class Surface implements Parcelable { "SurfaceControl native object is null. Are you using a released SurfaceControl?"); } mNativeObject = nativeCopyFrom(mNativeObject, other.mNativeObject); + if (mNativeObject == 0) { + // nativeCopyFrom released our reference + mCloseGuard.close(); + } mGenerationId++; } @@ -308,11 +304,15 @@ public class Surface implements Parcelable { nativeRelease(mNativeObject); } // transfer the reference from other to us + if (other.mNativeObject != 0 && mNativeObject == 0) { + mCloseGuard.open("release"); + } mNativeObject = other.mNativeObject; mGenerationId++; other.mNativeObject = 0; other.mGenerationId++; + other.mCloseGuard.close(); } } @@ -326,7 +326,11 @@ public class Surface implements Parcelable { throw new IllegalArgumentException("source must not be null"); } mName = source.readString(); - mNativeObject = nativeReadFromParcel(mNativeObject, source); + int nativeObject = nativeReadFromParcel(mNativeObject, source); + if (nativeObject !=0 && mNativeObject == 0) { + mCloseGuard.open("release"); + } + mNativeObject = nativeObject; mGenerationId++; } diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp index 41146bf..4671282 100644 --- a/core/jni/android_view_Surface.cpp +++ b/core/jni/android_view_Surface.cpp @@ -151,11 +151,6 @@ static void nativeRelease(JNIEnv* env, jclass clazz, jint nativeObject) { sur->decStrong(&sRefBaseOwner); } -static void nativeDestroy(JNIEnv* env, jclass clazz, jint nativeObject) { - sp<Surface> sur(reinterpret_cast<Surface *>(nativeObject)); - sur->decStrong(&sRefBaseOwner); -} - static jboolean nativeIsValid(JNIEnv* env, jclass clazz, jint nativeObject) { sp<Surface> sur(reinterpret_cast<Surface *>(nativeObject)); return isSurfaceValid(sur) ? JNI_TRUE : JNI_FALSE; @@ -379,8 +374,6 @@ static JNINativeMethod gSurfaceMethods[] = { (void*)nativeCreateFromSurfaceTexture }, {"nativeRelease", "(I)V", (void*)nativeRelease }, - {"nativeDestroy", "(I)V", - (void*)nativeDestroy }, {"nativeIsValid", "(I)Z", (void*)nativeIsValid }, {"nativeIsConsumerRunningBehind", "(I)Z", diff --git a/services/java/com/android/server/power/ElectronBeam.java b/services/java/com/android/server/power/ElectronBeam.java index 457e92d..4a74149 100644 --- a/services/java/com/android/server/power/ElectronBeam.java +++ b/services/java/com/android/server/power/ElectronBeam.java @@ -82,7 +82,7 @@ final class ElectronBeam { private int mDisplayHeight; // real height, not rotated private SurfaceSession mSurfaceSession; private SurfaceControl mSurfaceControl; - private final Surface mSurface = new Surface(); + private Surface mSurface; private NaturalSurfaceLayout mSurfaceLayout; private EGLDisplay mEglDisplay; private EGLConfig mEglConfig; @@ -519,6 +519,7 @@ final class ElectronBeam { mSurfaceControl.setLayerStack(mDisplayLayerStack); mSurfaceControl.setSize(mDisplayWidth, mDisplayHeight); + mSurface = new Surface(); mSurface.copyFrom(mSurfaceControl); mSurfaceLayout = new NaturalSurfaceLayout(mDisplayManager, mSurfaceControl); |
