2008-11-02 08:26:08 -07:00
|
|
|
/*
|
|
|
|
* Copyright © 2008 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Soft-
|
|
|
|
* ware"), to deal in the Software without restriction, including without
|
|
|
|
* limitation the rights to use, copy, modify, merge, publish, distribute,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, provided that the above copyright
|
|
|
|
* notice(s) and this permission notice appear in all copies of the Soft-
|
|
|
|
* ware and that both the above copyright notice(s) and this permission
|
|
|
|
* notice appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
|
|
|
|
* ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
|
|
|
|
* RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
|
|
|
|
* THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
|
|
|
|
* QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
|
|
|
|
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
|
|
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
|
|
|
|
* MANCE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Except as contained in this notice, the name of a copyright holder shall
|
|
|
|
* not be used in advertising or otherwise to promote the sale, use or
|
|
|
|
* other dealings in this Software without prior written authorization of
|
|
|
|
* the copyright holder.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Kristian Høgsberg (krh@redhat.com)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_XORG_CONFIG_H
|
|
|
|
#include <xorg-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#include <X11/extensions/dri2proto.h>
|
2009-09-06 13:44:18 -06:00
|
|
|
#include <X11/extensions/xfixeswire.h>
|
2008-11-02 08:26:08 -07:00
|
|
|
#include "dixstruct.h"
|
|
|
|
#include "scrnintstr.h"
|
|
|
|
#include "pixmapstr.h"
|
|
|
|
#include "extnsionst.h"
|
2009-09-06 13:44:18 -06:00
|
|
|
#include "xfixes.h"
|
2008-11-02 08:26:08 -07:00
|
|
|
#include "dri2.h"
|
2010-07-27 13:02:24 -06:00
|
|
|
#include "protocol-versions.h"
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
/* The only xf86 include */
|
|
|
|
#include "xf86Module.h"
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static ExtensionEntry *dri2Extension;
|
2011-12-18 09:08:59 -07:00
|
|
|
extern Bool DRI2ModuleSetup(void);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
static Bool
|
2010-07-27 13:02:24 -06:00
|
|
|
validDrawable(ClientPtr client, XID drawable, Mask access_mode,
|
2012-06-10 07:21:05 -06:00
|
|
|
DrawablePtr *pDrawable, int *status)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
2010-12-05 08:36:02 -07:00
|
|
|
*status = dixLookupDrawable(pDrawable, drawable, client,
|
2012-06-10 07:21:05 -06:00
|
|
|
M_DRAWABLE_WINDOW | M_DRAWABLE_PIXMAP,
|
|
|
|
access_mode);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (*status != Success) {
|
2012-06-10 07:21:05 -06:00
|
|
|
client->errorValue = drawable;
|
|
|
|
return FALSE;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcDRI2QueryVersion(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xDRI2QueryVersionReq);
|
|
|
|
xDRI2QueryVersionReply rep;
|
|
|
|
|
|
|
|
if (client->swapped)
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->length);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xDRI2QueryVersionReq);
|
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.length = 0;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
2010-07-27 13:02:24 -06:00
|
|
|
rep.majorVersion = dri2_major;
|
|
|
|
rep.minorVersion = dri2_minor;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
if (client->swapped) {
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&rep.sequenceNumber);
|
|
|
|
swapl(&rep.length);
|
|
|
|
swapl(&rep.majorVersion);
|
|
|
|
swapl(&rep.minorVersion);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
WriteToClient(client, sizeof(xDRI2QueryVersionReply), &rep);
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcDRI2Connect(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xDRI2ConnectReq);
|
|
|
|
xDRI2ConnectReply rep;
|
2009-09-06 13:44:18 -06:00
|
|
|
DrawablePtr pDraw;
|
|
|
|
int fd, status;
|
2008-11-02 08:26:08 -07:00
|
|
|
const char *driverName;
|
2009-09-06 13:44:18 -06:00
|
|
|
const char *deviceName;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xDRI2ConnectReq);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!validDrawable(client, stuff->window, DixGetAttrAccess,
|
2012-06-10 07:21:05 -06:00
|
|
|
&pDraw, &status))
|
|
|
|
return status;
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.length = 0;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
|
|
|
rep.driverNameLength = 0;
|
2009-09-06 13:44:18 -06:00
|
|
|
rep.deviceNameLength = 0;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (!DRI2Connect(pDraw->pScreen,
|
2012-06-10 07:21:05 -06:00
|
|
|
stuff->driverType, &fd, &driverName, &deviceName))
|
|
|
|
goto fail;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
rep.driverNameLength = strlen(driverName);
|
2009-09-06 13:44:18 -06:00
|
|
|
rep.deviceNameLength = strlen(deviceName);
|
|
|
|
rep.length = (rep.driverNameLength + 3) / 4 +
|
2012-06-10 07:21:05 -06:00
|
|
|
(rep.deviceNameLength + 3) / 4;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
fail:
|
|
|
|
WriteToClient(client, sizeof(xDRI2ConnectReply), &rep);
|
|
|
|
WriteToClient(client, rep.driverNameLength, driverName);
|
2009-09-06 13:44:18 -06:00
|
|
|
WriteToClient(client, rep.deviceNameLength, deviceName);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-09-06 13:44:18 -06:00
|
|
|
ProcDRI2Authenticate(ClientPtr client)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
REQUEST(xDRI2AuthenticateReq);
|
|
|
|
xDRI2AuthenticateReply rep;
|
|
|
|
DrawablePtr pDraw;
|
|
|
|
int status;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
REQUEST_SIZE_MATCH(xDRI2AuthenticateReq);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!validDrawable(client, stuff->window, DixGetAttrAccess,
|
2012-06-10 07:21:05 -06:00
|
|
|
&pDraw, &status))
|
|
|
|
return status;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
2009-09-06 13:44:18 -06:00
|
|
|
rep.length = 0;
|
|
|
|
rep.authenticated = DRI2Authenticate(pDraw->pScreen, stuff->magic);
|
|
|
|
WriteToClient(client, sizeof(xDRI2AuthenticateReply), &rep);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
DRI2InvalidateBuffersEvent(DrawablePtr pDraw, void *priv, XID id)
|
2010-12-05 08:36:02 -07:00
|
|
|
{
|
|
|
|
xDRI2InvalidateBuffers event;
|
|
|
|
ClientPtr client = priv;
|
|
|
|
|
|
|
|
event.type = DRI2EventBase + DRI2_InvalidateBuffers;
|
2012-06-10 07:21:05 -06:00
|
|
|
event.drawable = id;
|
2010-12-05 08:36:02 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
WriteEventsToClient(client, 1, (xEvent *) &event);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcDRI2CreateDrawable(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xDRI2CreateDrawableReq);
|
|
|
|
DrawablePtr pDrawable;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xDRI2CreateDrawableReq);
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!validDrawable(client, stuff->drawable, DixAddAccess,
|
2012-06-10 07:21:05 -06:00
|
|
|
&pDrawable, &status))
|
|
|
|
return status;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
status = DRI2CreateDrawable(client, pDrawable, stuff->drawable,
|
2012-06-10 07:21:05 -06:00
|
|
|
DRI2InvalidateBuffersEvent, client);
|
2009-09-06 13:44:18 -06:00
|
|
|
if (status != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return status;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcDRI2DestroyDrawable(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xDRI2DestroyDrawableReq);
|
|
|
|
DrawablePtr pDrawable;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xDRI2DestroyDrawableReq);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!validDrawable(client, stuff->drawable, DixRemoveAccess,
|
2012-06-10 07:21:05 -06:00
|
|
|
&pDrawable, &status))
|
|
|
|
return status;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
static int
|
2009-09-06 13:44:18 -06:00
|
|
|
send_buffers_reply(ClientPtr client, DrawablePtr pDrawable,
|
2012-06-10 07:21:05 -06:00
|
|
|
DRI2BufferPtr * buffers, int count, int width, int height)
|
2009-09-06 13:44:18 -06:00
|
|
|
{
|
|
|
|
xDRI2GetBuffersReply rep;
|
|
|
|
int skip = 0;
|
|
|
|
int i;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
if (buffers == NULL)
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadAlloc;
|
2010-12-05 08:36:02 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
if (pDrawable->type == DRAWABLE_WINDOW) {
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
/* Do not send the real front buffer of a window to the client.
|
|
|
|
*/
|
|
|
|
if (buffers[i]->attachment == DRI2BufferFrontLeft) {
|
|
|
|
skip++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.length = (count - skip) * sizeof(xDRI2Buffer) / 4;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
|
|
|
rep.width = width;
|
|
|
|
rep.height = height;
|
|
|
|
rep.count = count - skip;
|
|
|
|
WriteToClient(client, sizeof(xDRI2GetBuffersReply), &rep);
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
2012-06-10 07:21:05 -06:00
|
|
|
xDRI2Buffer buffer;
|
|
|
|
|
|
|
|
/* Do not send the real front buffer of a window to the client.
|
|
|
|
*/
|
|
|
|
if ((pDrawable->type == DRAWABLE_WINDOW)
|
|
|
|
&& (buffers[i]->attachment == DRI2BufferFrontLeft)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer.attachment = buffers[i]->attachment;
|
|
|
|
buffer.name = buffers[i]->name;
|
|
|
|
buffer.pitch = buffers[i]->pitch;
|
|
|
|
buffer.cpp = buffers[i]->cpp;
|
|
|
|
buffer.flags = buffers[i]->flags;
|
|
|
|
WriteToClient(client, sizeof(xDRI2Buffer), &buffer);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcDRI2GetBuffers(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xDRI2GetBuffersReq);
|
|
|
|
DrawablePtr pDrawable;
|
2010-07-27 13:02:24 -06:00
|
|
|
DRI2BufferPtr *buffers;
|
2009-09-06 13:44:18 -06:00
|
|
|
int status, width, height, count;
|
|
|
|
unsigned int *attachments;
|
|
|
|
|
|
|
|
REQUEST_FIXED_SIZE(xDRI2GetBuffersReq, stuff->count * 4);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!validDrawable(client, stuff->drawable, DixReadAccess | DixWriteAccess,
|
2012-06-10 07:21:05 -06:00
|
|
|
&pDrawable, &status))
|
|
|
|
return status;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (DRI2ThrottleClient(client, pDrawable))
|
2012-06-10 07:21:05 -06:00
|
|
|
return Success;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
attachments = (unsigned int *) &stuff[1];
|
|
|
|
buffers = DRI2GetBuffers(pDrawable, &width, &height,
|
2012-06-10 07:21:05 -06:00
|
|
|
attachments, stuff->count, &count);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return send_buffers_reply(client, pDrawable, buffers, count, width, height);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
static int
|
2009-09-06 13:44:18 -06:00
|
|
|
ProcDRI2GetBuffersWithFormat(ClientPtr client)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
2009-09-06 13:44:18 -06:00
|
|
|
REQUEST(xDRI2GetBuffersReq);
|
|
|
|
DrawablePtr pDrawable;
|
2010-07-27 13:02:24 -06:00
|
|
|
DRI2BufferPtr *buffers;
|
2009-09-06 13:44:18 -06:00
|
|
|
int status, width, height, count;
|
|
|
|
unsigned int *attachments;
|
|
|
|
|
|
|
|
REQUEST_FIXED_SIZE(xDRI2GetBuffersReq, stuff->count * (2 * 4));
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!validDrawable(client, stuff->drawable, DixReadAccess | DixWriteAccess,
|
2012-06-10 07:21:05 -06:00
|
|
|
&pDrawable, &status))
|
|
|
|
return status;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (DRI2ThrottleClient(client, pDrawable))
|
2012-06-10 07:21:05 -06:00
|
|
|
return Success;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
attachments = (unsigned int *) &stuff[1];
|
|
|
|
buffers = DRI2GetBuffersWithFormat(pDrawable, &width, &height,
|
2012-06-10 07:21:05 -06:00
|
|
|
attachments, stuff->count, &count);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return send_buffers_reply(client, pDrawable, buffers, count, width, height);
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcDRI2CopyRegion(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xDRI2CopyRegionReq);
|
|
|
|
xDRI2CopyRegionReply rep;
|
2008-11-02 08:26:08 -07:00
|
|
|
DrawablePtr pDrawable;
|
|
|
|
int status;
|
2009-09-06 13:44:18 -06:00
|
|
|
RegionPtr pRegion;
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xDRI2CopyRegionReq);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!validDrawable(client, stuff->drawable, DixWriteAccess,
|
2012-06-10 07:21:05 -06:00
|
|
|
&pDrawable, &status))
|
|
|
|
return status;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
VERIFY_REGION(pRegion, stuff->region, client, DixReadAccess);
|
|
|
|
|
|
|
|
status = DRI2CopyRegion(pDrawable, pRegion, stuff->dest, stuff->src);
|
|
|
|
if (status != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return status;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
/* CopyRegion needs to be a round trip to make sure the X server
|
|
|
|
* queues the swap buffer rendering commands before the DRI client
|
|
|
|
* continues rendering. The reply has a bitmask to signal the
|
|
|
|
* presense of optional return values as well, but we're not using
|
|
|
|
* that yet.
|
|
|
|
*/
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.length = 0;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
WriteToClient(client, sizeof(xDRI2CopyRegionReply), &rep);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
load_swap_reply(xDRI2SwapBuffersReply * rep, CARD64 sbc)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
rep->swap_hi = sbc >> 32;
|
|
|
|
rep->swap_lo = sbc & 0xffffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CARD64
|
|
|
|
vals_to_card64(CARD32 lo, CARD32 hi)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
return (CARD64) hi << 32 | lo;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
DRI2SwapEvent(ClientPtr client, void *data, int type, CARD64 ust, CARD64 msc,
|
2012-06-10 07:21:05 -06:00
|
|
|
CARD32 sbc)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
2011-11-05 07:32:40 -06:00
|
|
|
xDRI2BufferSwapComplete2 event;
|
2010-07-27 13:02:24 -06:00
|
|
|
DrawablePtr pDrawable = data;
|
|
|
|
|
|
|
|
event.type = DRI2EventBase + DRI2_BufferSwapComplete;
|
|
|
|
event.event_type = type;
|
|
|
|
event.drawable = pDrawable->id;
|
2012-06-10 07:21:05 -06:00
|
|
|
event.ust_hi = (CARD64) ust >> 32;
|
2010-07-27 13:02:24 -06:00
|
|
|
event.ust_lo = ust & 0xffffffff;
|
2012-06-10 07:21:05 -06:00
|
|
|
event.msc_hi = (CARD64) msc >> 32;
|
2010-07-27 13:02:24 -06:00
|
|
|
event.msc_lo = msc & 0xffffffff;
|
2011-11-05 07:32:40 -06:00
|
|
|
event.sbc = sbc;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
WriteEventsToClient(client, 1, (xEvent *) &event);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcDRI2SwapBuffers(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xDRI2SwapBuffersReq);
|
|
|
|
xDRI2SwapBuffersReply rep;
|
|
|
|
DrawablePtr pDrawable;
|
|
|
|
CARD64 target_msc, divisor, remainder, swap_target;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xDRI2SwapBuffersReq);
|
|
|
|
|
|
|
|
if (!validDrawable(client, stuff->drawable,
|
2012-06-10 07:21:05 -06:00
|
|
|
DixReadAccess | DixWriteAccess, &pDrawable, &status))
|
|
|
|
return status;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensures an out of control client can't exhaust our swap queue, and
|
|
|
|
* also orders swaps.
|
|
|
|
*/
|
|
|
|
if (DRI2ThrottleClient(client, pDrawable))
|
2012-06-10 07:21:05 -06:00
|
|
|
return Success;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
target_msc = vals_to_card64(stuff->target_msc_lo, stuff->target_msc_hi);
|
|
|
|
divisor = vals_to_card64(stuff->divisor_lo, stuff->divisor_hi);
|
|
|
|
remainder = vals_to_card64(stuff->remainder_lo, stuff->remainder_hi);
|
|
|
|
|
|
|
|
status = DRI2SwapBuffers(client, pDrawable, target_msc, divisor, remainder,
|
2012-06-10 07:21:05 -06:00
|
|
|
&swap_target, DRI2SwapEvent, pDrawable);
|
2010-07-27 13:02:24 -06:00
|
|
|
if (status != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadDrawable;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.length = 0;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
|
|
|
load_swap_reply(&rep, swap_target);
|
|
|
|
|
|
|
|
WriteToClient(client, sizeof(xDRI2SwapBuffersReply), &rep);
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
load_msc_reply(xDRI2MSCReply * rep, CARD64 ust, CARD64 msc, CARD64 sbc)
|
2010-07-27 13:02:24 -06:00
|
|
|
{
|
|
|
|
rep->ust_hi = ust >> 32;
|
|
|
|
rep->ust_lo = ust & 0xffffffff;
|
|
|
|
rep->msc_hi = msc >> 32;
|
|
|
|
rep->msc_lo = msc & 0xffffffff;
|
|
|
|
rep->sbc_hi = sbc >> 32;
|
|
|
|
rep->sbc_lo = sbc & 0xffffffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcDRI2GetMSC(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xDRI2GetMSCReq);
|
|
|
|
xDRI2MSCReply rep;
|
|
|
|
DrawablePtr pDrawable;
|
|
|
|
CARD64 ust, msc, sbc;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xDRI2GetMSCReq);
|
|
|
|
|
|
|
|
if (!validDrawable(client, stuff->drawable, DixReadAccess, &pDrawable,
|
2012-06-10 07:21:05 -06:00
|
|
|
&status))
|
|
|
|
return status;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
status = DRI2GetMSC(pDrawable, &ust, &msc, &sbc);
|
|
|
|
if (status != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return status;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.length = 0;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
|
|
|
load_msc_reply(&rep, ust, msc, sbc);
|
|
|
|
|
|
|
|
WriteToClient(client, sizeof(xDRI2MSCReply), &rep);
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcDRI2WaitMSC(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xDRI2WaitMSCReq);
|
|
|
|
DrawablePtr pDrawable;
|
|
|
|
CARD64 target, divisor, remainder;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
/* FIXME: in restart case, client may be gone at this point */
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xDRI2WaitMSCReq);
|
|
|
|
|
|
|
|
if (!validDrawable(client, stuff->drawable, DixReadAccess, &pDrawable,
|
2012-06-10 07:21:05 -06:00
|
|
|
&status))
|
|
|
|
return status;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
target = vals_to_card64(stuff->target_msc_lo, stuff->target_msc_hi);
|
|
|
|
divisor = vals_to_card64(stuff->divisor_lo, stuff->divisor_hi);
|
|
|
|
remainder = vals_to_card64(stuff->remainder_lo, stuff->remainder_hi);
|
|
|
|
|
|
|
|
status = DRI2WaitMSC(client, pDrawable, target, divisor, remainder);
|
|
|
|
if (status != Success)
|
2012-06-10 07:21:05 -06:00
|
|
|
return status;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ProcDRI2WaitMSCReply(ClientPtr client, CARD64 ust, CARD64 msc, CARD64 sbc)
|
|
|
|
{
|
|
|
|
xDRI2MSCReply rep;
|
|
|
|
|
|
|
|
rep.type = X_Reply;
|
|
|
|
rep.length = 0;
|
|
|
|
rep.sequenceNumber = client->sequence;
|
|
|
|
load_msc_reply(&rep, ust, msc, sbc);
|
|
|
|
|
|
|
|
WriteToClient(client, sizeof(xDRI2MSCReply), &rep);
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcDRI2SwapInterval(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xDRI2SwapIntervalReq);
|
|
|
|
DrawablePtr pDrawable;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
/* FIXME: in restart case, client may be gone at this point */
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xDRI2SwapIntervalReq);
|
|
|
|
|
|
|
|
if (!validDrawable(client, stuff->drawable, DixReadAccess | DixWriteAccess,
|
2012-06-10 07:21:05 -06:00
|
|
|
&pDrawable, &status))
|
|
|
|
return status;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
DRI2SwapInterval(pDrawable, stuff->interval);
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ProcDRI2WaitSBC(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xDRI2WaitSBCReq);
|
|
|
|
DrawablePtr pDrawable;
|
|
|
|
CARD64 target;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
REQUEST_SIZE_MATCH(xDRI2WaitSBCReq);
|
|
|
|
|
|
|
|
if (!validDrawable(client, stuff->drawable, DixReadAccess, &pDrawable,
|
2012-06-10 07:21:05 -06:00
|
|
|
&status))
|
|
|
|
return status;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
target = vals_to_card64(stuff->target_sbc_lo, stuff->target_sbc_hi);
|
|
|
|
status = DRI2WaitSBC(client, pDrawable, target);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
ProcDRI2Dispatch(ClientPtr client)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
REQUEST(xReq);
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
switch (stuff->data) {
|
|
|
|
case X_DRI2QueryVersion:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcDRI2QueryVersion(client);
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!LocalClient(client))
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadRequest;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
switch (stuff->data) {
|
|
|
|
case X_DRI2Connect:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcDRI2Connect(client);
|
2009-09-06 13:44:18 -06:00
|
|
|
case X_DRI2Authenticate:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcDRI2Authenticate(client);
|
2008-11-02 08:26:08 -07:00
|
|
|
case X_DRI2CreateDrawable:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcDRI2CreateDrawable(client);
|
2008-11-02 08:26:08 -07:00
|
|
|
case X_DRI2DestroyDrawable:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcDRI2DestroyDrawable(client);
|
2009-09-06 13:44:18 -06:00
|
|
|
case X_DRI2GetBuffers:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcDRI2GetBuffers(client);
|
2009-09-06 13:44:18 -06:00
|
|
|
case X_DRI2CopyRegion:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcDRI2CopyRegion(client);
|
2009-09-06 13:44:18 -06:00
|
|
|
case X_DRI2GetBuffersWithFormat:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcDRI2GetBuffersWithFormat(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_DRI2SwapBuffers:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcDRI2SwapBuffers(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_DRI2GetMSC:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcDRI2GetMSC(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_DRI2WaitMSC:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcDRI2WaitMSC(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_DRI2WaitSBC:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcDRI2WaitSBC(client);
|
2010-07-27 13:02:24 -06:00
|
|
|
case X_DRI2SwapInterval:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcDRI2SwapInterval(client);
|
2008-11-02 08:26:08 -07:00
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadRequest;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
SProcDRI2Connect(ClientPtr client)
|
|
|
|
{
|
|
|
|
REQUEST(xDRI2ConnectReq);
|
|
|
|
xDRI2ConnectReply rep;
|
|
|
|
|
|
|
|
/* If the client is swapped, it's not local. Talk to the hand. */
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&stuff->length);
|
2008-11-02 08:26:08 -07:00
|
|
|
if (sizeof(*stuff) / 4 != client->req_len)
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadLength;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
rep.sequenceNumber = client->sequence;
|
2012-06-10 07:21:05 -06:00
|
|
|
swaps(&rep.sequenceNumber);
|
2008-11-02 08:26:08 -07:00
|
|
|
rep.length = 0;
|
|
|
|
rep.driverNameLength = 0;
|
2009-09-06 13:44:18 -06:00
|
|
|
rep.deviceNameLength = 0;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
return Success;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
SProcDRI2Dispatch(ClientPtr client)
|
2008-11-02 08:26:08 -07:00
|
|
|
{
|
|
|
|
REQUEST(xReq);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only local clients are allowed DRI access, but remote clients
|
|
|
|
* still need these requests to find out cleanly.
|
|
|
|
*/
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (stuff->data) {
|
2008-11-02 08:26:08 -07:00
|
|
|
case X_DRI2QueryVersion:
|
2012-06-10 07:21:05 -06:00
|
|
|
return ProcDRI2QueryVersion(client);
|
2008-11-02 08:26:08 -07:00
|
|
|
case X_DRI2Connect:
|
2012-06-10 07:21:05 -06:00
|
|
|
return SProcDRI2Connect(client);
|
2008-11-02 08:26:08 -07:00
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
return BadRequest;
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
int DRI2EventBase;
|
2008-11-02 08:26:08 -07:00
|
|
|
|
|
|
|
static void
|
|
|
|
DRI2ExtensionInit(void)
|
|
|
|
{
|
|
|
|
dri2Extension = AddExtension(DRI2_NAME,
|
2012-06-10 07:21:05 -06:00
|
|
|
DRI2NumberEvents,
|
|
|
|
DRI2NumberErrors,
|
|
|
|
ProcDRI2Dispatch,
|
|
|
|
SProcDRI2Dispatch, NULL, StandardMinorOpcode);
|
2008-11-02 08:26:08 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
DRI2EventBase = dri2Extension->eventBase;
|
2011-12-18 09:08:59 -07:00
|
|
|
|
|
|
|
DRI2ModuleSetup();
|
2008-11-02 08:26:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
extern Bool noDRI2Extension;
|
|
|
|
|
|
|
|
_X_HIDDEN ExtensionModule dri2ExtensionModule = {
|
|
|
|
DRI2ExtensionInit,
|
|
|
|
DRI2_NAME,
|
|
|
|
&noDRI2Extension,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|