singlepix.c revision c491e585e43d48a2aeec96ccc4008da6c443fb42
1/* 2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice including the dates of first publication and 13 * either this permission notice or a reference to 14 * http://oss.sgi.com/projects/FreeB/ 15 * shall be included in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 * SOFTWARE. 24 * 25 * Except as contained in this notice, the name of Silicon Graphics, Inc. 26 * shall not be used in advertising or otherwise to promote the sale, use or 27 * other dealings in this Software without prior written authorization from 28 * Silicon Graphics, Inc. 29 */ 30 31#include "packsingle.h" 32#include "indirect.h" 33#include "glapitable.h" 34#include "glapidispatch.h" 35#include "glapi.h" 36#include "glthread.h" 37#include "glapioffsets.h" 38#include <GL/glxproto.h> 39 40void 41__indirect_glGetSeparableFilter(GLenum target, GLenum format, GLenum type, 42 GLvoid * row, GLvoid * column, GLvoid * span) 43{ 44 __GLX_SINGLE_DECLARE_VARIABLES(); 45 const __GLXattribute *state; 46 xGLXGetSeparableFilterReply reply; 47 GLubyte *rowBuf, *colBuf; 48 49 if (!dpy) 50 return; 51 __GLX_SINGLE_LOAD_VARIABLES(); 52 state = gc->client_state_private; 53 54 /* Send request */ 55 __GLX_SINGLE_BEGIN(X_GLsop_GetSeparableFilter, __GLX_PAD(13)); 56 __GLX_SINGLE_PUT_LONG(0, target); 57 __GLX_SINGLE_PUT_LONG(4, format); 58 __GLX_SINGLE_PUT_LONG(8, type); 59 __GLX_SINGLE_PUT_CHAR(12, state->storePack.swapEndian); 60 __GLX_SINGLE_READ_XREPLY(); 61 compsize = reply.length << 2; 62 63 if (compsize != 0) { 64 GLint width, height; 65 GLint widthsize, heightsize; 66 67 width = reply.width; 68 height = reply.height; 69 70 widthsize = __glImageSize(width, 1, 1, format, type, 0); 71 heightsize = __glImageSize(height, 1, 1, format, type, 0); 72 73 /* Allocate a holding buffer to transform the data from */ 74 rowBuf = (GLubyte *) Xmalloc(widthsize); 75 if (!rowBuf) { 76 /* Throw data away */ 77 _XEatData(dpy, compsize); 78 __glXSetError(gc, GL_OUT_OF_MEMORY); 79 UnlockDisplay(dpy); 80 SyncHandle(); 81 return; 82 } 83 else { 84 __GLX_SINGLE_GET_CHAR_ARRAY(((char *) rowBuf), widthsize); 85 __glEmptyImage(gc, 1, width, 1, 1, format, type, rowBuf, row); 86 Xfree((char *) rowBuf); 87 } 88 colBuf = (GLubyte *) Xmalloc(heightsize); 89 if (!colBuf) { 90 /* Throw data away */ 91 _XEatData(dpy, compsize - __GLX_PAD(widthsize)); 92 __glXSetError(gc, GL_OUT_OF_MEMORY); 93 UnlockDisplay(dpy); 94 SyncHandle(); 95 return; 96 } 97 else { 98 __GLX_SINGLE_GET_CHAR_ARRAY(((char *) colBuf), heightsize); 99 __glEmptyImage(gc, 1, height, 1, 1, format, type, colBuf, column); 100 Xfree((char *) colBuf); 101 } 102 } 103 else { 104 /* 105 ** don't modify user's buffer. 106 */ 107 } 108 __GLX_SINGLE_END(); 109 110} 111 112 113#define CONCAT(a,b) a ## b 114#define NAME(o) CONCAT(gl_dispatch_stub_, o) 115 116void NAME(_gloffset_GetSeparableFilter) (GLenum target, GLenum format, 117 GLenum type, GLvoid * row, 118 GLvoid * column, GLvoid * span) 119{ 120 struct glx_context *const gc = __glXGetCurrentContext(); 121 122#if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL) 123 if (gc->isDirect) { 124 CALL_GetSeparableFilter(GET_DISPATCH(), 125 (target, format, type, row, column, span)); 126 return; 127 } 128 else 129#endif 130 { 131 Display *const dpy = gc->currentDpy; 132 const GLuint cmdlen = __GLX_PAD(13); 133 134 if (dpy != NULL) { 135 const __GLXattribute *const state = gc->client_state_private; 136 xGLXGetSeparableFilterReply reply; 137 GLubyte const *pc = 138 __glXSetupVendorRequest(gc, X_GLXVendorPrivateWithReply, 139 X_GLvop_GetSeparableFilterEXT, cmdlen); 140 unsigned compsize; 141 142 143 (void) memcpy((void *) (pc + 0), (void *) (&target), 4); 144 (void) memcpy((void *) (pc + 4), (void *) (&format), 4); 145 (void) memcpy((void *) (pc + 8), (void *) (&type), 4); 146 *(int8_t *) (pc + 12) = state->storePack.swapEndian; 147 148 (void) _XReply(dpy, (xReply *) & reply, 0, False); 149 150 compsize = reply.length << 2; 151 152 if (compsize != 0) { 153 const GLint width = reply.width; 154 const GLint height = reply.height; 155 const GLint widthsize = 156 __glImageSize(width, 1, 1, format, type, 0); 157 const GLint heightsize = 158 __glImageSize(height, 1, 1, format, type, 0); 159 GLubyte *const buf = 160 (GLubyte *) Xmalloc((widthsize > heightsize) ? widthsize : 161 heightsize); 162 163 if (buf == NULL) { 164 /* Throw data away */ 165 _XEatData(dpy, compsize); 166 __glXSetError(gc, GL_OUT_OF_MEMORY); 167 168 UnlockDisplay(dpy); 169 SyncHandle(); 170 return; 171 } 172 else { 173 int extra; 174 175 extra = 4 - (widthsize & 3); 176 _XRead(dpy, (char *) buf, widthsize); 177 if (extra < 4) { 178 _XEatData(dpy, extra); 179 } 180 181 __glEmptyImage(gc, 1, width, 1, 1, format, type, buf, row); 182 183 extra = 4 - (heightsize & 3); 184 _XRead(dpy, (char *) buf, heightsize); 185 if (extra < 4) { 186 _XEatData(dpy, extra); 187 } 188 189 __glEmptyImage(gc, 1, height, 1, 1, format, type, buf, column); 190 191 Xfree((char *) buf); 192 } 193 } 194 } 195 } 196} 197