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

Commit f4cc9595 authored by Vishnu Nair's avatar Vishnu Nair
Browse files

SurfaceControl: Query native object for transform hint

When a new SurfaceControl was created, the java object's transform
hint was not updated. This created a mismatch between the java and
native objects resulting in the client getting an incorrect transform
hint. Fix this by making the native object the source of truth for
transform hints.

Test: in landscape mode, dismiss apps and check launcher does not reject buffers
Bug: 191841127

Change-Id: Icc87b8cf8158eedb87eea886392a0460a76c6443
parent 35929095
Loading
Loading
Loading
Loading
+4 −8
Original line number Diff line number Diff line
@@ -234,6 +234,7 @@ public final class SurfaceControl implements Parcelable {
    private static native long nativeCreateJankDataListenerWrapper(OnJankDataListener listener);
    private static native int nativeGetGPUContextPriority();
    private static native void nativeSetTransformHint(long nativeObject, int transformHint);
    private static native int nativeGetTransformHint(long nativeObject);

    @Nullable
    @GuardedBy("mLock")
@@ -608,7 +609,6 @@ public final class SurfaceControl implements Parcelable {
        mName = other.mName;
        mWidth = other.mWidth;
        mHeight = other.mHeight;
        mTransformHint = other.mTransformHint;
        mLocalOwnerView = other.mLocalOwnerView;
        assignNativeObject(nativeCopyFromSurfaceControl(other.mNativeObject), callsite);
    }
@@ -1471,7 +1471,6 @@ public final class SurfaceControl implements Parcelable {
        mName = in.readString8();
        mWidth = in.readInt();
        mHeight = in.readInt();
        mTransformHint = in.readInt();

        long object = 0;
        if (in.readInt() != 0) {
@@ -1490,7 +1489,6 @@ public final class SurfaceControl implements Parcelable {
        dest.writeString8(mName);
        dest.writeInt(mWidth);
        dest.writeInt(mHeight);
        dest.writeInt(mTransformHint);
        if (mNativeObject == 0) {
            dest.writeInt(0);
        } else {
@@ -3603,7 +3601,8 @@ public final class SurfaceControl implements Parcelable {
     * @hide
     */
    public int getTransformHint() {
        return mTransformHint;
        checkNotReleased();
        return nativeGetTransformHint(mNativeObject);
    }

    /**
@@ -3616,9 +3615,6 @@ public final class SurfaceControl implements Parcelable {
     * @hide
     */
    public void setTransformHint(@Surface.Rotation int transformHint) {
        if (mTransformHint != transformHint) {
            mTransformHint = transformHint;
        nativeSetTransformHint(mNativeObject, transformHint);
    }
}
}
+10 −0
Original line number Diff line number Diff line
@@ -1785,6 +1785,14 @@ static void nativeSetTransformHint(JNIEnv* env, jclass clazz, jlong nativeSurfac
            ui::Transform::toRotationFlags(static_cast<ui::Rotation>(transformHint)));
}

static jint nativeGetTransformHint(JNIEnv* env, jclass clazz, jlong nativeSurfaceControl) {
    sp<SurfaceControl> surface(reinterpret_cast<SurfaceControl*>(nativeSurfaceControl));
    ui::Transform::RotationFlags transformHintRotationFlags =
            static_cast<ui::Transform::RotationFlags>(surface->getTransformHint());

    return toRotationInt(ui::Transform::toRotation((transformHintRotationFlags)));
}

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

static const JNINativeMethod sSurfaceControlMethods[] = {
@@ -1974,6 +1982,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeGetGPUContextPriority },
    {"nativeSetTransformHint", "(JI)V",
            (void*)nativeSetTransformHint },
    {"nativeGetTransformHint", "(J)I",
            (void*)nativeGetTransformHint },
        // clang-format on
};