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

Commit ecd114ee authored by Vishnu Nair's avatar Vishnu Nair Committed by Automerger Merge Worker
Browse files

Merge "WM: Handle primary display orientation when calculating the transform...

Merge "WM: Handle primary display orientation when calculating the transform hint" into sc-v2-dev am: e84c7c63 am: 5619ebfa

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15838995

Change-Id: I54e16ca4058f3f90bf6e73a10ce8e6fd57e9d733
parents fbc8d1f8 5619ebfa
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -160,6 +160,7 @@ public final class SurfaceControl implements Parcelable {
    private static native boolean nativeGetAnimationFrameStats(WindowAnimationFrameStats outStats);

    private static native long[] nativeGetPhysicalDisplayIds();
    private static native long nativeGetPrimaryPhysicalDisplayId();
    private static native IBinder nativeGetPhysicalDisplayToken(long physicalDisplayId);
    private static native IBinder nativeCreateDisplay(String name, boolean secure);
    private static native void nativeDestroyDisplay(IBinder displayToken);
@@ -2274,6 +2275,15 @@ public final class SurfaceControl implements Parcelable {
        return nativeGetPhysicalDisplayIds();
    }

    /**
     * Exposed to identify the correct display to apply the primary display orientation. Avoid using
     * for any other purpose.
     * @hide
     */
    public static long getPrimaryPhysicalDisplayId() {
        return nativeGetPrimaryPhysicalDisplayId();
    }

    /**
     * @hide
     */
+8 −0
Original line number Diff line number Diff line
@@ -898,6 +898,12 @@ static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) {
    return array;
}

static jlong nativeGetPrimaryPhysicalDisplayId(JNIEnv* env, jclass clazz) {
    PhysicalDisplayId displayId;
    SurfaceComposerClient::getPrimaryPhysicalDisplayId(&displayId);
    return static_cast<jlong>(displayId.value);
}

static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong physicalDisplayId) {
    const auto id = DisplayId::fromValue<PhysicalDisplayId>(physicalDisplayId);
    if (!id) return nullptr;
@@ -1906,6 +1912,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeReleaseFrameRateFlexibilityToken },
    {"nativeGetPhysicalDisplayIds", "()[J",
            (void*)nativeGetPhysicalDisplayIds },
    {"nativeGetPrimaryPhysicalDisplayId", "()J",
            (void*)nativeGetPrimaryPhysicalDisplayId },
    {"nativeGetPhysicalDisplayToken", "(J)Landroid/os/IBinder;",
            (void*)nativeGetPhysicalDisplayToken },
    {"nativeCreateDisplay", "(Ljava/lang/String;Z)Landroid/os/IBinder;",
+6 −6
Original line number Diff line number Diff line
@@ -103,12 +103,6 @@
      "group": "WM_DEBUG_STATES",
      "at": "com\/android\/server\/wm\/TaskFragment.java"
    },
    "-2006946193": {
      "message": "setClientVisible: %s clientVisible=%b Callers=%s",
      "level": "VERBOSE",
      "group": "WM_DEBUG_APP_TRANSITIONS",
      "at": "com\/android\/server\/wm\/ActivityRecord.java"
    },
    "-2002500255": {
      "message": "Defer removing snapshot surface in %dms",
      "level": "VERBOSE",
@@ -511,6 +505,12 @@
      "group": "WM_DEBUG_STATES",
      "at": "com\/android\/server\/wm\/ActivityRecord.java"
    },
    "-1556507536": {
      "message": "Passing transform hint %d for window %s%s",
      "level": "VERBOSE",
      "group": "WM_DEBUG_ORIENTATION",
      "at": "com\/android\/server\/wm\/WindowManagerService.java"
    },
    "-1554521902": {
      "message": "showInsets(ime) was requested by different window: %s ",
      "level": "WARN",
+1 −1
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ java_library_static {
        "android.hardware.biometrics.fingerprint-V2.3-java",
        "android.hardware.biometrics.fingerprint-V1-java",
        "android.hardware.oemlock-V1.0-java",
        "android.hardware.configstore-V1.0-java",
        "android.hardware.configstore-V1.1-java",
        "android.hardware.contexthub-V1.0-java",
        "android.hardware.rebootescrow-V1-java",
        "android.hardware.soundtrigger-V2.3-java",
+60 −11
Original line number Diff line number Diff line
@@ -173,8 +173,10 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.hardware.configstore.V1_0.ISurfaceFlingerConfigs;
import android.hardware.configstore.V1_0.OptionalBool;
import android.hardware.configstore.V1_1.DisplayOrientation;
import android.hardware.configstore.V1_1.ISurfaceFlingerConfigs;
import android.hardware.configstore.V1_1.OptionalDisplayOrientation;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManagerInternal;
import android.hardware.input.InputManager;
@@ -227,6 +229,7 @@ import android.util.TypedValue;
import android.util.proto.ProtoOutputStream;
import android.view.Choreographer;
import android.view.Display;
import android.view.DisplayAddress;
import android.view.DisplayInfo;
import android.view.Gravity;
import android.view.IAppTransitionAnimationSpecsFuture;
@@ -451,6 +454,8 @@ public class WindowManagerService extends IWindowManager.Stub
     */
    static final boolean ENABLE_FIXED_ROTATION_TRANSFORM =
            SystemProperties.getBoolean("persist.wm.fixed_rotation_transform", true);
    private @Surface.Rotation int mPrimaryDisplayOrientation = Surface.ROTATION_0;
    private DisplayAddress mPrimaryDisplayPhysicalAddress;

    // Enums for animation scale update types.
    @Retention(RetentionPolicy.SOURCE)
@@ -2461,16 +2466,21 @@ public class WindowManagerService extends IWindowManager.Stub
            configChanged = displayContent.updateOrientation();
            Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);

            final DisplayInfo rotatedDisplayInfo =
                    win.mToken.getFixedRotationTransformDisplayInfo();
            if (rotatedDisplayInfo != null) {
                outSurfaceControl.setTransformHint(rotatedDisplayInfo.rotation);
            } else {
                // We have to update the transform hint of display here, but we need to get if from
                // SurfaceFlinger, so set it as rotation of display for most cases, then
                // SurfaceFlinger would still update the transform hint of display in next frame.
                outSurfaceControl.setTransformHint(displayContent.getDisplayInfo().rotation);
            }
            final DisplayInfo displayInfo = win.getDisplayInfo();
            int transformHint = displayInfo.rotation;
            // If the window is on the primary display, use the panel orientation to adjust the
            // transform hint
            final boolean isPrimaryDisplay = displayInfo.address != null &&
                    displayInfo.address.equals(mPrimaryDisplayPhysicalAddress);
            if (isPrimaryDisplay) {
                transformHint = (transformHint + mPrimaryDisplayOrientation) % 4;
            }
            outSurfaceControl.setTransformHint(transformHint);
            ProtoLog.v(WM_DEBUG_ORIENTATION,
                    "Passing transform hint %d for window %s%s",
                    transformHint, win,
                    isPrimaryDisplay ? " on primary display with orientation "
                            + mPrimaryDisplayOrientation : "");

            if (toBeDisplayed && win.mIsWallpaper) {
                displayContent.mWallpaperController.updateWallpaperOffset(win, false /* sync */);
@@ -4876,6 +4886,9 @@ public class WindowManagerService extends IWindowManager.Stub
        mTaskSnapshotController.systemReady();
        mHasWideColorGamutSupport = queryWideColorGamutSupport();
        mHasHdrSupport = queryHdrSupport();
        mPrimaryDisplayOrientation = queryPrimaryDisplayOrientation();
        mPrimaryDisplayPhysicalAddress =
            DisplayAddress.fromPhysicalDisplayId(SurfaceControl.getPrimaryPhysicalDisplayId());
        UiThread.getHandler().post(mSettingsObserver::loadSettings);
        IVrManager vrManager = IVrManager.Stub.asInterface(
                ServiceManager.getService(Context.VR_SERVICE));
@@ -4895,6 +4908,9 @@ public class WindowManagerService extends IWindowManager.Stub
        }
    }


    // Keep logic in sync with SurfaceFlingerProperties.cpp
    // Consider exposing properties via ISurfaceComposer instead.
    private static boolean queryWideColorGamutSupport() {
        boolean defaultValue = false;
        Optional<Boolean> hasWideColorProp = SurfaceFlingerProperties.has_wide_color_display();
@@ -4935,6 +4951,39 @@ public class WindowManagerService extends IWindowManager.Stub
        return false;
    }

    private static @Surface.Rotation int queryPrimaryDisplayOrientation() {
        Optional<SurfaceFlingerProperties.primary_display_orientation_values> prop =
                SurfaceFlingerProperties.primary_display_orientation();
        if (prop.isPresent()) {
            switch (prop.get()) {
                case ORIENTATION_90: return Surface.ROTATION_90;
                case ORIENTATION_180: return Surface.ROTATION_180;
                case ORIENTATION_270: return Surface.ROTATION_270;
                case ORIENTATION_0:
                default:
                    return Surface.ROTATION_0;
            }
        }
        try {
            ISurfaceFlingerConfigs surfaceFlinger = ISurfaceFlingerConfigs.getService();
            OptionalDisplayOrientation primaryDisplayOrientation =
                    surfaceFlinger.primaryDisplayOrientation();
            if (primaryDisplayOrientation != null && primaryDisplayOrientation.specified) {
                switch (primaryDisplayOrientation.value) {
                    case DisplayOrientation.ORIENTATION_90: return Surface.ROTATION_90;
                    case DisplayOrientation.ORIENTATION_180: return Surface.ROTATION_180;
                    case DisplayOrientation.ORIENTATION_270: return Surface.ROTATION_270;
                    case DisplayOrientation.ORIENTATION_0:
                    default:
                        return Surface.ROTATION_0;
                }
            }
        } catch (Exception e) {
            // Use default value if we can't talk to config store.
        }
        return Surface.ROTATION_0;
    }

    void reportFocusChanged(IBinder oldToken, IBinder newToken) {
        WindowState lastFocus;
        WindowState newFocus;