commit feee7c0

Michael Forney  ·  2013-06-14 10:12:12 +0000 UTC
parent cfc3346
Remove horrible workaround for getting drm handles
4 files changed,  +30, -56
+2, -1
 1@@ -313,7 +313,8 @@ bool swc_compositor_initialize(struct swc_compositor * compositor,
 2         goto error_gbm;
 3     }
 4 
 5-    if (!swc_renderer_initialize(&compositor->renderer, &compositor->drm))
 6+    if (!swc_renderer_initialize(&compositor->renderer, &compositor->drm,
 7+                                 compositor->gbm))
 8     {
 9         printf("could not initialize renderer\n");
10         goto error_egl;
+25, -53
  1@@ -5,45 +5,8 @@
  2 #include <stdio.h>
  3 #include <GLES2/gl2.h>
  4 #include <libdrm/intel_bufmgr.h>
  5-
  6-struct wl_drm_buffer
  7-{
  8-    struct wl_buffer buffer;
  9-    struct wl_drm * drm;
 10-    uint32_t format;
 11-    const void * driver_format;
 12-    int32_t offset[3];
 13-    int32_t stride[3];
 14-    void * driver_buffer;
 15-};
 16-
 17-struct __DRIimageRec
 18-{
 19-    struct intel_region * region;
 20-    GLenum internal_format;
 21-    uint32_t dri_format;
 22-    GLuint format;
 23-    uint32_t offset;
 24-    uint32_t strides[3];
 25-    uint32_t offsets[3];
 26-    struct intel_image_format * planar_format;
 27-    void * data;
 28-};
 29-
 30-struct intel_region
 31-{
 32-    drm_intel_bo * bo;
 33-    GLuint refcount;
 34-    GLuint cpp;
 35-    GLuint width;
 36-    GLuint height;
 37-    GLuint pitch;
 38-    GLubyte * map;
 39-    GLuint map_refcount;
 40-    uint32_t tiling;
 41-    uint32_t name;
 42-    struct intel_screen * screen;
 43-};
 44+#include <libdrm/drm.h>
 45+#include <xf86drm.h>
 46 
 47 static inline uint32_t format_wayland_to_pixman(uint32_t wayland_format)
 48 {
 49@@ -93,9 +56,11 @@ static void repaint_surface_for_output(struct swc_renderer * renderer,
 50 }
 51 
 52 bool swc_renderer_initialize(struct swc_renderer * renderer,
 53-                             struct swc_drm * drm)
 54+                             struct swc_drm * drm,
 55+                             struct gbm_device * gbm)
 56 {
 57     renderer->drm = drm;
 58+    renderer->gbm = gbm;
 59 
 60     intel_batch_initialize(&renderer->batch, drm->bufmgr);
 61 
 62@@ -137,6 +102,9 @@ void swc_renderer_attach(struct swc_renderer * renderer,
 63                          struct swc_surface * surface,
 64                          struct wl_buffer * buffer)
 65 {
 66+    struct gbm_bo * bo;
 67+
 68+    /* SHM buffer */
 69     if (wl_buffer_is_shm(buffer))
 70     {
 71         struct swc_output * output;
 72@@ -158,24 +126,28 @@ void swc_renderer_attach(struct swc_renderer * renderer,
 73             }
 74         }
 75     }
 76-    else
 77+    /* DRM buffer */
 78+    else if ((bo = gbm_bo_import(renderer->gbm, GBM_BO_IMPORT_WL_BUFFER, buffer,
 79+                                 GBM_BO_USE_RENDERING)))
 80     {
 81-        struct wl_drm_buffer * drm_buffer = (void *) surface->state.buffer;
 82-        struct __DRIimageRec * image = drm_buffer->driver_buffer;
 83-        struct intel_region * region = image->region;
 84-        drm_intel_bo * bo = region->bo;
 85+        int handle = gbm_bo_get_handle(bo).s32;
 86+        struct drm_gem_flink flink = { .handle = handle };
 87+
 88+        if (drmIoctl(renderer->drm->fd, DRM_IOCTL_GEM_FLINK, &flink) != 0)
 89+        {
 90+            printf("could not flink handle\n");
 91+            return;
 92+        }
 93 
 94         surface->renderer_state.drm.bo
 95             = drm_intel_bo_gem_create_from_name(renderer->drm->bufmgr,
 96-                                                "surface", region->name);
 97-
 98-        surface->renderer_state.drm.pitch = region->pitch;
 99-
100-        printf("buffer width: %u, height: %u\n", buffer->width, buffer->height);
101+                                                "surface", flink.name);
102+        surface->renderer_state.drm.pitch = gbm_bo_get_stride(bo);
103+        surface->renderer_state.drm.width = gbm_bo_get_width(bo);
104+        surface->renderer_state.drm.height = gbm_bo_get_height(bo);
105 
106-        printf("bo width: %u, height: %u, stride: %u, handle: %u\n",
107-               region->width, region->height,
108-               region->pitch, bo->handle);
109+        printf("pitch: %u, width: %u, height: %u\n", surface->renderer_state.drm.pitch,
110+            surface->renderer_state.drm.width, surface->renderer_state.drm.height);
111     }
112 }
113 
+2, -1
 1@@ -9,12 +9,13 @@
 2 struct swc_renderer
 3 {
 4     struct swc_drm * drm;
 5+    struct gbm_device * gbm;
 6 
 7     struct intel_batch batch;
 8 };
 9 
10 bool swc_renderer_initialize(struct swc_renderer * renderer,
11-                             struct swc_drm * drm);
12+                             struct swc_drm * drm, struct gbm_device * gbm);
13 
14 void swc_renderer_finalize(struct swc_renderer * renderer);
15 
+1, -1
1@@ -15,7 +15,7 @@ union swc_renderer_surface_state
2     struct
3     {
4         drm_intel_bo * bo;
5-        uint32_t pitch;
6+        uint32_t width, height, pitch;
7     } drm;
8 };
9