[cogl/cogl-1.18] cogl-winsys-egl-kms: Add cogl_kms_renderer_set_kms_fd



commit 0d91085193bb380ea28bdf5f3e30c2195569310a
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
    
    Reviewed-by: Neil Roberts <neil linux intel com>
    (cherry picked from commit 7bc7ea4cb5e8134a3aeed9615477f4152b558509)
    
    Conflicts:
        cogl/winsys/cogl-winsys-egl-kms.c

 cogl/cogl-kms-renderer.h          |   16 ++++++++++++++
 cogl/cogl-renderer-private.h      |    4 +++
 cogl/cogl-renderer.c              |    4 +++
 cogl/winsys/cogl-winsys-egl-kms.c |   40 +++++++++++++++++++++++++++++-------
 4 files changed, 56 insertions(+), 8 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..3c5460e 100644
--- a/cogl/winsys/cogl-winsys-egl-kms.c
+++ b/cogl/winsys/cogl-winsys-egl-kms.c
@@ -69,6 +69,7 @@ static const CoglWinsysVtable *parent_vtable;
 typedef struct _CoglRendererKMS
 {
   int fd;
+  int opened_fd;
   struct gbm_device *gbm;
   CoglClosure *swap_notify_idle;
 } CoglRendererKMS;
@@ -285,14 +286,25 @@ _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)
+  kms_renderer->fd = -1;
+  kms_renderer->opened_fd = -1;
+
+  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->opened_fd = open (device_name, O_RDWR);
+      kms_renderer->fd = kms_renderer->opened_fd;
+      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);
@@ -330,7 +342,8 @@ egl_terminate:
 destroy_gbm_device:
   gbm_device_destroy (kms_renderer->gbm);
 close_fd:
-  close (kms_renderer->fd);
+  if (kms_renderer->opened_fd >= 0)
+    close (kms_renderer->opened_fd);
 
   _cogl_winsys_renderer_disconnect (renderer);
 
@@ -1075,6 +1088,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]