qapi: Add missing JSON files in build dependencies
[qemu/armbru.git] / ui / egl-helpers.c
blob4c838346156b77d8968995e6460a42897bfac282
1 #include "qemu/osdep.h"
2 #include <glob.h>
4 #include "ui/egl-helpers.h"
6 EGLDisplay *qemu_egl_display;
7 EGLConfig qemu_egl_config;
9 /* ---------------------------------------------------------------------- */
11 static bool egl_gles;
12 static int egl_debug;
14 #define egl_dbg(_x ...) \
15 do { \
16 if (egl_debug) { \
17 fprintf(stderr, "egl: " _x); \
18 } \
19 } while (0);
21 /* ---------------------------------------------------------------------- */
23 EGLSurface qemu_egl_init_surface_x11(EGLContext ectx, Window win)
25 EGLSurface esurface;
26 EGLBoolean b;
28 egl_dbg("eglCreateWindowSurface (x11 win id 0x%lx) ...\n",
29 (unsigned long) win);
30 esurface = eglCreateWindowSurface(qemu_egl_display,
31 qemu_egl_config,
32 (EGLNativeWindowType)win, NULL);
33 if (esurface == EGL_NO_SURFACE) {
34 fprintf(stderr, "egl: eglCreateWindowSurface failed\n");
35 return NULL;
38 b = eglMakeCurrent(qemu_egl_display, esurface, esurface, ectx);
39 if (b == EGL_FALSE) {
40 fprintf(stderr, "egl: eglMakeCurrent failed\n");
41 return NULL;
44 return esurface;
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,
54 EGL_RED_SIZE, 5,
55 EGL_GREEN_SIZE, 5,
56 EGL_BLUE_SIZE, 5,
57 EGL_ALPHA_SIZE, 0,
58 EGL_NONE,
60 static const EGLint conf_att_gles[] = {
61 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
62 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
63 EGL_RED_SIZE, 5,
64 EGL_GREEN_SIZE, 5,
65 EGL_BLUE_SIZE, 5,
66 EGL_ALPHA_SIZE, 0,
67 EGL_NONE,
69 EGLint major, minor;
70 EGLBoolean b;
71 EGLint n;
73 if (debug) {
74 egl_debug = 1;
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");
83 return -1;
86 egl_dbg("eglInitialize ...\n");
87 b = eglInitialize(qemu_egl_display, &major, &minor);
88 if (b == EGL_FALSE) {
89 fprintf(stderr, "egl: eglInitialize failed\n");
90 return -1;
93 egl_dbg("eglBindAPI ...\n");
94 b = eglBindAPI(gles ? EGL_OPENGL_ES_API : EGL_OPENGL_API);
95 if (b == EGL_FALSE) {
96 fprintf(stderr, "egl: eglBindAPI failed\n");
97 return -1;
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");
106 return -1;
109 egl_gles = gles;
110 return 0;
113 EGLContext qemu_egl_init_ctx(void)
115 static const EGLint ctx_att_gl[] = {
116 EGL_NONE
118 static const EGLint ctx_att_gles[] = {
119 EGL_CONTEXT_CLIENT_VERSION, 2,
120 EGL_NONE
123 EGLContext ectx;
124 EGLBoolean b;
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");
131 return NULL;
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");
137 return NULL;
140 return ectx;