r300g: Conversion to to winsys handle
authorJakob Bornecrantz <jakob@vmware.com>
Mon, 1 Mar 2010 15:11:39 +0000 (15:11 +0000)
committerJakob Bornecrantz <jakob@vmware.com>
Mon, 1 Mar 2010 16:05:59 +0000 (16:05 +0000)
src/gallium/drivers/r300/r300_texture.c
src/gallium/winsys/drm/radeon/core/radeon_buffer.c
src/gallium/winsys/drm/radeon/core/radeon_drm.c
src/gallium/winsys/drm/radeon/core/radeon_drm.h
src/gallium/winsys/drm/radeon/core/radeon_winsys.h

index 2246c75056cc80204d273f242319e6becbef6c0f..3b39207a4555825af3ea83ea7f547ad9bf03c3da 100644 (file)
@@ -848,6 +848,70 @@ static struct pipe_texture*
     return (struct pipe_texture*)tex;
 }
 
+static struct pipe_texture*
+    r300_texture_from_handle(struct pipe_screen* screen,
+                             const struct pipe_texture* base,
+                             struct winsys_handle *whandle)
+{
+    struct radeon_winsys* winsys = (struct radeon_winsys*)screen->winsys;
+    struct r300_screen* rscreen = r300_screen(screen);
+    struct pipe_buffer *buffer;
+    struct r300_texture* tex;
+    unsigned stride;
+
+    /* Support only 2D textures without mipmaps */
+    if (base->target != PIPE_TEXTURE_2D ||
+        base->depth0 != 1 ||
+        base->last_level != 0) {
+        return NULL;
+    }
+
+    buffer = winsys->buffer_from_handle(winsys, screen, whandle, &stride);
+    if (!buffer) {
+        return NULL;
+    }
+
+    tex = CALLOC_STRUCT(r300_texture);
+    if (!tex) {
+        return NULL;
+    }
+
+    tex->tex = *base;
+    pipe_reference_init(&tex->tex.reference, 1);
+    tex->tex.screen = screen;
+
+    tex->stride_override = stride;
+    tex->pitch[0] = stride / util_format_get_blocksize(base->format);
+
+    r300_setup_flags(tex);
+    r300_setup_texture_state(rscreen, tex);
+
+    /* one ref already taken */
+    tex->buffer = buffer;
+
+    return (struct pipe_texture*)tex;
+}
+
+static boolean
+    r300_texture_get_handle(struct pipe_screen* screen,
+                            struct pipe_texture *texture,
+                            struct winsys_handle *whandle)
+{
+    struct radeon_winsys* winsys = (struct radeon_winsys*)screen->winsys;
+    struct r300_texture* tex = (struct r300_texture*)texture;
+    unsigned stride;
+
+    if (!tex) {
+        return FALSE;
+    }
+
+    stride = r300_texture_get_stride(r300_screen(screen), tex, 0);
+
+    winsys->buffer_get_handle(winsys, tex->buffer, stride, whandle);
+
+    return TRUE;
+}
+
 static struct pipe_video_surface *
 r300_video_surface_create(struct pipe_screen *screen,
                           enum pipe_video_chroma_format chroma_format,
@@ -899,6 +963,8 @@ static void r300_video_surface_destroy(struct pipe_video_surface *vsfc)
 void r300_init_screen_texture_functions(struct pipe_screen* screen)
 {
     screen->texture_create = r300_texture_create;
+    screen->texture_from_handle = r300_texture_from_handle;
+    screen->texture_get_handle = r300_texture_get_handle;
     screen->texture_destroy = r300_texture_destroy;
     screen->get_tex_surface = r300_get_tex_surface;
     screen->tex_surface_destroy = r300_tex_surface_destroy;
index e5c69199330214d646132ab91b0fd5aae8007285..daa032af6f2c7ba2aae489c13bd70869fde8f98e 100644 (file)
@@ -264,6 +264,75 @@ static int radeon_fence_finish(struct pipe_winsys *ws,
     return 0;
 }
 
+/* Create a buffer from a handle. */
+static struct pipe_buffer* radeon_buffer_from_handle(struct radeon_winsys *radeon_ws,
+                                                     struct pipe_screen *screen,
+                                                     struct winsys_handle *whandle,
+                                                     unsigned *stride)
+{
+    struct radeon_bo_manager* bom = radeon_ws->priv->bom;
+    struct radeon_pipe_buffer* radeon_buffer;
+    struct radeon_bo* bo = NULL;
+
+    bo = radeon_bo_open(bom, whandle->handle, 0, 0, 0, 0);
+    if (bo == NULL) {
+        return NULL;
+    }
+
+    radeon_buffer = CALLOC_STRUCT(radeon_pipe_buffer);
+    if (radeon_buffer == NULL) {
+        radeon_bo_unref(bo);
+        return NULL;
+    }
+
+    pipe_reference_init(&radeon_buffer->base.reference, 1);
+    radeon_buffer->base.screen = screen;
+    radeon_buffer->base.usage = PIPE_BUFFER_USAGE_PIXEL;
+    radeon_buffer->bo = bo;
+
+    *stride = whandle->stride;
+
+    return &radeon_buffer->base;
+}
+
+static boolean radeon_buffer_get_handle(struct radeon_winsys *radeon_ws,
+                                        struct pipe_buffer *buffer,
+                                        unsigned stride,
+                                        struct winsys_handle *whandle)
+{
+    int retval, fd;
+    struct drm_gem_flink flink;
+    struct radeon_pipe_buffer* radeon_buffer;
+
+    radeon_buffer = (struct radeon_pipe_buffer*)buffer;
+
+
+    if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) {
+        if (!radeon_buffer->flinked) {
+            fd = radeon_ws->priv->fd;
+
+            flink.handle = radeon_buffer->bo->handle;
+
+            retval = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
+            if (retval) {
+                debug_printf("radeon: DRM_IOCTL_GEM_FLINK failed, error %d\n",
+                             retval);
+                return FALSE;
+            }
+
+            radeon_buffer->flink = flink.name;
+            radeon_buffer->flinked = TRUE;
+        }
+
+        whandle->handle = radeon_buffer->flink;
+    } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) {
+        whandle->handle = ((struct radeon_pipe_buffer*)buffer)->bo->handle;
+    }
+    whandle->stride = stride;
+
+    return TRUE;
+}
+
 struct radeon_winsys* radeon_pipe_winsys(int fd)
 {
     struct radeon_winsys* radeon_ws;
@@ -298,6 +367,8 @@ struct radeon_winsys* radeon_pipe_winsys(int fd)
     radeon_ws->base.get_name = radeon_get_name;
 
     radeon_ws->buffer_set_tiling = radeon_buffer_set_tiling;
+    radeon_ws->buffer_from_handle = radeon_buffer_from_handle;
+    radeon_ws->buffer_get_handle = radeon_buffer_get_handle;
 
     return radeon_ws;
 }
index e817a26da6ddca926a097271e35bb66be9f83698..97edb6a47e395a847d48b1668ba16727d3a4d854 100644 (file)
@@ -148,124 +148,6 @@ struct pipe_screen* radeon_create_screen(struct drm_api* api,
     }
 }
 
-
-boolean radeon_buffer_from_texture(struct drm_api* api,
-                                   struct pipe_screen* screen,
-                                   struct pipe_texture* texture,
-                                   struct pipe_buffer** buffer,
-                                   unsigned* stride)
-{
-    /* XXX fix this */
-    return r300_get_texture_buffer(screen, texture, buffer, stride);
-}
-
-/* Create a buffer from a handle. */
-/* XXX what's up with name? */
-struct pipe_buffer* radeon_buffer_from_handle(struct drm_api* api,
-                                              struct pipe_screen* screen,
-                                              const char* name,
-                                              unsigned handle)
-{
-    struct radeon_bo_manager* bom =
-        ((struct radeon_winsys*)screen->winsys)->priv->bom;
-    struct radeon_pipe_buffer* radeon_buffer;
-    struct radeon_bo* bo = NULL;
-
-    bo = radeon_bo_open(bom, handle, 0, 0, 0, 0);
-    if (bo == NULL) {
-        return NULL;
-    }
-
-    radeon_buffer = CALLOC_STRUCT(radeon_pipe_buffer);
-    if (radeon_buffer == NULL) {
-        radeon_bo_unref(bo);
-        return NULL;
-    }
-
-    pipe_reference_init(&radeon_buffer->base.reference, 1);
-    radeon_buffer->base.screen = screen;
-    radeon_buffer->base.usage = PIPE_BUFFER_USAGE_PIXEL;
-    radeon_buffer->bo = bo;
-    return &radeon_buffer->base;
-}
-
-static struct pipe_texture*
-radeon_texture_from_shared_handle(struct drm_api *api,
-                                  struct pipe_screen *screen,
-                                  struct pipe_texture *templ,
-                                  const char *name,
-                                  unsigned stride,
-                                  unsigned handle)
-{
-    struct pipe_buffer *buffer;
-    struct pipe_texture *blanket;
-
-    buffer = radeon_buffer_from_handle(api, screen, name, handle);
-    if (!buffer) {
-        return NULL;
-    }
-
-    blanket = screen->texture_blanket(screen, templ, &stride, buffer);
-
-    pipe_buffer_reference(&buffer, NULL);
-
-    return blanket;
-}
-
-static boolean radeon_shared_handle_from_texture(struct drm_api *api,
-                                                 struct pipe_screen *screen,
-                                                 struct pipe_texture *texture,
-                                                 unsigned *stride,
-                                                 unsigned *handle)
-{
-    int retval, fd;
-    struct drm_gem_flink flink;
-    struct radeon_pipe_buffer* radeon_buffer;
-    struct pipe_buffer *buffer = NULL;
-
-    if (!radeon_buffer_from_texture(api, screen, texture, &buffer, stride)) {
-        return FALSE;
-    }
-
-    radeon_buffer = (struct radeon_pipe_buffer*)buffer;
-    if (!radeon_buffer->flinked) {
-        fd = ((struct radeon_winsys*)screen->winsys)->priv->fd;
-
-        flink.handle = radeon_buffer->bo->handle;
-
-        retval = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
-        if (retval) {
-            debug_printf("radeon: DRM_IOCTL_GEM_FLINK failed, error %d\n",
-                    retval);
-            return FALSE;
-        }
-
-        radeon_buffer->flink = flink.name;
-        radeon_buffer->flinked = TRUE;
-    }
-
-    *handle = radeon_buffer->flink;
-    return TRUE;
-}
-
-static boolean radeon_local_handle_from_texture(struct drm_api *api,
-                                                struct pipe_screen *screen,
-                                                struct pipe_texture *texture,
-                                                unsigned *stride,
-                                                unsigned *handle)
-{
-    struct pipe_buffer *buffer = NULL;
-    if (!radeon_buffer_from_texture(api, screen, texture, &buffer, stride)) {
-        return FALSE;
-    }
-
-    *handle = ((struct radeon_pipe_buffer*)buffer)->bo->handle;
-
-    pipe_buffer_reference(&buffer, NULL);
-
-    return TRUE;
-}
-
 static void radeon_drm_api_destroy(struct drm_api *api)
 {
     return;
@@ -275,9 +157,6 @@ struct drm_api drm_api_hooks = {
     .name = "radeon",
     .driver_name = "radeon",
     .create_screen = radeon_create_screen,
-    .texture_from_shared_handle = radeon_texture_from_shared_handle,
-    .shared_handle_from_texture = radeon_shared_handle_from_texture,
-    .local_handle_from_texture = radeon_local_handle_from_texture,
     .destroy = radeon_drm_api_destroy,
 };
 
index f62a9b80485dab8c62e44ae91adc333efd767048..78451b6f011c0f11cefb6655b723d5ba3c6d9025 100644 (file)
@@ -37,28 +37,6 @@ struct pipe_screen* radeon_create_screen(struct drm_api* api,
                                          int drmFB,
                                         struct drm_create_screen_arg *arg);
 
-
-boolean radeon_buffer_from_texture(struct drm_api* api,
-                                   struct pipe_screen* screen,
-                                   struct pipe_texture* texture,
-                                   struct pipe_buffer** buffer,
-                                   unsigned* stride);
-
-struct pipe_buffer* radeon_buffer_from_handle(struct drm_api* api,
-                                              struct pipe_screen* screen,
-                                              const char* name,
-                                              unsigned handle);
-
-boolean radeon_handle_from_buffer(struct drm_api* api,
-                                  struct pipe_screen* screen,
-                                  struct pipe_buffer* buffer,
-                                  unsigned* handle);
-
-boolean radeon_global_handle_from_buffer(struct drm_api* api,
-                                         struct pipe_screen* screen,
-                                         struct pipe_buffer* buffer,
-                                         unsigned* handle);
-
 void radeon_destroy_drm_api(struct drm_api* api);
 
 /* Guess at whether this chipset should use r300g.
index 4901080ca7be5f6a5e8a152e7e3ec3729e4b9d1b..37eeb459791ac1aacb489218426fb2feb01fb85e 100644 (file)
@@ -56,6 +56,18 @@ struct radeon_winsys {
     /* VRAM size. */
     uint32_t vram_size;
 
+    /* Create a buffer from a winsys handle. */
+    struct pipe_buffer *(*buffer_from_handle)(struct radeon_winsys *winsys,
+                                              struct pipe_screen *screen,
+                                              struct winsys_handle *whandle,
+                                              unsigned *stride);
+
+    /* Get the handle from a buffer. */
+    boolean (*buffer_get_handle)(struct radeon_winsys *winsys,
+                                 struct pipe_buffer *buffer,
+                                 unsigned stride,
+                                 struct winsys_handle *whandle);
+
     /* Add a pipe_buffer to the list of buffer objects to validate. */
     boolean (*add_buffer)(struct radeon_winsys* winsys,
                           struct pipe_buffer* pbuffer,