Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b1fa4f92 authored by Mathias Agopian's avatar Mathias Agopian Committed by Android (Google) Code Review
Browse files

Merge "fix CloseGuard usage in Surface" into jb-mr2-dev

parents 6d4dac74 86e1bc73
Loading
Loading
Loading
Loading
+16 −12
Original line number Diff line number Diff line
@@ -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++;
    }

+0 −7
Original line number Diff line number Diff line
@@ -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",
+2 −1
Original line number Diff line number Diff line
@@ -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);