[cogl/wip/wayland-for-demo: 2/3] cogl-winsys-egl-kms: Add cogl_kms_renderer_set_kms_fd



commit b357422f823e7fea7ae49e868974bf94ed33a1b4
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Feb 28 09:40:31 2014 -0500

    cogl-winsys-egl-kms: Add cogl_kms_renderer_set_kms_fd

 cogl/cogl-kms-renderer.h          |   16 ++++++++++++++++
 cogl/cogl-renderer-private.h      |    4 ++++
 cogl/cogl-renderer.c              |    4 ++++
 cogl/winsys/cogl-winsys-egl-kms.c |   32 +++++++++++++++++++++++++-------
 4 files changed, 49 insertions(+), 7 deletions(-)
---
diff --git a/cogl/cogl-kms-renderer.h b/cogl/cogl-kms-renderer.h
index 0ade3fe..c2606f8 100644
--- a/cogl/cogl-kms-renderer.h
+++ b/cogl/cogl-kms-renderer.h
@@ -39,6 +39,22 @@
 COGL_BEGIN_DECLS
 
 /**
+ * cogl_kms_renderer_set_kms_fd:
+ * @renderer: A #CoglRenderer
+ * @fd: The fd to kms to use
+ *
+ * Sets the file descriptor Cogl should use to communicate
+ * to the kms driver. If -1 (the default), then Cogl will
+ * open its own FD by trying to open "/dev/dri/card0".
+ *
+ * Since: 1.18
+ * Stability: unstable
+ */
+void
+cogl_kms_renderer_set_kms_fd (CoglRenderer *renderer,
+                              int fd);
+
+/**
  * cogl_kms_renderer_get_kms_fd:
  * @renderer: A #CoglRenderer
  *
diff --git a/cogl/cogl-renderer-private.h b/cogl/cogl-renderer-private.h
index 77a3593..3871d91 100644
--- a/cogl/cogl-renderer-private.h
+++ b/cogl/cogl-renderer-private.h
@@ -88,6 +88,10 @@ struct _CoglRenderer
   CoglBool wayland_enable_event_dispatch;
 #endif
 
+#if defined (COGL_HAS_EGL_PLATFORM_KMS_SUPPORT)
+  int kms_fd;
+#endif
+
 #ifdef COGL_HAS_SDL_SUPPORT
   CoglBool sdl_event_type_set;
   uint32_t sdl_event_type;
diff --git a/cogl/cogl-renderer.c b/cogl/cogl-renderer.c
index b1d8c0b..5bb3fa0 100644
--- a/cogl/cogl-renderer.c
+++ b/cogl/cogl-renderer.c
@@ -303,6 +303,10 @@ cogl_renderer_new (void)
   renderer->wayland_enable_event_dispatch = TRUE;
 #endif
 
+#ifdef COGL_HAS_EGL_PLATFORM_KMS_SUPPORT
+  renderer->kms_fd = -1;
+#endif
+
   return _cogl_renderer_object_new (renderer);
 }
 
diff --git a/cogl/winsys/cogl-winsys-egl-kms.c b/cogl/winsys/cogl-winsys-egl-kms.c
index 4af9848..41954ef 100644
--- a/cogl/winsys/cogl-winsys-egl-kms.c
+++ b/cogl/winsys/cogl-winsys-egl-kms.c
@@ -285,14 +285,21 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
    * we're doing here... */
   g_setenv ("EGL_PLATFORM", "drm", 1);
 
-  kms_renderer->fd = open (device_name, O_RDWR);
-  if (kms_renderer->fd < 0)
+  if (renderer->kms_fd > 0)
     {
-      /* Probably permissions error */
-      _cogl_set_error (error, COGL_WINSYS_ERROR,
-                   COGL_WINSYS_ERROR_INIT,
-                   "Couldn't open %s", device_name);
-      return FALSE;
+      kms_renderer->fd = renderer->kms_fd;
+    }
+  else
+    {
+      kms_renderer->fd = open (device_name, O_RDWR);
+      if (kms_renderer->fd < 0)
+        {
+          /* Probably permissions error */
+          _cogl_set_error (error, COGL_WINSYS_ERROR,
+                           COGL_WINSYS_ERROR_INIT,
+                           "Couldn't open %s", device_name);
+          return FALSE;
+        }
     }
 
   kms_renderer->gbm = gbm_create_device (kms_renderer->fd);
@@ -1075,6 +1082,17 @@ _cogl_winsys_egl_kms_get_vtable (void)
   return &vtable;
 }
 
+void
+cogl_kms_renderer_set_kms_fd (CoglRenderer *renderer,
+                              int fd)
+{
+  _COGL_RETURN_IF_FAIL (cogl_is_renderer (renderer));
+  /* NB: Renderers are considered immutable once connected */
+  _COGL_RETURN_IF_FAIL (!renderer->connected);
+
+  renderer->kms_fd = fd;
+}
+
 int
 cogl_kms_renderer_get_kms_fd (CoglRenderer *renderer)
 {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]