diff mbox

[v3,1/2] pxa2xx_lcd: add proper rotation support

Message ID 1307115397-6496-1-git-send-email-anarsoul@gmail.com
State New
Headers show

Commit Message

Vasily Khoruzhick June 3, 2011, 3:36 p.m. UTC
Until now, pxa2xx_lcd only supported 90deg rotation, but
some machines (for example Zipit Z2) needs 270deg rotation.

Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
---
v2: codestyle fixes
v3: fix dpy_update calls for 180 and 360 deg. rotation.

 hw/framebuffer.c |    2 +
 hw/pxa2xx_lcd.c  |  101 ++++++++++++++++++++++++++++++++++++++++++++++++------
 input.c          |   34 +++++++++++++-----
 qemu-options.hx  |    9 +++++
 vl.c             |   11 +++++-
 5 files changed, 136 insertions(+), 21 deletions(-)

Comments

Vasily Khoruzhick June 3, 2011, 3:38 p.m. UTC | #1
On Friday 03 June 2011 18:36:36 Vasily Khoruzhick wrote:
> Until now, pxa2xx_lcd only supported 90deg rotation, but
> some machines (for example Zipit Z2) needs 270deg rotation.
> 
> Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
> ---
> v2: codestyle fixes
> v3: fix dpy_update calls for 180 and 360 deg. rotation.

s/360/270
Vasily Khoruzhick June 8, 2011, 8:52 a.m. UTC | #2
On Friday 03 June 2011 18:36:36 Vasily Khoruzhick wrote:
> Until now, pxa2xx_lcd only supported 90deg rotation, but
> some machines (for example Zipit Z2) needs 270deg rotation.
> 
> Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>

Ping
Peter Maydell June 8, 2011, 9:50 a.m. UTC | #3
On 3 June 2011 16:36, Vasily Khoruzhick <anarsoul@gmail.com> wrote:
> Until now, pxa2xx_lcd only supported 90deg rotation, but
> some machines (for example Zipit Z2) needs 270deg rotation.
>
> Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>

Still haven't tested this yet, but some very quick first
pass comments.


> +static void pxa2xx_lcdc_dma0_redraw_rot180(PXA2xxLCDState *s,
> +                target_phys_addr_t addr, int *miny, int *maxy)
> +{
> +    int src_width, dest_width;
> +    drawfn fn = NULL;
> +    if (s->dest_width)
> +        fn = s->line_fn[s->transp][s->bpp];
> +    if (!fn)
> +        return;

Braces (here and elsewhere); if we're adding whole new functions
we might as well do them in accordance with the styl.

>             case QEMU_OPTION_portrait:
> -                graphic_rotate = 1;
> +                graphic_rotate = 90;
> +                break;
> +            case QEMU_OPTION_rotate:
> +                graphic_rotate = atoi(optarg);
> +                if (graphic_rotate != 0 && graphic_rotate != 90 &&
> +                    graphic_rotate != 180 && graphic_rotate != 270) {
> +                    fprintf(stderr,
> +                        "qemu: only 90, 180, 270 deg rotation is available\n");
> +                    exit(1);
> +                }

We seem to generally use strtol() for argument parsing rather
than atoi, might be nicer to be consistent.

The other bit of code that looks at graphic_rotate
is hw/spitz.c:spitz_keyboard_register(). Does that require
changes? It doesn't seem entirely right for us to assert
'tablet mode' for everything except 0deg rotation.

-- PMM
Vasily Khoruzhick June 8, 2011, 11:22 a.m. UTC | #4
On Wednesday 08 June 2011 12:50:50 Peter Maydell wrote:
> On 3 June 2011 16:36, Vasily Khoruzhick <anarsoul@gmail.com> wrote:
> > Until now, pxa2xx_lcd only supported 90deg rotation, but
> > some machines (for example Zipit Z2) needs 270deg rotation.
> > 
> > Signed-off-by: Vasily Khoruzhick <anarsoul@gmail.com>
> 
> Still haven't tested this yet, but some very quick first
> pass comments.
> 
> > +static void pxa2xx_lcdc_dma0_redraw_rot180(PXA2xxLCDState *s,
> > +                target_phys_addr_t addr, int *miny, int *maxy)
> > +{
> > +    int src_width, dest_width;
> > +    drawfn fn = NULL;
> > +    if (s->dest_width)
> > +        fn = s->line_fn[s->transp][s->bpp];
> > +    if (!fn)
> > +        return;
> 
> Braces (here and elsewhere); if we're adding whole new functions
> we might as well do them in accordance with the styl.

Oh, ok. I'll add patch to fix pxa2xx_lcd.c codestyle to the series, and then 
fix this patch.

> 
> >             case QEMU_OPTION_portrait:
> > -                graphic_rotate = 1;
> > +                graphic_rotate = 90;
> > +                break;
> > +            case QEMU_OPTION_rotate:
> > +                graphic_rotate = atoi(optarg);
> > +                if (graphic_rotate != 0 && graphic_rotate != 90 &&
> > +                    graphic_rotate != 180 && graphic_rotate != 270) {
> > +                    fprintf(stderr,
> > +                        "qemu: only 90, 180, 270 deg rotation is
> > available\n"); +                    exit(1);
> > +                }
> 
> We seem to generally use strtol() for argument parsing rather
> than atoi, might be nicer to be consistent.

Ok

> The other bit of code that looks at graphic_rotate
> is hw/spitz.c:spitz_keyboard_register(). Does that require
> changes? It doesn't seem entirely right for us to assert
> 'tablet mode' for everything except 0deg rotation.

Well, -portrait argument is preserved, so all old code should work fine 
(including scripts to start qemu). Passing -rotate 180 or -rotate 270 will 
produce unpredictable result (but not a crash). I have no spitz  image, so I 
can't test what happens.

Regards
Vasily
diff mbox

Patch

diff --git a/hw/framebuffer.c b/hw/framebuffer.c
index 24cdf25..5e9ab5e 100644
--- a/hw/framebuffer.c
+++ b/hw/framebuffer.c
@@ -78,6 +78,8 @@  void framebuffer_update_display(
     dest = ds_get_data(ds);
     if (dest_col_pitch < 0)
         dest -= dest_col_pitch * (cols - 1);
+    if (dest_row_pitch < 0)
+        dest -= dest_row_pitch * (rows - 1);
     first = -1;
     addr = pd;
 
diff --git a/hw/pxa2xx_lcd.c b/hw/pxa2xx_lcd.c
index e524802..3db900b 100644
--- a/hw/pxa2xx_lcd.c
+++ b/hw/pxa2xx_lcd.c
@@ -665,7 +665,7 @@  static void pxa2xx_palette_parse(PXA2xxLCDState *s, int ch, int bpp)
     }
 }
 
-static void pxa2xx_lcdc_dma0_redraw_horiz(PXA2xxLCDState *s,
+static void pxa2xx_lcdc_dma0_redraw_rot0(PXA2xxLCDState *s,
                 target_phys_addr_t addr, int *miny, int *maxy)
 {
     int src_width, dest_width;
@@ -692,7 +692,7 @@  static void pxa2xx_lcdc_dma0_redraw_horiz(PXA2xxLCDState *s,
                                fn, s->dma_ch[0].palette, miny, maxy);
 }
 
-static void pxa2xx_lcdc_dma0_redraw_vert(PXA2xxLCDState *s,
+static void pxa2xx_lcdc_dma0_redraw_rot90(PXA2xxLCDState *s,
                target_phys_addr_t addr, int *miny, int *maxy)
 {
     int src_width, dest_width;
@@ -720,6 +720,61 @@  static void pxa2xx_lcdc_dma0_redraw_vert(PXA2xxLCDState *s,
                                miny, maxy);
 }
 
+static void pxa2xx_lcdc_dma0_redraw_rot180(PXA2xxLCDState *s,
+                target_phys_addr_t addr, int *miny, int *maxy)
+{
+    int src_width, dest_width;
+    drawfn fn = NULL;
+    if (s->dest_width)
+        fn = s->line_fn[s->transp][s->bpp];
+    if (!fn)
+        return;
+
+    src_width = (s->xres + 3) & ~3;     /* Pad to a 4 pixels multiple */
+    if (s->bpp == pxa_lcdc_19pbpp || s->bpp == pxa_lcdc_18pbpp)
+        src_width *= 3;
+    else if (s->bpp > pxa_lcdc_16bpp)
+        src_width *= 4;
+    else if (s->bpp > pxa_lcdc_8bpp)
+        src_width *= 2;
+
+    dest_width = s->xres * s->dest_width;
+    *miny = 0;
+    framebuffer_update_display(s->ds,
+                               addr, s->xres, s->yres,
+                               src_width, -dest_width, -s->dest_width,
+                               s->invalidated,
+                               fn, s->dma_ch[0].palette, miny, maxy);
+}
+
+static void pxa2xx_lcdc_dma0_redraw_rot270(PXA2xxLCDState *s,
+               target_phys_addr_t addr, int *miny, int *maxy)
+{
+    int src_width, dest_width;
+    drawfn fn = NULL;
+    if (s->dest_width)
+        fn = s->line_fn[s->transp][s->bpp];
+    if (!fn)
+        return;
+
+    src_width = (s->xres + 3) & ~3;     /* Pad to a 4 pixels multiple */
+    if (s->bpp == pxa_lcdc_19pbpp || s->bpp == pxa_lcdc_18pbpp)
+        src_width *= 3;
+    else if (s->bpp > pxa_lcdc_16bpp)
+        src_width *= 4;
+    else if (s->bpp > pxa_lcdc_8bpp)
+        src_width *= 2;
+
+    dest_width = s->yres * s->dest_width;
+    *miny = 0;
+    framebuffer_update_display(s->ds,
+                               addr, s->xres, s->yres,
+                               src_width, -s->dest_width, dest_width,
+                               s->invalidated,
+                               fn, s->dma_ch[0].palette,
+                               miny, maxy);
+}
+
 static void pxa2xx_lcdc_resize(PXA2xxLCDState *s)
 {
     int width, height;
@@ -730,10 +785,11 @@  static void pxa2xx_lcdc_resize(PXA2xxLCDState *s)
     height = LCCR2_LPP(s->control[2]) + 1;
 
     if (width != s->xres || height != s->yres) {
-        if (s->orientation)
+        if (s->orientation == 90 || s->orientation == 270) {
             qemu_console_resize(s->ds, height, width);
-        else
+        } else {
             qemu_console_resize(s->ds, width, height);
+        }
         s->invalidated = 1;
         s->xres = width;
         s->yres = height;
@@ -797,10 +853,24 @@  static void pxa2xx_update_display(void *opaque)
     }
 
     if (miny >= 0) {
-        if (s->orientation)
-            dpy_update(s->ds, miny, 0, maxy - miny, s->xres);
-        else
+        switch (s->orientation) {
+        case 0:
             dpy_update(s->ds, 0, miny, s->xres, maxy - miny);
+            break;
+        case 90:
+            dpy_update(s->ds, miny, 0, maxy - miny, s->xres);
+            break;
+        case 180:
+            maxy = s->yres - maxy;
+            miny = s->yres - miny;
+            dpy_update(s->ds, 0, maxy, s->xres, miny - maxy);
+            break;
+        case 270:
+            maxy = s->yres - maxy;
+            miny = s->yres - miny;
+            dpy_update(s->ds, maxy, 0, miny - maxy, s->xres);
+            break;
+        }
     }
     pxa2xx_lcdc_int_update(s);
 
@@ -822,10 +892,19 @@  static void pxa2xx_lcdc_orientation(void *opaque, int angle)
 {
     PXA2xxLCDState *s = (PXA2xxLCDState *) opaque;
 
-    if (angle) {
-        s->dma_ch[0].redraw = pxa2xx_lcdc_dma0_redraw_vert;
-    } else {
-        s->dma_ch[0].redraw = pxa2xx_lcdc_dma0_redraw_horiz;
+    switch (angle) {
+    case 0:
+        s->dma_ch[0].redraw = pxa2xx_lcdc_dma0_redraw_rot0;
+        break;
+    case 90:
+        s->dma_ch[0].redraw = pxa2xx_lcdc_dma0_redraw_rot90;
+        break;
+    case 180:
+        s->dma_ch[0].redraw = pxa2xx_lcdc_dma0_redraw_rot180;
+        break;
+    case 270:
+        s->dma_ch[0].redraw = pxa2xx_lcdc_dma0_redraw_rot270;
+        break;
     }
 
     s->orientation = angle;
diff --git a/input.c b/input.c
index 5664d3a..f0a02e7 100644
--- a/input.c
+++ b/input.c
@@ -148,7 +148,7 @@  void kbd_mouse_event(int dx, int dy, int dz, int buttons_state)
     QEMUPutMouseEntry *entry;
     QEMUPutMouseEvent *mouse_event;
     void *mouse_event_opaque;
-    int width;
+    int width, height;
 
     if (QTAILQ_EMPTY(&mouse_handlers)) {
         return;
@@ -160,15 +160,31 @@  void kbd_mouse_event(int dx, int dy, int dz, int buttons_state)
     mouse_event_opaque = entry->qemu_put_mouse_event_opaque;
 
     if (mouse_event) {
-        if (graphic_rotate) {
-            if (entry->qemu_put_mouse_event_absolute) {
-                width = 0x7fff;
-            } else {
-                width = graphic_width - 1;
-            }
-            mouse_event(mouse_event_opaque, width - dy, dx, dz, buttons_state);
+        if (entry->qemu_put_mouse_event_absolute) {
+            width = 0x7fff;
+            height = 0x7fff;
         } else {
-            mouse_event(mouse_event_opaque, dx, dy, dz, buttons_state);
+            width = graphic_width - 1;
+            height = graphic_height - 1;
+        }
+
+        switch (graphic_rotate) {
+        case 0:
+            mouse_event(mouse_event_opaque,
+                        dx, dy, dz, buttons_state);
+            break;
+        case 90:
+            mouse_event(mouse_event_opaque,
+                        width - dy, dx, dz, buttons_state);
+            break;
+        case 180:
+            mouse_event(mouse_event_opaque,
+                        width - dx, height - dy, dz, buttons_state);
+            break;
+        case 270:
+            mouse_event(mouse_event_opaque,
+                        dy, height - dx, dz, buttons_state);
+            break;
         }
     }
 }
diff --git a/qemu-options.hx b/qemu-options.hx
index 82e085a..46d8f25 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -771,6 +771,15 @@  STEXI
 Rotate graphical output 90 deg left (only PXA LCD).
 ETEXI
 
+DEF("rotate", HAS_ARG, QEMU_OPTION_rotate,
+    "-rotate <deg>   rotate graphical output some deg left (only PXA LCD)\n",
+    QEMU_ARCH_ALL)
+STEXI
+@item -rotate
+@findex -rotate
+Rotate graphical output some deg left (only PXA LCD).
+ETEXI
+
 DEF("vga", HAS_ARG, QEMU_OPTION_vga,
     "-vga [std|cirrus|vmware|qxl|xenfb|none]\n"
     "                select video card type\n", QEMU_ARCH_ALL)
diff --git a/vl.c b/vl.c
index b362871..5074bfe 100644
--- a/vl.c
+++ b/vl.c
@@ -2289,7 +2289,16 @@  int main(int argc, char **argv, char **envp)
 #endif
                 break;
             case QEMU_OPTION_portrait:
-                graphic_rotate = 1;
+                graphic_rotate = 90;
+                break;
+            case QEMU_OPTION_rotate:
+                graphic_rotate = atoi(optarg);
+                if (graphic_rotate != 0 && graphic_rotate != 90 &&
+                    graphic_rotate != 180 && graphic_rotate != 270) {
+                    fprintf(stderr,
+                        "qemu: only 90, 180, 270 deg rotation is available\n");
+                    exit(1);
+                }
                 break;
             case QEMU_OPTION_kernel:
                 kernel_filename = optarg;