Merge "WM: Handle primary display orientation when calculating the transform hint" am: 5fb9f63795 am: b83ee72e64

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

Change-Id: I4a99911c7dbe8f69e35dd107e0d15b09f657bec0
This commit is contained in:
Vishnu Nair
2021-11-11 19:13:36 +00:00
committed by Automerger Merge Worker
5 changed files with 84 additions and 11 deletions

View File

@@ -157,6 +157,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);
@@ -2265,6 +2266,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
*/

View File

@@ -889,6 +889,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) {
sp<IBinder> token =
SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId(physicalDisplayId));
@@ -1879,6 +1885,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;",

View File

@@ -499,6 +499,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",

View File

@@ -151,7 +151,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",

View File

@@ -168,8 +168,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;
@@ -221,6 +223,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;
@@ -466,6 +469,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)
@@ -2462,16 +2467,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;