commit 6b8e13e

Michael Forney  ·  2013-09-05 08:36:30 +0000 UTC
parent 06017f5
Don't automatically export DRM drawable to PRIME
6 files changed,  +37, -20
M drm.c
M drm.h
+2, -1
 1@@ -32,6 +32,7 @@ typedef void * (* drm_create_context_func_t)(int drm_fd);
 2 typedef void (* drm_destroy_context_func_t)(void * context);
 3 typedef struct drm_drawable * (* drm_create_drawable_func_t)
 4     (void * context, uint32_t width, uint32_t height, uint32_t format);
 5+typedef int (* drm_export_func_t)(struct drm_drawable * drawable);
 6 
 7 struct wld_drm_interface
 8 {
 9@@ -39,6 +40,7 @@ struct wld_drm_interface
10     drm_create_context_func_t create_context;
11     drm_destroy_context_func_t destroy_context;
12     drm_create_drawable_func_t create_drawable;
13+    drm_export_func_t export;
14 };
15 
16 struct wld_drm_context
17@@ -51,7 +53,6 @@ struct drm_drawable
18 {
19     struct wld_drawable base;
20     struct wld_drm_context * drm;
21-    int fd;
22 };
23 
24 _Static_assert(offsetof(struct drm_drawable, base) == 0,
M drm.c
+7, -0
 1@@ -130,3 +130,10 @@ struct wld_drawable * wld_drm_create_drawable(struct wld_drm_context * drm,
 2     return finish_drawable(drm, drawable);
 3 }
 4 
 5+int wld_drm_export(struct wld_drawable * drawable)
 6+{
 7+    struct drm_drawable * drm_drawable = (void *) drawable;
 8+
 9+    return drm_drawable->drm->interface->export(drm_drawable);
10+}
11+
M drm.h
+7, -0
 1@@ -46,5 +46,12 @@ struct wld_drawable * wld_drm_create_drawable(struct wld_drm_context * drm,
 2                                               uint32_t width, uint32_t height,
 3                                               uint32_t format);
 4 
 5+/**
 6+ * Export a DRM drawable to a PRIME file descriptor.
 7+ *
 8+ * @return A PRIME file descriptor for this drawable
 9+ */
10+int wld_drm_export(struct wld_drawable * drawable);
11+
12 #endif
13 
+12, -2
 1@@ -72,6 +72,7 @@ static bool intel_device_supported(uint32_t vendor_id, uint32_t device_id);
 2 static struct drm_drawable * intel_create_drawable
 3     (struct wld_intel_context * context, uint32_t width, uint32_t height,
 4      uint32_t format);
 5+static int intel_export(struct drm_drawable * drawable);
 6 
 7 const static struct wld_draw_interface intel_draw = {
 8     .fill_rectangle = &intel_fill_rectangle,
 9@@ -88,6 +89,7 @@ const struct wld_drm_interface intel_drm = {
10     .create_context = (drm_create_context_func_t) &intel_create_context,
11     .destroy_context = (drm_destroy_context_func_t) &intel_destroy_context,
12     .create_drawable = (drm_create_drawable_func_t) &intel_create_drawable,
13+    .export = (drm_export_func_t) &intel_export,
14 };
15 
16 bool intel_device_supported(uint32_t vendor_id, uint32_t device_id)
17@@ -136,11 +138,20 @@ struct drm_drawable * intel_create_drawable
18     intel->bo = drm_intel_bo_alloc_tiled(context->bufmgr, "drawable",
19                                          width, height, 4,
20                                          &tiling_mode, &intel->drm.base.pitch, 0);
21-    drm_intel_bo_gem_export_to_prime(intel->bo, &intel->drm.fd);
22 
23     return &intel->drm;
24 }
25 
26+int intel_export(struct drm_drawable * drawable)
27+{
28+    struct intel_drawable * intel = (void *) drawable;
29+    int prime_fd;
30+
31+    drm_intel_bo_gem_export_to_prime(intel->bo, &prime_fd);
32+
33+    return prime_fd;
34+}
35+
36 static void intel_fill_rectangle(struct wld_drawable * drawable, uint32_t color,
37                                  int32_t x, int32_t y,
38                                  uint32_t width, uint32_t height)
39@@ -245,7 +256,6 @@ static void intel_destroy(struct wld_drawable * drawable)
40 {
41     struct intel_drawable * intel = (void *) drawable;
42     drm_intel_bo_unreference(intel->bo);
43-    close(intel->drm.fd);
44     free(intel);
45 }
46 
+9, -10
 1@@ -192,29 +192,28 @@ struct wld_drawable * wld_wayland_drm_create_drawable
 2     (struct wld_wayland_drm_context * drm, uint32_t width, uint32_t height,
 3      enum wld_format format, struct wl_buffer ** buffer)
 4 {
 5-    struct drm_drawable * drawable;
 6+    struct wld_drawable * drawable;
 7 
 8     if (buffer && !wld_wayland_drm_has_format(drm, format))
 9         return NULL;
10 
11-    drawable = (void *) wld_drm_create_drawable(&drm->context, width, height, format);
12+    drawable = wld_drm_create_drawable(&drm->context, width, height, format);
13 
14     if (!drawable)
15         return NULL;
16 
17     if (buffer)
18     {
19-        *buffer = wl_drm_create_prime_buffer(drm->wl, drawable->fd,
20+        int prime_fd;
21+
22+        prime_fd = wld_drm_export(drawable);
23+        *buffer = wl_drm_create_prime_buffer(drm->wl, prime_fd,
24                                              width, height, format,
25-                                             0, drawable->base.pitch, 0, 0, 0, 0);
26+                                             0, drawable->pitch, 0, 0, 0, 0);
27+        close(prime_fd);
28     }
29 
30-    return &drawable->base;
31-}
32-
33-int wld_wayland_drm_get_prime_fd(struct wld_drawable * drawable)
34-{
35-    return ((struct drm_drawable *)(void *) drawable)->fd;
36+    return drawable;
37 }
38 
39 void registry_global(void * data, struct wl_registry * registry, uint32_t name,
+0, -7
 1@@ -67,12 +67,5 @@ struct wld_drawable * wld_wayland_drm_create_drawable
 2     (struct wld_wayland_drm_context * context, uint32_t width, uint32_t height,
 3      enum wld_format format, struct wl_buffer ** buffer);
 4 
 5-/**
 6- * Get a PRIME file descriptor for this DRM drawable.
 7- *
 8- * @note The drawable must have been created with wld_drm_create_drawable
 9- */
10-int wld_wayland_drm_get_prime_fd(struct wld_drawable * drawable);
11-
12 #endif
13