radeon/uvd: recalculate dbp buffer size
[mesa.git] / src / gallium / state_trackers / xa / xa_tracker.c
index 529279ad8659fd65e0b34a22bee96b56c25d37f3..21ca57ca633729fe8a7e76c5e84ef8c2b619d10b 100644 (file)
  * Thomas Hellstrom <thellstrom-at-vmware-dot-com>
  */
 
+#include <unistd.h>
 #include "xa_tracker.h"
 #include "xa_priv.h"
 #include "pipe/p_state.h"
 #include "pipe/p_format.h"
+#include "pipe-loader/pipe_loader.h"
 #include "state_tracker/drm_driver.h"
 #include "util/u_inlines.h"
 
@@ -133,17 +135,27 @@ xa_get_pipe_format(enum xa_formats xa_format)
     return fdesc;
 }
 
-struct xa_tracker *
+XA_EXPORT struct xa_tracker *
 xa_tracker_create(int drm_fd)
 {
     struct xa_tracker *xa = calloc(1, sizeof(struct xa_tracker));
     enum xa_surface_type stype;
     unsigned int num_formats;
+    int loader_fd;
 
     if (!xa)
        return NULL;
 
-    xa->screen = driver_descriptor.create_screen(drm_fd);
+#if GALLIUM_STATIC_TARGETS
+    xa->screen = dd_create_screen(drm_fd);
+    (void) loader_fd; /* silence unused var warning */
+#else
+    loader_fd = dup(drm_fd);
+    if (loader_fd == -1)
+        return NULL;
+    if (pipe_loader_drm_probe_fd(&xa->dev, loader_fd))
+       xa->screen = pipe_loader_create_screen(xa->dev, PIPE_SEARCH_DIR);
+#endif
     if (!xa->screen)
        goto out_no_screen;
 
@@ -190,16 +202,23 @@ xa_tracker_create(int drm_fd)
  out_no_pipe:
     xa->screen->destroy(xa->screen);
  out_no_screen:
+#if !GALLIUM_STATIC_TARGETS
+    if (xa->dev)
+       pipe_loader_release(&xa->dev, 1);
+#endif
     free(xa);
     return NULL;
 }
 
-void
+XA_EXPORT void
 xa_tracker_destroy(struct xa_tracker *xa)
 {
     free(xa->supported_formats);
     xa_context_destroy(xa->default_ctx);
     xa->screen->destroy(xa->screen);
+#if !GALLIUM_STATIC_TARGETS
+    pipe_loader_release(&xa->dev, 1);
+#endif
     free(xa);
 }
 
@@ -254,7 +273,7 @@ xa_get_format_stype_depth(struct xa_tracker *xa,
     return fdesc;
 }
 
-int
+XA_EXPORT int
 xa_format_check_supported(struct xa_tracker *xa,
                          enum xa_formats xa_format, unsigned int flags)
 {
@@ -279,13 +298,14 @@ xa_format_check_supported(struct xa_tracker *xa,
     return XA_ERR_NONE;
 }
 
-struct xa_surface *
-xa_surface_create(struct xa_tracker *xa,
+static struct xa_surface *
+surface_create(struct xa_tracker *xa,
                  int width,
                  int height,
                  int depth,
                  enum xa_surface_type stype,
-                 enum xa_formats xa_format, unsigned int flags)
+                 enum xa_formats xa_format, unsigned int flags,
+                 struct winsys_handle *whandle)
 {
     struct pipe_resource *template;
     struct xa_surface *srf;
@@ -320,10 +340,14 @@ xa_surface_create(struct xa_tracker *xa,
     if (flags & XA_FLAG_SCANOUT)
        template->bind |= PIPE_BIND_SCANOUT;
 
-    srf->tex = xa->screen->resource_create(xa->screen, template);
+    if (whandle)
+       srf->tex = xa->screen->resource_from_handle(xa->screen, template, whandle);
+    else
+       srf->tex = xa->screen->resource_create(xa->screen, template);
     if (!srf->tex)
        goto out_no_tex;
 
+    srf->refcount = 1;
     srf->xa = xa;
     srf->flags = flags;
     srf->fdesc = fdesc;
@@ -334,7 +358,37 @@ xa_surface_create(struct xa_tracker *xa,
     return NULL;
 }
 
-int
+
+XA_EXPORT struct xa_surface *
+xa_surface_create(struct xa_tracker *xa,
+                 int width,
+                 int height,
+                 int depth,
+                 enum xa_surface_type stype,
+                 enum xa_formats xa_format, unsigned int flags)
+{
+    return surface_create(xa, width, height, depth, stype, xa_format, flags, NULL);
+}
+
+
+XA_EXPORT struct xa_surface *
+xa_surface_from_handle(struct xa_tracker *xa,
+                 int width,
+                 int height,
+                 int depth,
+                 enum xa_surface_type stype,
+                 enum xa_formats xa_format, unsigned int flags,
+                 uint32_t handle, uint32_t stride)
+{
+    struct winsys_handle whandle;
+    memset(&whandle, 0, sizeof(whandle));
+    whandle.type = DRM_API_HANDLE_TYPE_SHARED;
+    whandle.handle = handle;
+    whandle.stride = stride;
+    return surface_create(xa, width, height, depth, stype, xa_format, flags, &whandle);
+}
+
+XA_EXPORT int
 xa_surface_redefine(struct xa_surface *srf,
                    int width,
                    int height,
@@ -407,7 +461,7 @@ xa_surface_redefine(struct xa_surface *srf,
                        xa_min(save_height, template->height0), &src_box);
        pipe->resource_copy_region(pipe, texture,
                                   0, 0, 0, 0, srf->tex, 0, &src_box);
-       pipe->flush(pipe, &xa->default_ctx->last_fence);
+       xa_context_flush(xa->default_ctx);
     }
 
     pipe_resource_reference(&srf->tex, texture);
@@ -418,14 +472,27 @@ xa_surface_redefine(struct xa_surface *srf,
     return XA_ERR_NONE;
 }
 
-void
-xa_surface_destroy(struct xa_surface *srf)
+XA_EXPORT struct xa_surface*
+xa_surface_ref(struct xa_surface *srf)
+{
+    if (srf == NULL) {
+       return NULL;
+    }
+    srf->refcount++;
+    return srf;
+}
+
+XA_EXPORT void
+xa_surface_unref(struct xa_surface *srf)
 {
+    if (srf == NULL || --srf->refcount) {
+       return;
+    }
     pipe_resource_reference(&srf->tex, NULL);
     free(srf);
 }
 
-extern void
+XA_EXPORT void
 xa_tracker_version(int *major, int *minor, int *patch)
 {
     *major = XA_TRACKER_VERSION_MAJOR;
@@ -433,8 +500,9 @@ xa_tracker_version(int *major, int *minor, int *patch)
     *patch = XA_TRACKER_VERSION_PATCH;
 }
 
-extern int
+XA_EXPORT int
 xa_surface_handle(struct xa_surface *srf,
+                 enum xa_handle_type type,
                  uint32_t * handle, unsigned int *stride)
 {
     struct winsys_handle whandle;
@@ -443,7 +511,15 @@ xa_surface_handle(struct xa_surface *srf,
     boolean res;
 
     memset(&whandle, 0, sizeof(whandle));
-    whandle.type = DRM_API_HANDLE_TYPE_SHARED;
+    switch (type) {
+    case xa_handle_type_kms:
+       whandle.type = DRM_API_HANDLE_TYPE_KMS;
+       break;
+    case xa_handle_type_shared:
+    default:
+       whandle.type = DRM_API_HANDLE_TYPE_SHARED;
+       break;
+    }
     res = screen->resource_get_handle(screen, srf->tex, &whandle);
     if (!res)
        return -XA_ERR_INVAL;
@@ -454,7 +530,7 @@ xa_surface_handle(struct xa_surface *srf,
     return XA_ERR_NONE;
 }
 
-enum xa_formats
+XA_EXPORT enum xa_formats
 xa_surface_format(const struct xa_surface *srf)
 {
     return srf->fdesc.xa_format;