1706f2543Smrg/*
2706f2543Smrg * (C) Copyright IBM Corporation 2006
3706f2543Smrg * All Rights Reserved.
4706f2543Smrg *
5706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a
6706f2543Smrg * copy of this software and associated documentation files (the "Software"),
7706f2543Smrg * to deal in the Software without restriction, including without limitation
8706f2543Smrg * on the rights to use, copy, modify, merge, publish, distribute, sub
9706f2543Smrg * license, and/or sell copies of the Software, and to permit persons to whom
10706f2543Smrg * the Software is furnished to do so, subject to the following conditions:
11706f2543Smrg *
12706f2543Smrg * The above copyright notice and this permission notice (including the next
13706f2543Smrg * paragraph) shall be included in all copies or substantial portions of the
14706f2543Smrg * Software.
15706f2543Smrg *
16706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17706f2543Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19706f2543Smrg * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20706f2543Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21706f2543Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22706f2543Smrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
23706f2543Smrg */
24706f2543Smrg
25706f2543Smrg#ifdef HAVE_DIX_CONFIG_H
26706f2543Smrg#include <dix-config.h>
27706f2543Smrg#endif
28706f2543Smrg
29706f2543Smrg#include "glxserver.h"
30706f2543Smrg#include "glxutil.h"
31706f2543Smrg#include "glxext.h"
32706f2543Smrg#include "singlesize.h"
33706f2543Smrg#include "unpack.h"
34706f2543Smrg#include "indirect_size_get.h"
35706f2543Smrg#include "indirect_dispatch.h"
36706f2543Smrg#include "glapitable.h"
37706f2543Smrg#include "glapi.h"
38706f2543Smrg#include "glthread.h"
39706f2543Smrg#include "dispatch.h"
40706f2543Smrg#include "glapioffsets.h"
41706f2543Smrg#include "glxbyteorder.h"
42706f2543Smrg
43706f2543Smrgstatic int DoSwapInterval(__GLXclientState *cl, GLbyte *pc, int do_swap);
44706f2543Smrg
45706f2543Smrgint DoSwapInterval(__GLXclientState *cl, GLbyte *pc, int do_swap)
46706f2543Smrg{
47706f2543Smrg    xGLXVendorPrivateReq * const req = (xGLXVendorPrivateReq *) pc;
48706f2543Smrg    ClientPtr client = cl->client;
49706f2543Smrg    const GLXContextTag tag = req->contextTag;
50706f2543Smrg    __GLXcontext *cx;
51706f2543Smrg    GLint interval;
52706f2543Smrg
53706f2543Smrg
54706f2543Smrg    REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 4);
55706f2543Smrg
56706f2543Smrg    cx = __glXLookupContextByTag(cl, tag);
57706f2543Smrg
58706f2543Smrg    if ((cx == NULL) || (cx->pGlxScreen == NULL)) {
59706f2543Smrg	client->errorValue = tag;
60706f2543Smrg	return __glXError(GLXBadContext);
61706f2543Smrg    }
62706f2543Smrg
63706f2543Smrg    if (cx->pGlxScreen->swapInterval == NULL) {
64706f2543Smrg	LogMessage(X_ERROR, "AIGLX: cx->pGlxScreen->swapInterval == NULL\n");
65706f2543Smrg	client->errorValue = tag;
66706f2543Smrg	return __glXError(GLXUnsupportedPrivateRequest);
67706f2543Smrg    }
68706f2543Smrg
69706f2543Smrg    if (cx->drawPriv == NULL) {
70706f2543Smrg	client->errorValue = tag;
71706f2543Smrg	return BadValue;
72706f2543Smrg    }
73706f2543Smrg
74706f2543Smrg    pc += __GLX_VENDPRIV_HDR_SIZE;
75706f2543Smrg    interval = (do_swap)
76706f2543Smrg      ? bswap_32(*(int *)(pc + 0))
77706f2543Smrg      :          *(int *)(pc + 0);
78706f2543Smrg
79706f2543Smrg    if (interval <= 0)
80706f2543Smrg	return BadValue;
81706f2543Smrg
82706f2543Smrg    (void) (*cx->pGlxScreen->swapInterval)(cx->drawPriv, interval);
83706f2543Smrg    return Success;
84706f2543Smrg}
85706f2543Smrg
86706f2543Smrgint __glXDisp_SwapIntervalSGI(__GLXclientState *cl, GLbyte *pc)
87706f2543Smrg{
88706f2543Smrg    return DoSwapInterval(cl, pc, 0);
89706f2543Smrg}
90706f2543Smrg
91706f2543Smrgint __glXDispSwap_SwapIntervalSGI(__GLXclientState *cl, GLbyte *pc)
92706f2543Smrg{
93706f2543Smrg    return DoSwapInterval(cl, pc, 1);
94706f2543Smrg}
95