What part of the graphics chain rotates computer displays when in portrait mode? When the display hardware is physically rotated 90 degrees, your graphics can still be rendered with the correct side up. Where is this rotation accomplished?
I can imagine a few possibilities:

A) The code for every low-level graphics primitive contains something to converts its arguments, like

if (portrait) {
   swap(x,y);
}


(or perhaps multiplying every coordinate with a matrix)

B) The part of the graphics card that continuously scans its memory to create a video signal reads the data in a different order.

C) The monitor paints the received data column by column instead of row by row

A and B sounds like they would be inefficient and C means that it would only work on monitors that has special hardware-support for rotation.
Which one is it?
On typical GPUs today it's option B: monitor rotation is done by the video output hardware ("display engine") during scan-out. In addition to rotating/flipping, the display engine can also scale the image within certain limits, do simple color/gamma correction, and even composite multiple image layers ("planes") together, all dynamically during scan-out.