11 #include "ui/egl-helpers.h"
13 EGLDisplay
*qemu_egl_display
;
14 EGLConfig qemu_egl_config
;
16 /* ---------------------------------------------------------------------- */
21 #define egl_dbg(_x ...) \
24 fprintf(stderr, "egl: " _x); \
28 /* ---------------------------------------------------------------------- */
30 EGLSurface
qemu_egl_init_surface_x11(EGLContext ectx
, Window win
)
35 egl_dbg("eglCreateWindowSurface (x11 win id 0x%lx) ...\n",
37 esurface
= eglCreateWindowSurface(qemu_egl_display
,
39 (EGLNativeWindowType
)win
, NULL
);
40 if (esurface
== EGL_NO_SURFACE
) {
41 fprintf(stderr
, "egl: eglCreateWindowSurface failed\n");
45 b
= eglMakeCurrent(qemu_egl_display
, esurface
, esurface
, ectx
);
47 fprintf(stderr
, "egl: eglMakeCurrent failed\n");
54 /* ---------------------------------------------------------------------- */
56 int qemu_egl_init_dpy(EGLNativeDisplayType dpy
, bool gles
, bool debug
)
58 static const EGLint conf_att_gl
[] = {
59 EGL_SURFACE_TYPE
, EGL_WINDOW_BIT
,
60 EGL_RENDERABLE_TYPE
, EGL_OPENGL_BIT
,
67 static const EGLint conf_att_gles
[] = {
68 EGL_SURFACE_TYPE
, EGL_WINDOW_BIT
,
69 EGL_RENDERABLE_TYPE
, EGL_OPENGL_ES2_BIT
,
82 setenv("EGL_LOG_LEVEL", "debug", true);
83 setenv("LIBGL_DEBUG", "verbose", true);
86 egl_dbg("eglGetDisplay (dpy %p) ...\n", dpy
);
87 qemu_egl_display
= eglGetDisplay(dpy
);
88 if (qemu_egl_display
== EGL_NO_DISPLAY
) {
89 fprintf(stderr
, "egl: eglGetDisplay failed\n");
93 egl_dbg("eglInitialize ...\n");
94 b
= eglInitialize(qemu_egl_display
, &major
, &minor
);
96 fprintf(stderr
, "egl: eglInitialize failed\n");
100 egl_dbg("eglBindAPI ...\n");
101 b
= eglBindAPI(gles
? EGL_OPENGL_ES_API
: EGL_OPENGL_API
);
102 if (b
== EGL_FALSE
) {
103 fprintf(stderr
, "egl: eglBindAPI failed\n");
107 egl_dbg("eglChooseConfig ...\n");
108 b
= eglChooseConfig(qemu_egl_display
,
109 gles
? conf_att_gles
: conf_att_gl
,
110 &qemu_egl_config
, 1, &n
);
111 if (b
== EGL_FALSE
|| n
!= 1) {
112 fprintf(stderr
, "egl: eglChooseConfig failed\n");
120 EGLContext
qemu_egl_init_ctx(void)
122 static const EGLint ctx_att_gl
[] = {
125 static const EGLint ctx_att_gles
[] = {
126 EGL_CONTEXT_CLIENT_VERSION
, 2,
133 egl_dbg("eglCreateContext ...\n");
134 ectx
= eglCreateContext(qemu_egl_display
, qemu_egl_config
, EGL_NO_CONTEXT
,
135 egl_gles
? ctx_att_gles
: ctx_att_gl
);
136 if (ectx
== EGL_NO_CONTEXT
) {
137 fprintf(stderr
, "egl: eglCreateContext failed\n");
141 b
= eglMakeCurrent(qemu_egl_display
, EGL_NO_SURFACE
, EGL_NO_SURFACE
, ectx
);
142 if (b
== EGL_FALSE
) {
143 fprintf(stderr
, "egl: eglMakeCurrent failed\n");