1cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson/* 2dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008) 3dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved. 4dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * 5dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * Permission is hereby granted, free of charge, to any person obtaining a 6dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * copy of this software and associated documentation files (the "Software"), 7dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * to deal in the Software without restriction, including without limitation 8dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * and/or sell copies of the Software, and to permit persons to whom the 10dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * Software is furnished to do so, subject to the following conditions: 11dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * 12dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * The above copyright notice including the dates of first publication and 13dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * either this permission notice or a reference to 14dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * http://oss.sgi.com/projects/FreeB/ 15dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * shall be included in all copies or substantial portions of the Software. 16dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * 17dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 22dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * SOFTWARE. 24dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * 25dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * Except as contained in this notice, the name of Silicon Graphics, Inc. 26dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * shall not be used in advertising or otherwise to promote the sale, use or 27dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * other dealings in this Software without prior written authorization from 28dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson * Silicon Graphics, Inc. 29dc8058c3370588bfcad49fadace1691da47d58cdAdam Jackson */ 30cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson 31cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson/* 325f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * (C) Copyright IBM Corporation 2005 335f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * All Rights Reserved. 345f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * 355f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * Permission is hereby granted, free of charge, to any person obtaining a 365f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * copy of this software and associated documentation files (the "Software"), 375f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * to deal in the Software without restriction, including without limitation 385f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * the rights to use, copy, modify, merge, publish, distribute, sub license, 395f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * and/or sell copies of the Software, and to permit persons to whom the 405f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * Software is furnished to do so, subject to the following conditions: 415f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * 425f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * The above copyright notice and this permission notice (including the next 435f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * paragraph) shall be included in all copies or substantial portions of the 445f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * Software. 455f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * 465f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 475f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 485f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 495f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * IBM, 505f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 515f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF 525f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 535f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * SOFTWARE. 545f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick */ 55cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson 565f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick#include "packrender.h" 57f434e07a6ac849cd127d70eee8b3349da7cfb360Ian Romanick#include "indirect.h" 585f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick 595f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick/** 605f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * Send a large image to the server. If necessary, a buffer is allocated 615f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * to hold the unpacked data that is copied from the clients memory. 625f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * 635f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * \param gc Current GLX context 645f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * \param compsize Size, in bytes, of the image portion 655f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * \param dim Number of dimensions of the image 665f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * \param width Width of the image 675f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * \param height Height of the image, must be 1 for 1D images 685f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * \param depth Depth of the image, must be 1 for 1D or 2D images 695f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * \param format Format of the image 705f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * \param type Data type of the image 715f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * \param src Pointer to the image data 725f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * \param pc Pointer to end of the command header 735f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * \param modes Pointer to the pixel unpack data 745f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * 755f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * \todo 765f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * Modify this function so that \c NULL images are sent using 775f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * \c __glXSendLargeChunk instead of __glXSendLargeCommand. Doing this 785f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * will eliminate the need to allocate a buffer for that case. 795f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick */ 805f1f229f8da255ca9b390da1757ad781978cf619Ian Romanickvoid 81c356f5867f2c1fad7155df538b9affa8dbdcf869Kristian Høgsberg__glXSendLargeImage(struct glx_context * gc, GLint compsize, GLint dim, 82507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf GLint width, GLint height, GLint depth, 83507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf GLenum format, GLenum type, const GLvoid * src, 84507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf GLubyte * pc, GLubyte * modes) 855f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick{ 86e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson /* Allocate a temporary holding buffer */ 87e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson GLubyte *buf = (GLubyte *) Xmalloc(compsize); 88e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson if (!buf) { 89e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson __glXSetError(gc, GL_OUT_OF_MEMORY); 90e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson return; 91e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson } 92cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson 93e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson /* Apply pixel store unpack modes to copy data into buf */ 94e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson if (src != NULL) { 95e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson (*gc->fillImage) (gc, dim, width, height, depth, format, type, 96e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson src, buf, modes); 97e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson } 98e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson else { 99e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson if (dim < 3) { 100e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson (void) memcpy(modes, __glXDefaultPixelStore + 4, 20); 101e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson } 102e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson else { 103e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson (void) memcpy(modes, __glXDefaultPixelStore + 0, 36); 104e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson } 105e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson } 106cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson 107e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson /* Send large command */ 108e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson __glXSendLargeCommand(gc, gc->pc, pc - gc->pc, buf, compsize); 109cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson 110e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson /* Free buffer */ 111e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson Xfree((char *) buf); 112cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson} 113cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson 114cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson/************************************************************************/ 115cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson 1165f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick/** 1175f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick * Implement GLX protocol for \c glSeparableFilter2D. 1185f1f229f8da255ca9b390da1757ad781978cf619Ian Romanick */ 119507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristófvoid 120507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf__indirect_glSeparableFilter2D(GLenum target, GLenum internalformat, 121507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf GLsizei width, GLsizei height, GLenum format, 122507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf GLenum type, const GLvoid * row, 123507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf const GLvoid * column) 124cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson{ 125507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_DECLARE_VARIABLES(); 126507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf GLuint compsize2, hdrlen, totalhdrlen, image1len, image2len; 127cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson 128507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_LOAD_VARIABLES(); 129507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf compsize = __glImageSize(width, 1, 1, format, type, 0); 130507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf compsize2 = __glImageSize(height, 1, 1, format, type, 0); 131507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf totalhdrlen = __GLX_PAD(__GLX_CONV_FILT_CMD_HDR_SIZE); 132507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf hdrlen = __GLX_PAD(__GLX_CONV_FILT_HDR_SIZE); 133507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf image1len = __GLX_PAD(compsize); 134507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf image2len = __GLX_PAD(compsize2); 135507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf cmdlen = totalhdrlen + image1len + image2len; 136507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf if (!gc->currentDpy) 137507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf return; 138cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson 139507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf if (cmdlen <= gc->maxSmallRenderCommandSize) { 140507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf /* Use GLXRender protocol to send small command */ 141507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_SeparableFilter2D, cmdlen); 142507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_PUT_LONG(0, target); 143507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_PUT_LONG(4, internalformat); 144507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_PUT_LONG(8, width); 145507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_PUT_LONG(12, height); 146507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_PUT_LONG(16, format); 147507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_PUT_LONG(20, type); 148507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf pc += hdrlen; 149507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf if (compsize > 0) { 150507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf (*gc->fillImage) (gc, 1, width, 1, 1, format, type, 151507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf row, pc, pixelHeaderPC); 152507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf pc += image1len; 153507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf } 154507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf if (compsize2 > 0) { 155507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf (*gc->fillImage) (gc, 1, height, 1, 1, format, type, 156507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf column, pc, NULL); 157507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf pc += image2len; 158507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf } 159507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf if ((compsize == 0) && (compsize2 == 0)) { 160507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf /* Setup default store modes */ 161507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf (void) memcpy(pixelHeaderPC, __glXDefaultPixelStore + 4, 20); 162507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf } 163507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_END(0); 164507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf } 165507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf else { 166e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson GLubyte *buf; 167507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf const GLint bufsize = image1len + image2len; 168cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson 169507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf /* Use GLXRenderLarge protocol to send command */ 170507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_SeparableFilter2D, 171507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf cmdlen + 4); 172507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_PUT_LONG(0, target); 173507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_PUT_LONG(4, internalformat); 174507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_PUT_LONG(8, width); 175507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_PUT_LONG(12, height); 176507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_PUT_LONG(16, format); 177507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf __GLX_PUT_LONG(20, type); 178507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf pc += hdrlen; 179cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson 180e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson /* Allocate a temporary holding buffer */ 181e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson buf = (GLubyte *) Xmalloc(bufsize); 182e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson if (!buf) { 183e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson __glXSetError(gc, GL_OUT_OF_MEMORY); 184e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson return; 185e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson } 186e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson (*gc->fillImage) (gc, 1, width, 1, 1, format, type, row, buf, 187e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson pixelHeaderPC); 188cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson 189e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson (*gc->fillImage) (gc, 1, height, 1, 1, format, type, column, 190e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson buf + image1len, pixelHeaderPC); 191cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson 192e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson /* Send large command */ 193e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson __glXSendLargeCommand(gc, gc->pc, (GLint) (pc - gc->pc), buf, 194e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson bufsize); 195e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson /* Free buffer */ 196e09e5cb7d8b2d7a9d0ec61476e654528010b2b91Adam Jackson Xfree((char *) buf); 197507808875de6fce4324b67ef88ae4e320df826d3RALOVICH, Kristóf } 198cb3610e37c4c0a40520441b8515d044dabcc8854Adam Jackson} 199