aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Zeni <simon@bl4ckb0ne.ca>2021-04-20 14:48:22 -0400
committerSimon Ser <contact@emersion.fr>2021-04-20 21:14:27 +0200
commit10c5199d85f54079a759f5de37574ccf8ae30825 (patch)
tree650a02112c41f9a9018912a900c565dff2286db4
parent014c59aa401cfb5566f840a97308c619edaec840 (diff)
render/gles2: introduce wlr_gles2_renderer_create_with_drm_fd
-rw-r--r--include/wlr/render/gles2.h1
-rw-r--r--render/gles2/renderer.c27
2 files changed, 28 insertions, 0 deletions
diff --git a/include/wlr/render/gles2.h b/include/wlr/render/gles2.h
index 5a3e9d5c..5bdf6edb 100644
--- a/include/wlr/render/gles2.h
+++ b/include/wlr/render/gles2.h
@@ -15,6 +15,7 @@
struct wlr_egl;
+struct wlr_renderer *wlr_gles2_renderer_create_with_drm_fd(int drm_fd);
struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl);
struct wlr_egl *wlr_gles2_renderer_get_egl(struct wlr_renderer *renderer);
diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c
index 5f1dfa4a..212289e6 100644
--- a/render/gles2/renderer.c
+++ b/render/gles2/renderer.c
@@ -1,5 +1,6 @@
#include <assert.h>
#include <drm_fourcc.h>
+#include <gbm.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <stdint.h>
@@ -717,6 +718,32 @@ extern const GLchar tex_fragment_src_rgba[];
extern const GLchar tex_fragment_src_rgbx[];
extern const GLchar tex_fragment_src_external[];
+struct wlr_renderer *wlr_gles2_renderer_create_with_drm_fd(int drm_fd) {
+ struct gbm_device *gbm_device = gbm_create_device(drm_fd);
+ if (!gbm_device) {
+ wlr_log(WLR_ERROR, "Failed to create GBM device");
+ return NULL;
+ }
+
+ struct wlr_egl *egl = wlr_egl_create(EGL_PLATFORM_GBM_KHR, gbm_device);
+ if (egl == NULL) {
+ wlr_log(WLR_ERROR, "Could not initialize EGL");
+ gbm_device_destroy(gbm_device);
+ return NULL;
+ }
+
+ egl->gbm_device = gbm_device;
+
+ struct wlr_renderer *renderer = wlr_gles2_renderer_create(egl);
+ if (!renderer) {
+ wlr_log(WLR_ERROR, "Failed to create GLES2 renderer");
+ wlr_egl_destroy(egl);
+ return NULL;
+ }
+
+ return renderer;
+}
+
struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_egl *egl) {
if (!wlr_egl_make_current(egl)) {
return NULL;