[Spice-devel] [PATCH RFC 03/12] Implements spice_qxl_gl_init

Frediano Ziglio fziglio at redhat.com
Fri Jul 15 13:49:28 UTC 2016


Save display and context for EGL.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/Makefile.am |  2 ++
 server/egl.c       | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 server/egl.h       | 23 ++++++++++++++++++++
 server/red-qxl.c   |  7 ++++++
 4 files changed, 95 insertions(+)
 create mode 100644 server/egl.c
 create mode 100644 server/egl.h

diff --git a/server/Makefile.am b/server/Makefile.am
index 0bed89c..5537417 100644
--- a/server/Makefile.am
+++ b/server/Makefile.am
@@ -149,6 +149,8 @@ libserver_la_SOURCES =				\
 	dcc.c					\
 	dcc-send.c					\
 	dcc.h					\
+	egl.c					\
+	egl.h					\
 	display-limits.h			\
 	image-encoders.c					\
 	image-encoders.h					\
diff --git a/server/egl.c b/server/egl.c
new file mode 100644
index 0000000..85f7264
--- /dev/null
+++ b/server/egl.c
@@ -0,0 +1,63 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   Copyright (C) 2016 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <epoxy/gl.h>
+#include <epoxy/egl.h>
+#include <gbm.h>
+#include <common/log.h>
+
+#include "egl.h"
+
+void *egl_own_context(void *egl_display, void *egl_context)
+{
+    static const EGLint ctx_att_gl[] = {
+        EGL_CONTEXT_MAJOR_VERSION, 3,
+        EGL_NONE
+    };
+
+    static const EGLint conf_att[] = {
+        EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+        EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
+        EGL_RED_SIZE, 8,
+        EGL_GREEN_SIZE, 8,
+        EGL_BLUE_SIZE, 8,
+        EGL_ALPHA_SIZE, 0,
+        EGL_NONE,
+    };
+
+    EGLContext ectx;
+    EGLBoolean b;
+    EGLint n;
+    EGLConfig egl_config;
+
+    b = eglBindAPI(EGL_OPENGL_API);
+    spice_assert(b);
+
+    b = eglChooseConfig(egl_display, conf_att, &egl_config,
+                        1, &n);
+    spice_assert(b && n == 1);
+
+    ectx = eglCreateContext(egl_display, egl_config, egl_context,
+                            ctx_att_gl);
+    spice_assert(ectx != EGL_NO_CONTEXT);
+
+    return ectx;
+}
diff --git a/server/egl.h b/server/egl.h
new file mode 100644
index 0000000..c2ab722
--- /dev/null
+++ b/server/egl.h
@@ -0,0 +1,23 @@
+/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/*
+   Copyright (C) 2016 Red Hat, Inc.
+
+   This library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   This library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with this library; if not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef EGL_H_
+#define EGL_H_
+
+void *egl_own_context(void *egl_display, void *egl_context);
+
+#endif /* EGL_H_ */
diff --git a/server/red-qxl.c b/server/red-qxl.c
index d21b93f..7a68144 100644
--- a/server/red-qxl.c
+++ b/server/red-qxl.c
@@ -36,6 +36,7 @@
 #include "reds.h"
 #include "dispatcher.h"
 #include "red-parse-qxl.h"
+#include "egl.h"
 
 #include "red-qxl.h"
 
@@ -58,6 +59,9 @@ struct QXLState {
     unsigned int max_monitors;
     RedsState *reds;
 
+    void *egl_display;
+    void *egl_context;
+
     pthread_mutex_t scanout_mutex;
     SpiceMsgDisplayGlScanoutUnix scanout;
     struct AsyncCommand *gl_draw_async;
@@ -858,6 +862,9 @@ void spice_qxl_gl_init(QXLInstance *qxl,
                        void *egl_display,
                        void *egl_context)
 {
+    QXLState *qxl_state = qxl->st;
+    qxl_state->egl_display = egl_display;
+    qxl_state->egl_context = egl_own_context(egl_display, egl_context);
 }
 
 SPICE_GNUC_VISIBLE
-- 
2.7.4



More information about the Spice-devel mailing list