Enable GLX_EXT_texture_from_pixmap in software.
authornobled <nobled@dreamwidth.org>
Mon, 29 Aug 2011 23:24:59 +0000 (16:24 -0700)
committerStéphane Marchesin <marcheu@chromium.org>
Tue, 6 Sep 2011 22:03:00 +0000 (15:03 -0700)
Signed-off-by: nobled <nobled@dreamwidth.org>
Signed-off-by: Stuart Abercrombie <sabercrombie@chromium.org>
Signed-off-by: Stéphane Marchesin <marcheu@chromium.org>
src/glx/drisw_glx.c

index 7bd64506ee8ed2074066be373391409b4fba468c..21d0a0a9c8f1373b78bba8c35c4a321a3e44acb1 100644 (file)
@@ -48,6 +48,8 @@ struct drisw_screen
    __GLXDRIscreen vtable;
    const __DRIcoreExtension *core;
    const __DRIswrastExtension *swrast;
+   const __DRItexBufferExtension *texBuffer;
+
    const __DRIconfig **driver_configs;
 
    void *driver;
@@ -294,6 +296,66 @@ drisw_unbind_context(struct glx_context *context, struct glx_context *new)
    (*psc->core->unbindContext) (pcp->driContext);
 }
 
+static void
+drisw_bind_tex_image(Display * dpy,
+                   GLXDrawable drawable,
+                   int buffer, const int *attrib_list)
+{
+   struct glx_context *gc = __glXGetCurrentContext();
+   struct drisw_context *pcp = (struct drisw_context *) gc;
+   __GLXDRIdrawable *base = GetGLXDRIDrawable(dpy, drawable);
+   struct glx_display *dpyPriv = __glXInitialize(dpy);
+   struct drisw_drawable *pdraw = (struct drisw_drawable *) base;
+   struct drisw_screen *psc;
+
+   if (pdraw != NULL) {
+      psc = (struct drisw_screen *) base->psc;
+
+      if (!psc->texBuffer)
+         return;
+
+      if (psc->texBuffer->base.version >= 2 &&
+        psc->texBuffer->setTexBuffer2 != NULL) {
+             (*psc->texBuffer->setTexBuffer2) (pcp->driContext,
+                                          pdraw->base.textureTarget,
+                                          pdraw->base.textureFormat,
+                                          pdraw->driDrawable);
+      }
+      else {
+             (*psc->texBuffer->setTexBuffer) (pcp->driContext,
+                                         pdraw->base.textureTarget,
+                                         pdraw->driDrawable);
+      }
+   }
+}
+
+static void
+drisw_release_tex_image(Display * dpy, GLXDrawable drawable, int buffer)
+{
+#if __DRI_TEX_BUFFER_VERSION >= 3
+   struct glx_context *gc = __glXGetCurrentContext();
+   struct dri2_context *pcp = (struct dri2_context *) gc;
+   __GLXDRIdrawable *base = GetGLXDRIDrawable(dpy, drawable);
+   struct glx_display *dpyPriv = __glXInitialize(dpy);
+   struct dri2_drawable *pdraw = (struct dri2_drawable *) base;
+   struct dri2_screen *psc;
+
+   if (pdraw != NULL) {
+      psc = (struct dri2_screen *) base->psc;
+
+      if (!psc->texBuffer)
+         return;
+
+      if (psc->texBuffer->base.version >= 3 &&
+          psc->texBuffer->releaseTexBuffer != NULL) {
+         (*psc->texBuffer->releaseTexBuffer) (pcp->driContext,
+                                           pdraw->base.textureTarget,
+                                           pdraw->driDrawable);
+      }
+   }
+#endif
+}
+
 static const struct glx_context_vtable drisw_context_vtable = {
    drisw_destroy_context,
    drisw_bind_context,
@@ -301,8 +363,8 @@ static const struct glx_context_vtable drisw_context_vtable = {
    NULL,
    NULL,
    DRI_glXUseXFont,
-   NULL,
-   NULL,
+   drisw_bind_tex_image,
+   drisw_release_tex_image,
    NULL, /* get_proc_address */
 };
 
@@ -439,6 +501,20 @@ static const struct glx_screen_vtable drisw_screen_vtable = {
    drisw_create_context
 };
 
+static void
+driswBindExtensions(struct drisw_screen *psc, const __DRIextension **extensions)
+{
+   int i;
+
+   /* FIXME: Figure out what other extensions can be ported here from dri2. */
+   for (i = 0; extensions[i]; i++) {
+      if ((strcmp(extensions[i]->name, __DRI_TEX_BUFFER) == 0)) {
+        psc->texBuffer = (__DRItexBufferExtension *) extensions[i];
+        __glXEnableDirectExtension(&psc->base, "GLX_EXT_texture_from_pixmap");
+      }
+   }
+}
+
 static struct glx_screen *
 driswCreateScreen(int screen, struct glx_display *priv)
 {
@@ -488,6 +564,9 @@ driswCreateScreen(int screen, struct glx_display *priv)
       goto handle_error;
    }
 
+   extensions = psc->core->getExtensions(psc->driScreen);
+   driswBindExtensions(psc, extensions);
+
    psc->base.configs =
       driConvertConfigs(psc->core, psc->base.configs, driver_configs);
    psc->base.visuals =