Fix bug #4681.
[mesa.git] / src / glx / x11 / singlepix.c
index d2e8860d1f3ad0392ce769f96ae28a73c54c9229..5eeb4cedab3f05c59aa5de1548f3cdd50e53e8e5 100644 (file)
 */
 
 #include "packsingle.h"
-
-void __indirect_glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,
-                 GLenum format, GLenum type, GLvoid *pixels)
-{
-    __GLX_SINGLE_DECLARE_VARIABLES();
-    const __GLXattribute * state;
-    xGLXReadPixelsReply reply;
-    GLubyte *buf;
-
-    if (!dpy) return;
-    __GLX_SINGLE_LOAD_VARIABLES();
-    state = gc->client_state_private;
-
-    /* Send request */
-    __GLX_SINGLE_BEGIN(X_GLsop_ReadPixels,__GLX_PAD(26));
-    __GLX_SINGLE_PUT_LONG(0,x);
-    __GLX_SINGLE_PUT_LONG(4,y);
-    __GLX_SINGLE_PUT_LONG(8,width);
-    __GLX_SINGLE_PUT_LONG(12,height);
-    __GLX_SINGLE_PUT_LONG(16,format);
-    __GLX_SINGLE_PUT_LONG(20,type);
-    __GLX_SINGLE_PUT_CHAR(24,state->storePack.swapEndian);
-    __GLX_SINGLE_PUT_CHAR(25,GL_FALSE);
-    __GLX_SINGLE_READ_XREPLY();
-    compsize = reply.length << 2;
-
-    if (compsize != 0) {
-       /* Allocate a holding buffer to transform the data from */
-       buf = (GLubyte*) Xmalloc(compsize);
-       if (!buf) {
-           /* Throw data away */
-           _XEatData(dpy, compsize);
-           __glXSetError(gc, GL_OUT_OF_MEMORY);
-       } else {
-           /*
-           ** Fetch data into holding buffer.  Apply pixel store pack modes
-           ** to put data back into client memory
-           */
-           __GLX_SINGLE_GET_CHAR_ARRAY(buf,compsize);
-           __glEmptyImage(gc, 2, width, height, 1, format, type, buf, pixels);
-           Xfree((char*) buf);
-       }
-    } else {
-       /*
-       ** GL error occurred; don't modify user's buffer.
-       */
-    }
-    __GLX_SINGLE_END();
-}
-
-void __indirect_glGetTexImage(GLenum target, GLint level, GLenum format, GLenum type,
-                  GLvoid *texels)
-{
-    __GLX_SINGLE_DECLARE_VARIABLES();
-    const __GLXattribute * state;
-    xGLXGetTexImageReply reply;
-    GLubyte *buf;
-
-    if (!dpy) return;
-    __GLX_SINGLE_LOAD_VARIABLES();
-    state = gc->client_state_private;
-
-    /* Send request */
-    __GLX_SINGLE_BEGIN(X_GLsop_GetTexImage,__GLX_PAD(17));
-    __GLX_SINGLE_PUT_LONG(0,target);
-    __GLX_SINGLE_PUT_LONG(4,level);
-    __GLX_SINGLE_PUT_LONG(8,format);
-    __GLX_SINGLE_PUT_LONG(12,type);
-    __GLX_SINGLE_PUT_CHAR(16,state->storePack.swapEndian);
-    __GLX_SINGLE_READ_XREPLY();
-    compsize = reply.length << 2;
-
-    if (compsize != 0) {
-       /* Allocate a holding buffer to transform the data from */
-       buf = (GLubyte*) Xmalloc(compsize);
-       if (!buf) {
-           /* Throw data away */
-           _XEatData(dpy, compsize);
-           __glXSetError(gc, GL_OUT_OF_MEMORY);
-       } else {
-           GLint width, height, depth;
-
-           /*
-           ** Fetch data into holding buffer.  Apply pixel store pack modes
-           ** to put data back into client memory
-           */
-           width = reply.width;
-           height = reply.height;
-           depth = reply.depth;
-           __GLX_SINGLE_GET_CHAR_ARRAY(buf,compsize);
-           __glEmptyImage(gc, 2, width, height, depth, format, type, buf,
-                          texels);
-           Xfree((char*) buf);
-       }
-    } else {
-       /*
-       ** GL error occured, don't modify user's buffer.
-       */
-    }
-    __GLX_SINGLE_END();
-}
-
-void __indirect_glGetPolygonStipple(GLubyte *mask)
-{
-    __GLX_SINGLE_DECLARE_VARIABLES();
-    xGLXSingleReply reply;
-    GLubyte buf[128];
-
-    if (!dpy) return;
-
-    __GLX_SINGLE_LOAD_VARIABLES();
-    __GLX_SINGLE_BEGIN(X_GLsop_GetPolygonStipple,__GLX_PAD(1));
-    __GLX_SINGLE_PUT_CHAR(0,GL_FALSE);
-    __GLX_SINGLE_READ_XREPLY();
-    if (reply.length == 32) {
-       __GLX_SINGLE_GET_CHAR_ARRAY(buf,128);
-       __glEmptyImage(gc, 2, 32, 32, 1, GL_COLOR_INDEX, GL_BITMAP, buf, mask);
-    }
-    __GLX_SINGLE_END();
-}
-
-void __indirect_glGetColorTable(GLenum target, GLenum format, GLenum type, GLvoid *table)
-{
-    __GLX_SINGLE_DECLARE_VARIABLES();
-    const __GLXattribute * state;
-    xGLXGetColorTableReply reply;
-    GLubyte *buf;
-
-    if (!dpy) return;
-    __GLX_SINGLE_LOAD_VARIABLES();
-    state = gc->client_state_private;
-
-    /* Send request */
-    __GLX_SINGLE_BEGIN(X_GLsop_GetColorTable,__GLX_PAD(13));
-    __GLX_SINGLE_PUT_LONG(0,(long)target);
-    __GLX_SINGLE_PUT_LONG(4,(long)format);
-    __GLX_SINGLE_PUT_LONG(8,(long)type);
-    __GLX_SINGLE_PUT_CHAR(12,state->storePack.swapEndian);
-    __GLX_SINGLE_READ_XREPLY();
-    compsize = (long)reply.length << 2;
-
-    if (compsize != 0) {
-        /* Allocate a holding buffer to transform the data from */
-        buf = (GLubyte*)Xmalloc(compsize);
-        if (!buf) {
-            /* Throw data away */
-            _XEatData(dpy, compsize);
-            __glXSetError(gc, GL_OUT_OF_MEMORY);
-        } else {
-            GLint width;
-
-            /*
-            ** Fetch data into holding buffer.  Apply pixel store pack modes
-            ** to put data back into client memory
-            */
-            width = (int)reply.width;
-            __GLX_SINGLE_GET_CHAR_ARRAY(((char*)buf),(long)compsize);
-            __glEmptyImage(gc, 1, width, 1, 1, format, type, buf, table);
-            Xfree((char*) buf);
-        }
-    } else {
-        /*
-        ** GL error occured, don't modify user's buffer.
-        */
-    }
-    __GLX_SINGLE_END();
-}
-
-void __indirect_glGetConvolutionFilter(GLenum target, GLenum format, GLenum type,
-                           GLvoid *image)
-{
-    __GLX_SINGLE_DECLARE_VARIABLES();
-    const __GLXattribute * state;
-    xGLXGetConvolutionFilterReply reply;
-    GLubyte *buf;
-
-    if (!dpy) return;
-    __GLX_SINGLE_LOAD_VARIABLES();
-    state = gc->client_state_private;
-
-    /* Send request */
-    __GLX_SINGLE_BEGIN(X_GLsop_GetConvolutionFilter, __GLX_PAD(13));
-    __GLX_SINGLE_PUT_LONG(0,target);
-    __GLX_SINGLE_PUT_LONG(4,format);
-    __GLX_SINGLE_PUT_LONG(8,type);
-    __GLX_SINGLE_PUT_CHAR(12,state->storePack.swapEndian);
-    __GLX_SINGLE_READ_XREPLY();
-    compsize = reply.length << 2;
-
-    if (compsize != 0) {
-       /* Allocate a holding buffer to transform the data from */
-       buf = (GLubyte*) Xmalloc(compsize);
-       if (!buf) {
-           /* Throw data away */
-           _XEatData(dpy, compsize);
-           __glXSetError(gc, GL_OUT_OF_MEMORY);
-       } else {
-           GLint width, height;
-
-           /*
-           ** Fetch data into holding buffer.  Apply pixel store pack modes
-           ** to put data back into client memory
-           */
-           width = reply.width;
-           height = reply.height;
-           __GLX_SINGLE_GET_CHAR_ARRAY(((char*)buf),compsize);
-           __glEmptyImage(gc, 2, width, height, 1, format, type, buf, image);
-           Xfree((char*) buf);
-       }
-    } else {
-       /*
-       ** GL error occured, don't modify user's buffer.
-       */
-    }
-    __GLX_SINGLE_END();
-}
+#include "indirect.h"
+#include "dispatch.h"
+#include "glthread.h"
+#include "glapioffsets.h"
+#include <GL/glxproto.h>
 
 void __indirect_glGetSeparableFilter(GLenum target, GLenum format, GLenum type,
                          GLvoid *row, GLvoid *column, GLvoid *span)
@@ -319,97 +108,84 @@ void __indirect_glGetSeparableFilter(GLenum target, GLenum format, GLenum type,
     
 }
 
-void __indirect_glGetHistogram(GLenum target, GLboolean reset, GLenum format,
-                   GLenum type, GLvoid *values)
-{
-    __GLX_SINGLE_DECLARE_VARIABLES();
-    const __GLXattribute * state;
-    xGLXGetHistogramReply reply;
-    GLubyte *buf;
-
-    if (!dpy) return;
-    __GLX_SINGLE_LOAD_VARIABLES();
-    state = gc->client_state_private;
-
-    /* Send request */
-    __GLX_SINGLE_BEGIN(X_GLsop_GetHistogram,__GLX_PAD(14));
-    __GLX_SINGLE_PUT_LONG(0,(long)target);
-    __GLX_SINGLE_PUT_LONG(4,(long)format);
-    __GLX_SINGLE_PUT_LONG(8,(long)type);
-    __GLX_SINGLE_PUT_CHAR(12,state->storePack.swapEndian);
-    __GLX_SINGLE_PUT_CHAR(13,reset);
-    __GLX_SINGLE_READ_XREPLY();
-    compsize = (long)reply.length << 2;
-
-    if (compsize != 0) {
-        /* Allocate a holding buffer to transform the data from */
-        buf = (GLubyte*)Xmalloc(compsize);
-        if (!buf) {
-            /* Throw data away */
-            _XEatData(dpy, compsize);
-            __glXSetError(gc, GL_OUT_OF_MEMORY);
-        } else {
-            GLint width;
 
-            /*
-            ** Fetch data into holding buffer.  Apply pixel store pack modes
-            ** to put data back into client memory
-            */
-            width = (int)reply.width;
-            __GLX_SINGLE_GET_CHAR_ARRAY(((char*)buf),(long)compsize);
-            __glEmptyImage(gc, 1, width, 1, 1, format, type, buf, values);
-            Xfree((char*) buf);
-        }
-    } else {
-        /*
-        ** GL error occured, don't modify user's buffer.
-        */
-    }
-    __GLX_SINGLE_END();
-}
+#define CONCAT(a,b) a ## b
+#define NAME(o) CONCAT(gl_dispatch_stub_, o)
 
-void __indirect_glGetMinmax(GLenum target, GLboolean reset, GLenum format, GLenum type,
-                GLvoid *values)
+void NAME(_gloffset_GetSeparableFilter)(GLenum target, GLenum format, GLenum type,
+                                       GLvoid *row, GLvoid *column, GLvoid *span)
 {
-    __GLX_SINGLE_DECLARE_VARIABLES();
-    const __GLXattribute * state;
-    xGLXGetMinmaxReply reply;
-    GLubyte *buf;
-
-    if (!dpy) return;
-    __GLX_SINGLE_LOAD_VARIABLES();
-    state = gc->client_state_private;
+    __GLXcontext * const gc = __glXGetCurrentContext();
 
-    /* Send request */
-    __GLX_SINGLE_BEGIN(X_GLsop_GetMinmax,__GLX_PAD(14));
-    __GLX_SINGLE_PUT_LONG(0,(long)target);
-    __GLX_SINGLE_PUT_LONG(4,(long)format);
-    __GLX_SINGLE_PUT_LONG(8,(long)type);
-    __GLX_SINGLE_PUT_CHAR(12,state->storePack.swapEndian);
-    __GLX_SINGLE_PUT_CHAR(13,reset);
-    __GLX_SINGLE_READ_XREPLY();
-    compsize = (long)reply.length << 2;
-
-    if (compsize != 0) {
-        /* Allocate a holding buffer to transform the data from */
-        buf = (GLubyte*)Xmalloc(compsize);
-        if (!buf) {
-            /* Throw data away */
-            _XEatData(dpy, compsize);
-            __glXSetError(gc, GL_OUT_OF_MEMORY);
-        } else {
-            /*
-            ** Fetch data into holding buffer.  Apply pixel store pack modes
-            ** to put data back into client memory
-            */
-            __GLX_SINGLE_GET_CHAR_ARRAY(((char*)buf),(long)compsize);
-            __glEmptyImage(gc, 1, 2, 1, 1, format, type, buf, values);
-            Xfree((char*) buf);
-        }
-    } else {
-        /*
-        ** GL error occured, don't modify user's buffer.
-        */
+    if (gc->isDirect) {
+       CALL_GetSeparableFilter(GET_DISPATCH(),
+                               (target, format, type, row, column, span));
+       return;
+    }
+    else {
+        Display *const dpy = gc->currentDpy;
+       const GLuint cmdlen = __GLX_PAD(13);
+
+       if (dpy != NULL) {
+           const __GLXattribute * const state = gc->client_state_private;
+           xGLXGetSeparableFilterReply reply;
+           GLubyte const *pc =
+             __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply,
+                                     X_GLvop_GetSeparableFilterEXT, cmdlen);
+           unsigned compsize;
+
+
+           (void) memcpy((void *) (pc + 0), (void *) (&target), 4);
+           (void) memcpy((void *) (pc + 4), (void *) (&format), 4);
+           (void) memcpy((void *) (pc + 8), (void *) (&type), 4);
+           *(int8_t *) (pc + 12) = state->storePack.swapEndian;
+
+           (void) _XReply(dpy, (xReply *) & reply, 0, False);
+
+           compsize = reply.length << 2;
+
+           if (compsize != 0) {
+               const GLint width = reply.width;
+               const GLint height = reply.height;
+               const GLint widthsize =
+                 __glImageSize(width, 1, 1, format, type, 0);
+               const GLint heightsize =
+                 __glImageSize(height, 1, 1, format, type, 0);
+               GLubyte * const buf =
+                 (GLubyte*) Xmalloc((widthsize > heightsize) ? widthsize : heightsize);
+
+               if (buf == NULL) {
+                   /* Throw data away */
+                   _XEatData(dpy, compsize);
+                   __glXSetError(gc, GL_OUT_OF_MEMORY);
+
+                   UnlockDisplay(dpy);
+                   SyncHandle();
+                   return;
+               } else {
+                   int extra;
+                   
+                   extra = 4 - (widthsize & 3);
+                   _XRead(dpy, (char *)buf, widthsize);
+                   if (extra < 4) {
+                       _XEatData(dpy, extra);
+                   }
+
+                   __glEmptyImage(gc, 1, width, 1, 1, format, type, buf,
+                                  row);
+
+                   extra = 4 - (heightsize & 3);
+                   _XRead(dpy, (char *)buf, heightsize);
+                   if (extra < 4) {
+                       _XEatData(dpy, extra);
+                   }
+
+                   __glEmptyImage(gc, 1, height, 1, 1, format, type, buf,
+                                  column);
+
+                   Xfree((char*) buf);
+               }
+           }
+       }
     }
-    __GLX_SINGLE_END();
 }