swap_interval.c revision 4642e01f
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#define NEED_REPLIES
26#ifdef HAVE_DIX_CONFIG_H
27#include <dix-config.h>
28#endif
29
30#include "glxserver.h"
31#include "glxutil.h"
32#include "glxext.h"
33#include "singlesize.h"
34#include "unpack.h"
35#include "indirect_size_get.h"
36#include "indirect_dispatch.h"
37#include "glapitable.h"
38#include "glapi.h"
39#include "glthread.h"
40#include "dispatch.h"
41#include "glapioffsets.h"
42#include "glxbyteorder.h"
43
44static int DoSwapInterval(__GLXclientState *cl, GLbyte *pc, int do_swap);
45
46int DoSwapInterval(__GLXclientState *cl, GLbyte *pc, int do_swap)
47{
48    xGLXVendorPrivateReq * const req = (xGLXVendorPrivateReq *) pc;
49    ClientPtr client = cl->client;
50    const GLXContextTag tag = req->contextTag;
51    __GLXcontext *cx;
52    GLint interval;
53
54
55    cx = __glXLookupContextByTag(cl, tag);
56
57    LogMessage(X_ERROR, "%s: cx = %p, GLX screen = %p\n", __func__,
58	       cx, (cx == NULL) ? NULL : cx->pGlxScreen);
59    if ((cx == NULL) || (cx->pGlxScreen == NULL)) {
60	client->errorValue = tag;
61	return __glXError(GLXBadContext);
62    }
63
64    if (cx->pGlxScreen->swapInterval == NULL) {
65	LogMessage(X_ERROR, "AIGLX: cx->pGlxScreen->swapInterval == NULL\n");
66	client->errorValue = tag;
67	return __glXError(GLXUnsupportedPrivateRequest);
68    }
69
70    if (cx->drawPriv == NULL) {
71	client->errorValue = tag;
72	return __glXError(GLXBadDrawable);
73    }
74
75    pc += __GLX_VENDPRIV_HDR_SIZE;
76    interval = (do_swap)
77      ? bswap_32(*(int *)(pc + 0))
78      :          *(int *)(pc + 0);
79
80    (void) (*cx->pGlxScreen->swapInterval)(cx->drawPriv, interval);
81    return Success;
82}
83
84int __glXDisp_SwapIntervalSGI(__GLXclientState *cl, GLbyte *pc)
85{
86    return DoSwapInterval(cl, pc, 0);
87}
88
89int __glXDispSwap_SwapIntervalSGI(__GLXclientState *cl, GLbyte *pc)
90{
91    return DoSwapInterval(cl, pc, 1);
92}
93