gallium: add type parameter to create_fence_fd
[mesa.git] / src / gallium / state_trackers / dri / dri_helpers.c
index 07c4086310da298fbf29ef9854aa6bab894598df..f1501bfb81531944df51cca21ac2c50c0979be97 100644 (file)
@@ -25,6 +25,7 @@
 #include "pipe/p_screen.h"
 #include "state_tracker/st_texture.h"
 #include "state_tracker/st_context.h"
+#include "state_tracker/st_cb_fbo.h"
 #include "main/texobj.h"
 
 #include "dri_helpers.h"
@@ -89,13 +90,13 @@ static unsigned dri2_fence_get_caps(__DRIscreen *_screen)
 static void *
 dri2_create_fence(__DRIcontext *_ctx)
 {
-   struct pipe_context *ctx = dri_context(_ctx)->st->pipe;
+   struct st_context_iface *stapi = dri_context(_ctx)->st;
    struct dri2_fence *fence = CALLOC_STRUCT(dri2_fence);
 
    if (!fence)
       return NULL;
 
-   ctx->flush(ctx, &fence->pipe_fence, 0);
+   stapi->flush(stapi, 0, &fence->pipe_fence);
 
    if (!fence->pipe_fence) {
       FREE(fence);
@@ -109,16 +110,16 @@ dri2_create_fence(__DRIcontext *_ctx)
 static void *
 dri2_create_fence_fd(__DRIcontext *_ctx, int fd)
 {
-   struct pipe_context *ctx = dri_context(_ctx)->st->pipe;
+   struct st_context_iface *stapi = dri_context(_ctx)->st;
+   struct pipe_context *ctx = stapi->pipe;
    struct dri2_fence *fence = CALLOC_STRUCT(dri2_fence);
 
    if (fd == -1) {
       /* exporting driver created fence, flush: */
-      ctx->flush(ctx, &fence->pipe_fence,
-                 PIPE_FLUSH_DEFERRED | PIPE_FLUSH_FENCE_FD);
+      stapi->flush(stapi, ST_FLUSH_FENCE_FD, &fence->pipe_fence);
    } else {
       /* importing a foreign fence fd: */
-      ctx->create_fence_fd(ctx, &fence->pipe_fence, fd);
+      ctx->create_fence_fd(ctx, &fence->pipe_fence, fd, PIPE_FD_TYPE_NATIVE_SYNC);
    }
    if (!fence->pipe_fence) {
       FREE(fence);
@@ -246,16 +247,68 @@ dri2_lookup_egl_image(struct dri_screen *screen, void *handle)
 }
 
 __DRIimage *
-dri2_create_image_from_renderbuffer(__DRIcontext *context,
-                                   int renderbuffer, void *loaderPrivate)
+dri2_create_image_from_renderbuffer2(__DRIcontext *context,
+                                    int renderbuffer, void *loaderPrivate,
+                                     unsigned *error)
 {
-   struct dri_context *ctx = dri_context(context);
+   struct gl_context *ctx = ((struct st_context *)dri_context(context)->st)->ctx;
+   struct gl_renderbuffer *rb;
+   struct pipe_resource *tex;
+   __DRIimage *img;
+
+   /* Section 3.9 (EGLImage Specification and Management) of the EGL 1.5
+    * specification says:
+    *
+    *   "If target is EGL_GL_RENDERBUFFER and buffer is not the name of a
+    *    renderbuffer object, or if buffer is the name of a multisampled
+    *    renderbuffer object, the error EGL_BAD_PARAMETER is generated."
+    *
+    *   "If target is EGL_GL_TEXTURE_2D , EGL_GL_TEXTURE_CUBE_MAP_*,
+    *    EGL_GL_RENDERBUFFER or EGL_GL_TEXTURE_3D and buffer refers to the
+    *    default GL texture object (0) for the corresponding GL target, the
+    *    error EGL_BAD_PARAMETER is generated."
+    *   (rely on _mesa_lookup_renderbuffer returning NULL in this case)
+    */
+   rb = _mesa_lookup_renderbuffer(ctx, renderbuffer);
+   if (!rb || rb->NumSamples > 0) {
+      *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
+      return NULL;
+   }
+
+   tex = st_get_renderbuffer_resource(rb);
+   if (!tex) {
+      *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
+      return NULL;
+   }
+
+   img = CALLOC_STRUCT(__DRIimageRec);
+   if (!img) {
+      *error = __DRI_IMAGE_ERROR_BAD_ALLOC;
+      return NULL;
+   }
+
+   img->dri_format = driGLFormatToImageFormat(rb->Format);
+   img->loader_private = loaderPrivate;
 
-   if (!ctx->st->get_resource_for_egl_image)
+   if (img->dri_format == __DRI_IMAGE_FORMAT_NONE) {
+      *error = __DRI_IMAGE_ERROR_BAD_PARAMETER;
+      free(img);
       return NULL;
+   }
 
-   /* TODO */
-   return NULL;
+   pipe_resource_reference(&img->texture, tex);
+
+   *error = __DRI_IMAGE_ERROR_SUCCESS;
+   return img;
+}
+
+__DRIimage *
+dri2_create_image_from_renderbuffer(__DRIcontext *context,
+                                   int renderbuffer, void *loaderPrivate)
+{
+   unsigned error;
+   return dri2_create_image_from_renderbuffer2(context, renderbuffer,
+                                               loaderPrivate, &error);
 }
 
 void