swap_interval.c revision f7df2e56
14642e01fSmrg/*
24642e01fSmrg * (C) Copyright IBM Corporation 2006
34642e01fSmrg * All Rights Reserved.
44642e01fSmrg *
54642e01fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
64642e01fSmrg * copy of this software and associated documentation files (the "Software"),
74642e01fSmrg * to deal in the Software without restriction, including without limitation
84642e01fSmrg * on the rights to use, copy, modify, merge, publish, distribute, sub
94642e01fSmrg * license, and/or sell copies of the Software, and to permit persons to whom
104642e01fSmrg * the Software is furnished to do so, subject to the following conditions:
114642e01fSmrg *
124642e01fSmrg * The above copyright notice and this permission notice (including the next
134642e01fSmrg * paragraph) shall be included in all copies or substantial portions of the
144642e01fSmrg * Software.
154642e01fSmrg *
164642e01fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
174642e01fSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
184642e01fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
194642e01fSmrg * THE COPYRIGHT HOLDERS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
204642e01fSmrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
214642e01fSmrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
224642e01fSmrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
234642e01fSmrg */
244642e01fSmrg
254642e01fSmrg#ifdef HAVE_DIX_CONFIG_H
264642e01fSmrg#include <dix-config.h>
274642e01fSmrg#endif
284642e01fSmrg
294642e01fSmrg#include "glxserver.h"
304642e01fSmrg#include "glxutil.h"
314642e01fSmrg#include "glxext.h"
324642e01fSmrg#include "singlesize.h"
334642e01fSmrg#include "unpack.h"
344642e01fSmrg#include "indirect_size_get.h"
354642e01fSmrg#include "indirect_dispatch.h"
364642e01fSmrg#include "glxbyteorder.h"
374642e01fSmrg
38f7df2e56Smrgstatic int DoSwapInterval(__GLXclientState * cl, GLbyte * pc, int do_swap);
394642e01fSmrg
40f7df2e56Smrgint
41f7df2e56SmrgDoSwapInterval(__GLXclientState * cl, GLbyte * pc, int do_swap)
424642e01fSmrg{
43f7df2e56Smrg    xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
444642e01fSmrg    ClientPtr client = cl->client;
454642e01fSmrg    const GLXContextTag tag = req->contextTag;
464642e01fSmrg    __GLXcontext *cx;
474642e01fSmrg    GLint interval;
484642e01fSmrg
49f7df2e56Smrg    REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 4);
504642e01fSmrg
510b0d8713Smrg    REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 4);
520b0d8713Smrg
534642e01fSmrg    cx = __glXLookupContextByTag(cl, tag);
544642e01fSmrg
554642e01fSmrg    if ((cx == NULL) || (cx->pGlxScreen == NULL)) {
56f7df2e56Smrg        client->errorValue = tag;
57f7df2e56Smrg        return __glXError(GLXBadContext);
584642e01fSmrg    }
59f7df2e56Smrg
604642e01fSmrg    if (cx->pGlxScreen->swapInterval == NULL) {
61f7df2e56Smrg        LogMessage(X_ERROR, "AIGLX: cx->pGlxScreen->swapInterval == NULL\n");
62f7df2e56Smrg        client->errorValue = tag;
63f7df2e56Smrg        return __glXError(GLXUnsupportedPrivateRequest);
644642e01fSmrg    }
654642e01fSmrg
664642e01fSmrg    if (cx->drawPriv == NULL) {
67f7df2e56Smrg        client->errorValue = tag;
68f7df2e56Smrg        return BadValue;
694642e01fSmrg    }
70f7df2e56Smrg
714642e01fSmrg    pc += __GLX_VENDPRIV_HDR_SIZE;
724642e01fSmrg    interval = (do_swap)
73f7df2e56Smrg        ? bswap_32(*(int *) (pc + 0))
74f7df2e56Smrg        : *(int *) (pc + 0);
754642e01fSmrg
766747b715Smrg    if (interval <= 0)
77f7df2e56Smrg        return BadValue;
786747b715Smrg
79f7df2e56Smrg    (void) (*cx->pGlxScreen->swapInterval) (cx->drawPriv, interval);
804642e01fSmrg    return Success;
814642e01fSmrg}
824642e01fSmrg
83f7df2e56Smrgint
84f7df2e56Smrg__glXDisp_SwapIntervalSGI(__GLXclientState * cl, GLbyte * pc)
854642e01fSmrg{
864642e01fSmrg    return DoSwapInterval(cl, pc, 0);
874642e01fSmrg}
884642e01fSmrg
89f7df2e56Smrgint
90f7df2e56Smrg__glXDispSwap_SwapIntervalSGI(__GLXclientState * cl, GLbyte * pc)
914642e01fSmrg{
924642e01fSmrg    return DoSwapInterval(cl, pc, 1);
934642e01fSmrg}
94