1 /* 2 * (C) Copyright Apple Inc. 2008 3 * (C) Copyright IBM Corporation 2004, 2005 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sub license, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the next 14 * paragraph) shall be included in all copies or substantial portions of the 15 * Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 20 * IBM, 21 * AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 23 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 * SOFTWARE. 25 */ 26 27 #include <GL/gl.h> 28 #include "glxclient.h" 29 #include <GL/glxproto.h> 30 31 CARD32 32 __glXReadReply(Display * dpy, size_t size, void *dest, 33 GLboolean reply_is_always_array) 34 { 35 xGLXSingleReply reply; 36 37 (void) _XReply(dpy, (xReply *) & reply, 0, False); 38 if (size != 0) { 39 if ((reply.length > 0) || reply_is_always_array) { 40 const GLint bytes = (reply_is_always_array) 41 ? (4 * reply.length) : (reply.size * size); 42 const GLint extra = 4 - (bytes & 3); 43 44 _XRead(dpy, dest, bytes); 45 if (extra < 4) { 46 _XEatData(dpy, extra); 47 } 48 } 49 else { 50 (void) memcpy(dest, &(reply.pad3), size); 51 } 52 } 53 54 return reply.retval; 55 } 56 57 void 58 __glXReadPixelReply(Display * dpy, struct glx_context * gc, unsigned max_dim, 59 GLint width, GLint height, GLint depth, GLenum format, 60 GLenum type, void *dest, GLboolean dimensions_in_reply) 61 { 62 xGLXSingleReply reply; 63 GLint size; 64 65 (void) _XReply(dpy, (xReply *) & reply, 0, False); 66 67 if (dimensions_in_reply) { 68 width = reply.pad3; 69 height = reply.pad4; 70 depth = reply.pad5; 71 72 if ((height == 0) || (max_dim < 2)) { 73 height = 1; 74 } 75 if ((depth == 0) || (max_dim < 3)) { 76 depth = 1; 77 } 78 } 79 80 size = reply.length * 4; 81 if (size != 0) { 82 void *buf = Xmalloc(size); 83 84 if (buf == NULL) { 85 _XEatData(dpy, size); 86 __glXSetError(gc, GL_OUT_OF_MEMORY); 87 } 88 else { 89 const GLint extra = 4 - (size & 3); 90 91 _XRead(dpy, buf, size); 92 if (extra < 4) { 93 _XEatData(dpy, extra); 94 } 95 96 __glEmptyImage(gc, 3, width, height, depth, format, type, buf, dest); 97 Xfree(buf); 98 } 99 } 100 } 101 102 #if 0 103 GLubyte * 104 __glXSetupSingleRequest(struct glx_context * gc, GLint sop, GLint cmdlen) 105 { 106 xGLXSingleReq *req; 107 Display *const dpy = gc->currentDpy; 108 109 (void) __glXFlushRenderBuffer(gc, gc->pc); 110 LockDisplay(dpy); 111 GetReqExtra(GLXSingle, cmdlen, req); 112 req->reqType = gc->majorOpcode; 113 req->contextTag = gc->currentContextTag; 114 req->glxCode = sop; 115 return (GLubyte *) (req) + sz_xGLXSingleReq; 116 } 117 #endif 118 119 GLubyte * 120 __glXSetupVendorRequest(struct glx_context * gc, GLint code, GLint vop, 121 GLint cmdlen) 122 { 123 xGLXVendorPrivateReq *req; 124 Display *const dpy = gc->currentDpy; 125 126 (void) __glXFlushRenderBuffer(gc, gc->pc); 127 LockDisplay(dpy); 128 GetReqExtra(GLXVendorPrivate, cmdlen, req); 129 req->reqType = gc->majorOpcode; 130 req->glxCode = code; 131 req->vendorCode = vop; 132 req->contextTag = gc->currentContextTag; 133 return (GLubyte *) (req) + sz_xGLXVendorPrivateReq; 134 } 135