From nobody Tue May 7 19:20:46 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; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=collabora.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529045339320958.7015883609051; Thu, 14 Jun 2018 23:48:59 -0700 (PDT) Received: from localhost ([::1]:44629 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTiXR-0007Xw-Eg for importer@patchew.org; Fri, 15 Jun 2018 02:48:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTiWM-0007CL-IK for qemu-devel@nongnu.org; Fri, 15 Jun 2018 02:47:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fTiWJ-000770-ED for qemu-devel@nongnu.org; Fri, 15 Jun 2018 02:47:42 -0400 Received: from mail-wm0-x232.google.com ([2a00:1450:400c:c09::232]:52460) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fTiWJ-000756-4t for qemu-devel@nongnu.org; Fri, 15 Jun 2018 02:47:39 -0400 Received: by mail-wm0-x232.google.com with SMTP id p126-v6so1755347wmb.2 for ; Thu, 14 Jun 2018 23:47:38 -0700 (PDT) Received: from cizrna.lan ([109.72.12.206]) by smtp.gmail.com with ESMTPSA id c10-v6sm6968957wrs.6.2018.06.14.23.47.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Jun 2018 23:47:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=9backLBPxUjbFjsO1oI7pYU0OuwtO9+6+nLSc/fnvyg=; b=sgGYMsRZLfUfFGEAz0rtf8yl0jUpBVTyq0lQhrrFOTl/o4/LpuuaVcgdlvlsqiNf1T /FsSIVuoAwUBPU06bWwBhlppyXgBQcF0QHj8AV+njpU7z+ymXciWgovSN5lo4Yhs+1S/ pMUvOnUHsdKoOFQ+ahSKGIUojmJpvWb13wjOZ1uOYppehmp6186sKJdrzpLWxpanmc2D Rmk8JTWsPpCZvX1PqFnE36T0aGXx0JvtJt+dVJovcOeNtZ5S6ojOV0Ug1uWtU9hYF60k mir6CKH1OIUNl/+ET//bP6h7rFCVYNLxmXIzUZasAnUjuL1x5oRVFw4j87aq/qd5OEAP RWng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=9backLBPxUjbFjsO1oI7pYU0OuwtO9+6+nLSc/fnvyg=; b=ESKNiOseZeiPx9gTFFcCT4A1WTIBDwQFBD3BCU+r5tpC+hwwaCsIG3btAHjoFu9npH hK2/+HRaJetG6qYdifKOxR9wOwC1i09CUDdGYq2rryIazlh/l4765cJybedX2niIujvx 400Ahz1HaLwEl2mP3oam0KZTRNqq9EwAeqt1N4PFst93Hvlpj3XLURsRzTwwBiABqhEp G1YNdFU1/k8las4BOI0bX8/d+A7JfkoQv4TU23+elWt34S8mrZc2GCu5nL2DVPhMzfQZ QFx+pgtxzQk62d0CTn0QfTNIsYFHULf9etAGqbZIBKsXlOtFphp7yJnA/3FxmXEwaAR1 Xx5w== X-Gm-Message-State: APt69E2R9yhn0ycpIBNClIyDaub+3DCmpzzcr0WHLPAPP9YThm2d4V3K Uh0zjIdlm6O3BftDxRHM3sVWHpSD X-Google-Smtp-Source: ADUXVKLU+7/2QZQy1dSL8a/I3kmMKiuMVtx07LU8b83l2QoU6fzohKmti8+OS3EWcOiBAEsWIskQzw== X-Received: by 2002:a1c:14cc:: with SMTP id 195-v6mr191816wmu.48.1529045257436; Thu, 14 Jun 2018 23:47:37 -0700 (PDT) From: Tomeu Vizoso To: qemu-devel@nongnu.org Date: Fri, 15 Jun 2018 08:47:01 +0200 Message-Id: <20180615064701.40928-1-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.17.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::232 Subject: [Qemu-devel] [PATCH] egl-headless: Allow OpenGL ES context creation 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: kernel@collabora.com, Gerd Hoffmann , Tomeu Vizoso Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This will be mainly useful for automated testing of virglrenderer on ES. Signed-off-by: Tomeu Vizoso --- include/ui/egl-helpers.h | 6 ++--- qemu-options.hx | 1 + ui/egl-headless.c | 2 +- ui/egl-helpers.c | 56 +++++++++++++++++++++++++++++----------- ui/gtk-egl.c | 2 +- ui/spice-core.c | 2 +- 6 files changed, 48 insertions(+), 21 deletions(-) diff --git a/include/ui/egl-helpers.h b/include/ui/egl-helpers.h index 747233ce5846..9c76a04a2492 100644 --- a/include/ui/egl-helpers.h +++ b/include/ui/egl-helpers.h @@ -34,7 +34,7 @@ extern int qemu_egl_rn_fd; extern struct gbm_device *qemu_egl_rn_gbm_dev; extern EGLContext qemu_egl_rn_ctx; =20 -int egl_rendernode_init(const char *rendernode); +int egl_rendernode_init(const char *rendernode, bool gles); int egl_get_fd_for_texture(uint32_t tex_id, EGLint *stride, EGLint *fourcc= ); =20 void egl_dmabuf_import_texture(QemuDmaBuf *dmabuf); @@ -45,7 +45,7 @@ void egl_dmabuf_release_texture(QemuDmaBuf *dmabuf); EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, Window win); =20 int qemu_egl_init_dpy_x11(EGLNativeDisplayType dpy); -int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy); -EGLContext qemu_egl_init_ctx(void); +int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, bool gles); +EGLContext qemu_egl_init_ctx(bool gles); =20 #endif /* EGL_HELPERS_H */ diff --git a/qemu-options.hx b/qemu-options.hx index c0d3951e9ffd..baa320ce615d 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1242,6 +1242,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display, "-display sdl[,frame=3Don|off][,alt_grab=3Don|off][,ctrl_grab=3Don|off= ]\n" " [,window_close=3Don|off][,gl=3Don|core|es|off]\n" "-display gtk[,grab_on_hover=3Don|off][,gl=3Don|off]|\n" + "-display egl-headless[,gl=3Dcore|es]|\n" "-display vnc=3D[,]\n" "-display curses\n" "-display none" diff --git a/ui/egl-headless.c b/ui/egl-headless.c index 7c877122d385..796bce0bfa67 100644 --- a/ui/egl-headless.c +++ b/ui/egl-headless.c @@ -175,7 +175,7 @@ static void egl_headless_init(DisplayState *ds, Display= Options *opts) egl_dpy *edpy; int idx; =20 - if (egl_rendernode_init(NULL) < 0) { + if (egl_rendernode_init(NULL, opts->gl =3D=3D DISPLAYGL_MODE_ES) < 0) { error_report("egl: render node init failed"); exit(1); } diff --git a/ui/egl-helpers.c b/ui/egl-helpers.c index 16dc3ded3630..a775f4ffb725 100644 --- a/ui/egl-helpers.c +++ b/ui/egl-helpers.c @@ -191,7 +191,7 @@ static int qemu_egl_rendernode_open(const char *rendern= ode) return fd; } =20 -int egl_rendernode_init(const char *rendernode) +int egl_rendernode_init(const char *rendernode, bool gles) { qemu_egl_rn_fd =3D -1; int rc; @@ -208,7 +208,8 @@ int egl_rendernode_init(const char *rendernode) goto err; } =20 - rc =3D qemu_egl_init_dpy_mesa((EGLNativeDisplayType)qemu_egl_rn_gbm_de= v); + rc =3D qemu_egl_init_dpy_mesa((EGLNativeDisplayType)qemu_egl_rn_gbm_de= v, + gles); if (rc !=3D 0) { /* qemu_egl_init_dpy_mesa reports error */ goto err; @@ -225,7 +226,7 @@ int egl_rendernode_init(const char *rendernode) goto err; } =20 - qemu_egl_rn_ctx =3D qemu_egl_init_ctx(); + qemu_egl_rn_ctx =3D qemu_egl_init_ctx(gles); if (!qemu_egl_rn_ctx) { error_report("egl: egl_init_ctx failed"); goto err; @@ -392,7 +393,8 @@ static EGLDisplay qemu_egl_get_display(EGLNativeDisplay= Type native, } =20 static int qemu_egl_init_dpy(EGLNativeDisplayType dpy, - EGLenum platform) + EGLenum platform, + bool gles) { static const EGLint conf_att_gl[] =3D { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, @@ -403,6 +405,15 @@ static int qemu_egl_init_dpy(EGLNativeDisplayType dpy, EGL_ALPHA_SIZE, 0, EGL_NONE, }; + static const EGLint conf_att_gles[] =3D { + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_RED_SIZE, 5, + EGL_GREEN_SIZE, 5, + EGL_BLUE_SIZE, 5, + EGL_ALPHA_SIZE, 0, + EGL_NONE, + }; EGLint major, minor; EGLBoolean b; EGLint n; @@ -419,14 +430,21 @@ static int qemu_egl_init_dpy(EGLNativeDisplayType dpy, return -1; } =20 - b =3D eglBindAPI(EGL_OPENGL_API); + if (gles) + b =3D eglBindAPI(EGL_OPENGL_ES_API); + else + b =3D eglBindAPI(EGL_OPENGL_API); if (b =3D=3D EGL_FALSE) { error_report("egl: eglBindAPI failed"); return -1; } =20 - b =3D eglChooseConfig(qemu_egl_display, conf_att_gl, - &qemu_egl_config, 1, &n); + if (gles) + b =3D eglChooseConfig(qemu_egl_display, conf_att_gles, + &qemu_egl_config, 1, &n); + else + b =3D eglChooseConfig(qemu_egl_display, conf_att_gl, + &qemu_egl_config, 1, &n); if (b =3D=3D EGL_FALSE || n !=3D 1) { error_report("egl: eglChooseConfig failed"); return -1; @@ -437,32 +455,40 @@ static int qemu_egl_init_dpy(EGLNativeDisplayType dpy, int qemu_egl_init_dpy_x11(EGLNativeDisplayType dpy) { #ifdef EGL_KHR_platform_x11 - return qemu_egl_init_dpy(dpy, EGL_PLATFORM_X11_KHR); + return qemu_egl_init_dpy(dpy, EGL_PLATFORM_X11_KHR, false); #else - return qemu_egl_init_dpy(dpy, 0); + return qemu_egl_init_dpy(dpy, 0, false); #endif } =20 -int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy) +int qemu_egl_init_dpy_mesa(EGLNativeDisplayType dpy, bool gles) { #ifdef EGL_MESA_platform_gbm - return qemu_egl_init_dpy(dpy, EGL_PLATFORM_GBM_MESA); + return qemu_egl_init_dpy(dpy, EGL_PLATFORM_GBM_MESA, gles); #else - return qemu_egl_init_dpy(dpy, 0); + return qemu_egl_init_dpy(dpy, 0, gles); #endif } =20 -EGLContext qemu_egl_init_ctx(void) +EGLContext qemu_egl_init_ctx(bool gles) { static const EGLint ctx_att_gl[] =3D { EGL_CONTEXT_OPENGL_PROFILE_MASK, EGL_CONTEXT_OPENGL_CORE_PROFILE_B= IT, EGL_NONE }; + static const EGLint ctx_att_gles[] =3D { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; EGLContext ectx; EGLBoolean b; =20 - ectx =3D eglCreateContext(qemu_egl_display, qemu_egl_config, EGL_NO_CO= NTEXT, - ctx_att_gl); + if (gles) + ectx =3D eglCreateContext(qemu_egl_display, qemu_egl_config, + EGL_NO_CONTEXT, ctx_att_gles); + else + ectx =3D eglCreateContext(qemu_egl_display, qemu_egl_config, + EGL_NO_CONTEXT, ctx_att_gl); if (ectx =3D=3D EGL_NO_CONTEXT) { error_report("egl: eglCreateContext failed"); return NULL; diff --git a/ui/gtk-egl.c b/ui/gtk-egl.c index 9390c6762e87..9ab50a17c029 100644 --- a/ui/gtk-egl.c +++ b/ui/gtk-egl.c @@ -57,7 +57,7 @@ void gd_egl_init(VirtualConsole *vc) return; } =20 - vc->gfx.ectx =3D qemu_egl_init_ctx(); + vc->gfx.ectx =3D qemu_egl_init_ctx(false); vc->gfx.esurface =3D qemu_egl_init_surface_x11(vc->gfx.ectx, x11_windo= w); =20 assert(vc->gfx.esurface); diff --git a/ui/spice-core.c b/ui/spice-core.c index ae8921a201ca..6d659b64b4ce 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -829,7 +829,7 @@ void qemu_spice_init(void) "incompatible with -spice port/tls-port"); exit(1); } - if (egl_rendernode_init(qemu_opt_get(opts, "rendernode")) !=3D 0) { + if (egl_rendernode_init(qemu_opt_get(opts, "rendernode"), false) != =3D 0) { error_report("Failed to initialize EGL render node for SPICE G= L"); exit(1); } --=20 2.17.0