st/glx: Set the drawable attribute on xmesa_buffer creation.
[mesa.git] / src / gallium / state_trackers / glx / xlib / xm_api.c
index 8332633f01b950f1bbd77a38c3588ef21d67dc32..faaa5a7501057a031ae391b5710a4325ecce4a65 100644 (file)
@@ -59,6 +59,7 @@
 #include "pipe/p_defines.h"
 #include "pipe/p_screen.h"
 #include "pipe/p_context.h"
+#include "util/u_atomic.h"
 
 #include "xm_public.h"
 #include <GL/glx.h>
@@ -376,8 +377,6 @@ choose_depth_stencil_format(XMesaDisplay xmdpy, int depth, int stencil)
 {
    const enum pipe_texture_target target = PIPE_TEXTURE_2D;
    const unsigned tex_usage = PIPE_BIND_DEPTH_STENCIL;
-   const unsigned geom_flags = (PIPE_TEXTURE_GEOM_NON_SQUARE |
-                                PIPE_TEXTURE_GEOM_NON_POWER_OF_TWO);
    const unsigned sample_count = 0;
    enum pipe_format formats[8], fmt;
    int count, i;
@@ -403,7 +402,7 @@ choose_depth_stencil_format(XMesaDisplay xmdpy, int depth, int stencil)
    for (i = 0; i < count; i++) {
       if (xmdpy->screen->is_format_supported(xmdpy->screen, formats[i],
                                              target, sample_count,
-                                             tex_usage, geom_flags)) {
+                                             tex_usage)) {
          fmt = formats[i];
          break;
       }
@@ -449,7 +448,7 @@ create_xmesa_buffer(Drawable d, BufferType type,
    if (!b)
       return NULL;
 
-   b->ws.drawable = d;
+   b->ws.drawable = b->drawable = d;
    b->ws.visual = vis->visinfo->visual;
    b->ws.depth = vis->visinfo->depth;
 
@@ -827,6 +826,16 @@ void XMesaDestroyVisual( XMesaVisual v )
 }
 
 
+/**
+ * Return the informative name.
+ */
+const char *
+xmesa_get_name(void)
+{
+   return stapi->name;
+}
+
+
 /**
  * Do per-display initializations.
  */
@@ -845,7 +854,9 @@ xmesa_init( Display *display )
  * \return an XMesaContext or NULL if error.
  */
 PUBLIC
-XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list )
+XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list,
+                                 GLuint major, GLuint minor,
+                                 GLuint profileMask, GLuint contextFlags)
 {
    XMesaDisplay xmdpy = xmesa_init_display(v->display);
    struct st_context_attribs attribs;
@@ -866,6 +877,18 @@ XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list )
    memset(&attribs, 0, sizeof(attribs));
    attribs.profile = ST_PROFILE_DEFAULT;
    attribs.visual = v->stvis;
+   attribs.major = major;
+   attribs.minor = minor;
+   if (contextFlags & GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB)
+      attribs.flags |= ST_CONTEXT_FLAG_FORWARD_COMPATIBLE;
+   if (contextFlags & GLX_CONTEXT_DEBUG_BIT_ARB)
+      attribs.flags |= ST_CONTEXT_FLAG_DEBUG;
+   if (contextFlags & GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB)
+      attribs.flags |= ST_CONTEXT_FLAG_ROBUST_ACCESS;
+   if (profileMask & GLX_CONTEXT_CORE_PROFILE_BIT_ARB)
+      attribs.flags |= ST_CONTEXT_FLAG_CORE_PROFILE;
+   if (profileMask & GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB)
+      attribs.flags |= ST_CONTEXT_FLAG_COMPATIBLE_PROFILE;
 
    c->st = stapi->create_context(stapi, xmdpy->smapi,
          &attribs, (share_list) ? share_list->st : NULL);
@@ -1091,10 +1114,7 @@ XMesaDestroyBuffer(XMesaBuffer b)
 void
 xmesa_notify_invalid_buffer(XMesaBuffer b)
 {
-   XMesaContext xmctx = XMesaGetCurrentContext();
-
-   if (xmctx && xmctx->xm_buffer == b)
-      xmctx->st->notify_invalid_framebuffer(xmctx->st, b->stfb);
+   p_atomic_inc(&b->stfb->stamp);
 }
 
 
@@ -1104,11 +1124,18 @@ xmesa_notify_invalid_buffer(XMesaBuffer b)
 void
 xmesa_check_buffer_size(XMesaBuffer b)
 {
+   GLuint old_width, old_height;
+
    if (b->type == PBUFFER)
       return;
 
+   old_width = b->width;
+   old_height = b->height;
+
    xmesa_get_window_size(b->xm_visual->display, b, &b->width, &b->height);
-   xmesa_notify_invalid_buffer(b);
+
+   if (b->width != old_width || b->height != old_height)
+      xmesa_notify_invalid_buffer(b);
 }
 
 
@@ -1185,11 +1212,7 @@ void XMesaSwapBuffers( XMesaBuffer b )
    XMesaContext xmctx = XMesaGetCurrentContext();
 
    if (xmctx && xmctx->xm_buffer == b) {
-      xmctx->st->flush( xmctx->st,
-            PIPE_FLUSH_RENDER_CACHE | 
-            PIPE_FLUSH_SWAPBUFFERS |
-            PIPE_FLUSH_FRAME,
-            NULL);
+      xmctx->st->flush( xmctx->st, ST_FLUSH_FRONT, NULL);
    }
 
    xmesa_swap_st_framebuffer(b->stfb);
@@ -1215,9 +1238,10 @@ void XMesaFlush( XMesaContext c )
       XMesaDisplay xmdpy = xmesa_init_display(c->xm_visual->display);
       struct pipe_fence_handle *fence = NULL;
 
-      c->st->flush(c->st, PIPE_FLUSH_RENDER_CACHE | PIPE_FLUSH_FRAME, &fence);
+      c->st->flush(c->st, ST_FLUSH_FRONT, &fence);
       if (fence) {
-         xmdpy->screen->fence_finish(xmdpy->screen, fence, 0);
+         xmdpy->screen->fence_finish(xmdpy->screen, fence,
+                                     PIPE_TIMEOUT_INFINITE);
          xmdpy->screen->fence_reference(xmdpy->screen, &fence, NULL);
       }
       XFlush( c->xm_visual->display );