summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Clark <robdclark@gmail.com>2017-02-21 11:49:03 -0500
committerRob Clark <robdclark@gmail.com>2017-02-21 11:49:03 -0500
commitc6a1571a9b6a55b6d00040bac6172ffb4fd2d3b8 (patch)
tree0cf0f3ba17ed5b4ee6893d7916e68e036d84d3be
parent9180f2feccc3f98b68f42cb0c8687ada74a78685 (diff)
split gbm out
-rw-r--r--Makefile.am2
-rw-r--r--common.c44
-rw-r--r--common.h36
-rw-r--r--kmscube.c48
4 files changed, 98 insertions, 32 deletions
diff --git a/Makefile.am b/Makefile.am
index f28269d..602fbf4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -40,5 +40,7 @@ kmscube_CFLAGS = \
$(GLES2_CFLAGS)
kmscube_SOURCES = \
+ common.c \
+ common.h \
kmscube.c \
esTransform.c
diff --git a/common.c b/common.c
new file mode 100644
index 0000000..b3c2212
--- /dev/null
+++ b/common.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2017 Rob Clark <rclark@redhat.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdio.h>
+
+#include "common.h"
+
+static struct gbm gbm;
+
+const struct gbm * init_gbm(int drm_fd, int w, int h)
+{
+ gbm.dev = gbm_create_device(drm_fd);
+
+ gbm.surface = gbm_surface_create(gbm.dev, w, h,
+ GBM_FORMAT_XRGB8888,
+ GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
+ if (!gbm.surface) {
+ printf("failed to create gbm surface\n");
+ return NULL;
+ }
+
+ return &gbm;
+}
+
diff --git a/common.h b/common.h
new file mode 100644
index 0000000..8f3a827
--- /dev/null
+++ b/common.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017 Rob Clark <rclark@redhat.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sub license,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _COMMON_H
+#define _COMMON_H
+
+#include <gbm.h>
+
+struct gbm {
+ struct gbm_device *dev;
+ struct gbm_surface *surface;
+};
+
+const struct gbm * init_gbm(int drm_fd, int w, int h);
+
+#endif /* _COMMON_H */
diff --git a/kmscube.c b/kmscube.c
index 3d74f9d..bb557b5 100644
--- a/kmscube.c
+++ b/kmscube.c
@@ -35,7 +35,6 @@
#include <xf86drm.h>
#include <xf86drmMode.h>
-#include <gbm.h>
#define GL_GLEXT_PROTOTYPES 1
#include <GLES2/gl2.h>
@@ -45,6 +44,7 @@
#include <assert.h>
+#include "common.h"
#include "esUtil.h"
@@ -64,10 +64,7 @@ static struct {
PFNEGLGETPLATFORMDISPLAYEXTPROC eglGetPlatformDisplayEXT;
} gl;
-static struct {
- struct gbm_device *dev;
- struct gbm_surface *surface;
-} gbm;
+static const struct gbm *gbm;
static struct {
int fd;
@@ -207,22 +204,6 @@ static int init_drm(const char *dev)
return 0;
}
-static int init_gbm(void)
-{
- gbm.dev = gbm_create_device(drm.fd);
-
- gbm.surface = gbm_surface_create(gbm.dev,
- drm.mode->hdisplay, drm.mode->vdisplay,
- GBM_FORMAT_XRGB8888,
- GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
- if (!gbm.surface) {
- printf("failed to create gbm surface\n");
- return -1;
- }
-
- return 0;
-}
-
static int init_gl(void)
{
EGLint major, minor, n;
@@ -383,10 +364,12 @@ static int init_gl(void)
get_proc(eglGetPlatformDisplayEXT);
- if (gl.eglGetPlatformDisplayEXT)
- gl.display = gl.eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_KHR, gbm.dev, NULL);
- else
- gl.display = eglGetDisplay(gbm.dev);
+ if (gl.eglGetPlatformDisplayEXT) {
+ gl.display = gl.eglGetPlatformDisplayEXT(EGL_PLATFORM_GBM_KHR,
+ gbm->dev, NULL);
+ } else {
+ gl.display = eglGetDisplay((void *)gbm->dev);
+ }
if (!eglInitialize(gl.display, &major, &minor)) {
printf("failed to initialize\n");
@@ -417,7 +400,8 @@ static int init_gl(void)
return -1;
}
- gl.surface = eglCreateWindowSurface(gl.display, gl.config, gbm.surface, NULL);
+ gl.surface = eglCreateWindowSurface(gl.display, gl.config,
+ (EGLNativeWindowType)gbm->surface, NULL);
if (gl.surface == EGL_NO_SURFACE) {
printf("failed to create egl surface\n");
return -1;
@@ -670,10 +654,10 @@ int main(int argc, char *argv[])
FD_SET(0, &fds);
FD_SET(drm.fd, &fds);
- ret = init_gbm();
- if (ret) {
+ gbm = init_gbm(drm.fd, drm.mode->hdisplay, drm.mode->vdisplay);
+ if (!gbm) {
printf("failed to initialize GBM\n");
- return ret;
+ return -1;
}
ret = init_gl();
@@ -686,7 +670,7 @@ int main(int argc, char *argv[])
glClearColor(0.5, 0.5, 0.5, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
eglSwapBuffers(gl.display, gl.surface);
- bo = gbm_surface_lock_front_buffer(gbm.surface);
+ bo = gbm_surface_lock_front_buffer(gbm->surface);
fb = drm_fb_get_from_bo(bo);
/* set mode: */
@@ -704,7 +688,7 @@ int main(int argc, char *argv[])
draw(i++);
eglSwapBuffers(gl.display, gl.surface);
- next_bo = gbm_surface_lock_front_buffer(gbm.surface);
+ next_bo = gbm_surface_lock_front_buffer(gbm->surface);
fb = drm_fb_get_from_bo(next_bo);
/*
@@ -735,7 +719,7 @@ int main(int argc, char *argv[])
}
/* release last buffer to render on again: */
- gbm_surface_release_buffer(gbm.surface, bo);
+ gbm_surface_release_buffer(gbm->surface, bo);
bo = next_bo;
}