Allow rotate into portrait mode but do not rotate external display To avoid this question being flagged as a duplicate, I have included a list of similar questions at the end of this post with an explanation about why my question is different.  Please read these reasons before you flag this question as a duplicate!



I'm trying to work out how to get my Nexus 5, in portrait mode, to display on an external monitor, in portrait mode (connected via SlimPort/HDMI).

In landscape mode everything is fine:



However in portrait mode, the signal is still output as if it is meant to be displayed on a landscape screen, which doesn't work at all if the screen is in portrait mode:



You can see here that in both landscape and portrait mode the phone is outputting the same 1920x1080 signal, except in portrait mode the screen content is being rotated by the phone's GPU and displayed as a 607x1080 image in the middle of the 1920x1080 screen.  (It is not, as some people have suggested, outputting a 1080x1920 signal that the monitor is centering.  You can verify this because changing the phone between landscape and portrait shows a nice rotation animation and the monitor does not lose sync as it would if the resolution changed.)

Since the phone, when in portrait mode, is rotating the picture sent to the external display, I want to disable this, so it is just output as-is with no rotation.  This will of course appear wrong on a landscape monitor, but when you rotate that monitor into portrait mode it will be fine:



Is there any way to disable this rotation, so that an external display in portrait mode can display the phone's content when it too is in portrait mode?



Similar questions have been asked before, but none are after the same solution:


35402 - Show Fullscreen Portrait Layout with Miracast is very similar, except the question is about using Miracast wireless display whereas this question is about wired displays, in this case via SlimPort.
37887 - HDMI output mirroring in Portrait mode is asking how to prevent apps from being forced into landscape mode when an external display is connected - my question is about apps that do not get forced into landscape mode
67648 - How to change Android default-natural orientation? asks how to change the default rotation of an app, it has nothing to do with the image sent to an external monitor
100196 - Is there are way to change Android's default screen orientation? asks how to make apps default to landscape, as the external screen is landscape (in my question the external screen is in portrait)
101305 - Force portrait mode on device is about forcing a specific app into portrait mode, and is not about adjusting the picture sent to an external display
Try these instructions, using a computer with adb installed and your phone connected:

Android Jelly Bean (4.2) locks HDMI rotation by default. You can unlock by the instruction of this commit.


  
  Add special mirroring modes for demonstration purposes.
  Assume rotation of HDMI display is portrait.

adb shell setprop persist.demo.hdmirotation portrait

  Don't lock rotation while HDMI is plugged in.  

adb shell setprop persist.demo.hdmirotationlock false

  Hide secondary displays from apps but continue mirroring to them.

adb shell setprop persist.demo.singledisplay true

  


Source: https://community.freescale.com/docs/DOC-97740