Merge remote branch 'origin/master' into nv50-compiler
[mesa.git] / src / gallium / state_trackers / dri / drm / dri2.c
index e1216f14c0e7718883e233d19f0bc2c1421a779e..47005c17e2bd600ee370a43db5cf9458701a7abb 100644 (file)
 #include "util/u_inlines.h"
 #include "util/u_format.h"
 #include "util/u_debug.h"
-#include "state_tracker/drm_api.h"
+#include "state_tracker/drm_driver.h"
 
 #include "dri_screen.h"
 #include "dri_context.h"
 #include "dri_drawable.h"
-#include "dri2.h"
-
-#include "GL/internal/dri_interface.h"
 
 /**
  * DRI2 flush extension.
@@ -69,86 +66,6 @@ static const __DRI2flushExtension dri2FlushExtension = {
     dri2_invalidate_drawable,
 };
 
-/**
- * These are used for GLX_EXT_texture_from_pixmap
- */
-static void
-dri2_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target,
-                     GLint format, __DRIdrawable *dPriv)
-{
-   struct dri_context *ctx = dri_context(pDRICtx);
-   struct dri_drawable *drawable = dri_drawable(dPriv);
-   struct pipe_resource *pt;
-
-   dri_drawable_validate_att(drawable, ST_ATTACHMENT_FRONT_LEFT);
-
-   pt = drawable->textures[ST_ATTACHMENT_FRONT_LEFT];
-
-   if (pt) {
-      enum pipe_format internal_format = pt->format;
-
-      if (format == __DRI_TEXTURE_FORMAT_RGB)  {
-         /* only need to cover the formats recognized by dri_fill_st_visual */
-         switch (internal_format) {
-         case PIPE_FORMAT_B8G8R8A8_UNORM:
-            internal_format = PIPE_FORMAT_B8G8R8X8_UNORM;
-            break;
-         case PIPE_FORMAT_A8R8G8B8_UNORM:
-            internal_format = PIPE_FORMAT_X8R8G8B8_UNORM;
-            break;
-         default:
-            break;
-         }
-      }
-
-      ctx->st->teximage(ctx->st,
-            (target == GL_TEXTURE_2D) ? ST_TEXTURE_2D : ST_TEXTURE_RECT,
-            0, internal_format, pt, FALSE);
-   }
-}
-
-static void
-dri2_set_tex_buffer(__DRIcontext *pDRICtx, GLint target,
-                    __DRIdrawable *dPriv)
-{
-   dri2_set_tex_buffer2(pDRICtx, target, __DRI_TEXTURE_FORMAT_RGBA, dPriv);
-}
-
-static const __DRItexBufferExtension dri2TexBufferExtension = {
-    { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
-   dri2_set_tex_buffer,
-   dri2_set_tex_buffer2,
-};
-
-/**
- * Get the format and binding of an attachment.
- */
-static INLINE void
-dri2_drawable_get_format(struct dri_drawable *drawable,
-                         enum st_attachment_type statt,
-                         enum pipe_format *format,
-                         unsigned *bind)
-{
-   switch (statt) {
-   case ST_ATTACHMENT_FRONT_LEFT:
-   case ST_ATTACHMENT_BACK_LEFT:
-   case ST_ATTACHMENT_FRONT_RIGHT:
-   case ST_ATTACHMENT_BACK_RIGHT:
-      *format = drawable->stvis.color_format;
-      *bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
-      break;
-   case ST_ATTACHMENT_DEPTH_STENCIL:
-      *format = drawable->stvis.depth_stencil_format;
-      *bind = PIPE_BIND_DEPTH_STENCIL; /* XXX sampler? */
-      break;
-   default:
-      *format = PIPE_FORMAT_NONE;
-      *bind = 0;
-      break;
-   }
-}
-
-
 /**
  * Retrieve __DRIbuffer from the DRI loader.
  */
@@ -179,7 +96,7 @@ dri2_drawable_get_buffers(struct dri_drawable *drawable,
       unsigned bind;
       int att, bpp;
 
-      dri2_drawable_get_format(drawable, statts[i], &format, &bind);
+      dri_drawable_get_format(drawable, statts[i], &format, &bind);
       if (format == PIPE_FORMAT_NONE)
          continue;
 
@@ -321,7 +238,7 @@ dri2_drawable_process_buffers(struct dri_drawable *drawable,
          break;
       }
 
-      dri2_drawable_get_format(drawable, statt, &format, &bind);
+      dri_drawable_get_format(drawable, statt, &format, &bind);
       if (statt == ST_ATTACHMENT_INVALID || format == PIPE_FORMAT_NONE)
          continue;
 
@@ -354,7 +271,8 @@ dri2_allocate_textures(struct dri_drawable *drawable,
    unsigned num_buffers = count;
 
    buffers = dri2_drawable_get_buffers(drawable, statts, &num_buffers);
-   dri2_drawable_process_buffers(drawable, buffers, num_buffers);
+   if (buffers)
+      dri2_drawable_process_buffers(drawable, buffers, num_buffers);
 }
 
 static void
@@ -484,11 +402,11 @@ static const __DRIextension *dri_screen_extensions[] = {
    &driReadDrawableExtension,
    &driCopySubBufferExtension.base,
    &driSwapControlExtension.base,
-   &driFrameTrackingExtension.base,
    &driMediaStreamCounterExtension.base,
-   &dri2TexBufferExtension.base,
+   &driTexBufferExtension.base,
    &dri2FlushExtension.base,
    &dri2ImageExtension.base,
+   &dri2ConfigQueryExtension.base,
    NULL
 };
 
@@ -497,7 +415,7 @@ static const __DRIextension *dri_screen_extensions[] = {
  *
  * Returns the __GLcontextModes supported by this driver.
  */
-const __DRIconfig **
+static const __DRIconfig **
 dri2_init_screen(__DRIscreen * sPriv)
 {
    const __DRIconfig **configs;
@@ -508,17 +426,13 @@ dri2_init_screen(__DRIscreen * sPriv)
    if (!screen)
       return NULL;
 
-   screen->api = drm_api_create();
    screen->sPriv = sPriv;
    screen->fd = sPriv->fd;
-   screen->lookup_egl_image = dri2_lookup_egl_image;
-   screen->allocate_textures = dri2_allocate_textures;
-   screen->flush_frontbuffer = dri2_flush_frontbuffer;
 
    sPriv->private = (void *)screen;
    sPriv->extensions = dri_screen_extensions;
 
-   pscreen = screen->api->create_screen(screen->api, screen->fd, NULL);
+   pscreen = driver_descriptor.create_screen(screen->fd);
    /* dri_init_screen_helper checks pscreen for us */
 
    configs = dri_init_screen_helper(screen, pscreen, 32);
@@ -526,6 +440,7 @@ dri2_init_screen(__DRIscreen * sPriv)
       goto fail;
 
    screen->auto_fake_front = dri_with_format(sPriv);
+   screen->broken_invalidate = !sPriv->dri2.useInvalidate;
 
    return configs;
 fail:
@@ -534,6 +449,64 @@ fail:
    return NULL;
 }
 
+static boolean
+dri2_create_context(gl_api api, const __GLcontextModes * visual,
+                    __DRIcontext * cPriv, void *sharedContextPrivate)
+{
+   struct dri_context *ctx = NULL;
+
+   if (!dri_create_context(api, visual, cPriv, sharedContextPrivate))
+      return FALSE;
+
+   ctx = cPriv->driverPrivate;
+
+   ctx->lookup_egl_image = dri2_lookup_egl_image;
+
+   return TRUE;
+}
+
+static boolean
+dri2_create_buffer(__DRIscreen * sPriv,
+                   __DRIdrawable * dPriv,
+                   const __GLcontextModes * visual, boolean isPixmap)
+{
+   struct dri_drawable *drawable = NULL;
+
+   if (!dri_create_buffer(sPriv, dPriv, visual, isPixmap))
+      return FALSE;
+
+   drawable = dPriv->driverPrivate;
+
+   drawable->allocate_textures = dri2_allocate_textures;
+   drawable->flush_frontbuffer = dri2_flush_frontbuffer;
+
+   return TRUE;
+}
+
+/**
+ * DRI driver virtual function table.
+ *
+ * DRI versions differ in their implementation of init_screen and swap_buffers.
+ */
+const struct __DriverAPIRec driDriverAPI = {
+   .InitScreen = NULL,
+   .InitScreen2 = dri2_init_screen,
+   .DestroyScreen = dri_destroy_screen,
+   .CreateContext = dri2_create_context,
+   .DestroyContext = dri_destroy_context,
+   .CreateBuffer = dri2_create_buffer,
+   .DestroyBuffer = dri_destroy_buffer,
+   .MakeCurrent = dri_make_current,
+   .UnbindContext = dri_unbind_context,
+
+   .GetSwapInfo = NULL,
+   .GetDrawableMSC = NULL,
+   .WaitForMSC = NULL,
+
+   .SwapBuffers = NULL,
+   .CopySubBuffer = NULL,
+};
+
 /* This is the table of extensions that the loader will dlsym() for. */
 PUBLIC const __DRIextension *__driDriverExtensions[] = {
     &driCoreExtension.base,