Pipe display install orientation 2/2

This is a step to move the layout logic to the client side. We won't
invoke IWindowSession#relayout then, and the client should be able to
set the transform hint on its own.

Bug: 161810301
Test: presubmit
Change-Id: Ib12a76fcc9906b3d9c487fb89bbe4520c682379a
This commit is contained in:
Vishnu Nair
2022-01-13 10:49:16 -08:00
committed by Tiger Huang
parent e5ee7c8473
commit 80d665bbbc
8 changed files with 45 additions and 94 deletions

View File

@@ -318,6 +318,12 @@ public final class DisplayInfo implements Parcelable {
@Nullable
public RoundedCorners roundedCorners;
/**
* Install orientation of the display relative to its natural orientation.
*/
@Surface.Rotation
public int installOrientation;
public static final @android.annotation.NonNull Creator<DisplayInfo> CREATOR = new Creator<DisplayInfo>() {
@Override
public DisplayInfo createFromParcel(Parcel source) {
@@ -389,7 +395,8 @@ public final class DisplayInfo implements Parcelable {
&& brightnessMaximum == other.brightnessMaximum
&& brightnessDefault == other.brightnessDefault
&& Objects.equals(roundedCorners, other.roundedCorners)
&& shouldConstrainMetricsForLauncher == other.shouldConstrainMetricsForLauncher;
&& shouldConstrainMetricsForLauncher == other.shouldConstrainMetricsForLauncher
&& installOrientation == other.installOrientation;
}
@Override
@@ -441,6 +448,7 @@ public final class DisplayInfo implements Parcelable {
brightnessDefault = other.brightnessDefault;
roundedCorners = other.roundedCorners;
shouldConstrainMetricsForLauncher = other.shouldConstrainMetricsForLauncher;
installOrientation = other.installOrientation;
}
public void readFromParcel(Parcel source) {
@@ -498,6 +506,7 @@ public final class DisplayInfo implements Parcelable {
userDisabledHdrTypes[i] = source.readInt();
}
shouldConstrainMetricsForLauncher = source.readBoolean();
installOrientation = source.readInt();
}
@Override
@@ -553,6 +562,7 @@ public final class DisplayInfo implements Parcelable {
dest.writeInt(userDisabledHdrTypes[i]);
}
dest.writeBoolean(shouldConstrainMetricsForLauncher);
dest.writeInt(installOrientation);
}
@Override
@@ -809,6 +819,8 @@ public final class DisplayInfo implements Parcelable {
sb.append(brightnessDefault);
sb.append(", shouldConstrainMetricsForLauncher ");
sb.append(shouldConstrainMetricsForLauncher);
sb.append(", installOrientation ");
sb.append(Surface.rotationToString(installOrientation));
sb.append("}");
return sb.toString();
}

View File

@@ -1831,13 +1831,15 @@ public final class SurfaceControl implements Parcelable {
public float density;
public boolean secure;
public DeviceProductInfo deviceProductInfo;
public @Surface.Rotation int installOrientation;
@Override
public String toString() {
return "StaticDisplayInfo{isInternal=" + isInternal
+ ", density=" + density
+ ", secure=" + secure
+ ", deviceProductInfo=" + deviceProductInfo + "}";
+ ", deviceProductInfo=" + deviceProductInfo
+ ", installOrientation=" + installOrientation + "}";
}
@Override
@@ -1848,12 +1850,13 @@ public final class SurfaceControl implements Parcelable {
return isInternal == that.isInternal
&& density == that.density
&& secure == that.secure
&& Objects.equals(deviceProductInfo, that.deviceProductInfo);
&& Objects.equals(deviceProductInfo, that.deviceProductInfo)
&& installOrientation == that.installOrientation;
}
@Override
public int hashCode() {
return Objects.hash(isInternal, density, secure, deviceProductInfo);
return Objects.hash(isInternal, density, secure, deviceProductInfo, installOrientation);
}
}

View File

@@ -91,6 +91,7 @@ static struct {
jfieldID density;
jfieldID secure;
jfieldID deviceProductInfo;
jfieldID installOrientation;
} gStaticDisplayInfoClassInfo;
static struct {
@@ -1210,6 +1211,8 @@ static jobject nativeGetStaticDisplayInfo(JNIEnv* env, jclass clazz, jobject tok
env->SetBooleanField(object, gStaticDisplayInfoClassInfo.secure, info.secure);
env->SetObjectField(object, gStaticDisplayInfoClassInfo.deviceProductInfo,
convertDeviceProductInfoToJavaObject(env, info.deviceProductInfo));
env->SetIntField(object, gStaticDisplayInfoClassInfo.installOrientation,
static_cast<uint32_t>(info.installOrientation));
return object;
}
@@ -2152,6 +2155,8 @@ int register_android_view_SurfaceControl(JNIEnv* env)
gStaticDisplayInfoClassInfo.deviceProductInfo =
GetFieldIDOrDie(env, infoClazz, "deviceProductInfo",
"Landroid/hardware/display/DeviceProductInfo;");
gStaticDisplayInfoClassInfo.installOrientation =
GetFieldIDOrDie(env, infoClazz, "installOrientation", "I");
jclass dynamicInfoClazz = FindClassOrDie(env, "android/view/SurfaceControl$DynamicDisplayInfo");
gDynamicDisplayInfoClassInfo.clazz = MakeGlobalRefOrDie(env, dynamicInfoClazz);

View File

@@ -103,18 +103,6 @@
"group": "WM_DEBUG_STATES",
"at": "com\/android\/server\/wm\/TaskFragment.java"
},
"-2002500255": {
"message": "Defer removing snapshot surface in %dms",
"level": "VERBOSE",
"group": "WM_DEBUG_STARTING_WINDOW",
"at": "com\/android\/server\/wm\/TaskSnapshotSurface.java"
},
"-1991255017": {
"message": "Drawing snapshot surface sizeMismatch=%b",
"level": "VERBOSE",
"group": "WM_DEBUG_STARTING_WINDOW",
"at": "com\/android\/server\/wm\/TaskSnapshotSurface.java"
},
"-1980468143": {
"message": "DisplayArea appeared name=%s",
"level": "VERBOSE",
@@ -505,12 +493,6 @@
"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",
@@ -823,6 +805,12 @@
"group": "WM_DEBUG_REMOTE_ANIMATIONS",
"at": "com\/android\/server\/wm\/RemoteAnimationController.java"
},
"-1248290210": {
"message": "Passing transform hint %d for window %s",
"level": "VERBOSE",
"group": "WM_DEBUG_ORIENTATION",
"at": "com\/android\/server\/wm\/WindowManagerService.java"
},
"-1228653755": {
"message": "Launch on display check: displayId=%d callingPid=%d callingUid=%d",
"level": "DEBUG",
@@ -1597,12 +1585,6 @@
"group": "WM_DEBUG_FOCUS_LIGHT",
"at": "com\/android\/server\/wm\/DisplayContent.java"
},
"-405536909": {
"message": "Removing snapshot surface",
"level": "VERBOSE",
"group": "WM_DEBUG_STARTING_WINDOW",
"at": "com\/android\/server\/wm\/TaskSnapshotSurface.java"
},
"-401282500": {
"message": "destroyIfPossible: r=%s destroy returned removed=%s",
"level": "DEBUG",
@@ -2005,12 +1987,6 @@
"group": "WM_ERROR",
"at": "com\/android\/server\/wm\/WindowManagerService.java"
},
"44438983": {
"message": "performLayout: Activity exiting now removed %s",
"level": "VERBOSE",
"group": "WM_DEBUG_ADD_REMOVE",
"at": "com\/android\/server\/wm\/DisplayContent.java"
},
"45285419": {
"message": "startingWindow was set but startingSurface==null, couldn't remove",
"level": "VERBOSE",
@@ -3271,12 +3247,6 @@
"group": "WM_DEBUG_LAYER_MIRRORING",
"at": "com\/android\/server\/wm\/DisplayContent.java"
},
"1417601133": {
"message": "Enqueueing ADD_STARTING",
"level": "VERBOSE",
"group": "WM_DEBUG_STARTING_WINDOW",
"at": "com\/android\/server\/wm\/ActivityRecord.java"
},
"1422781269": {
"message": "Resuming rotation after re-position",
"level": "DEBUG",

View File

@@ -358,6 +358,12 @@ final class DisplayDeviceInfo {
public float brightnessMaximum;
public float brightnessDefault;
/**
* Install orientation of display panel relative to its natural orientation.
*/
@Surface.Rotation
public int installOrientation = Surface.ROTATION_0;
public void setAssumedDensityForExternalDisplay(int width, int height) {
densityDpi = Math.min(width, height) * DisplayMetrics.DENSITY_XHIGH / 1080;
// Technically, these values should be smaller than the apparent density
@@ -417,7 +423,8 @@ final class DisplayDeviceInfo {
|| !BrightnessSynchronizer.floatEquals(brightnessMaximum, other.brightnessMaximum)
|| !BrightnessSynchronizer.floatEquals(brightnessDefault,
other.brightnessDefault)
|| !Objects.equals(roundedCorners, other.roundedCorners)) {
|| !Objects.equals(roundedCorners, other.roundedCorners)
|| installOrientation != other.installOrientation) {
diff |= DIFF_OTHER;
}
return diff;
@@ -461,6 +468,7 @@ final class DisplayDeviceInfo {
brightnessMaximum = other.brightnessMaximum;
brightnessDefault = other.brightnessDefault;
roundedCorners = other.roundedCorners;
installOrientation = other.installOrientation;
}
// For debugging purposes
@@ -508,6 +516,7 @@ final class DisplayDeviceInfo {
sb.append(", roundedCorners ").append(roundedCorners);
}
sb.append(flagsToString(flags));
sb.append(", installOrientation ").append(installOrientation);
sb.append("}");
return sb.toString();
}

View File

@@ -641,6 +641,7 @@ final class LocalDisplayAdapter extends DisplayAdapter {
mInfo.roundedCorners = RoundedCorners.fromResources(
res, mInfo.uniqueId, mInfo.width, mInfo.height);
mInfo.installOrientation = mStaticDisplayInfo.installOrientation;
if (mStaticDisplayInfo.isInternal) {
mInfo.type = Display.TYPE_INTERNAL;

View File

@@ -429,6 +429,7 @@ final class LogicalDisplay {
mBaseDisplayInfo.brightnessMaximum = deviceInfo.brightnessMaximum;
mBaseDisplayInfo.brightnessDefault = deviceInfo.brightnessDefault;
mBaseDisplayInfo.roundedCorners = deviceInfo.roundedCorners;
mBaseDisplayInfo.installOrientation = deviceInfo.installOrientation;
mPrimaryDisplayDeviceInfo = deviceInfo;
mInfo.set(null);
}

View File

@@ -175,9 +175,7 @@ import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Region;
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;
@@ -229,7 +227,6 @@ 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;
@@ -438,8 +435,6 @@ 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)
@@ -2436,21 +2431,12 @@ public class WindowManagerService extends IWindowManager.Stub
Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
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;
}
final int transformHint = (displayInfo.rotation + displayInfo.installOrientation) % 4;
outSurfaceControl.setTransformHint(
SurfaceControl.rotationToBufferTransform(transformHint));
ProtoLog.v(WM_DEBUG_ORIENTATION,
"Passing transform hint %d for window %s%s",
transformHint, win,
isPrimaryDisplay ? " on primary display with orientation "
+ mPrimaryDisplayOrientation : "");
"Passing transform hint %d for window %s",
transformHint, win);
if (toBeDisplayed && win.mIsWallpaper) {
displayContent.mWallpaperController.updateWallpaperOffset(win, false /* sync */);
@@ -4885,9 +4871,6 @@ 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));
@@ -4950,39 +4933,6 @@ 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;
}
// Returns an input target which is mapped to the given input token. This can be a WindowState
// or an embedded window.
@Nullable InputTarget getInputTargetFromToken(IBinder inputToken) {