1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * (C) Copyright IBM Corporation 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 * on the rights to use, copy, modify, merge, publish, distribute, sub
9*4882a593Smuzhiyun * license, and/or sell copies of the Software, and to permit persons to whom
10*4882a593Smuzhiyun * the 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 * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20*4882a593Smuzhiyun * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21*4882a593Smuzhiyun * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22*4882a593Smuzhiyun * USE OR OTHER DEALINGS IN THE SOFTWARE.
23*4882a593Smuzhiyun */
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
26*4882a593Smuzhiyun #include <dix-config.h>
27*4882a593Smuzhiyun #endif
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun #include "glxserver.h"
30*4882a593Smuzhiyun #include "glxutil.h"
31*4882a593Smuzhiyun #include "glxext.h"
32*4882a593Smuzhiyun #include "singlesize.h"
33*4882a593Smuzhiyun #include "unpack.h"
34*4882a593Smuzhiyun #include "indirect_size_get.h"
35*4882a593Smuzhiyun #include "indirect_dispatch.h"
36*4882a593Smuzhiyun #include "glxbyteorder.h"
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun static int DoSwapInterval(__GLXclientState * cl, GLbyte * pc, int do_swap);
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun int
DoSwapInterval(__GLXclientState * cl,GLbyte * pc,int do_swap)41*4882a593Smuzhiyun DoSwapInterval(__GLXclientState * cl, GLbyte * pc, int do_swap)
42*4882a593Smuzhiyun {
43*4882a593Smuzhiyun xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
44*4882a593Smuzhiyun ClientPtr client = cl->client;
45*4882a593Smuzhiyun const GLXContextTag tag = req->contextTag;
46*4882a593Smuzhiyun __GLXcontext *cx;
47*4882a593Smuzhiyun GLint interval;
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 4);
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun cx = __glXLookupContextByTag(cl, tag);
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun if ((cx == NULL) || (cx->pGlxScreen == NULL)) {
54*4882a593Smuzhiyun client->errorValue = tag;
55*4882a593Smuzhiyun return __glXError(GLXBadContext);
56*4882a593Smuzhiyun }
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun if (cx->pGlxScreen->swapInterval == NULL) {
59*4882a593Smuzhiyun LogMessage(X_ERROR, "AIGLX: cx->pGlxScreen->swapInterval == NULL\n");
60*4882a593Smuzhiyun client->errorValue = tag;
61*4882a593Smuzhiyun return __glXError(GLXUnsupportedPrivateRequest);
62*4882a593Smuzhiyun }
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun if (cx->drawPriv == NULL) {
65*4882a593Smuzhiyun client->errorValue = tag;
66*4882a593Smuzhiyun return BadValue;
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun pc += __GLX_VENDPRIV_HDR_SIZE;
70*4882a593Smuzhiyun interval = (do_swap)
71*4882a593Smuzhiyun ? bswap_32(*(int *) (pc + 0))
72*4882a593Smuzhiyun : *(int *) (pc + 0);
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun if (interval <= 0)
75*4882a593Smuzhiyun return BadValue;
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun (void) (*cx->pGlxScreen->swapInterval) (cx->drawPriv, interval);
78*4882a593Smuzhiyun return Success;
79*4882a593Smuzhiyun }
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun int
__glXDisp_SwapIntervalSGI(__GLXclientState * cl,GLbyte * pc)82*4882a593Smuzhiyun __glXDisp_SwapIntervalSGI(__GLXclientState * cl, GLbyte * pc)
83*4882a593Smuzhiyun {
84*4882a593Smuzhiyun return DoSwapInterval(cl, pc, 0);
85*4882a593Smuzhiyun }
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun int
__glXDispSwap_SwapIntervalSGI(__GLXclientState * cl,GLbyte * pc)88*4882a593Smuzhiyun __glXDispSwap_SwapIntervalSGI(__GLXclientState * cl, GLbyte * pc)
89*4882a593Smuzhiyun {
90*4882a593Smuzhiyun return DoSwapInterval(cl, pc, 1);
91*4882a593Smuzhiyun }
92