1/*
2 * (C) Copyright IBM Corporation 2006
3 * 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 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#ifdef HAVE_DIX_CONFIG_H
26#include <dix-config.h>
27#endif
28
29#include "glxserver.h"
30#include "glxutil.h"
31#include "glxext.h"
32#include "singlesize.h"
33#include "unpack.h"
34#include "indirect_size_get.h"
35#include "indirect_dispatch.h"
36#include "glxbyteorder.h"
37
38static int DoSwapInterval(__GLXclientState * cl, GLbyte * pc, int do_swap);
39
40int
41DoSwapInterval(__GLXclientState * cl, GLbyte * pc, int do_swap)
42{
43    xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
44    ClientPtr client = cl->client;
45    const GLXContextTag tag = req->contextTag;
46    __GLXcontext *cx;
47    GLint interval;
48
49    REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 4);
50
51    cx = __glXLookupContextByTag(cl, tag);
52
53    if ((cx == NULL) || (cx->pGlxScreen == NULL)) {
54        client->errorValue = tag;
55        return __glXError(GLXBadContext);
56    }
57
58    if (cx->pGlxScreen->swapInterval == NULL) {
59        LogMessage(X_ERROR, "AIGLX: cx->pGlxScreen->swapInterval == NULL\n");
60        client->errorValue = tag;
61        return __glXError(GLXUnsupportedPrivateRequest);
62    }
63
64    if (cx->drawPriv == NULL) {
65        client->errorValue = tag;
66        return BadValue;
67    }
68
69    pc += __GLX_VENDPRIV_HDR_SIZE;
70    interval = (do_swap)
71        ? bswap_32(*(int *) (pc + 0))
72        : *(int *) (pc + 0);
73
74    if (interval <= 0)
75        return BadValue;
76
77    (void) (*cx->pGlxScreen->swapInterval) (cx->drawPriv, interval);
78    return Success;
79}
80
81int
82__glXDisp_SwapIntervalSGI(__GLXclientState * cl, GLbyte * pc)
83{
84    return DoSwapInterval(cl, pc, 0);
85}
86
87int
88__glXDispSwap_SwapIntervalSGI(__GLXclientState * cl, GLbyte * pc)
89{
90    return DoSwapInterval(cl, pc, 1);
91}
92