qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>, Anthony Liguori <aliguori@amazon.com>
Subject: [Qemu-devel] [PATCH 2/8] ui: Add dpy_gfx_check_format() to check backend shared surface support
Date: Fri,  9 Jan 2015 10:28:31 +0100	[thread overview]
Message-ID: <1420795717-28966-3-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1420795717-28966-1-git-send-email-kraxel@redhat.com>

From: Benjamin Herrenschmidt <benh@kernel.crashing.org>

This allows VGA to decide whether to use a shared surface based on
whether the UI backend supports the format or not. Backends that
don't provide the new callback fallback to native 32 bpp which
is equivalent to what was supported before.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

[ kraxel: fix console check, allow only 32 bpp as fallback ]

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/display/vga.c     | 18 ++++++++++++++----
 include/ui/console.h |  4 ++++
 ui/console.c         | 25 +++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/hw/display/vga.c b/hw/display/vga.c
index a620c07..ffcfce3 100644
--- a/hw/display/vga.c
+++ b/hw/display/vga.c
@@ -1437,6 +1437,7 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)
     uint32_t v, addr1, addr;
     vga_draw_line_func *vga_draw_line = NULL;
     bool share_surface;
+    pixman_format_code_t format;
 #ifdef HOST_WORDS_BIGENDIAN
     bool byteswap = !s->big_endian_fb;
 #else
@@ -1481,8 +1482,19 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)
 
     depth = s->get_bpp(s);
 
-    share_surface = (!s->force_shadow) &&
-            ( depth == 32 || (depth == 16 && !byteswap) );
+    /*
+     * Check whether we can share the surface with the backend
+     * or whether we need a shadow surface. We share native
+     * endian surfaces for 15bpp and above and byteswapped
+     * surfaces for 24bpp and above.
+     */
+    format = qemu_default_pixman_format(depth, !byteswap);
+    if (format) {
+        share_surface = dpy_gfx_check_format(s->con, format)
+            && !s->force_shadow;
+    } else {
+        share_surface = false;
+    }
     if (s->line_offset != s->last_line_offset ||
         disp_width != s->last_width ||
         height != s->last_height ||
@@ -1490,8 +1502,6 @@ static void vga_draw_graphic(VGACommonState *s, int full_update)
         s->last_byteswap != byteswap ||
         share_surface != is_buffer_shared(surface)) {
         if (share_surface) {
-            pixman_format_code_t format =
-                qemu_default_pixman_format(depth, !byteswap);
             surface = qemu_create_displaysurface_from(disp_width,
                     height, format, s->line_offset,
                     s->vram_ptr + (s->start_addr * 4));
diff --git a/include/ui/console.h b/include/ui/console.h
index 22ef8ca..047b6da 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -161,6 +161,8 @@ typedef struct DisplayChangeListenerOps {
     void (*dpy_gfx_copy)(DisplayChangeListener *dcl,
                          int src_x, int src_y,
                          int dst_x, int dst_y, int w, int h);
+    bool (*dpy_gfx_check_format)(DisplayChangeListener *dcl,
+                                 pixman_format_code_t format);
 
     void (*dpy_text_cursor)(DisplayChangeListener *dcl,
                             int x, int y);
@@ -235,6 +237,8 @@ void dpy_gfx_update_dirty(QemuConsole *con,
                           MemoryRegion *address_space,
                           uint64_t base,
                           bool invalidate);
+bool dpy_gfx_check_format(QemuConsole *con,
+                          pixman_format_code_t format);
 
 static inline int surface_stride(DisplaySurface *s)
 {
diff --git a/ui/console.c b/ui/console.c
index 258af5d..87574a7 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1439,6 +1439,31 @@ void dpy_gfx_replace_surface(QemuConsole *con,
     qemu_free_displaysurface(old_surface);
 }
 
+bool dpy_gfx_check_format(QemuConsole *con,
+                          pixman_format_code_t format)
+{
+    DisplayChangeListener *dcl;
+    DisplayState *s = con->ds;
+
+    QLIST_FOREACH(dcl, &s->listeners, next) {
+        if (dcl->con && dcl->con != con) {
+            /* dcl bound to another console -> skip */
+            continue;
+        }
+        if (dcl->ops->dpy_gfx_check_format) {
+            if (!dcl->ops->dpy_gfx_check_format(dcl, format)) {
+                return false;
+            }
+        } else {
+            /* default is to whitelist native 32 bpp only */
+            if (format != qemu_default_pixman_format(32, true)) {
+                return false;
+            }
+        }
+    }
+    return true;
+}
+
 static void dpy_refresh(DisplayState *s)
 {
     DisplayChangeListener *dcl;
-- 
1.8.3.1

  parent reply	other threads:[~2015-01-09  9:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-09  9:28 [Qemu-devel] [PATCH 0/8] ui/console: add format negotiation for shared surfaces Gerd Hoffmann
2015-01-09  9:28 ` [Qemu-devel] [PATCH 1/8] ui: Make qemu_default_pixman_format() return 0 on unsupported formats Gerd Hoffmann
2015-01-09  9:28 ` Gerd Hoffmann [this message]
2015-01-09  9:28 ` [Qemu-devel] [PATCH 3/8] ui/pixman: add qemu_pixman_check_format Gerd Hoffmann
2015-01-09  9:28 ` [Qemu-devel] [PATCH 4/8] ui/vnc: Support shared surface for most pixman formats Gerd Hoffmann
2015-01-09  9:28 ` [Qemu-devel] [PATCH 5/8] ui/spice: " Gerd Hoffmann
2015-01-09  9:28 ` [Qemu-devel] [PATCH 6/8] ui/gtk: " Gerd Hoffmann
2015-01-09  9:28 ` [Qemu-devel] [PATCH 7/8] ui/sdl: Support shared surface for more " Gerd Hoffmann
2015-01-09  9:28 ` [Qemu-devel] [PATCH 8/8] ui/sdl2: " Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1420795717-28966-3-git-send-email-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=aliguori@amazon.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).