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

Commit beb7a0cf authored by chaviw's avatar chaviw Committed by Robert Carr
Browse files

Allow SurfaceControl to be passed over AIDL.

Test: Manual
Bug: 62536731
Bug: 111373437
Bug: 111297488
Change-Id: I52d9d314f1997560bc5498a1501827868db8b807
parent c54ffd28
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ public class SurfaceControl implements Parcelable {
            int w, int h, int format, int flags, long parentObject, int windowType, int ownerUid)
            throws OutOfResourcesException;
    private static native long nativeReadFromParcel(Parcel in);
    private static native long nativeCopyFromSurfaceControl(long nativeObject);
    private static native void nativeWriteToParcel(long nativeObject, Parcel out);
    private static native void nativeRelease(long nativeObject);
    private static native void nativeDestroy(long nativeObject);
@@ -168,7 +169,7 @@ public class SurfaceControl implements Parcelable {


    private final CloseGuard mCloseGuard = CloseGuard.get();
    private final String mName;
    private String mName;
    long mNativeObject; // package visibility only for Surface.java access

    // TODO: Move this to native.
@@ -358,6 +359,13 @@ public class SurfaceControl implements Parcelable {
     */
    public static final int WINDOW_TYPE_DONT_SCREENSHOT = 441731;

    public void copyFrom(SurfaceControl other) {
        mName = other.mName;
        mWidth = other.mWidth;
        mHeight = other.mHeight;
        mNativeObject = nativeCopyFromSurfaceControl(other.mNativeObject);
    }

    /**
     * Builder class for {@link SurfaceControl} objects.
     */
@@ -659,14 +667,23 @@ public class SurfaceControl implements Parcelable {
    }

    private SurfaceControl(Parcel in) {
        readFromParcel(in);
        mCloseGuard.open("release");
    }

    public SurfaceControl() {
        mCloseGuard.open("release");
    }

    public void readFromParcel(Parcel in) {
        if (in == null) {
            throw new IllegalArgumentException("source must not be null");
        }

        mName = in.readString();
        mWidth = in.readInt();
        mHeight = in.readInt();
        mNativeObject = nativeReadFromParcel(in);
        if (mNativeObject == 0) {
            throw new IllegalArgumentException("Couldn't read SurfaceControl from parcel=" + in);
        }
        mCloseGuard.open("release");
    }

    @Override
+14 −1
Original line number Diff line number Diff line
@@ -907,6 +907,15 @@ static jlong nativeReadFromParcel(JNIEnv* env, jclass clazz, jobject parcelObj)
    return reinterpret_cast<jlong>(surface.get());
}

static jlong nativeCopyFromSurfaceControl(JNIEnv* env, jclass clazz, jlong surfaceControlNativeObj) {
    sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl *>(surfaceControlNativeObj));
    if (surface == nullptr) {
        return 0;
    }
    surface->incStrong((void *)nativeCreate);
    return reinterpret_cast<jlong>(surface.get());
}

static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
        jlong nativeObject, jobject parcelObj) {
    Parcel* parcel = parcelForJavaObject(env, parcelObj);
@@ -915,8 +924,10 @@ static void nativeWriteToParcel(JNIEnv* env, jclass clazz,
        return;
    }
    SurfaceControl* const self = reinterpret_cast<SurfaceControl *>(nativeObject);
    if (self != nullptr) {
        self->writeToParcel(parcel);
    }
}

// ----------------------------------------------------------------------------

@@ -925,6 +936,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeCreate },
    {"nativeReadFromParcel", "(Landroid/os/Parcel;)J",
            (void*)nativeReadFromParcel },
    {"nativeCopyFromSurfaceControl", "(J)J" ,
            (void*)nativeCopyFromSurfaceControl },
    {"nativeWriteToParcel", "(JLandroid/os/Parcel;)V",
            (void*)nativeWriteToParcel },
    {"nativeRelease", "(J)V",