xref: /OK3568_Linux_fs/external/xserver/glx/indirect_texture_compression.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * (C) Copyright IBM Corporation 2005, 2006
3*4882a593Smuzhiyun  * All Rights Reserved.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
6*4882a593Smuzhiyun  * copy of this software and associated documentation files (the "Software"),
7*4882a593Smuzhiyun  * to deal in the Software without restriction, including without limitation
8*4882a593Smuzhiyun  * the rights to use, copy, modify, merge, publish, distribute, sub license,
9*4882a593Smuzhiyun  * and/or sell copies of the Software, and to permit persons to whom the
10*4882a593Smuzhiyun  * Software is furnished to do so, subject to the following conditions:
11*4882a593Smuzhiyun  *
12*4882a593Smuzhiyun  * The above copyright notice and this permission notice (including the next
13*4882a593Smuzhiyun  * paragraph) shall be included in all copies or substantial portions of the
14*4882a593Smuzhiyun  * Software.
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19*4882a593Smuzhiyun  * IBM,
20*4882a593Smuzhiyun  * AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21*4882a593Smuzhiyun  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22*4882a593Smuzhiyun  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23*4882a593Smuzhiyun  * SOFTWARE.
24*4882a593Smuzhiyun  */
25*4882a593Smuzhiyun 
26*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
27*4882a593Smuzhiyun #include <dix-config.h>
28*4882a593Smuzhiyun #endif
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #include "glxserver.h"
31*4882a593Smuzhiyun #include "glxbyteorder.h"
32*4882a593Smuzhiyun #include "glxext.h"
33*4882a593Smuzhiyun #include "singlesize.h"
34*4882a593Smuzhiyun #include "unpack.h"
35*4882a593Smuzhiyun #include "indirect_size_get.h"
36*4882a593Smuzhiyun #include "indirect_dispatch.h"
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun int
__glXDisp_GetCompressedTexImage(struct __GLXclientStateRec * cl,GLbyte * pc)39*4882a593Smuzhiyun __glXDisp_GetCompressedTexImage(struct __GLXclientStateRec *cl, GLbyte * pc)
40*4882a593Smuzhiyun {
41*4882a593Smuzhiyun     xGLXSingleReq *const req = (xGLXSingleReq *) pc;
42*4882a593Smuzhiyun     int error;
43*4882a593Smuzhiyun     __GLXcontext *const cx = __glXForceCurrent(cl, req->contextTag, &error);
44*4882a593Smuzhiyun     ClientPtr client = cl->client;
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun     REQUEST_FIXED_SIZE(xGLXSingleReq, 8);
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun     pc += __GLX_SINGLE_HDR_SIZE;
49*4882a593Smuzhiyun     if (cx != NULL) {
50*4882a593Smuzhiyun         const GLenum target = *(GLenum *) (pc + 0);
51*4882a593Smuzhiyun         const GLint level = *(GLint *) (pc + 4);
52*4882a593Smuzhiyun         GLint compsize = 0;
53*4882a593Smuzhiyun         char *answer = NULL, answerBuffer[200];
54*4882a593Smuzhiyun         xGLXSingleReply reply = { 0, };
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun         glGetTexLevelParameteriv(target, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
57*4882a593Smuzhiyun                                  &compsize);
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun         if (compsize != 0) {
60*4882a593Smuzhiyun             PFNGLGETCOMPRESSEDTEXIMAGEARBPROC GetCompressedTexImageARB =
61*4882a593Smuzhiyun                 __glGetProcAddress("glGetCompressedTexImageARB");
62*4882a593Smuzhiyun             __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
63*4882a593Smuzhiyun             __glXClearErrorOccured();
64*4882a593Smuzhiyun             GetCompressedTexImageARB(target, level, answer);
65*4882a593Smuzhiyun         }
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun         if (__glXErrorOccured()) {
68*4882a593Smuzhiyun             __GLX_BEGIN_REPLY(0);
69*4882a593Smuzhiyun             __GLX_SEND_HEADER();
70*4882a593Smuzhiyun         }
71*4882a593Smuzhiyun         else {
72*4882a593Smuzhiyun             __GLX_BEGIN_REPLY(compsize);
73*4882a593Smuzhiyun             ((xGLXGetTexImageReply *) &reply)->width = compsize;
74*4882a593Smuzhiyun             __GLX_SEND_HEADER();
75*4882a593Smuzhiyun             __GLX_SEND_VOID_ARRAY(compsize);
76*4882a593Smuzhiyun         }
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun         error = Success;
79*4882a593Smuzhiyun     }
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun     return error;
82*4882a593Smuzhiyun }
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun int
__glXDispSwap_GetCompressedTexImage(struct __GLXclientStateRec * cl,GLbyte * pc)85*4882a593Smuzhiyun __glXDispSwap_GetCompressedTexImage(struct __GLXclientStateRec *cl, GLbyte * pc)
86*4882a593Smuzhiyun {
87*4882a593Smuzhiyun     xGLXSingleReq *const req = (xGLXSingleReq *) pc;
88*4882a593Smuzhiyun     int error;
89*4882a593Smuzhiyun     __GLXcontext *const cx =
90*4882a593Smuzhiyun         __glXForceCurrent(cl, bswap_32(req->contextTag), &error);
91*4882a593Smuzhiyun     ClientPtr client = cl->client;
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun     REQUEST_FIXED_SIZE(xGLXSingleReq, 8);
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun     pc += __GLX_SINGLE_HDR_SIZE;
96*4882a593Smuzhiyun     if (cx != NULL) {
97*4882a593Smuzhiyun         const GLenum target = (GLenum) bswap_32(*(int *) (pc + 0));
98*4882a593Smuzhiyun         const GLint level = (GLint) bswap_32(*(int *) (pc + 4));
99*4882a593Smuzhiyun         GLint compsize = 0;
100*4882a593Smuzhiyun         char *answer = NULL, answerBuffer[200];
101*4882a593Smuzhiyun         xGLXSingleReply reply = { 0, };
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun         glGetTexLevelParameteriv(target, level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE,
104*4882a593Smuzhiyun                                  &compsize);
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun         if (compsize != 0) {
107*4882a593Smuzhiyun             PFNGLGETCOMPRESSEDTEXIMAGEARBPROC GetCompressedTexImageARB =
108*4882a593Smuzhiyun                 __glGetProcAddress("glGetCompressedTexImageARB");
109*4882a593Smuzhiyun             __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
110*4882a593Smuzhiyun             __glXClearErrorOccured();
111*4882a593Smuzhiyun             GetCompressedTexImageARB(target, level, answer);
112*4882a593Smuzhiyun         }
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun         if (__glXErrorOccured()) {
115*4882a593Smuzhiyun             __GLX_BEGIN_REPLY(0);
116*4882a593Smuzhiyun             __GLX_SEND_HEADER();
117*4882a593Smuzhiyun         }
118*4882a593Smuzhiyun         else {
119*4882a593Smuzhiyun             __GLX_BEGIN_REPLY(compsize);
120*4882a593Smuzhiyun             ((xGLXGetTexImageReply *) &reply)->width = compsize;
121*4882a593Smuzhiyun             __GLX_SEND_HEADER();
122*4882a593Smuzhiyun             __GLX_SEND_VOID_ARRAY(compsize);
123*4882a593Smuzhiyun         }
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun         error = Success;
126*4882a593Smuzhiyun     }
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun     return error;
129*4882a593Smuzhiyun }
130