Merge "Allow VR Virtual display to rotate with content." into oc-dr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
9747b4ace5
@@ -256,6 +256,15 @@ public final class DisplayManager {
|
||||
*/
|
||||
public static final int VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH = 1 << 6;
|
||||
|
||||
/**
|
||||
* Virtual display flag: Indicates that the orientation of this display device is coupled to
|
||||
* the rotation of its associated logical display.
|
||||
*
|
||||
* @see #createVirtualDisplay
|
||||
* @hide
|
||||
*/
|
||||
public static final int VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT = 1 << 7;
|
||||
|
||||
/** @hide */
|
||||
public DisplayManager(Context context) {
|
||||
mContext = context;
|
||||
|
||||
@@ -1221,6 +1221,18 @@ public final class DisplayManagerService extends SystemService {
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
DisplayDeviceInfo getDisplayDeviceInfoInternal(int displayId) {
|
||||
synchronized (mSyncRoot) {
|
||||
LogicalDisplay display = mLogicalDisplays.get(displayId);
|
||||
if (display != null) {
|
||||
DisplayDevice displayDevice = display.getPrimaryDisplayDeviceLocked();
|
||||
return displayDevice.getDisplayDeviceInfoLocked();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private final class DisplayManagerHandler extends Handler {
|
||||
public DisplayManagerHandler(Looper looper) {
|
||||
super(looper, null, true /*async*/);
|
||||
|
||||
@@ -23,6 +23,7 @@ import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PRESE
|
||||
import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC;
|
||||
import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_SECURE;
|
||||
import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH;
|
||||
import static android.hardware.display.DisplayManager.VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.display.IVirtualDisplayCallback;
|
||||
@@ -359,6 +360,10 @@ public class VirtualDisplayAdapter extends DisplayAdapter {
|
||||
if ((mFlags & VIRTUAL_DISPLAY_FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD) != 0) {
|
||||
mInfo.flags |= DisplayDeviceInfo.FLAG_CAN_SHOW_WITH_INSECURE_KEYGUARD;
|
||||
}
|
||||
if ((mFlags & VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT) != 0) {
|
||||
mInfo.flags |= DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT;
|
||||
}
|
||||
|
||||
mInfo.type = Display.TYPE_VIRTUAL;
|
||||
mInfo.touch = ((mFlags & VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH) == 0) ?
|
||||
DisplayDeviceInfo.TOUCH_NONE : DisplayDeviceInfo.TOUCH_VIRTUAL;
|
||||
|
||||
@@ -266,6 +266,7 @@ class Vr2dDisplay {
|
||||
}
|
||||
|
||||
int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_SUPPORTS_TOUCH;
|
||||
flags |= DisplayManager.VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT;
|
||||
mVirtualDisplay = mDisplayManager.createVirtualDisplay(null /* projection */,
|
||||
DISPLAY_NAME, mVirtualDisplayWidth, mVirtualDisplayHeight, mVirtualDisplayDpi,
|
||||
null /* surface */, flags, null /* callback */, null /* handler */,
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.view.SurfaceControl;
|
||||
import android.view.WindowManagerInternal;
|
||||
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.display.DisplayDeviceInfo;
|
||||
import com.android.server.display.DisplayManagerService.SyncRoot;
|
||||
import com.android.server.display.VirtualDisplayAdapter.SurfaceControlDisplayFactory;
|
||||
|
||||
@@ -115,4 +116,30 @@ public class DisplayManagerServiceTest extends AndroidTestCase {
|
||||
assertEquals(uniqueIdPrefix + uniqueId, dv.uniqueId);
|
||||
assertEquals(displayId, dv.displayId);
|
||||
}
|
||||
|
||||
public void testCreateVirtualDisplayRotatesWithContent() throws Exception {
|
||||
// This is effectively the DisplayManager service published to ServiceManager.
|
||||
DisplayManagerService.BinderService bs = mDisplayManager.new BinderService();
|
||||
|
||||
String uniqueId = "uniqueId --- Rotates With Content Test";
|
||||
int width = 600;
|
||||
int height = 800;
|
||||
int dpi = 320;
|
||||
int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_ROTATES_WITH_CONTENT;
|
||||
|
||||
when(mMockAppToken.asBinder()).thenReturn(mMockAppToken);
|
||||
int displayId = bs.createVirtualDisplay(mMockAppToken /* callback */,
|
||||
null /* projection */, "com.android.frameworks.servicestests",
|
||||
"Test Virtual Display", width, height, dpi, null /* surface */, flags /* flags */,
|
||||
uniqueId);
|
||||
|
||||
mDisplayManager.performTraversalInTransactionFromWindowManagerInternal();
|
||||
|
||||
// flush the handler
|
||||
mHandler.runWithScissors(() -> {}, 0 /* now */);
|
||||
|
||||
DisplayDeviceInfo ddi = mDisplayManager.getDisplayDeviceInfoInternal(displayId);
|
||||
assertNotNull(ddi);
|
||||
assertTrue((ddi.flags & DisplayDeviceInfo.FLAG_ROTATES_WITH_CONTENT) != 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user