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