1 #include "qemu/osdep.h"
4 #include "ui/egl-helpers.h"
6 EGLDisplay
*qemu_egl_display
;
7 EGLConfig qemu_egl_config
;
9 /* ---------------------------------------------------------------------- */
14 #define egl_dbg(_x ...) \
17 fprintf(stderr, "egl: " _x); \
21 /* ---------------------------------------------------------------------- */
23 EGLSurface
qemu_egl_init_surface_x11(EGLContext ectx
, Window win
)
28 egl_dbg("eglCreateWindowSurface (x11 win id 0x%lx) ...\n",
30 esurface
= eglCreateWindowSurface(qemu_egl_display
,
32 (EGLNativeWindowType
)win
, NULL
);
33 if (esurface
== EGL_NO_SURFACE
) {
34 fprintf(stderr
, "egl: eglCreateWindowSurface failed\n");
38 b
= eglMakeCurrent(qemu_egl_display
, esurface
, esurface
, ectx
);
40 fprintf(stderr
, "egl: eglMakeCurrent failed\n");
47 /* ---------------------------------------------------------------------- */
49 int qemu_egl_init_dpy(EGLNativeDisplayType dpy
, bool gles
, bool debug
)
51 static const EGLint conf_att_gl
[] = {
52 EGL_SURFACE_TYPE
, EGL_WINDOW_BIT
,
53 EGL_RENDERABLE_TYPE
, EGL_OPENGL_BIT
,
60 static const EGLint conf_att_gles
[] = {
61 EGL_SURFACE_TYPE
, EGL_WINDOW_BIT
,
62 EGL_RENDERABLE_TYPE
, EGL_OPENGL_ES2_BIT
,
75 setenv("EGL_LOG_LEVEL", "debug", true);
76 setenv("LIBGL_DEBUG", "verbose", true);
79 egl_dbg("eglGetDisplay (dpy %p) ...\n", dpy
);
80 qemu_egl_display
= eglGetDisplay(dpy
);
81 if (qemu_egl_display
== EGL_NO_DISPLAY
) {
82 fprintf(stderr
, "egl: eglGetDisplay failed\n");
86 egl_dbg("eglInitialize ...\n");
87 b
= eglInitialize(qemu_egl_display
, &major
, &minor
);
89 fprintf(stderr
, "egl: eglInitialize failed\n");
93 egl_dbg("eglBindAPI ...\n");
94 b
= eglBindAPI(gles
? EGL_OPENGL_ES_API
: EGL_OPENGL_API
);
96 fprintf(stderr
, "egl: eglBindAPI failed\n");
100 egl_dbg("eglChooseConfig ...\n");
101 b
= eglChooseConfig(qemu_egl_display
,
102 gles
? conf_att_gles
: conf_att_gl
,
103 &qemu_egl_config
, 1, &n
);
104 if (b
== EGL_FALSE
|| n
!= 1) {
105 fprintf(stderr
, "egl: eglChooseConfig failed\n");
113 EGLContext
qemu_egl_init_ctx(void)
115 static const EGLint ctx_att_gl
[] = {
118 static const EGLint ctx_att_gles
[] = {
119 EGL_CONTEXT_CLIENT_VERSION
, 2,
126 egl_dbg("eglCreateContext ...\n");
127 ectx
= eglCreateContext(qemu_egl_display
, qemu_egl_config
, EGL_NO_CONTEXT
,
128 egl_gles
? ctx_att_gles
: ctx_att_gl
);
129 if (ectx
== EGL_NO_CONTEXT
) {
130 fprintf(stderr
, "egl: eglCreateContext failed\n");
134 b
= eglMakeCurrent(qemu_egl_display
, EGL_NO_SURFACE
, EGL_NO_SURFACE
, ectx
);
135 if (b
== EGL_FALSE
) {
136 fprintf(stderr
, "egl: eglMakeCurrent failed\n");