Merge "Pipe display install orientation 2/2"

This commit is contained in:
Tiger Huang 2022-01-22 08:01:00 +00:00 committed by Android (Google) Code Review
commit c5ee8aa405
8 changed files with 45 additions and 64 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

@ -493,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",
@ -817,6 +811,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",

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

@ -177,9 +177,7 @@ import android.graphics.PointF;
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;
@ -231,7 +229,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;
@ -442,8 +439,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)
@ -2444,21 +2439,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 */);
@ -4927,9 +4913,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));
@ -4992,39 +4975,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) {