From nobody Sun Apr 28 14:19:41 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1512725688355995.0694415328716; Fri, 8 Dec 2017 01:34:48 -0800 (PST) Received: from localhost ([::1]:36215 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eNF3G-0004OS-4V for importer@patchew.org; Fri, 08 Dec 2017 04:34:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eNF1g-0003QL-Tn for qemu-devel@nongnu.org; Fri, 08 Dec 2017 04:33:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eNF1d-00042q-Ni for qemu-devel@nongnu.org; Fri, 08 Dec 2017 04:33:00 -0500 Received: from mga17.intel.com ([192.55.52.151]:9950) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eNF1d-00040t-E4 for qemu-devel@nongnu.org; Fri, 08 Dec 2017 04:32:57 -0500 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Dec 2017 01:32:55 -0800 Received: from tinazhang-linux-1.bj.intel.com ([10.238.158.67]) by orsmga002.jf.intel.com with ESMTP; 08 Dec 2017 01:32:53 -0800 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,377,1508828400"; d="scan'208";a="16521938" From: Tina Zhang To: qemu-devel@nongnu.org, kraxel@redhat.com Date: Fri, 8 Dec 2017 17:32:37 +0800 Message-Id: <1512725557-9729-1-git-send-email-tina.zhang@intel.com> X-Mailer: git-send-email 2.7.4 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.151 Subject: [Qemu-devel] [Rfc PATCH] ui: Enable SDL to use dma-buf for direct guest framebuffer rendering X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: zhenyuw@linux.intel.com, hang.yuan@intel.com, zhiyuan.lv@intel.com, Tina Zhang , intel-gvt-dev@lists.freedesktop.org, zhi.a.wang@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This RFC patch is based on Qemu UI on-going work of rendering guest framebuffer through dma-buf interface, to show a protype of SDL with dma-buf interface. Against branch: work/intel-vgpu Signed-off-by: Tina Zhang --- include/ui/sdl2.h | 11 ++++++++ ui/sdl2-gl.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++-----= ---- ui/sdl2.c | 6 ++-- 3 files changed, 86 insertions(+), 15 deletions(-) diff --git a/include/ui/sdl2.h b/include/ui/sdl2.h index 7811d33..e6e334c 100644 --- a/include/ui/sdl2.h +++ b/include/ui/sdl2.h @@ -29,6 +29,9 @@ struct sdl2_console { QemuGLShader *gls; egl_fb guest_fb; egl_fb win_fb; + egl_fb cursor_fb; + int cursor_x; + int cursor_y; bool y0_top; bool scanout_mode; #endif @@ -76,6 +79,14 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *dcl, uint32_t w, uint32_t h); void sdl2_gl_scanout_dmabuf(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf); +void sdl2_gl_cursor_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf); +void sdl2_gl_cursor_position(DisplayChangeListener *dcl, + bool have_hot, bool have_pos, + uint32_t hot_x, uint32_t hot_y, + uint32_t pos_x, uint32_t pos_y); +void sdl2_gl_release_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf); void sdl2_gl_scanout_flush(DisplayChangeListener *dcl, uint32_t x, uint32_t y, uint32_t w, uint32_t h); =20 diff --git a/ui/sdl2-gl.c b/ui/sdl2-gl.c index ab31c5a..dbe7435 100644 --- a/ui/sdl2-gl.c +++ b/ui/sdl2-gl.c @@ -72,9 +72,12 @@ void sdl2_gl_update(DisplayChangeListener *dcl, =20 assert(scon->opengl); =20 - SDL_GL_MakeCurrent(scon->real_window, scon->winctx); - surface_gl_update_texture(scon->gls, scon->surface, x, y, w, h); - scon->updates++; + if (!scon->scanout_mode) { + /* Fixme: unmarking these leads to flashing issue */ + //SDL_GL_MakeCurrent(scon->real_window, scon->winctx); + surface_gl_update_texture(scon->gls, scon->surface, x, y, w, h); + //scon->updates++; + } } =20 void sdl2_gl_switch(DisplayChangeListener *dcl, @@ -116,7 +119,7 @@ void sdl2_gl_refresh(DisplayChangeListener *dcl) assert(scon->opengl); =20 graphic_hw_update(dcl->con); - if (scon->updates && scon->surface) { + if (!scon->scanout_mode && scon->updates && scon->surface) { scon->updates =3D 0; sdl2_gl_render_surface(scon); } @@ -127,8 +130,12 @@ void sdl2_gl_redraw(struct sdl2_console *scon) { assert(scon->opengl); =20 - if (scon->surface) { - sdl2_gl_render_surface(scon); + if (scon->scanout_mode) { + sdl2_gl_scanout_flush(&scon->dcl, 0, 0 , 0, 0); + } else { + if (scon->surface) { + sdl2_gl_render_surface(scon); + } } } =20 @@ -208,22 +215,64 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *d= cl, SDL_GL_MakeCurrent(scon->real_window, scon->winctx); =20 sdl2_set_scanout_mode(scon, true); + egl_fb_setup_for_tex(&scon->guest_fb, backing_width, backing_height, backing_id, false); } =20 + void sdl2_gl_scanout_dmabuf(DisplayChangeListener *dcl, QemuDmaBuf *dmabuf) { - struct sdl2_console *scon =3D container_of(dcl, struct sdl2_console, d= cl); - int tex_id =3D 0; +#ifdef CONFIG_OPENGL_DMABUF + + egl_dmabuf_import_texture(dmabuf); =20 - /* TODO: import dmabuf */ + if (!dmabuf->texture) { + return; + } =20 - sdl2_gl_scanout_texture(dcl, tex_id, + sdl2_gl_scanout_texture(dcl, dmabuf->texture, false, dmabuf->width, dmabuf->height, 0, 0, dmabuf->width, dmabuf->height); - scon->guest_fb.delete_texture =3D true; +#endif =20 +} + +void sdl2_gl_cursor_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf) +{ +#ifdef CONFIG_OPENGL_DMABUF + struct sdl2_console *scon =3D container_of(dcl, struct sdl2_console, d= cl); + + egl_dmabuf_import_texture(dmabuf); + if (!dmabuf->texture) { + return; + } + + egl_fb_setup_for_tex(&scon->cursor_fb, dmabuf->width, dmabuf->height, + dmabuf->texture, false); +#endif +} + +void sdl2_gl_cursor_position(DisplayChangeListener *dcl, + bool have_hot, bool have_pos, + uint32_t hot_x, uint32_t hot_y, + uint32_t pos_x, uint32_t pos_y) +{ +#ifdef CONFIG_OPENGL_DMABUF + struct sdl2_console *scon =3D container_of(dcl, struct sdl2_console, d= cl); + + scon->cursor_x =3D pos_x; + scon->cursor_y =3D pos_y; +#endif +} + +void sdl2_gl_release_dmabuf(DisplayChangeListener *dcl, + QemuDmaBuf *dmabuf) +{ +#ifdef CONFIG_OPENGL_DMABUF + egl_dmabuf_release_texture(dmabuf); +#endif } =20 void sdl2_gl_scanout_flush(DisplayChangeListener *dcl, @@ -236,15 +285,24 @@ void sdl2_gl_scanout_flush(DisplayChangeListener *dcl, if (!scon->scanout_mode) { return; } + if (!scon->guest_fb.framebuffer) { return; } =20 SDL_GL_MakeCurrent(scon->real_window, scon->winctx); - SDL_GetWindowSize(scon->real_window, &ww, &wh); + egl_fb_setup_default(&scon->win_fb, ww, wh); - egl_fb_blit(&scon->win_fb, &scon->guest_fb, !scon->y0_top); =20 + if (scon->cursor_fb.texture) { + egl_texture_blit(scon->gls, &scon->win_fb, &scon->guest_fb, + scon->y0_top); + egl_texture_blend(scon->gls, &scon->win_fb, &scon->cursor_fb, + scon->y0_top, + scon->cursor_x, scon->cursor_y); + } else { + egl_fb_blit(&scon->win_fb, &scon->guest_fb, !scon->y0_top); + } SDL_GL_SwapWindow(scon->real_window); } diff --git a/ui/sdl2.c b/ui/sdl2.c index 71efd24..c865cba 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -84,7 +84,6 @@ void sdl2_window_create(struct sdl2_console *scon) if (scon->hidden) { flags |=3D SDL_WINDOW_HIDDEN; } - scon->real_window =3D SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, surface_width(scon->surface), @@ -118,7 +117,6 @@ void sdl2_window_resize(struct sdl2_console *scon) if (!scon->real_window) { return; } - SDL_SetWindowSize(scon->real_window, surface_width(scon->surface), surface_height(scon->surface)); @@ -740,6 +738,9 @@ static const DisplayChangeListenerOps dcl_gl_ops =3D { .dpy_gl_scanout_disable =3D sdl2_gl_scanout_disable, .dpy_gl_scanout_texture =3D sdl2_gl_scanout_texture, .dpy_gl_scanout_dmabuf =3D sdl2_gl_scanout_dmabuf, + .dpy_gl_cursor_dmabuf =3D sdl2_gl_cursor_dmabuf, + .dpy_gl_cursor_position =3D sdl2_gl_cursor_position, + .dpy_gl_release_dmabuf =3D sdl2_gl_release_dmabuf, .dpy_gl_update =3D sdl2_gl_scanout_flush, }; #endif @@ -835,6 +836,7 @@ void sdl_display_init(DisplayState *ds, int full_screen= , int no_frame) #endif } =20 + qemu_egl_init_dpy_x11(info.info.x11.display); /* Load a 32x32x4 image. White pixels are transparent. */ filename =3D qemu_find_file(QEMU_FILE_TYPE_BIOS, "qemu-icon.bmp"); if (filename) { --=20 2.7.4