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

Commit 93de746e authored by Jeff Brown's avatar Jeff Brown
Browse files

Separate the internal and external display rotations.

When attached to an HDMI touch screen, the input system needs
to know the size and rotation of the external display independent
of the internal display.  The size was already being reported
separately but not the rotation.  The inconsistency can cause problems
if the internal display's natural rotation is portrait but
the external display's natural rotation is landscape.

Change-Id: Id344f04c1ba032625f6265766be66f9ddaa2cc0b
parent 39f412d8
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -390,6 +390,15 @@ public class Display {
        return 720;
    }

    /**
     * If the display is mirrored to an external HDMI display, returns the
     * rotation of that display relative to its natural orientation.
     * @hide
     */
    public int getExternalRotation() {
        return Surface.ROTATION_0;
    }

    /**
     * Gets display metrics based on an explicit assumed display size.
     * @hide
+6 −4
Original line number Diff line number Diff line
@@ -140,7 +140,8 @@ public class InputManagerService extends IInputManager.Stub implements Watchdog.
    private static native void nativeStart(int ptr);
    private static native void nativeSetDisplaySize(int ptr, int displayId,
            int width, int height, int externalWidth, int externalHeight);
    private static native void nativeSetDisplayOrientation(int ptr, int displayId, int rotation);
    private static native void nativeSetDisplayOrientation(int ptr, int displayId,
            int rotation, int externalRotation);
    
    private static native int nativeGetScanCodeState(int ptr,
            int deviceId, int sourceMask, int scanCode);
@@ -287,15 +288,16 @@ public class InputManagerService extends IInputManager.Stub implements Watchdog.
        nativeSetDisplaySize(mPtr, displayId, width, height, externalWidth, externalHeight);
    }
    
    public void setDisplayOrientation(int displayId, int rotation) {
    public void setDisplayOrientation(int displayId, int rotation, int externalRotation) {
        if (rotation < Surface.ROTATION_0 || rotation > Surface.ROTATION_270) {
            throw new IllegalArgumentException("Invalid rotation.");
        }
        
        if (DEBUG) {
            Slog.d(TAG, "Setting display #" + displayId + " orientation to " + rotation);
            Slog.d(TAG, "Setting display #" + displayId + " orientation to rotation " + rotation
                    + " external rotation " + externalRotation);
        }
        nativeSetDisplayOrientation(mPtr, displayId, rotation);
        nativeSetDisplayOrientation(mPtr, displayId, rotation, externalRotation);
    }

    /**
+4 −1
Original line number Diff line number Diff line
@@ -5569,7 +5569,8 @@ public class WindowManagerService extends IWindowManager.Stub
        mWaitingForConfig = true;
        mLayoutNeeded = true;
        startFreezingDisplayLocked(inTransaction);
        mInputManager.setDisplayOrientation(0, rotation);
        mInputManager.setDisplayOrientation(0, rotation,
                mDisplay != null ? mDisplay.getExternalRotation() : Surface.ROTATION_0);

        // We need to update our screen size information to match the new
        // rotation.  Note that this is redundant with the later call to
@@ -6595,6 +6596,8 @@ public class WindowManagerService extends IWindowManager.Stub
            mInputManager.setDisplaySize(Display.DEFAULT_DISPLAY,
                    mDisplay.getRawWidth(), mDisplay.getRawHeight(),
                    mDisplay.getRawExternalWidth(), mDisplay.getRawExternalHeight());
            mInputManager.setDisplayOrientation(Display.DEFAULT_DISPLAY,
                    mDisplay.getRotation(), mDisplay.getExternalRotation());
            mPolicy.setInitialDisplaySize(mDisplay, mInitialDisplayWidth, mInitialDisplayHeight);
        }

+16 −8
Original line number Diff line number Diff line
@@ -166,7 +166,7 @@ public:

    void setDisplaySize(int32_t displayId, int32_t width, int32_t height,
            int32_t externalWidth, int32_t externalHeight);
    void setDisplayOrientation(int32_t displayId, int32_t orientation);
    void setDisplayOrientation(int32_t displayId, int32_t orientation, int32_t externalOrientation);

    status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
            const sp<InputWindowHandle>& inputWindowHandle, bool monitor);
@@ -224,8 +224,9 @@ private:
    struct Locked {
        // Display size information.
        int32_t displayWidth, displayHeight; // -1 when not initialized
        int32_t displayExternalWidth, displayExternalHeight; // -1 when not initialized
        int32_t displayOrientation;
        int32_t displayExternalWidth, displayExternalHeight; // -1 when not initialized
        int32_t displayExternalOrientation;

        // System UI visibility.
        int32_t systemUiVisibility;
@@ -275,9 +276,10 @@ NativeInputManager::NativeInputManager(jobject contextObj,
        AutoMutex _l(mLock);
        mLocked.displayWidth = -1;
        mLocked.displayHeight = -1;
        mLocked.displayOrientation = DISPLAY_ORIENTATION_0;
        mLocked.displayExternalWidth = -1;
        mLocked.displayExternalHeight = -1;
        mLocked.displayOrientation = DISPLAY_ORIENTATION_0;
        mLocked.displayExternalOrientation = DISPLAY_ORIENTATION_0;

        mLocked.systemUiVisibility = ASYSTEM_UI_VISIBILITY_STATUS_BAR_VISIBLE;
        mLocked.pointerSpeed = 0;
@@ -345,7 +347,8 @@ void NativeInputManager::setDisplaySize(int32_t displayId, int32_t width, int32_
    }
}

void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orientation) {
void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orientation,
        int32_t externalOrientation) {
    bool changed = false;
    if (displayId == 0) {
        AutoMutex _l(mLock);
@@ -359,6 +362,11 @@ void NativeInputManager::setDisplayOrientation(int32_t displayId, int32_t orient
                controller->setDisplayOrientation(orientation);
            }
        }

        if (mLocked.displayExternalOrientation != externalOrientation) {
            changed = true;
            mLocked.displayExternalOrientation = externalOrientation;
        }
    }

    if (changed) {
@@ -444,7 +452,7 @@ void NativeInputManager::getReaderConfiguration(InputReaderConfiguration* outCon
                mLocked.displayWidth, mLocked.displayHeight, mLocked.displayOrientation);
        outConfig->setDisplayInfo(0, true /*external*/,
                mLocked.displayExternalWidth, mLocked.displayExternalHeight,
                mLocked.displayOrientation);
                mLocked.displayExternalOrientation);
    } // release lock
}

@@ -1041,10 +1049,10 @@ static void nativeSetDisplaySize(JNIEnv* env, jclass clazz, jint ptr,
}

static void nativeSetDisplayOrientation(JNIEnv* env, jclass clazz,
        jint ptr, jint displayId, jint orientation) {
        jint ptr, jint displayId, jint orientation, jint externalOrientation) {
    NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);

    im->setDisplayOrientation(displayId, orientation);
    im->setDisplayOrientation(displayId, orientation, externalOrientation);
}

static jint nativeGetScanCodeState(JNIEnv* env, jclass clazz,
@@ -1327,7 +1335,7 @@ static JNINativeMethod gInputManagerMethods[] = {
            (void*) nativeStart },
    { "nativeSetDisplaySize", "(IIIIII)V",
            (void*) nativeSetDisplaySize },
    { "nativeSetDisplayOrientation", "(III)V",
    { "nativeSetDisplayOrientation", "(IIII)V",
            (void*) nativeSetDisplayOrientation },
    { "nativeGetScanCodeState", "(IIII)I",
            (void*) nativeGetScanCodeState },