summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorChia-I Wu <[email protected]>2010-05-30 10:21:09 +0800
committerChia-I Wu <[email protected]>2010-05-30 10:52:50 +0800
commit20c3d7190ed2c748cf959366a963b7dc973c5423 (patch)
tree83f2dc7c5b23c6938d44a14ccb04a97c2f763c0d /src
parentb202c785862363d0534f04a8f2e8f0b5232d9b13 (diff)
st/egl: Initialize KMS backend from an fd.
Check if the native native is EGL_DEFAULT_DISPLAY. If not, treat it as an fd.
Diffstat (limited to 'src')
-rw-r--r--src/gallium/state_trackers/egl/kms/native_kms.c37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/gallium/state_trackers/egl/kms/native_kms.c b/src/gallium/state_trackers/egl/kms/native_kms.c
index d7e7b2bd7bd..27cf84e0fe7 100644
--- a/src/gallium/state_trackers/egl/kms/native_kms.c
+++ b/src/gallium/state_trackers/egl/kms/native_kms.c
@@ -28,6 +28,7 @@
#include "util/u_debug.h"
#include "util/u_memory.h"
#include "util/u_inlines.h"
+#include "util/u_pointer.h"
#include "util/u_string.h"
#include "egllog.h"
@@ -694,7 +695,27 @@ kms_display_init_screen(struct native_display *ndpy)
struct kms_display *kdpy = kms_display(ndpy);
int fd;
- fd = drmOpen(kdpy->api->driver_name, NULL);
+ fd = kdpy->fd;
+ if (fd >= 0) {
+ drmVersionPtr version = drmGetVersion(fd);
+ if (!version || strcmp(version->name, kdpy->api->driver_name)) {
+ if (version) {
+ _eglLog(_EGL_WARNING, "unknown driver name %s", version->name);
+ drmFreeVersion(version);
+ }
+ else {
+ _eglLog(_EGL_WARNING, "invalid fd %d", fd);
+ }
+
+ return FALSE;
+ }
+
+ drmFreeVersion(version);
+ }
+ else {
+ fd = drmOpen(kdpy->api->driver_name, NULL);
+ }
+
if (fd < 0) {
_eglLog(_EGL_WARNING, "failed to open DRM device");
return FALSE;
@@ -727,8 +748,7 @@ static struct native_display_modeset kms_display_modeset = {
};
static struct native_display *
-kms_create_display(EGLNativeDisplayType dpy,
- struct native_event_handler *event_handler,
+kms_create_display(int fd, struct native_event_handler *event_handler,
struct drm_api *api)
{
struct kms_display *kdpy;
@@ -746,7 +766,7 @@ kms_create_display(EGLNativeDisplayType dpy,
return NULL;
}
- kdpy->fd = -1;
+ kdpy->fd = fd;
if (!kms_display_init_screen(&kdpy->base)) {
kms_display_destroy(&kdpy->base);
return NULL;
@@ -818,12 +838,17 @@ native_create_display(EGLNativeDisplayType dpy,
struct native_event_handler *event_handler)
{
struct native_display *ndpy = NULL;
+ int fd;
if (!drm_api)
drm_api = drm_api_create();
- if (drm_api)
- ndpy = kms_create_display(dpy, event_handler, drm_api);
+ if (drm_api) {
+ /* well, this makes fd 0 being ignored */
+ fd = (dpy != EGL_DEFAULT_DISPLAY) ?
+ (int) pointer_to_intptr((void *) dpy) : -1;
+ ndpy = kms_create_display(fd, event_handler, drm_api);
+ }
return ndpy;
}