[3/4] bochs-display: add dirty tracking support

Message ID 20180517092513.735-4-kraxel@redhat.com
State New
Headers show
Series
  • Untitled series #44895
Related show

Commit Message

Gerd Hoffmann May 17, 2018, 9:25 a.m.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/display/bochs-display.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

Comments

Marc-André Lureau May 18, 2018, 3:10 p.m. | #1
Hi

On Thu, May 17, 2018 at 11:25 AM, Gerd Hoffmann <kraxel@redhat.com> wrote:
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
>  hw/display/bochs-display.c | 33 ++++++++++++++++++++++++++++++++-
>  1 file changed, 32 insertions(+), 1 deletion(-)
>
> diff --git a/hw/display/bochs-display.c b/hw/display/bochs-display.c
> index beeda58475..9ea6f798f4 100644
> --- a/hw/display/bochs-display.c
> +++ b/hw/display/bochs-display.c
> @@ -192,9 +192,13 @@ nofb:
>  static void bochs_display_update(void *opaque)
>  {
>      BochsDisplayState *s = opaque;
> +    DirtyBitmapSnapshot *snap = NULL;
> +    bool full_update = false;
>      BochsDisplayMode mode;
>      DisplaySurface *ds;
>      uint8_t *ptr;
> +    bool dirty;
> +    int y, ys;
>
>      bochs_display_get_mode(s, &mode);
>      if (!mode.size) {
> @@ -212,9 +216,34 @@ static void bochs_display_update(void *opaque)
>                                               mode.stride,
>                                               ptr + mode.offset);
>          dpy_gfx_replace_surface(s->con, ds);
> +        full_update = true;
>      }
>
> -    dpy_gfx_update_full(s->con);
> +    if (full_update) {
> +        dpy_gfx_update_full(s->con);
> +    } else {
> +        snap = memory_region_snapshot_and_clear_dirty(&s->vram,
> +                                                      mode.offset, mode.size,
> +                                                      DIRTY_MEMORY_VGA);
> +        ys = -1;
> +        for (y = 0; y < mode.height; y++) {
> +            dirty = memory_region_snapshot_get_dirty(&s->vram, snap,
> +                                                     mode.offset + mode.stride * y,
> +                                                     mode.stride);
> +            if (dirty && ys < 0) {
> +                ys = y;
> +            }
> +            if (!dirty && ys >= 0) {
> +                dpy_gfx_update(s->con, 0, ys,
> +                               mode.width, y - ys);
> +                ys = -1;
> +            }
> +        }
> +        if (ys >= 0) {
> +            dpy_gfx_update(s->con, 0, ys,
> +                           mode.width, y - ys);
> +        }
> +    }
>  }
>
>  static const GraphicHwOps bochs_display_gfx_ops = {
> @@ -250,6 +279,8 @@ static void bochs_display_realize(PCIDevice *dev, Error **errp)
>      pci_set_byte(&s->pci.config[PCI_REVISION_ID], 2);
>      pci_register_bar(&s->pci, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->vram);
>      pci_register_bar(&s->pci, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mmio);
> +
> +    memory_region_set_log(&s->vram, true, DIRTY_MEMORY_VGA);
>  }
>
>  static bool bochs_display_get_big_endian_fb(Object *obj, Error **errp)
> --
> 2.9.3
>
>

Patch

diff --git a/hw/display/bochs-display.c b/hw/display/bochs-display.c
index beeda58475..9ea6f798f4 100644
--- a/hw/display/bochs-display.c
+++ b/hw/display/bochs-display.c
@@ -192,9 +192,13 @@  nofb:
 static void bochs_display_update(void *opaque)
 {
     BochsDisplayState *s = opaque;
+    DirtyBitmapSnapshot *snap = NULL;
+    bool full_update = false;
     BochsDisplayMode mode;
     DisplaySurface *ds;
     uint8_t *ptr;
+    bool dirty;
+    int y, ys;
 
     bochs_display_get_mode(s, &mode);
     if (!mode.size) {
@@ -212,9 +216,34 @@  static void bochs_display_update(void *opaque)
                                              mode.stride,
                                              ptr + mode.offset);
         dpy_gfx_replace_surface(s->con, ds);
+        full_update = true;
     }
 
-    dpy_gfx_update_full(s->con);
+    if (full_update) {
+        dpy_gfx_update_full(s->con);
+    } else {
+        snap = memory_region_snapshot_and_clear_dirty(&s->vram,
+                                                      mode.offset, mode.size,
+                                                      DIRTY_MEMORY_VGA);
+        ys = -1;
+        for (y = 0; y < mode.height; y++) {
+            dirty = memory_region_snapshot_get_dirty(&s->vram, snap,
+                                                     mode.offset + mode.stride * y,
+                                                     mode.stride);
+            if (dirty && ys < 0) {
+                ys = y;
+            }
+            if (!dirty && ys >= 0) {
+                dpy_gfx_update(s->con, 0, ys,
+                               mode.width, y - ys);
+                ys = -1;
+            }
+        }
+        if (ys >= 0) {
+            dpy_gfx_update(s->con, 0, ys,
+                           mode.width, y - ys);
+        }
+    }
 }
 
 static const GraphicHwOps bochs_display_gfx_ops = {
@@ -250,6 +279,8 @@  static void bochs_display_realize(PCIDevice *dev, Error **errp)
     pci_set_byte(&s->pci.config[PCI_REVISION_ID], 2);
     pci_register_bar(&s->pci, 0, PCI_BASE_ADDRESS_MEM_PREFETCH, &s->vram);
     pci_register_bar(&s->pci, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->mmio);
+
+    memory_region_set_log(&s->vram, true, DIRTY_MEMORY_VGA);
 }
 
 static bool bochs_display_get_big_endian_fb(Object *obj, Error **errp)