Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  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. /*
  32.  * (C) Copyright IBM Corporation 2005
  33.  * All Rights Reserved.
  34.  *
  35.  * Permission is hereby granted, free of charge, to any person obtaining a
  36.  * copy of this software and associated documentation files (the "Software"),
  37.  * to deal in the Software without restriction, including without limitation
  38.  * the rights to use, copy, modify, merge, publish, distribute, sub license,
  39.  * and/or sell copies of the Software, and to permit persons to whom the
  40.  * Software is furnished to do so, subject to the following conditions:
  41.  *
  42.  * The above copyright notice and this permission notice (including the next
  43.  * paragraph) shall be included in all copies or substantial portions of the
  44.  * Software.
  45.  *
  46.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  47.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  48.  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
  49.  * IBM,
  50.  * AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  51.  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
  52.  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  53.  * SOFTWARE.
  54.  */
  55.  
  56. #include "packrender.h"
  57. #include "indirect.h"
  58.  
  59. /**
  60.  * Send a large image to the server.  If necessary, a buffer is allocated
  61.  * to hold the unpacked data that is copied from the clients memory.
  62.  *
  63.  * \param gc        Current GLX context
  64.  * \param compsize  Size, in bytes, of the image portion
  65.  * \param dim       Number of dimensions of the image
  66.  * \param width     Width of the image
  67.  * \param height    Height of the image, must be 1 for 1D images
  68.  * \param depth     Depth of the image, must be 1 for 1D or 2D images
  69.  * \param format    Format of the image
  70.  * \param type      Data type of the image
  71.  * \param src       Pointer to the image data
  72.  * \param pc        Pointer to end of the command header
  73.  * \param modes     Pointer to the pixel unpack data
  74.  *
  75.  * \todo
  76.  * Modify this function so that \c NULL images are sent using
  77.  * \c __glXSendLargeChunk instead of __glXSendLargeCommand.  Doing this
  78.  * will eliminate the need to allocate a buffer for that case.
  79.  */
  80. void
  81. __glXSendLargeImage(struct glx_context * gc, GLint compsize, GLint dim,
  82.                     GLint width, GLint height, GLint depth,
  83.                     GLenum format, GLenum type, const GLvoid * src,
  84.                     GLubyte * pc, GLubyte * modes)
  85. {
  86.     /* Allocate a temporary holding buffer */
  87.     GLubyte *buf = malloc(compsize);
  88.     if (!buf) {
  89.         __glXSetError(gc, GL_OUT_OF_MEMORY);
  90.         return;
  91.     }
  92.  
  93.     /* Apply pixel store unpack modes to copy data into buf */
  94.     if (src != NULL) {
  95.         (*gc->fillImage) (gc, dim, width, height, depth, format, type,
  96.                           src, buf, modes);
  97.     }
  98.     else {
  99.         if (dim < 3) {
  100.             (void) memcpy(modes, __glXDefaultPixelStore + 4, 20);
  101.         }
  102.         else {
  103.             (void) memcpy(modes, __glXDefaultPixelStore + 0, 36);
  104.         }
  105.     }
  106.  
  107.     /* Send large command */
  108.     __glXSendLargeCommand(gc, gc->pc, pc - gc->pc, buf, compsize);
  109.  
  110.     /* Free buffer */
  111.     free((char *) buf);
  112. }
  113.  
  114. /************************************************************************/
  115.  
  116. /**
  117.  * Implement GLX protocol for \c glSeparableFilter2D.
  118.  */
  119. void
  120. __indirect_glSeparableFilter2D(GLenum target, GLenum internalformat,
  121.                                GLsizei width, GLsizei height, GLenum format,
  122.                                GLenum type, const GLvoid * row,
  123.                                const GLvoid * column)
  124. {
  125.    __GLX_DECLARE_VARIABLES();
  126.    GLuint compsize2, hdrlen, totalhdrlen, image1len, image2len;
  127.  
  128.    __GLX_LOAD_VARIABLES();
  129.    compsize = __glImageSize(width, 1, 1, format, type, 0);
  130.    compsize2 = __glImageSize(height, 1, 1, format, type, 0);
  131.    totalhdrlen = __GLX_PAD(__GLX_CONV_FILT_CMD_HDR_SIZE);
  132.    hdrlen = __GLX_PAD(__GLX_CONV_FILT_HDR_SIZE);
  133.    image1len = __GLX_PAD(compsize);
  134.    image2len = __GLX_PAD(compsize2);
  135.    cmdlen = totalhdrlen + image1len + image2len;
  136.    if (!gc->currentDpy)
  137.       return;
  138.  
  139.    if (cmdlen <= gc->maxSmallRenderCommandSize) {
  140.       /* Use GLXRender protocol to send small command */
  141.       __GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_SeparableFilter2D, cmdlen);
  142.       __GLX_PUT_LONG(0, target);
  143.       __GLX_PUT_LONG(4, internalformat);
  144.       __GLX_PUT_LONG(8, width);
  145.       __GLX_PUT_LONG(12, height);
  146.       __GLX_PUT_LONG(16, format);
  147.       __GLX_PUT_LONG(20, type);
  148.       pc += hdrlen;
  149.       if (compsize > 0) {
  150.          (*gc->fillImage) (gc, 1, width, 1, 1, format, type,
  151.                            row, pc, pixelHeaderPC);
  152.          pc += image1len;
  153.       }
  154.       if (compsize2 > 0) {
  155.          (*gc->fillImage) (gc, 1, height, 1, 1, format, type,
  156.                            column, pc, NULL);
  157.          pc += image2len;
  158.       }
  159.       if ((compsize == 0) && (compsize2 == 0)) {
  160.          /* Setup default store modes */
  161.          (void) memcpy(pixelHeaderPC, __glXDefaultPixelStore + 4, 20);
  162.       }
  163.       __GLX_END(0);
  164.    }
  165.    else {
  166.       GLubyte *buf;
  167.       const GLint bufsize = image1len + image2len;
  168.  
  169.       /* Use GLXRenderLarge protocol to send command */
  170.       __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_SeparableFilter2D,
  171.                                             cmdlen + 4);
  172.       __GLX_PUT_LONG(0, target);
  173.       __GLX_PUT_LONG(4, internalformat);
  174.       __GLX_PUT_LONG(8, width);
  175.       __GLX_PUT_LONG(12, height);
  176.       __GLX_PUT_LONG(16, format);
  177.       __GLX_PUT_LONG(20, type);
  178.       pc += hdrlen;
  179.  
  180.       /* Allocate a temporary holding buffer */
  181.       buf = malloc(bufsize);
  182.       if (!buf) {
  183.          __glXSetError(gc, GL_OUT_OF_MEMORY);
  184.          return;
  185.       }
  186.       (*gc->fillImage) (gc, 1, width, 1, 1, format, type, row, buf,
  187.                         pixelHeaderPC);
  188.  
  189.       (*gc->fillImage) (gc, 1, height, 1, 1, format, type, column,
  190.                         buf + image1len, pixelHeaderPC);
  191.  
  192.       /* Send large command */
  193.       __glXSendLargeCommand(gc, gc->pc, (GLint) (pc - gc->pc), buf,
  194.                             bufsize);
  195.       /* Free buffer */
  196.       free((char *) buf);
  197.    }
  198. }
  199.