diff options
author | marha <marha@users.sourceforge.net> | 2010-05-17 06:57:43 +0000 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2010-05-17 06:57:43 +0000 |
commit | b103ec11e433e85764d9b82eed17b9284056d164 (patch) | |
tree | 90df907a7ce20622ee3f975c9fcd30ab87668158 | |
parent | 98d261187099eea8112d0953778882ba3d7c9c00 (diff) | |
download | vcxsrv-b103ec11e433e85764d9b82eed17b9284056d164.tar.gz vcxsrv-b103ec11e433e85764d9b82eed17b9284056d164.tar.bz2 vcxsrv-b103ec11e433e85764d9b82eed17b9284056d164.zip |
xserver git update 17/5/2010
-rw-r--r-- | xorg-server/dbe/dbe.c | 3356 | ||||
-rw-r--r-- | xorg-server/dbe/dbestruct.h | 4 | ||||
-rw-r--r-- | xorg-server/render/render.c | 6733 |
3 files changed, 5047 insertions, 5046 deletions
diff --git a/xorg-server/dbe/dbe.c b/xorg-server/dbe/dbe.c index a6c1c4f56..a49a46d69 100644 --- a/xorg-server/dbe/dbe.c +++ b/xorg-server/dbe/dbe.c @@ -1,1679 +1,1677 @@ -/******************************************************************************
- *
- * Copyright (c) 1994, 1995 Hewlett-Packard Company
- *
- * Permission is hereby granted, free of charge, to any person obtaining
- * a copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sublicense, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
- * IN NO EVENT SHALL HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
- * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name of the Hewlett-Packard
- * Company shall not be used in advertising or otherwise to promote the
- * sale, use or other dealings in this Software without prior written
- * authorization from the Hewlett-Packard Company.
- *
- * DIX DBE code
- *
- *****************************************************************************/
-
-
-/* INCLUDES */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <string.h>
-#if HAVE_STDINT_H
-#include <stdint.h>
-#elif !defined(UINT32_MAX)
-#define UINT32_MAX 0xffffffffU
-#endif
-
-#include <X11/X.h>
-#include <X11/Xproto.h>
-#include "scrnintstr.h"
-#include "extnsionst.h"
-#include "gcstruct.h"
-#include "dixstruct.h"
-#define NEED_DBE_PROTOCOL
-#include "dbestruct.h"
-#include "midbe.h"
-#include "xace.h"
-
-/* GLOBALS */
-
-/* These are static globals copied to DBE's screen private for use by DDX */
-static int dbeScreenPrivKeyIndex;
-static DevPrivateKey dbeScreenPrivKey = &dbeScreenPrivKeyIndex;
-static int dbeWindowPrivKeyIndex;
-static DevPrivateKey dbeWindowPrivKey = &dbeWindowPrivKeyIndex;
-
-/* These are static globals copied to DBE's screen private for use by DDX */
-static RESTYPE dbeDrawableResType;
-static RESTYPE dbeWindowPrivResType;
-
-/* Used to generate DBE's BadBuffer error. */
-static int dbeErrorBase;
-
-/******************************************************************************
- *
- * DBE DIX Procedure: DbeStubScreen
- *
- * Description:
- *
- * This is function stubs the function pointers in the given DBE screen
- * private and increments the number of stubbed screens.
- *
- *****************************************************************************/
-
-static void
-DbeStubScreen(DbeScreenPrivPtr pDbeScreenPriv, int *nStubbedScreens)
-{
- /* Stub DIX. */
- pDbeScreenPriv->SetupBackgroundPainter = NULL;
-
- /* Do not unwrap PositionWindow nor DestroyWindow. If the DDX
- * initialization function failed, we assume that it did not wrap
- * PositionWindow. Also, DestroyWindow is only wrapped if the DDX
- * initialization function succeeded.
- */
-
- /* Stub DDX. */
- pDbeScreenPriv->GetVisualInfo = NULL;
- pDbeScreenPriv->AllocBackBufferName = NULL;
- pDbeScreenPriv->SwapBuffers = NULL;
- pDbeScreenPriv->BeginIdiom = NULL;
- pDbeScreenPriv->EndIdiom = NULL;
- pDbeScreenPriv->WinPrivDelete = NULL;
- pDbeScreenPriv->ResetProc = NULL;
-
- (*nStubbedScreens)++;
-
-} /* DbeStubScreen() */
-
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: ProcDbeGetVersion
- *
- * Description:
- *
- * This function is for processing a DbeGetVersion request.
- * This request returns the major and minor version numbers of this
- * extension.
- *
- * Return Values:
- *
- * Success
- *
- *****************************************************************************/
-
-static int
-ProcDbeGetVersion(ClientPtr client)
-{
- /* REQUEST(xDbeGetVersionReq); */
- xDbeGetVersionReply rep;
- register int n;
-
-
- REQUEST_SIZE_MATCH(xDbeGetVersionReq);
-
- rep.type = X_Reply;
- rep.length = 0;
- rep.sequenceNumber = client->sequence;
- rep.majorVersion = DBE_MAJOR_VERSION;
- rep.minorVersion = DBE_MINOR_VERSION;
-
- if (client->swapped)
- {
- swaps(&rep.sequenceNumber, n);
- }
-
- WriteToClient(client, sizeof(xDbeGetVersionReply), (char *)&rep);
-
- return Success;
-
-} /* ProcDbeGetVersion() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: ProcDbeAllocateBackBufferName
- *
- * Description:
- *
- * This function is for processing a DbeAllocateBackBufferName request.
- * This request allocates a drawable ID used to refer to the back buffer
- * of a window.
- *
- * Return Values:
- *
- * BadAlloc - server can not allocate resources
- * BadIDChoice - id is out of range for client; id is already in use
- * BadMatch - window is not an InputOutput window;
- * visual of window is not on list returned by
- * DBEGetVisualInfo;
- * BadValue - invalid swap action is specified
- * BadWindow - window is not a valid window
- * Success
- *
- *****************************************************************************/
-
-static int
-ProcDbeAllocateBackBufferName(ClientPtr client)
-{
- REQUEST(xDbeAllocateBackBufferNameReq);
- WindowPtr pWin;
- DbeScreenPrivPtr pDbeScreenPriv;
- DbeWindowPrivPtr pDbeWindowPriv;
- XdbeScreenVisualInfo scrVisInfo;
- register int i;
- Bool visualMatched = FALSE;
- xDbeSwapAction swapAction;
- VisualID visual;
- int status;
- int add_index;
-
-
- REQUEST_SIZE_MATCH(xDbeAllocateBackBufferNameReq);
-
- /* The window must be valid. */
- status = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess);
- if (status != Success)
- return status;
-
- /* The window must be InputOutput. */
- if (pWin->drawable.class != InputOutput)
- {
- return(BadMatch);
- }
-
- /* The swap action must be valid. */
- swapAction = stuff->swapAction; /* use local var for performance. */
- if ((swapAction != XdbeUndefined ) &&
- (swapAction != XdbeBackground) &&
- (swapAction != XdbeUntouched ) &&
- (swapAction != XdbeCopied ))
- {
- return(BadValue);
- }
-
- /* The id must be in range and not already in use. */
- LEGAL_NEW_RESOURCE(stuff->buffer, client);
-
- /* The visual of the window must be in the list returned by
- * GetVisualInfo.
- */
- pDbeScreenPriv = DBE_SCREEN_PRIV_FROM_WINDOW(pWin);
- if (!pDbeScreenPriv->GetVisualInfo)
- return(BadMatch); /* screen doesn't support double buffering */
-
- if (!(*pDbeScreenPriv->GetVisualInfo)(pWin->drawable.pScreen, &scrVisInfo))
- {
- /* GetVisualInfo() failed to allocate visual info data. */
- return(BadAlloc);
- }
-
- /* See if the window's visual is on the list. */
- visual = wVisual(pWin);
- for (i = 0; (i < scrVisInfo.count) && !visualMatched; i++)
- {
- if (scrVisInfo.visinfo[i].visual == visual)
- {
- visualMatched = TRUE;
- }
- }
-
- /* Free what was allocated by the GetVisualInfo() call above. */
- free(scrVisInfo.visinfo);
-
- if (!visualMatched)
- {
- return(BadMatch);
- }
-
- if ((pDbeWindowPriv = DBE_WINDOW_PRIV(pWin)) == NULL)
- {
- /* There is no buffer associated with the window.
- * Allocate a window priv.
- */
-
- pDbeWindowPriv = calloc(1, sizeof(DbeWindowPrivRec));
- if (!pDbeWindowPriv)
- return(BadAlloc);
-
- /* Fill out window priv information. */
- pDbeWindowPriv->pWindow = pWin;
- pDbeWindowPriv->width = pWin->drawable.width;
- pDbeWindowPriv->height = pWin->drawable.height;
- pDbeWindowPriv->x = pWin->drawable.x;
- pDbeWindowPriv->y = pWin->drawable.y;
- pDbeWindowPriv->nBufferIDs = 0;
-
- /* Set the buffer ID array pointer to the initial (static) array). */
- pDbeWindowPriv->IDs = pDbeWindowPriv->initIDs;
-
- /* Initialize the buffer ID list. */
- pDbeWindowPriv->maxAvailableIDs = DBE_INIT_MAX_IDS;
- pDbeWindowPriv->IDs[0] = stuff->buffer;
-
- add_index = 0;
- for (i = 0; i < DBE_INIT_MAX_IDS; i++)
- {
- pDbeWindowPriv->IDs[i] = DBE_FREE_ID_ELEMENT;
- }
-
- /* Actually connect the window priv to the window. */
- dixSetPrivate(&pWin->devPrivates, dbeWindowPrivKey, pDbeWindowPriv);
-
- } /* if -- There is no buffer associated with the window. */
-
- else
- {
- /* A buffer is already associated with the window.
- * Add the new buffer ID to the array, reallocating the array memory
- * if necessary.
- */
-
- /* Determine if there is a free element in the ID array. */
- for (i = 0; i < pDbeWindowPriv->maxAvailableIDs; i++)
- {
- if (pDbeWindowPriv->IDs[i] == DBE_FREE_ID_ELEMENT)
- {
- /* There is still room in the ID array. */
- break;
- }
- }
-
- if (i == pDbeWindowPriv->maxAvailableIDs)
- {
- /* No more room in the ID array -- reallocate another array. */
- XID *pIDs;
-
- /* Setup an array pointer for the realloc operation below. */
- if (pDbeWindowPriv->maxAvailableIDs == DBE_INIT_MAX_IDS)
- {
- /* We will malloc a new array. */
- pIDs = NULL;
- }
- else
- {
- /* We will realloc a new array. */
- pIDs = pDbeWindowPriv->IDs;
- }
-
- /* malloc/realloc a new array and initialize all elements to 0. */
- pDbeWindowPriv->IDs = (XID *)realloc(pIDs,
- (pDbeWindowPriv->maxAvailableIDs+DBE_INCR_MAX_IDS)*sizeof(XID));
- if (!pDbeWindowPriv->IDs)
- {
- return(BadAlloc);
- }
- memset(&pDbeWindowPriv->IDs[pDbeWindowPriv->nBufferIDs], 0,
- (pDbeWindowPriv->maxAvailableIDs + DBE_INCR_MAX_IDS -
- pDbeWindowPriv->nBufferIDs) * sizeof(XID));
-
- if (pDbeWindowPriv->maxAvailableIDs == DBE_INIT_MAX_IDS)
- {
- /* We just went from using the initial (static) array to a
- * newly allocated array. Copy the IDs from the initial array
- * to the new array.
- */
- memcpy(pDbeWindowPriv->IDs, pDbeWindowPriv->initIDs,
- DBE_INIT_MAX_IDS * sizeof(XID));
- }
-
- pDbeWindowPriv->maxAvailableIDs += DBE_INCR_MAX_IDS;
- }
-
- add_index = i;
-
- } /* else -- A buffer is already associated with the window. */
-
-
- /* Call the DDX routine to allocate the back buffer. */
- status = (*pDbeScreenPriv->AllocBackBufferName)(pWin, stuff->buffer,
- stuff->swapAction);
-
- if (status == Success)
- {
- pDbeWindowPriv->IDs[add_index] = stuff->buffer;
- if (!AddResource(stuff->buffer, dbeWindowPrivResType,
- (pointer)pDbeWindowPriv))
- {
- pDbeWindowPriv->IDs[add_index] = DBE_FREE_ID_ELEMENT;
-
- if (pDbeWindowPriv->nBufferIDs == 0) {
- status = BadAlloc;
- goto out_free;
- }
- }
- } else {
- /* The DDX buffer allocation routine failed for the first buffer of
- * this window.
- */
- if (pDbeWindowPriv->nBufferIDs == 0) {
- goto out_free;
- }
- }
-
- /* Increment the number of buffers (XIDs) associated with this window. */
- pDbeWindowPriv->nBufferIDs++;
-
- /* Set swap action on all calls. */
- pDbeWindowPriv->swapAction = stuff->swapAction;
-
- return(status);
-
-out_free:
- dixSetPrivate(&pWin->devPrivates, dbeWindowPrivKey, NULL);
- free(pDbeWindowPriv);
- return (status);
-
-} /* ProcDbeAllocateBackBufferName() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: ProcDbeDeallocateBackBufferName
- *
- * Description:
- *
- * This function is for processing a DbeDeallocateBackBufferName request.
- * This request frees a drawable ID that was obtained by a
- * DbeAllocateBackBufferName request.
- *
- * Return Values:
- *
- * BadBuffer - buffer to deallocate is not associated with a window
- * Success
- *
- *****************************************************************************/
-
-static int
-ProcDbeDeallocateBackBufferName(ClientPtr client)
-{
- REQUEST(xDbeDeallocateBackBufferNameReq);
- DbeWindowPrivPtr pDbeWindowPriv;
- int rc, i;
- pointer val;
-
-
- REQUEST_SIZE_MATCH(xDbeDeallocateBackBufferNameReq);
-
- /* Buffer name must be valid */
- rc = dixLookupResourceByType((pointer *)&pDbeWindowPriv, stuff->buffer,
- dbeWindowPrivResType, client,
- DixDestroyAccess);
- if (rc != Success)
- return (rc == BadValue) ? dbeErrorBase + DbeBadBuffer : rc;
-
- rc = dixLookupResourceByType(&val, stuff->buffer, dbeDrawableResType,
- client, DixDestroyAccess);
- if (rc != Success)
- return (rc == BadValue) ? dbeErrorBase + DbeBadBuffer : rc;
-
- /* Make sure that the id is valid for the window.
- * This is paranoid code since we already looked up the ID by type
- * above.
- */
-
- for (i = 0; i < pDbeWindowPriv->nBufferIDs; i++)
- {
- /* Loop through the ID list to find the ID. */
- if (pDbeWindowPriv->IDs[i] == stuff->buffer)
- {
- break;
- }
- }
-
- if (i == pDbeWindowPriv->nBufferIDs)
- {
- /* We did not find the ID in the ID list. */
- client->errorValue = stuff->buffer;
- return(dbeErrorBase + DbeBadBuffer);
- }
-
- FreeResource(stuff->buffer, RT_NONE);
-
- return(Success);
-
-} /* ProcDbeDeallocateBackBufferName() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: ProcDbeSwapBuffers
- *
- * Description:
- *
- * This function is for processing a DbeSwapBuffers request.
- * This request swaps the buffers for all windows listed, applying the
- * appropriate swap action for each window.
- *
- * Return Values:
- *
- * BadAlloc - local allocation failed; this return value is not defined
- * by the protocol
- * BadMatch - a window in request is not double-buffered; a window in
- * request is listed more than once
- * BadValue - invalid swap action is specified; no swap action is
- * specified
- * BadWindow - a window in request is not valid
- * Success
- *
- *****************************************************************************/
-
-static int
-ProcDbeSwapBuffers(ClientPtr client)
-{
- REQUEST(xDbeSwapBuffersReq);
- WindowPtr pWin;
- DbeScreenPrivPtr pDbeScreenPriv;
- DbeSwapInfoPtr swapInfo;
- xDbeSwapInfo *dbeSwapInfo;
- int error;
- register int i, j;
- int nStuff;
-
-
- REQUEST_AT_LEAST_SIZE(xDbeSwapBuffersReq);
- nStuff = stuff->n; /* use local variable for performance. */
-
- if (nStuff == 0)
- {
- return(Success);
- }
-
- if (nStuff > UINT32_MAX / sizeof(DbeSwapInfoRec))
- return BadAlloc;
-
- /* Get to the swap info appended to the end of the request. */
- dbeSwapInfo = (xDbeSwapInfo *)&stuff[1];
-
- /* Allocate array to record swap information. */
- swapInfo = (DbeSwapInfoPtr)malloc(nStuff * sizeof(DbeSwapInfoRec));
- if (swapInfo == NULL)
- {
- return(BadAlloc);
- }
-
-
- for (i = 0; i < nStuff; i++)
- {
- /* Check all windows to swap. */
-
- /* Each window must be a valid window - BadWindow. */
- error = dixLookupWindow(&pWin, dbeSwapInfo[i].window, client,
- DixWriteAccess);
- if (error != Success) {
- free(swapInfo);
- return error;
- }
-
- /* Each window must be double-buffered - BadMatch. */
- if (DBE_WINDOW_PRIV(pWin) == NULL)
- {
- free(swapInfo);
- return(BadMatch);
- }
-
- /* Each window must only be specified once - BadMatch. */
- for (j = i + 1; j < nStuff; j++)
- {
- if (dbeSwapInfo[i].window == dbeSwapInfo[j].window)
- {
- free(swapInfo);
- return(BadMatch);
- }
- }
-
- /* Each swap action must be valid - BadValue. */
- if ((dbeSwapInfo[i].swapAction != XdbeUndefined ) &&
- (dbeSwapInfo[i].swapAction != XdbeBackground) &&
- (dbeSwapInfo[i].swapAction != XdbeUntouched ) &&
- (dbeSwapInfo[i].swapAction != XdbeCopied ))
- {
- free(swapInfo);
- return(BadValue);
- }
-
- /* Everything checks out OK. Fill in the swap info array. */
- swapInfo[i].pWindow = pWin;
- swapInfo[i].swapAction = dbeSwapInfo[i].swapAction;
-
- } /* for (i = 0; i < nStuff; i++) */
-
-
- /* Call the DDX routine to perform the swap(s). The DDX routine should
- * scan the swap list (swap info), swap any buffers that it knows how to
- * handle, delete them from the list, and update nStuff to indicate how
- * many windows it did not handle.
- *
- * This scheme allows a range of sophistication in the DDX SwapBuffers()
- * implementation. Naive implementations could just swap the first buffer
- * in the list, move the last buffer to the front, decrement nStuff, and
- * return. The next level of sophistication could be to scan the whole
- * list for windows on the same screen. Up another level, the DDX routine
- * could deal with cross-screen synchronization.
- */
-
- while (nStuff > 0)
- {
- pDbeScreenPriv = DBE_SCREEN_PRIV_FROM_WINDOW(swapInfo[0].pWindow);
- error = (*pDbeScreenPriv->SwapBuffers)(client, &nStuff, swapInfo);
- if (error != Success)
- {
- free(swapInfo);
- return(error);
- }
- }
-
- free(swapInfo);
- return(Success);
-
-} /* ProcDbeSwapBuffers() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: ProcDbeBeginIdiom
- *
- * Description:
- *
- * This function is for processing a DbeBeginIdiom request.
- * This request informs the server that a complex swap will immediately
- * follow this request.
- *
- * Return Values:
- *
- * Success
- *
- *****************************************************************************/
-
-static int
-ProcDbeBeginIdiom(ClientPtr client)
-{
- /* REQUEST(xDbeBeginIdiomReq); */
- DbeScreenPrivPtr pDbeScreenPriv;
- register int i;
-
-
- REQUEST_SIZE_MATCH(xDbeBeginIdiomReq);
-
- for (i = 0; i < screenInfo.numScreens; i++)
- {
- pDbeScreenPriv = DBE_SCREEN_PRIV(screenInfo.screens[i]);
-
- /* Call the DDX begin idiom procedure if there is one. */
- if (pDbeScreenPriv->BeginIdiom)
- {
- (*pDbeScreenPriv->BeginIdiom)(client);
- }
- }
-
- return(Success);
-
-} /* ProcDbeBeginIdiom() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: ProcDbeGetVisualInfo
- *
- * Description:
- *
- * This function is for processing a ProcDbeGetVisualInfo request.
- * This request returns information about which visuals support
- * double buffering.
- *
- * Return Values:
- *
- * BadDrawable - value in screen specifiers is not a valid drawable
- * Success
- *
- *****************************************************************************/
-
-static int
-ProcDbeGetVisualInfo(ClientPtr client)
-{
- REQUEST(xDbeGetVisualInfoReq);
- DbeScreenPrivPtr pDbeScreenPriv;
- xDbeGetVisualInfoReply rep;
- Drawable *drawables;
- DrawablePtr *pDrawables = NULL;
- register int i, j, n, rc;
- register int count; /* number of visual infos in reply */
- register int length; /* length of reply */
- ScreenPtr pScreen;
- XdbeScreenVisualInfo *pScrVisInfo;
-
-
- REQUEST_AT_LEAST_SIZE(xDbeGetVisualInfoReq);
-
- if (stuff->n > UINT32_MAX / sizeof(DrawablePtr))
- return BadAlloc;
- /* Make sure any specified drawables are valid. */
- if (stuff->n != 0)
- {
- if (!(pDrawables = (DrawablePtr *)malloc(stuff->n *
- sizeof(DrawablePtr))))
- {
- return(BadAlloc);
- }
-
- drawables = (Drawable *)&stuff[1];
-
- for (i = 0; i < stuff->n; i++)
- {
- rc = dixLookupDrawable(pDrawables+i, drawables[i], client, 0,
- DixGetAttrAccess);
- if (rc != Success) {
- free(pDrawables);
- return rc;
- }
- }
- }
-
- count = (stuff->n == 0) ? screenInfo.numScreens : stuff->n;
- if (!(pScrVisInfo = (XdbeScreenVisualInfo *)malloc(count *
- sizeof(XdbeScreenVisualInfo))))
- {
- if (pDrawables)
- {
- free(pDrawables);
- }
-
- return(BadAlloc);
- }
-
- length = 0;
-
- for (i = 0; i < count; i++)
- {
- pScreen = (stuff->n == 0) ? screenInfo.screens[i] :
- pDrawables[i]->pScreen;
- pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
-
- rc = XaceHook(XACE_SCREEN_ACCESS, client, pScreen, DixGetAttrAccess);
- if ((rc != Success) ||
- !(*pDbeScreenPriv->GetVisualInfo)(pScreen, &pScrVisInfo[i]))
- {
- /* We failed to alloc pScrVisInfo[i].visinfo. */
-
- /* Free visinfos that we allocated for previous screen infos.*/
- for (j = 0; j < i; j++)
- {
- free(pScrVisInfo[j].visinfo);
- }
-
- /* Free pDrawables if we needed to allocate it above. */
- if (pDrawables)
- {
- free(pDrawables);
- }
-
- return (rc == Success) ? BadAlloc : rc;
- }
-
- /* Account for n, number of xDbeVisInfo items in list. */
- length += sizeof(CARD32);
-
- /* Account for n xDbeVisInfo items */
- length += pScrVisInfo[i].count * sizeof(xDbeVisInfo);
- }
-
- rep.type = X_Reply;
- rep.sequenceNumber = client->sequence;
- rep.length = bytes_to_int32(length);
- rep.m = count;
-
- if (client->swapped)
- {
- swaps(&rep.sequenceNumber, n);
- swapl(&rep.length, n);
- swapl(&rep.m, n);
- }
-
- /* Send off reply. */
- WriteToClient(client, sizeof(xDbeGetVisualInfoReply), (char *)&rep);
-
- for (i = 0; i < count; i++)
- {
- CARD32 data32;
-
- /* For each screen in the reply, send off the visual info */
-
- /* Send off number of visuals. */
- data32 = (CARD32)pScrVisInfo[i].count;
-
- if (client->swapped)
- {
- swapl(&data32, n);
- }
-
- WriteToClient(client, sizeof(CARD32), (char *)&data32);
-
- /* Now send off visual info items. */
- for (j = 0; j < pScrVisInfo[i].count; j++)
- {
- xDbeVisInfo visInfo;
-
- /* Copy the data in the client data structure to a protocol
- * data structure. We will send data to the client from the
- * protocol data structure.
- */
-
- visInfo.visualID = (CARD32)pScrVisInfo[i].visinfo[j].visual;
- visInfo.depth = (CARD8) pScrVisInfo[i].visinfo[j].depth;
- visInfo.perfLevel = (CARD8) pScrVisInfo[i].visinfo[j].perflevel;
-
- if (client->swapped)
- {
- swapl(&visInfo.visualID, n);
-
- /* We do not need to swap depth and perfLevel since they are
- * already 1 byte quantities.
- */
- }
-
- /* Write visualID(32), depth(8), perfLevel(8), and pad(16). */
- WriteToClient(client, 2*sizeof(CARD32), (char *)&visInfo.visualID);
- }
- }
-
- /* Clean up memory. */
- for (i = 0; i < count; i++)
- {
- free(pScrVisInfo[i].visinfo);
- }
- free(pScrVisInfo);
-
- if (pDrawables)
- {
- free(pDrawables);
- }
-
- return Success;
-
-} /* ProcDbeGetVisualInfo() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: ProcDbeGetbackBufferAttributes
- *
- * Description:
- *
- * This function is for processing a ProcDbeGetbackBufferAttributes
- * request. This request returns information about a back buffer.
- *
- * Return Values:
- *
- * Success
- *
- *****************************************************************************/
-
-static int
-ProcDbeGetBackBufferAttributes(ClientPtr client)
-{
- REQUEST(xDbeGetBackBufferAttributesReq);
- xDbeGetBackBufferAttributesReply rep;
- DbeWindowPrivPtr pDbeWindowPriv;
- int rc, n;
-
-
- REQUEST_SIZE_MATCH(xDbeGetBackBufferAttributesReq);
-
- rc = dixLookupResourceByType((pointer *)&pDbeWindowPriv, stuff->buffer,
- dbeWindowPrivResType, client,
- DixGetAttrAccess);
- if (rc == Success)
- {
- rep.attributes = pDbeWindowPriv->pWindow->drawable.id;
- }
- else
- {
- rep.attributes = None;
- }
-
- rep.type = X_Reply;
- rep.sequenceNumber = client->sequence;
- rep.length = 0;
-
- if (client->swapped)
- {
- swaps(&rep.sequenceNumber, n);
- swapl(&rep.length, n);
- swapl(&rep.attributes, n);
- }
-
- WriteToClient(client, sizeof(xDbeGetBackBufferAttributesReply),
- (char *)&rep);
- return Success;
-
-} /* ProcDbeGetbackBufferAttributes() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: ProcDbeDispatch
- *
- * Description:
- *
- * This function dispatches DBE requests.
- *
- *****************************************************************************/
-
-static int
-ProcDbeDispatch(ClientPtr client)
-{
- REQUEST(xReq);
-
-
- switch (stuff->data)
- {
- case X_DbeGetVersion:
- return(ProcDbeGetVersion(client));
-
- case X_DbeAllocateBackBufferName:
- return(ProcDbeAllocateBackBufferName(client));
-
- case X_DbeDeallocateBackBufferName:
- return(ProcDbeDeallocateBackBufferName(client));
-
- case X_DbeSwapBuffers:
- return(ProcDbeSwapBuffers(client));
-
- case X_DbeBeginIdiom:
- return(ProcDbeBeginIdiom(client));
-
- case X_DbeEndIdiom:
- return(Success);
-
- case X_DbeGetVisualInfo:
- return(ProcDbeGetVisualInfo(client));
-
- case X_DbeGetBackBufferAttributes:
- return(ProcDbeGetBackBufferAttributes(client));
-
- default:
- return(BadRequest);
- }
-
-} /* ProcDbeDispatch() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: SProcDbeGetVersion
- *
- * Description:
- *
- * This function is for processing a DbeGetVersion request on a swapped
- * server. This request returns the major and minor version numbers of
- * this extension.
- *
- * Return Values:
- *
- * Success
- *
- *****************************************************************************/
-
-static int
-SProcDbeGetVersion(ClientPtr client)
-{
- REQUEST(xDbeGetVersionReq);
- register int n;
-
-
- swaps(&stuff->length, n);
- return(ProcDbeGetVersion(client));
-
-} /* SProcDbeGetVersion() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: SProcDbeAllocateBackBufferName
- *
- * Description:
- *
- * This function is for processing a DbeAllocateBackBufferName request on
- * a swapped server. This request allocates a drawable ID used to refer
- * to the back buffer of a window.
- *
- * Return Values:
- *
- * BadAlloc - server can not allocate resources
- * BadIDChoice - id is out of range for client; id is already in use
- * BadMatch - window is not an InputOutput window;
- * visual of window is not on list returned by
- * DBEGetVisualInfo;
- * BadValue - invalid swap action is specified
- * BadWindow - window is not a valid window
- * Success
- *
- *****************************************************************************/
-
-static int
-SProcDbeAllocateBackBufferName(ClientPtr client)
-{
- REQUEST(xDbeAllocateBackBufferNameReq);
- register int n;
-
- swaps(&stuff->length, n);
- REQUEST_SIZE_MATCH(xDbeAllocateBackBufferNameReq);
-
- swapl(&stuff->window, n);
- swapl(&stuff->buffer, n);
- /* stuff->swapAction is a byte. We do not need to swap this field. */
-
- return(ProcDbeAllocateBackBufferName(client));
-
-} /* SProcDbeAllocateBackBufferName() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: SProcDbeDeallocateBackBufferName
- *
- * Description:
- *
- * This function is for processing a DbeDeallocateBackBufferName request
- * on a swapped server. This request frees a drawable ID that was
- * obtained by a DbeAllocateBackBufferName request.
- *
- * Return Values:
- *
- * BadBuffer - buffer to deallocate is not associated with a window
- * Success
- *
- *****************************************************************************/
-
-static int
-SProcDbeDeallocateBackBufferName(ClientPtr client)
-{
- REQUEST (xDbeDeallocateBackBufferNameReq);
- register int n;
-
-
- swaps(&stuff->length, n);
- REQUEST_SIZE_MATCH(xDbeDeallocateBackBufferNameReq);
-
- swapl(&stuff->buffer, n);
-
- return(ProcDbeDeallocateBackBufferName(client));
-
-} /* SProcDbeDeallocateBackBufferName() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: SProcDbeSwapBuffers
- *
- * Description:
- *
- * This function is for processing a DbeSwapBuffers request on a swapped
- * server. This request swaps the buffers for all windows listed,
- * applying the appropriate swap action for each window.
- *
- * Return Values:
- *
- * BadMatch - a window in request is not double-buffered; a window in
- * request is listed more than once; all windows in request do
- * not have the same root
- * BadValue - invalid swap action is specified
- * BadWindow - a window in request is not valid
- * Success
- *
- *****************************************************************************/
-
-static int
-SProcDbeSwapBuffers(ClientPtr client)
-{
- REQUEST(xDbeSwapBuffersReq);
- register int i, n;
- xDbeSwapInfo *pSwapInfo;
-
-
- swaps(&stuff->length, n);
- REQUEST_AT_LEAST_SIZE(xDbeSwapBuffersReq);
-
- swapl(&stuff->n, n);
-
- if (stuff->n != 0)
- {
- pSwapInfo = (xDbeSwapInfo *)stuff+1;
-
- /* The swap info following the fix part of this request is a window(32)
- * followed by a 1 byte swap action and then 3 pad bytes. We only need
- * to swap the window information.
- */
- for (i = 0; i < stuff->n; i++)
- {
- swapl(&pSwapInfo->window, n);
- }
- }
-
- return(ProcDbeSwapBuffers(client));
-
-} /* SProcDbeSwapBuffers() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: SProcDbeBeginIdiom
- *
- * Description:
- *
- * This function is for processing a DbeBeginIdiom request on a swapped
- * server. This request informs the server that a complex swap will
- * immediately follow this request.
- *
- * Return Values:
- *
- * Success
- *
- *****************************************************************************/
-
-static int
-SProcDbeBeginIdiom(ClientPtr client)
-{
- REQUEST(xDbeBeginIdiomReq);
- register int n;
-
- swaps(&stuff->length, n);
- return(ProcDbeBeginIdiom(client));
-
-} /* SProcDbeBeginIdiom() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: SProcDbeGetVisualInfo
- *
- * Description:
- *
- * This function is for processing a ProcDbeGetVisualInfo request on a
- * swapped server. This request returns information about which visuals
- * support double buffering.
- *
- * Return Values:
- *
- * BadDrawable - value in screen specifiers is not a valid drawable
- * Success
- *
- *****************************************************************************/
-
-static int
-SProcDbeGetVisualInfo(ClientPtr client)
-{
- REQUEST(xDbeGetVisualInfoReq);
- register int n;
-
-
- swaps(&stuff->length, n);
- REQUEST_AT_LEAST_SIZE(xDbeGetVisualInfoReq);
-
- swapl(&stuff->n, n);
- SwapRestL(stuff);
-
- return(ProcDbeGetVisualInfo(client));
-
-} /* SProcDbeGetVisualInfo() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: SProcDbeGetbackBufferAttributes
- *
- * Description:
- *
- * This function is for processing a ProcDbeGetbackBufferAttributes
- * request on a swapped server. This request returns information about a
- * back buffer.
- *
- * Return Values:
- *
- * Success
- *
- *****************************************************************************/
-
-static int
-SProcDbeGetBackBufferAttributes(ClientPtr client)
-{
- REQUEST (xDbeGetBackBufferAttributesReq);
- register int n;
-
- swaps(&stuff->length, n);
- REQUEST_SIZE_MATCH(xDbeGetBackBufferAttributesReq);
-
- swapl(&stuff->buffer, n);
-
- return(ProcDbeGetBackBufferAttributes(client));
-
-} /* SProcDbeGetBackBufferAttributes() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: SProcDbeDispatch
- *
- * Description:
- *
- * This function dispatches DBE requests on a swapped server.
- *
- *****************************************************************************/
-
-static int
-SProcDbeDispatch(ClientPtr client)
-{
- REQUEST(xReq);
-
-
- switch (stuff->data)
- {
- case X_DbeGetVersion:
- return(SProcDbeGetVersion(client));
-
- case X_DbeAllocateBackBufferName:
- return(SProcDbeAllocateBackBufferName(client));
-
- case X_DbeDeallocateBackBufferName:
- return(SProcDbeDeallocateBackBufferName(client));
-
- case X_DbeSwapBuffers:
- return(SProcDbeSwapBuffers(client));
-
- case X_DbeBeginIdiom:
- return(SProcDbeBeginIdiom(client));
-
- case X_DbeEndIdiom:
- return(Success);
-
- case X_DbeGetVisualInfo:
- return(SProcDbeGetVisualInfo(client));
-
- case X_DbeGetBackBufferAttributes:
- return(SProcDbeGetBackBufferAttributes(client));
-
- default:
- return (BadRequest);
- }
-
-} /* SProcDbeDispatch() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: DbeSetupBackgroundPainter
- *
- * Description:
- *
- * This function sets up pGC to clear pixmaps.
- *
- * Return Values:
- *
- * TRUE - setup was successful
- * FALSE - the window's background state is NONE
- *
- *****************************************************************************/
-
-static Bool
-DbeSetupBackgroundPainter(WindowPtr pWin, GCPtr pGC)
-{
- ChangeGCVal gcvalues[4];
- int ts_x_origin, ts_y_origin;
- PixUnion background;
- int backgroundState;
- Mask gcmask;
-
-
- /* First take care of any ParentRelative stuff by altering the
- * tile/stipple origin to match the coordinates of the upper-left
- * corner of the first ancestor without a ParentRelative background.
- * This coordinate is, of course, negative.
- */
- ts_x_origin = ts_y_origin = 0;
- while (pWin->backgroundState == ParentRelative)
- {
- ts_x_origin -= pWin->origin.x;
- ts_y_origin -= pWin->origin.y;
-
- pWin = pWin->parent;
- }
- backgroundState = pWin->backgroundState;
- background = pWin->background;
-
- switch (backgroundState)
- {
- case BackgroundPixel:
- gcvalues[0].val = background.pixel;
- gcvalues[1].val = FillSolid;
- gcmask = GCForeground|GCFillStyle;
- break;
-
- case BackgroundPixmap:
- gcvalues[0].val = FillTiled;
- gcvalues[1].ptr = background.pixmap;
- gcvalues[2].val = ts_x_origin;
- gcvalues[3].val = ts_y_origin;
- gcmask = GCFillStyle|GCTile|GCTileStipXOrigin|GCTileStipYOrigin;
- break;
-
- default:
- /* pWin->backgroundState == None */
- return(FALSE);
- }
-
- return ChangeGC(NullClient, pGC, gcmask, gcvalues) == 0;
-} /* DbeSetupBackgroundPainter() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: DbeDrawableDelete
- *
- * Description:
- *
- * This is the resource delete function for dbeDrawableResType.
- * It is registered when the drawable resource type is created in
- * DbeExtensionInit().
- *
- * To make resource deletion simple, we do not do anything in this function
- * and leave all resource deleteion to DbeWindowPrivDelete(), which will
- * eventually be called or already has been called. Deletion functions are
- * not guaranteed to be called in any particular order.
- *
- *****************************************************************************/
-static int
-DbeDrawableDelete(pointer pDrawable, XID id)
-{
- return(Success);
-
-} /* DbeDrawableDelete() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: DbeWindowPrivDelete
- *
- * Description:
- *
- * This is the resource delete function for dbeWindowPrivResType.
- * It is registered when the drawable resource type is created in
- * DbeExtensionInit().
- *
- *****************************************************************************/
-static int
-DbeWindowPrivDelete(pointer pDbeWinPriv, XID id)
-{
- DbeScreenPrivPtr pDbeScreenPriv;
- DbeWindowPrivPtr pDbeWindowPriv = (DbeWindowPrivPtr)pDbeWinPriv;
- int i;
-
-
- /*
- **************************************************************************
- ** Remove the buffer ID from the ID array.
- **************************************************************************
- */
-
- /* Find the ID in the ID array. */
- i = 0;
- while ((i < pDbeWindowPriv->nBufferIDs) && (pDbeWindowPriv->IDs[i] != id))
- {
- i++;
- }
-
- if (i == pDbeWindowPriv->nBufferIDs)
- {
- /* We did not find the ID in the array. We should never get here. */
- return(BadValue);
- }
-
- /* Remove the ID from the array. */
-
- if (i < (pDbeWindowPriv->nBufferIDs - 1))
- {
- /* Compress the buffer ID array, overwriting the ID in the process. */
- memmove(&pDbeWindowPriv->IDs[i], &pDbeWindowPriv->IDs[i+1],
- (pDbeWindowPriv->nBufferIDs - i - 1) * sizeof(XID));
- }
- else
- {
- /* We are removing the last ID in the array, in which case, the
- * assignement below is all that we need to do.
- */
- }
- pDbeWindowPriv->IDs[pDbeWindowPriv->nBufferIDs - 1] = DBE_FREE_ID_ELEMENT;
-
- pDbeWindowPriv->nBufferIDs--;
-
- /* If an extended array was allocated, then check to see if the remaining
- * buffer IDs will fit in the static array.
- */
-
- if ((pDbeWindowPriv->maxAvailableIDs > DBE_INIT_MAX_IDS) &&
- (pDbeWindowPriv->nBufferIDs == DBE_INIT_MAX_IDS))
- {
- /* Copy the IDs back into the static array. */
- memcpy(pDbeWindowPriv->initIDs, pDbeWindowPriv->IDs,
- DBE_INIT_MAX_IDS * sizeof(XID));
-
- /* Free the extended array; use the static array. */
- free(pDbeWindowPriv->IDs);
- pDbeWindowPriv->IDs = pDbeWindowPriv->initIDs;
- pDbeWindowPriv->maxAvailableIDs = DBE_INIT_MAX_IDS;
- }
-
-
- /*
- **************************************************************************
- ** Perform DDX level tasks.
- **************************************************************************
- */
-
- pDbeScreenPriv = DBE_SCREEN_PRIV_FROM_WINDOW_PRIV(
- (DbeWindowPrivPtr)pDbeWindowPriv);
- (*pDbeScreenPriv->WinPrivDelete)((DbeWindowPrivPtr)pDbeWindowPriv, id);
-
-
- /*
- **************************************************************************
- ** Perform miscellaneous tasks if this is the last buffer associated
- ** with the window.
- **************************************************************************
- */
-
- if (pDbeWindowPriv->nBufferIDs == 0)
- {
- /* Reset the DBE window priv pointer. */
- dixSetPrivate(&pDbeWindowPriv->pWindow->devPrivates, dbeWindowPrivKey,
- NULL);
-
- /* We are done with the window priv. */
- dixFreePrivates(pDbeWindowPriv->devPrivates);
- free(pDbeWindowPriv);
- }
-
- return(Success);
-
-} /* DbeWindowPrivDelete() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: DbeResetProc
- *
- * Description:
- *
- * This routine is called at the end of every server generation.
- * It deallocates any memory reserved for the extension and performs any
- * other tasks related to shutting down the extension.
- *
- *****************************************************************************/
-static void
-DbeResetProc(ExtensionEntry *extEntry)
-{
- int i;
- ScreenPtr pScreen;
- DbeScreenPrivPtr pDbeScreenPriv;
-
- for (i = 0; i < screenInfo.numScreens; i++)
- {
- pScreen = screenInfo.screens[i];
- pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
-
- if (pDbeScreenPriv)
- {
- /* Unwrap DestroyWindow, which was wrapped in DbeExtensionInit().*/
- pScreen->DestroyWindow = pDbeScreenPriv->DestroyWindow;
-
- if (pDbeScreenPriv->ResetProc)
- (*pDbeScreenPriv->ResetProc)(pScreen);
-
- dixFreePrivates(pDbeScreenPriv->devPrivates);
- free(pDbeScreenPriv);
- }
- }
-} /* DbeResetProc() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: DbeDestroyWindow
- *
- * Description:
- *
- * This is the wrapper for pScreen->DestroyWindow.
- * This function frees buffer resources for a window before it is
- * destroyed.
- *
- *****************************************************************************/
-
-static Bool
-DbeDestroyWindow(WindowPtr pWin)
-{
- DbeScreenPrivPtr pDbeScreenPriv;
- DbeWindowPrivPtr pDbeWindowPriv;
- ScreenPtr pScreen;
- Bool ret;
-
-
- /*
- **************************************************************************
- ** 1. Unwrap the member routine.
- **************************************************************************
- */
-
- pScreen = pWin->drawable.pScreen;
- pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
- pScreen->DestroyWindow = pDbeScreenPriv->DestroyWindow;
-
- /*
- **************************************************************************
- ** 2. Do any work necessary before the member routine is called.
- **
- ** Call the window priv delete function for all buffer IDs associated
- ** with this window.
- **************************************************************************
- */
-
- if ((pDbeWindowPriv = DBE_WINDOW_PRIV(pWin)))
- {
- while (pDbeWindowPriv)
- {
- /* *DbeWinPrivDelete() will free the window private and set it to
- * NULL if there are no more buffer IDs associated with this
- * window.
- */
- FreeResource(pDbeWindowPriv->IDs[0], RT_NONE);
- pDbeWindowPriv = DBE_WINDOW_PRIV(pWin);
- }
- }
-
- /*
- **************************************************************************
- ** 3. Call the member routine, saving its result if necessary.
- **************************************************************************
- */
-
- ret = (*pScreen->DestroyWindow)(pWin);
-
- /*
- **************************************************************************
- ** 4. Rewrap the member routine, restoring the wrapper value first in case
- ** the wrapper (or something that it wrapped) change this value.
- **************************************************************************
- */
-
- pDbeScreenPriv->DestroyWindow = pScreen->DestroyWindow;
- pScreen->DestroyWindow = DbeDestroyWindow;
-
- /*
- **************************************************************************
- ** 5. Do any work necessary after the member routine has been called.
- **
- ** In this case we do not need to do anything.
- **************************************************************************
- */
-
- return(ret);
-
-} /* DbeDestroyWindow() */
-
-
-/******************************************************************************
- *
- * DBE DIX Procedure: DbeExtensionInit
- *
- * Description:
- *
- * Called from InitExtensions in main()
- *
- *****************************************************************************/
-
-void
-DbeExtensionInit(void)
-{
- ExtensionEntry *extEntry;
- register int i, j;
- ScreenPtr pScreen = NULL;
- DbeScreenPrivPtr pDbeScreenPriv;
- int nStubbedScreens = 0;
- Bool ddxInitSuccess;
-
-#ifdef PANORAMIX
- if(!noPanoramiXExtension) return;
-#endif
-
- /* Create the resource types. */
- dbeDrawableResType =
- CreateNewResourceType(DbeDrawableDelete, "dbeDrawable");
- if (!dbeDrawableResType)
- return;
- dbeDrawableResType |= RC_DRAWABLE;
-
- dbeWindowPrivResType =
- CreateNewResourceType(DbeWindowPrivDelete, "dbeWindow");
- if (!dbeWindowPrivResType)
- return;
-
- if (!dixRegisterPrivateOffset(dbeDrawableResType,
- offsetof(PixmapRec, devPrivates)))
- return;
-
- for (i = 0; i < screenInfo.numScreens; i++)
- {
- /* For each screen, set up DBE screen privates and init DIX and DDX
- * interface.
- */
-
- pScreen = screenInfo.screens[i];
-
- if (!(pDbeScreenPriv =
- (DbeScreenPrivPtr)calloc(1, sizeof(DbeScreenPrivRec))))
- {
- /* If we can not alloc a window or screen private,
- * then free any privates that we already alloc'ed and return
- */
-
- for (j = 0; j < i; j++)
- {
- free(dixLookupPrivate(&screenInfo.screens[j]->devPrivates,
- dbeScreenPrivKey));
- dixSetPrivate(&screenInfo.screens[j]->devPrivates,
- dbeScreenPrivKey, NULL);
- }
- return;
- }
-
- dixSetPrivate(&pScreen->devPrivates, dbeScreenPrivKey, pDbeScreenPriv);
-
- /* Copy the resource types */
- pDbeScreenPriv->dbeDrawableResType = dbeDrawableResType;
- pDbeScreenPriv->dbeWindowPrivResType = dbeWindowPrivResType;
-
- /* Copy the private indices */
- pDbeScreenPriv->dbeScreenPrivKey = dbeScreenPrivKey;
- pDbeScreenPriv->dbeWindowPrivKey = dbeWindowPrivKey;
-
- {
- /* We don't have DDX support for DBE anymore */
-
-#ifndef DISABLE_MI_DBE_BY_DEFAULT
- /* Setup DIX. */
- pDbeScreenPriv->SetupBackgroundPainter = DbeSetupBackgroundPainter;
-
- /* Setup DDX. */
- ddxInitSuccess = miDbeInit(pScreen, pDbeScreenPriv);
-
- /* DDX DBE initialization may have the side affect of
- * reallocating pDbeScreenPriv, so we need to update it.
- */
- pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
-
- if (ddxInitSuccess)
- {
- /* Wrap DestroyWindow. The DDX initialization function
- * already wrapped PositionWindow for us.
- */
-
- pDbeScreenPriv->DestroyWindow = pScreen->DestroyWindow;
- pScreen->DestroyWindow = DbeDestroyWindow;
- }
- else
- {
- /* DDX initialization failed. Stub the screen. */
- DbeStubScreen(pDbeScreenPriv, &nStubbedScreens);
- }
-#else
- DbeStubScreen(pDbeScreenPriv, &nStubbedScreens);
-#endif
-
- }
-
- } /* for (i = 0; i < screenInfo.numScreens; i++) */
-
-
- if (nStubbedScreens == screenInfo.numScreens)
- {
- /* All screens stubbed. Clean up and return. */
-
- for (i = 0; i < screenInfo.numScreens; i++)
- {
- free(dixLookupPrivate(&screenInfo.screens[i]->devPrivates,
- dbeScreenPrivKey));
- dixSetPrivate(&pScreen->devPrivates, dbeScreenPrivKey, NULL);
- }
- return;
- }
-
-
- /* Now add the extension. */
- extEntry = AddExtension(DBE_PROTOCOL_NAME, DbeNumberEvents,
- DbeNumberErrors, ProcDbeDispatch, SProcDbeDispatch,
- DbeResetProc, StandardMinorOpcode);
-
- dbeErrorBase = extEntry->errorBase;
-
-} /* DbeExtensionInit() */
-
+/****************************************************************************** + * + * Copyright (c) 1994, 1995 Hewlett-Packard Company + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of the Hewlett-Packard + * Company shall not be used in advertising or otherwise to promote the + * sale, use or other dealings in this Software without prior written + * authorization from the Hewlett-Packard Company. + * + * DIX DBE code + * + *****************************************************************************/ + + +/* INCLUDES */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include <string.h> +#if HAVE_STDINT_H +#include <stdint.h> +#elif !defined(UINT32_MAX) +#define UINT32_MAX 0xffffffffU +#endif + +#include <X11/X.h> +#include <X11/Xproto.h> +#include "scrnintstr.h" +#include "extnsionst.h" +#include "gcstruct.h" +#include "dixstruct.h" +#define NEED_DBE_PROTOCOL +#include "dbestruct.h" +#include "midbe.h" +#include "xace.h" + +/* GLOBALS */ + +/* These are static globals copied to DBE's screen private for use by DDX */ +static int dbeScreenPrivKeyIndex; +static DevPrivateKey dbeScreenPrivKey = &dbeScreenPrivKeyIndex; +static int dbeWindowPrivKeyIndex; +static DevPrivateKey dbeWindowPrivKey = &dbeWindowPrivKeyIndex; + +/* These are static globals copied to DBE's screen private for use by DDX */ +static RESTYPE dbeDrawableResType; +static RESTYPE dbeWindowPrivResType; + +/* Used to generate DBE's BadBuffer error. */ +static int dbeErrorBase; + +/****************************************************************************** + * + * DBE DIX Procedure: DbeStubScreen + * + * Description: + * + * This is function stubs the function pointers in the given DBE screen + * private and increments the number of stubbed screens. + * + *****************************************************************************/ + +static void +DbeStubScreen(DbeScreenPrivPtr pDbeScreenPriv, int *nStubbedScreens) +{ + /* Stub DIX. */ + pDbeScreenPriv->SetupBackgroundPainter = NULL; + + /* Do not unwrap PositionWindow nor DestroyWindow. If the DDX + * initialization function failed, we assume that it did not wrap + * PositionWindow. Also, DestroyWindow is only wrapped if the DDX + * initialization function succeeded. + */ + + /* Stub DDX. */ + pDbeScreenPriv->GetVisualInfo = NULL; + pDbeScreenPriv->AllocBackBufferName = NULL; + pDbeScreenPriv->SwapBuffers = NULL; + pDbeScreenPriv->BeginIdiom = NULL; + pDbeScreenPriv->EndIdiom = NULL; + pDbeScreenPriv->WinPrivDelete = NULL; + pDbeScreenPriv->ResetProc = NULL; + + (*nStubbedScreens)++; + +} /* DbeStubScreen() */ + + + +/****************************************************************************** + * + * DBE DIX Procedure: ProcDbeGetVersion + * + * Description: + * + * This function is for processing a DbeGetVersion request. + * This request returns the major and minor version numbers of this + * extension. + * + * Return Values: + * + * Success + * + *****************************************************************************/ + +static int +ProcDbeGetVersion(ClientPtr client) +{ + /* REQUEST(xDbeGetVersionReq); */ + xDbeGetVersionReply rep; + register int n; + + + REQUEST_SIZE_MATCH(xDbeGetVersionReq); + + rep.type = X_Reply; + rep.length = 0; + rep.sequenceNumber = client->sequence; + rep.majorVersion = DBE_MAJOR_VERSION; + rep.minorVersion = DBE_MINOR_VERSION; + + if (client->swapped) + { + swaps(&rep.sequenceNumber, n); + } + + WriteToClient(client, sizeof(xDbeGetVersionReply), (char *)&rep); + + return Success; + +} /* ProcDbeGetVersion() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: ProcDbeAllocateBackBufferName + * + * Description: + * + * This function is for processing a DbeAllocateBackBufferName request. + * This request allocates a drawable ID used to refer to the back buffer + * of a window. + * + * Return Values: + * + * BadAlloc - server can not allocate resources + * BadIDChoice - id is out of range for client; id is already in use + * BadMatch - window is not an InputOutput window; + * visual of window is not on list returned by + * DBEGetVisualInfo; + * BadValue - invalid swap action is specified + * BadWindow - window is not a valid window + * Success + * + *****************************************************************************/ + +static int +ProcDbeAllocateBackBufferName(ClientPtr client) +{ + REQUEST(xDbeAllocateBackBufferNameReq); + WindowPtr pWin; + DbeScreenPrivPtr pDbeScreenPriv; + DbeWindowPrivPtr pDbeWindowPriv; + XdbeScreenVisualInfo scrVisInfo; + register int i; + Bool visualMatched = FALSE; + xDbeSwapAction swapAction; + VisualID visual; + int status; + int add_index; + + + REQUEST_SIZE_MATCH(xDbeAllocateBackBufferNameReq); + + /* The window must be valid. */ + status = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess); + if (status != Success) + return status; + + /* The window must be InputOutput. */ + if (pWin->drawable.class != InputOutput) + { + return(BadMatch); + } + + /* The swap action must be valid. */ + swapAction = stuff->swapAction; /* use local var for performance. */ + if ((swapAction != XdbeUndefined ) && + (swapAction != XdbeBackground) && + (swapAction != XdbeUntouched ) && + (swapAction != XdbeCopied )) + { + return(BadValue); + } + + /* The id must be in range and not already in use. */ + LEGAL_NEW_RESOURCE(stuff->buffer, client); + + /* The visual of the window must be in the list returned by + * GetVisualInfo. + */ + pDbeScreenPriv = DBE_SCREEN_PRIV_FROM_WINDOW(pWin); + if (!pDbeScreenPriv->GetVisualInfo) + return(BadMatch); /* screen doesn't support double buffering */ + + if (!(*pDbeScreenPriv->GetVisualInfo)(pWin->drawable.pScreen, &scrVisInfo)) + { + /* GetVisualInfo() failed to allocate visual info data. */ + return(BadAlloc); + } + + /* See if the window's visual is on the list. */ + visual = wVisual(pWin); + for (i = 0; (i < scrVisInfo.count) && !visualMatched; i++) + { + if (scrVisInfo.visinfo[i].visual == visual) + { + visualMatched = TRUE; + } + } + + /* Free what was allocated by the GetVisualInfo() call above. */ + free(scrVisInfo.visinfo); + + if (!visualMatched) + { + return(BadMatch); + } + + if ((pDbeWindowPriv = DBE_WINDOW_PRIV(pWin)) == NULL) + { + /* There is no buffer associated with the window. + * Allocate a window priv. + */ + + pDbeWindowPriv = calloc(1, sizeof(DbeWindowPrivRec)); + if (!pDbeWindowPriv) + return(BadAlloc); + + /* Fill out window priv information. */ + pDbeWindowPriv->pWindow = pWin; + pDbeWindowPriv->width = pWin->drawable.width; + pDbeWindowPriv->height = pWin->drawable.height; + pDbeWindowPriv->x = pWin->drawable.x; + pDbeWindowPriv->y = pWin->drawable.y; + pDbeWindowPriv->nBufferIDs = 0; + + /* Set the buffer ID array pointer to the initial (static) array). */ + pDbeWindowPriv->IDs = pDbeWindowPriv->initIDs; + + /* Initialize the buffer ID list. */ + pDbeWindowPriv->maxAvailableIDs = DBE_INIT_MAX_IDS; + pDbeWindowPriv->IDs[0] = stuff->buffer; + + add_index = 0; + for (i = 0; i < DBE_INIT_MAX_IDS; i++) + { + pDbeWindowPriv->IDs[i] = DBE_FREE_ID_ELEMENT; + } + + /* Actually connect the window priv to the window. */ + dixSetPrivate(&pWin->devPrivates, dbeWindowPrivKey, pDbeWindowPriv); + + } /* if -- There is no buffer associated with the window. */ + + else + { + /* A buffer is already associated with the window. + * Add the new buffer ID to the array, reallocating the array memory + * if necessary. + */ + + /* Determine if there is a free element in the ID array. */ + for (i = 0; i < pDbeWindowPriv->maxAvailableIDs; i++) + { + if (pDbeWindowPriv->IDs[i] == DBE_FREE_ID_ELEMENT) + { + /* There is still room in the ID array. */ + break; + } + } + + if (i == pDbeWindowPriv->maxAvailableIDs) + { + /* No more room in the ID array -- reallocate another array. */ + XID *pIDs; + + /* Setup an array pointer for the realloc operation below. */ + if (pDbeWindowPriv->maxAvailableIDs == DBE_INIT_MAX_IDS) + { + /* We will malloc a new array. */ + pIDs = NULL; + } + else + { + /* We will realloc a new array. */ + pIDs = pDbeWindowPriv->IDs; + } + + /* malloc/realloc a new array and initialize all elements to 0. */ + pDbeWindowPriv->IDs = (XID *)realloc(pIDs, + (pDbeWindowPriv->maxAvailableIDs+DBE_INCR_MAX_IDS)*sizeof(XID)); + if (!pDbeWindowPriv->IDs) + { + return(BadAlloc); + } + memset(&pDbeWindowPriv->IDs[pDbeWindowPriv->nBufferIDs], 0, + (pDbeWindowPriv->maxAvailableIDs + DBE_INCR_MAX_IDS - + pDbeWindowPriv->nBufferIDs) * sizeof(XID)); + + if (pDbeWindowPriv->maxAvailableIDs == DBE_INIT_MAX_IDS) + { + /* We just went from using the initial (static) array to a + * newly allocated array. Copy the IDs from the initial array + * to the new array. + */ + memcpy(pDbeWindowPriv->IDs, pDbeWindowPriv->initIDs, + DBE_INIT_MAX_IDS * sizeof(XID)); + } + + pDbeWindowPriv->maxAvailableIDs += DBE_INCR_MAX_IDS; + } + + add_index = i; + + } /* else -- A buffer is already associated with the window. */ + + + /* Call the DDX routine to allocate the back buffer. */ + status = (*pDbeScreenPriv->AllocBackBufferName)(pWin, stuff->buffer, + stuff->swapAction); + + if (status == Success) + { + pDbeWindowPriv->IDs[add_index] = stuff->buffer; + if (!AddResource(stuff->buffer, dbeWindowPrivResType, + (pointer)pDbeWindowPriv)) + { + pDbeWindowPriv->IDs[add_index] = DBE_FREE_ID_ELEMENT; + + if (pDbeWindowPriv->nBufferIDs == 0) { + status = BadAlloc; + goto out_free; + } + } + } else { + /* The DDX buffer allocation routine failed for the first buffer of + * this window. + */ + if (pDbeWindowPriv->nBufferIDs == 0) { + goto out_free; + } + } + + /* Increment the number of buffers (XIDs) associated with this window. */ + pDbeWindowPriv->nBufferIDs++; + + /* Set swap action on all calls. */ + pDbeWindowPriv->swapAction = stuff->swapAction; + + return(status); + +out_free: + dixSetPrivate(&pWin->devPrivates, dbeWindowPrivKey, NULL); + free(pDbeWindowPriv); + return (status); + +} /* ProcDbeAllocateBackBufferName() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: ProcDbeDeallocateBackBufferName + * + * Description: + * + * This function is for processing a DbeDeallocateBackBufferName request. + * This request frees a drawable ID that was obtained by a + * DbeAllocateBackBufferName request. + * + * Return Values: + * + * BadBuffer - buffer to deallocate is not associated with a window + * Success + * + *****************************************************************************/ + +static int +ProcDbeDeallocateBackBufferName(ClientPtr client) +{ + REQUEST(xDbeDeallocateBackBufferNameReq); + DbeWindowPrivPtr pDbeWindowPriv; + int rc, i; + pointer val; + + + REQUEST_SIZE_MATCH(xDbeDeallocateBackBufferNameReq); + + /* Buffer name must be valid */ + rc = dixLookupResourceByType((pointer *)&pDbeWindowPriv, stuff->buffer, + dbeWindowPrivResType, client, + DixDestroyAccess); + if (rc != Success) + return (rc == BadValue) ? dbeErrorBase + DbeBadBuffer : rc; + + rc = dixLookupResourceByType(&val, stuff->buffer, dbeDrawableResType, + client, DixDestroyAccess); + if (rc != Success) + return (rc == BadValue) ? dbeErrorBase + DbeBadBuffer : rc; + + /* Make sure that the id is valid for the window. + * This is paranoid code since we already looked up the ID by type + * above. + */ + + for (i = 0; i < pDbeWindowPriv->nBufferIDs; i++) + { + /* Loop through the ID list to find the ID. */ + if (pDbeWindowPriv->IDs[i] == stuff->buffer) + { + break; + } + } + + if (i == pDbeWindowPriv->nBufferIDs) + { + /* We did not find the ID in the ID list. */ + client->errorValue = stuff->buffer; + return(dbeErrorBase + DbeBadBuffer); + } + + FreeResource(stuff->buffer, RT_NONE); + + return(Success); + +} /* ProcDbeDeallocateBackBufferName() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: ProcDbeSwapBuffers + * + * Description: + * + * This function is for processing a DbeSwapBuffers request. + * This request swaps the buffers for all windows listed, applying the + * appropriate swap action for each window. + * + * Return Values: + * + * BadAlloc - local allocation failed; this return value is not defined + * by the protocol + * BadMatch - a window in request is not double-buffered; a window in + * request is listed more than once + * BadValue - invalid swap action is specified; no swap action is + * specified + * BadWindow - a window in request is not valid + * Success + * + *****************************************************************************/ + +static int +ProcDbeSwapBuffers(ClientPtr client) +{ + REQUEST(xDbeSwapBuffersReq); + WindowPtr pWin; + DbeScreenPrivPtr pDbeScreenPriv; + DbeSwapInfoPtr swapInfo; + xDbeSwapInfo *dbeSwapInfo; + int error; + register int i, j; + int nStuff; + + + REQUEST_AT_LEAST_SIZE(xDbeSwapBuffersReq); + nStuff = stuff->n; /* use local variable for performance. */ + + if (nStuff == 0) + { + return(Success); + } + + if (nStuff > UINT32_MAX / sizeof(DbeSwapInfoRec)) + return BadAlloc; + + /* Get to the swap info appended to the end of the request. */ + dbeSwapInfo = (xDbeSwapInfo *)&stuff[1]; + + /* Allocate array to record swap information. */ + swapInfo = (DbeSwapInfoPtr)malloc(nStuff * sizeof(DbeSwapInfoRec)); + if (swapInfo == NULL) + { + return(BadAlloc); + } + + + for (i = 0; i < nStuff; i++) + { + /* Check all windows to swap. */ + + /* Each window must be a valid window - BadWindow. */ + error = dixLookupWindow(&pWin, dbeSwapInfo[i].window, client, + DixWriteAccess); + if (error != Success) { + free(swapInfo); + return error; + } + + /* Each window must be double-buffered - BadMatch. */ + if (DBE_WINDOW_PRIV(pWin) == NULL) + { + free(swapInfo); + return(BadMatch); + } + + /* Each window must only be specified once - BadMatch. */ + for (j = i + 1; j < nStuff; j++) + { + if (dbeSwapInfo[i].window == dbeSwapInfo[j].window) + { + free(swapInfo); + return(BadMatch); + } + } + + /* Each swap action must be valid - BadValue. */ + if ((dbeSwapInfo[i].swapAction != XdbeUndefined ) && + (dbeSwapInfo[i].swapAction != XdbeBackground) && + (dbeSwapInfo[i].swapAction != XdbeUntouched ) && + (dbeSwapInfo[i].swapAction != XdbeCopied )) + { + free(swapInfo); + return(BadValue); + } + + /* Everything checks out OK. Fill in the swap info array. */ + swapInfo[i].pWindow = pWin; + swapInfo[i].swapAction = dbeSwapInfo[i].swapAction; + + } /* for (i = 0; i < nStuff; i++) */ + + + /* Call the DDX routine to perform the swap(s). The DDX routine should + * scan the swap list (swap info), swap any buffers that it knows how to + * handle, delete them from the list, and update nStuff to indicate how + * many windows it did not handle. + * + * This scheme allows a range of sophistication in the DDX SwapBuffers() + * implementation. Naive implementations could just swap the first buffer + * in the list, move the last buffer to the front, decrement nStuff, and + * return. The next level of sophistication could be to scan the whole + * list for windows on the same screen. Up another level, the DDX routine + * could deal with cross-screen synchronization. + */ + + while (nStuff > 0) + { + pDbeScreenPriv = DBE_SCREEN_PRIV_FROM_WINDOW(swapInfo[0].pWindow); + error = (*pDbeScreenPriv->SwapBuffers)(client, &nStuff, swapInfo); + if (error != Success) + { + free(swapInfo); + return(error); + } + } + + free(swapInfo); + return(Success); + +} /* ProcDbeSwapBuffers() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: ProcDbeBeginIdiom + * + * Description: + * + * This function is for processing a DbeBeginIdiom request. + * This request informs the server that a complex swap will immediately + * follow this request. + * + * Return Values: + * + * Success + * + *****************************************************************************/ + +static int +ProcDbeBeginIdiom(ClientPtr client) +{ + /* REQUEST(xDbeBeginIdiomReq); */ + DbeScreenPrivPtr pDbeScreenPriv; + register int i; + + + REQUEST_SIZE_MATCH(xDbeBeginIdiomReq); + + for (i = 0; i < screenInfo.numScreens; i++) + { + pDbeScreenPriv = DBE_SCREEN_PRIV(screenInfo.screens[i]); + + /* Call the DDX begin idiom procedure if there is one. */ + if (pDbeScreenPriv->BeginIdiom) + { + (*pDbeScreenPriv->BeginIdiom)(client); + } + } + + return(Success); + +} /* ProcDbeBeginIdiom() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: ProcDbeGetVisualInfo + * + * Description: + * + * This function is for processing a ProcDbeGetVisualInfo request. + * This request returns information about which visuals support + * double buffering. + * + * Return Values: + * + * BadDrawable - value in screen specifiers is not a valid drawable + * Success + * + *****************************************************************************/ + +static int +ProcDbeGetVisualInfo(ClientPtr client) +{ + REQUEST(xDbeGetVisualInfoReq); + DbeScreenPrivPtr pDbeScreenPriv; + xDbeGetVisualInfoReply rep; + Drawable *drawables; + DrawablePtr *pDrawables = NULL; + register int i, j, n, rc; + register int count; /* number of visual infos in reply */ + register int length; /* length of reply */ + ScreenPtr pScreen; + XdbeScreenVisualInfo *pScrVisInfo; + + + REQUEST_AT_LEAST_SIZE(xDbeGetVisualInfoReq); + + if (stuff->n > UINT32_MAX / sizeof(DrawablePtr)) + return BadAlloc; + /* Make sure any specified drawables are valid. */ + if (stuff->n != 0) + { + if (!(pDrawables = (DrawablePtr *)malloc(stuff->n * + sizeof(DrawablePtr)))) + { + return(BadAlloc); + } + + drawables = (Drawable *)&stuff[1]; + + for (i = 0; i < stuff->n; i++) + { + rc = dixLookupDrawable(pDrawables+i, drawables[i], client, 0, + DixGetAttrAccess); + if (rc != Success) { + free(pDrawables); + return rc; + } + } + } + + count = (stuff->n == 0) ? screenInfo.numScreens : stuff->n; + if (!(pScrVisInfo = (XdbeScreenVisualInfo *)malloc(count * + sizeof(XdbeScreenVisualInfo)))) + { + if (pDrawables) + { + free(pDrawables); + } + + return(BadAlloc); + } + + length = 0; + + for (i = 0; i < count; i++) + { + pScreen = (stuff->n == 0) ? screenInfo.screens[i] : + pDrawables[i]->pScreen; + pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen); + + rc = XaceHook(XACE_SCREEN_ACCESS, client, pScreen, DixGetAttrAccess); + if ((rc != Success) || + !(*pDbeScreenPriv->GetVisualInfo)(pScreen, &pScrVisInfo[i])) + { + /* We failed to alloc pScrVisInfo[i].visinfo. */ + + /* Free visinfos that we allocated for previous screen infos.*/ + for (j = 0; j < i; j++) + { + free(pScrVisInfo[j].visinfo); + } + + /* Free pDrawables if we needed to allocate it above. */ + if (pDrawables) + { + free(pDrawables); + } + + return (rc == Success) ? BadAlloc : rc; + } + + /* Account for n, number of xDbeVisInfo items in list. */ + length += sizeof(CARD32); + + /* Account for n xDbeVisInfo items */ + length += pScrVisInfo[i].count * sizeof(xDbeVisInfo); + } + + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.length = bytes_to_int32(length); + rep.m = count; + + if (client->swapped) + { + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.m, n); + } + + /* Send off reply. */ + WriteToClient(client, sizeof(xDbeGetVisualInfoReply), (char *)&rep); + + for (i = 0; i < count; i++) + { + CARD32 data32; + + /* For each screen in the reply, send off the visual info */ + + /* Send off number of visuals. */ + data32 = (CARD32)pScrVisInfo[i].count; + + if (client->swapped) + { + swapl(&data32, n); + } + + WriteToClient(client, sizeof(CARD32), (char *)&data32); + + /* Now send off visual info items. */ + for (j = 0; j < pScrVisInfo[i].count; j++) + { + xDbeVisInfo visInfo; + + /* Copy the data in the client data structure to a protocol + * data structure. We will send data to the client from the + * protocol data structure. + */ + + visInfo.visualID = (CARD32)pScrVisInfo[i].visinfo[j].visual; + visInfo.depth = (CARD8) pScrVisInfo[i].visinfo[j].depth; + visInfo.perfLevel = (CARD8) pScrVisInfo[i].visinfo[j].perflevel; + + if (client->swapped) + { + swapl(&visInfo.visualID, n); + + /* We do not need to swap depth and perfLevel since they are + * already 1 byte quantities. + */ + } + + /* Write visualID(32), depth(8), perfLevel(8), and pad(16). */ + WriteToClient(client, 2*sizeof(CARD32), (char *)&visInfo.visualID); + } + } + + /* Clean up memory. */ + for (i = 0; i < count; i++) + { + free(pScrVisInfo[i].visinfo); + } + free(pScrVisInfo); + + if (pDrawables) + { + free(pDrawables); + } + + return Success; + +} /* ProcDbeGetVisualInfo() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: ProcDbeGetbackBufferAttributes + * + * Description: + * + * This function is for processing a ProcDbeGetbackBufferAttributes + * request. This request returns information about a back buffer. + * + * Return Values: + * + * Success + * + *****************************************************************************/ + +static int +ProcDbeGetBackBufferAttributes(ClientPtr client) +{ + REQUEST(xDbeGetBackBufferAttributesReq); + xDbeGetBackBufferAttributesReply rep; + DbeWindowPrivPtr pDbeWindowPriv; + int rc, n; + + + REQUEST_SIZE_MATCH(xDbeGetBackBufferAttributesReq); + + rc = dixLookupResourceByType((pointer *)&pDbeWindowPriv, stuff->buffer, + dbeWindowPrivResType, client, + DixGetAttrAccess); + if (rc == Success) + { + rep.attributes = pDbeWindowPriv->pWindow->drawable.id; + } + else + { + rep.attributes = None; + } + + rep.type = X_Reply; + rep.sequenceNumber = client->sequence; + rep.length = 0; + + if (client->swapped) + { + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.attributes, n); + } + + WriteToClient(client, sizeof(xDbeGetBackBufferAttributesReply), + (char *)&rep); + return Success; + +} /* ProcDbeGetbackBufferAttributes() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: ProcDbeDispatch + * + * Description: + * + * This function dispatches DBE requests. + * + *****************************************************************************/ + +static int +ProcDbeDispatch(ClientPtr client) +{ + REQUEST(xReq); + + + switch (stuff->data) + { + case X_DbeGetVersion: + return(ProcDbeGetVersion(client)); + + case X_DbeAllocateBackBufferName: + return(ProcDbeAllocateBackBufferName(client)); + + case X_DbeDeallocateBackBufferName: + return(ProcDbeDeallocateBackBufferName(client)); + + case X_DbeSwapBuffers: + return(ProcDbeSwapBuffers(client)); + + case X_DbeBeginIdiom: + return(ProcDbeBeginIdiom(client)); + + case X_DbeEndIdiom: + return(Success); + + case X_DbeGetVisualInfo: + return(ProcDbeGetVisualInfo(client)); + + case X_DbeGetBackBufferAttributes: + return(ProcDbeGetBackBufferAttributes(client)); + + default: + return(BadRequest); + } + +} /* ProcDbeDispatch() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: SProcDbeGetVersion + * + * Description: + * + * This function is for processing a DbeGetVersion request on a swapped + * server. This request returns the major and minor version numbers of + * this extension. + * + * Return Values: + * + * Success + * + *****************************************************************************/ + +static int +SProcDbeGetVersion(ClientPtr client) +{ + REQUEST(xDbeGetVersionReq); + register int n; + + + swaps(&stuff->length, n); + return(ProcDbeGetVersion(client)); + +} /* SProcDbeGetVersion() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: SProcDbeAllocateBackBufferName + * + * Description: + * + * This function is for processing a DbeAllocateBackBufferName request on + * a swapped server. This request allocates a drawable ID used to refer + * to the back buffer of a window. + * + * Return Values: + * + * BadAlloc - server can not allocate resources + * BadIDChoice - id is out of range for client; id is already in use + * BadMatch - window is not an InputOutput window; + * visual of window is not on list returned by + * DBEGetVisualInfo; + * BadValue - invalid swap action is specified + * BadWindow - window is not a valid window + * Success + * + *****************************************************************************/ + +static int +SProcDbeAllocateBackBufferName(ClientPtr client) +{ + REQUEST(xDbeAllocateBackBufferNameReq); + register int n; + + swaps(&stuff->length, n); + REQUEST_SIZE_MATCH(xDbeAllocateBackBufferNameReq); + + swapl(&stuff->window, n); + swapl(&stuff->buffer, n); + /* stuff->swapAction is a byte. We do not need to swap this field. */ + + return(ProcDbeAllocateBackBufferName(client)); + +} /* SProcDbeAllocateBackBufferName() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: SProcDbeDeallocateBackBufferName + * + * Description: + * + * This function is for processing a DbeDeallocateBackBufferName request + * on a swapped server. This request frees a drawable ID that was + * obtained by a DbeAllocateBackBufferName request. + * + * Return Values: + * + * BadBuffer - buffer to deallocate is not associated with a window + * Success + * + *****************************************************************************/ + +static int +SProcDbeDeallocateBackBufferName(ClientPtr client) +{ + REQUEST (xDbeDeallocateBackBufferNameReq); + register int n; + + + swaps(&stuff->length, n); + REQUEST_SIZE_MATCH(xDbeDeallocateBackBufferNameReq); + + swapl(&stuff->buffer, n); + + return(ProcDbeDeallocateBackBufferName(client)); + +} /* SProcDbeDeallocateBackBufferName() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: SProcDbeSwapBuffers + * + * Description: + * + * This function is for processing a DbeSwapBuffers request on a swapped + * server. This request swaps the buffers for all windows listed, + * applying the appropriate swap action for each window. + * + * Return Values: + * + * BadMatch - a window in request is not double-buffered; a window in + * request is listed more than once; all windows in request do + * not have the same root + * BadValue - invalid swap action is specified + * BadWindow - a window in request is not valid + * Success + * + *****************************************************************************/ + +static int +SProcDbeSwapBuffers(ClientPtr client) +{ + REQUEST(xDbeSwapBuffersReq); + register int i, n; + xDbeSwapInfo *pSwapInfo; + + + swaps(&stuff->length, n); + REQUEST_AT_LEAST_SIZE(xDbeSwapBuffersReq); + + swapl(&stuff->n, n); + + if (stuff->n != 0) + { + pSwapInfo = (xDbeSwapInfo *)stuff+1; + + /* The swap info following the fix part of this request is a window(32) + * followed by a 1 byte swap action and then 3 pad bytes. We only need + * to swap the window information. + */ + for (i = 0; i < stuff->n; i++) + { + swapl(&pSwapInfo->window, n); + } + } + + return(ProcDbeSwapBuffers(client)); + +} /* SProcDbeSwapBuffers() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: SProcDbeBeginIdiom + * + * Description: + * + * This function is for processing a DbeBeginIdiom request on a swapped + * server. This request informs the server that a complex swap will + * immediately follow this request. + * + * Return Values: + * + * Success + * + *****************************************************************************/ + +static int +SProcDbeBeginIdiom(ClientPtr client) +{ + REQUEST(xDbeBeginIdiomReq); + register int n; + + swaps(&stuff->length, n); + return(ProcDbeBeginIdiom(client)); + +} /* SProcDbeBeginIdiom() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: SProcDbeGetVisualInfo + * + * Description: + * + * This function is for processing a ProcDbeGetVisualInfo request on a + * swapped server. This request returns information about which visuals + * support double buffering. + * + * Return Values: + * + * BadDrawable - value in screen specifiers is not a valid drawable + * Success + * + *****************************************************************************/ + +static int +SProcDbeGetVisualInfo(ClientPtr client) +{ + REQUEST(xDbeGetVisualInfoReq); + register int n; + + + swaps(&stuff->length, n); + REQUEST_AT_LEAST_SIZE(xDbeGetVisualInfoReq); + + swapl(&stuff->n, n); + SwapRestL(stuff); + + return(ProcDbeGetVisualInfo(client)); + +} /* SProcDbeGetVisualInfo() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: SProcDbeGetbackBufferAttributes + * + * Description: + * + * This function is for processing a ProcDbeGetbackBufferAttributes + * request on a swapped server. This request returns information about a + * back buffer. + * + * Return Values: + * + * Success + * + *****************************************************************************/ + +static int +SProcDbeGetBackBufferAttributes(ClientPtr client) +{ + REQUEST (xDbeGetBackBufferAttributesReq); + register int n; + + swaps(&stuff->length, n); + REQUEST_SIZE_MATCH(xDbeGetBackBufferAttributesReq); + + swapl(&stuff->buffer, n); + + return(ProcDbeGetBackBufferAttributes(client)); + +} /* SProcDbeGetBackBufferAttributes() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: SProcDbeDispatch + * + * Description: + * + * This function dispatches DBE requests on a swapped server. + * + *****************************************************************************/ + +static int +SProcDbeDispatch(ClientPtr client) +{ + REQUEST(xReq); + + + switch (stuff->data) + { + case X_DbeGetVersion: + return(SProcDbeGetVersion(client)); + + case X_DbeAllocateBackBufferName: + return(SProcDbeAllocateBackBufferName(client)); + + case X_DbeDeallocateBackBufferName: + return(SProcDbeDeallocateBackBufferName(client)); + + case X_DbeSwapBuffers: + return(SProcDbeSwapBuffers(client)); + + case X_DbeBeginIdiom: + return(SProcDbeBeginIdiom(client)); + + case X_DbeEndIdiom: + return(Success); + + case X_DbeGetVisualInfo: + return(SProcDbeGetVisualInfo(client)); + + case X_DbeGetBackBufferAttributes: + return(SProcDbeGetBackBufferAttributes(client)); + + default: + return (BadRequest); + } + +} /* SProcDbeDispatch() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: DbeSetupBackgroundPainter + * + * Description: + * + * This function sets up pGC to clear pixmaps. + * + * Return Values: + * + * TRUE - setup was successful + * FALSE - the window's background state is NONE + * + *****************************************************************************/ + +static Bool +DbeSetupBackgroundPainter(WindowPtr pWin, GCPtr pGC) +{ + ChangeGCVal gcvalues[4]; + int ts_x_origin, ts_y_origin; + PixUnion background; + int backgroundState; + Mask gcmask; + + + /* First take care of any ParentRelative stuff by altering the + * tile/stipple origin to match the coordinates of the upper-left + * corner of the first ancestor without a ParentRelative background. + * This coordinate is, of course, negative. + */ + ts_x_origin = ts_y_origin = 0; + while (pWin->backgroundState == ParentRelative) + { + ts_x_origin -= pWin->origin.x; + ts_y_origin -= pWin->origin.y; + + pWin = pWin->parent; + } + backgroundState = pWin->backgroundState; + background = pWin->background; + + switch (backgroundState) + { + case BackgroundPixel: + gcvalues[0].val = background.pixel; + gcvalues[1].val = FillSolid; + gcmask = GCForeground|GCFillStyle; + break; + + case BackgroundPixmap: + gcvalues[0].val = FillTiled; + gcvalues[1].ptr = background.pixmap; + gcvalues[2].val = ts_x_origin; + gcvalues[3].val = ts_y_origin; + gcmask = GCFillStyle|GCTile|GCTileStipXOrigin|GCTileStipYOrigin; + break; + + default: + /* pWin->backgroundState == None */ + return(FALSE); + } + + return ChangeGC(NullClient, pGC, gcmask, gcvalues) == 0; +} /* DbeSetupBackgroundPainter() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: DbeDrawableDelete + * + * Description: + * + * This is the resource delete function for dbeDrawableResType. + * It is registered when the drawable resource type is created in + * DbeExtensionInit(). + * + * To make resource deletion simple, we do not do anything in this function + * and leave all resource deleteion to DbeWindowPrivDelete(), which will + * eventually be called or already has been called. Deletion functions are + * not guaranteed to be called in any particular order. + * + *****************************************************************************/ +static int +DbeDrawableDelete(pointer pDrawable, XID id) +{ + return(Success); + +} /* DbeDrawableDelete() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: DbeWindowPrivDelete + * + * Description: + * + * This is the resource delete function for dbeWindowPrivResType. + * It is registered when the drawable resource type is created in + * DbeExtensionInit(). + * + *****************************************************************************/ +static int +DbeWindowPrivDelete(pointer pDbeWinPriv, XID id) +{ + DbeScreenPrivPtr pDbeScreenPriv; + DbeWindowPrivPtr pDbeWindowPriv = (DbeWindowPrivPtr)pDbeWinPriv; + int i; + + + /* + ************************************************************************** + ** Remove the buffer ID from the ID array. + ************************************************************************** + */ + + /* Find the ID in the ID array. */ + i = 0; + while ((i < pDbeWindowPriv->nBufferIDs) && (pDbeWindowPriv->IDs[i] != id)) + { + i++; + } + + if (i == pDbeWindowPriv->nBufferIDs) + { + /* We did not find the ID in the array. We should never get here. */ + return(BadValue); + } + + /* Remove the ID from the array. */ + + if (i < (pDbeWindowPriv->nBufferIDs - 1)) + { + /* Compress the buffer ID array, overwriting the ID in the process. */ + memmove(&pDbeWindowPriv->IDs[i], &pDbeWindowPriv->IDs[i+1], + (pDbeWindowPriv->nBufferIDs - i - 1) * sizeof(XID)); + } + else + { + /* We are removing the last ID in the array, in which case, the + * assignement below is all that we need to do. + */ + } + pDbeWindowPriv->IDs[pDbeWindowPriv->nBufferIDs - 1] = DBE_FREE_ID_ELEMENT; + + pDbeWindowPriv->nBufferIDs--; + + /* If an extended array was allocated, then check to see if the remaining + * buffer IDs will fit in the static array. + */ + + if ((pDbeWindowPriv->maxAvailableIDs > DBE_INIT_MAX_IDS) && + (pDbeWindowPriv->nBufferIDs == DBE_INIT_MAX_IDS)) + { + /* Copy the IDs back into the static array. */ + memcpy(pDbeWindowPriv->initIDs, pDbeWindowPriv->IDs, + DBE_INIT_MAX_IDS * sizeof(XID)); + + /* Free the extended array; use the static array. */ + free(pDbeWindowPriv->IDs); + pDbeWindowPriv->IDs = pDbeWindowPriv->initIDs; + pDbeWindowPriv->maxAvailableIDs = DBE_INIT_MAX_IDS; + } + + + /* + ************************************************************************** + ** Perform DDX level tasks. + ************************************************************************** + */ + + pDbeScreenPriv = DBE_SCREEN_PRIV_FROM_WINDOW_PRIV( + (DbeWindowPrivPtr)pDbeWindowPriv); + (*pDbeScreenPriv->WinPrivDelete)((DbeWindowPrivPtr)pDbeWindowPriv, id); + + + /* + ************************************************************************** + ** Perform miscellaneous tasks if this is the last buffer associated + ** with the window. + ************************************************************************** + */ + + if (pDbeWindowPriv->nBufferIDs == 0) + { + /* Reset the DBE window priv pointer. */ + dixSetPrivate(&pDbeWindowPriv->pWindow->devPrivates, dbeWindowPrivKey, + NULL); + + /* We are done with the window priv. */ + dixFreePrivates(pDbeWindowPriv->devPrivates); + free(pDbeWindowPriv); + } + + return(Success); + +} /* DbeWindowPrivDelete() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: DbeResetProc + * + * Description: + * + * This routine is called at the end of every server generation. + * It deallocates any memory reserved for the extension and performs any + * other tasks related to shutting down the extension. + * + *****************************************************************************/ +static void +DbeResetProc(ExtensionEntry *extEntry) +{ + int i; + ScreenPtr pScreen; + DbeScreenPrivPtr pDbeScreenPriv; + + for (i = 0; i < screenInfo.numScreens; i++) + { + pScreen = screenInfo.screens[i]; + pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen); + + if (pDbeScreenPriv) + { + /* Unwrap DestroyWindow, which was wrapped in DbeExtensionInit().*/ + pScreen->DestroyWindow = pDbeScreenPriv->DestroyWindow; + + if (pDbeScreenPriv->ResetProc) + (*pDbeScreenPriv->ResetProc)(pScreen); + + free(pDbeScreenPriv); + } + } +} /* DbeResetProc() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: DbeDestroyWindow + * + * Description: + * + * This is the wrapper for pScreen->DestroyWindow. + * This function frees buffer resources for a window before it is + * destroyed. + * + *****************************************************************************/ + +static Bool +DbeDestroyWindow(WindowPtr pWin) +{ + DbeScreenPrivPtr pDbeScreenPriv; + DbeWindowPrivPtr pDbeWindowPriv; + ScreenPtr pScreen; + Bool ret; + + + /* + ************************************************************************** + ** 1. Unwrap the member routine. + ************************************************************************** + */ + + pScreen = pWin->drawable.pScreen; + pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen); + pScreen->DestroyWindow = pDbeScreenPriv->DestroyWindow; + + /* + ************************************************************************** + ** 2. Do any work necessary before the member routine is called. + ** + ** Call the window priv delete function for all buffer IDs associated + ** with this window. + ************************************************************************** + */ + + if ((pDbeWindowPriv = DBE_WINDOW_PRIV(pWin))) + { + while (pDbeWindowPriv) + { + /* *DbeWinPrivDelete() will free the window private and set it to + * NULL if there are no more buffer IDs associated with this + * window. + */ + FreeResource(pDbeWindowPriv->IDs[0], RT_NONE); + pDbeWindowPriv = DBE_WINDOW_PRIV(pWin); + } + } + + /* + ************************************************************************** + ** 3. Call the member routine, saving its result if necessary. + ************************************************************************** + */ + + ret = (*pScreen->DestroyWindow)(pWin); + + /* + ************************************************************************** + ** 4. Rewrap the member routine, restoring the wrapper value first in case + ** the wrapper (or something that it wrapped) change this value. + ************************************************************************** + */ + + pDbeScreenPriv->DestroyWindow = pScreen->DestroyWindow; + pScreen->DestroyWindow = DbeDestroyWindow; + + /* + ************************************************************************** + ** 5. Do any work necessary after the member routine has been called. + ** + ** In this case we do not need to do anything. + ************************************************************************** + */ + + return(ret); + +} /* DbeDestroyWindow() */ + + +/****************************************************************************** + * + * DBE DIX Procedure: DbeExtensionInit + * + * Description: + * + * Called from InitExtensions in main() + * + *****************************************************************************/ + +void +DbeExtensionInit(void) +{ + ExtensionEntry *extEntry; + register int i, j; + ScreenPtr pScreen = NULL; + DbeScreenPrivPtr pDbeScreenPriv; + int nStubbedScreens = 0; + Bool ddxInitSuccess; + +#ifdef PANORAMIX + if(!noPanoramiXExtension) return; +#endif + + /* Create the resource types. */ + dbeDrawableResType = + CreateNewResourceType(DbeDrawableDelete, "dbeDrawable"); + if (!dbeDrawableResType) + return; + dbeDrawableResType |= RC_DRAWABLE; + + dbeWindowPrivResType = + CreateNewResourceType(DbeWindowPrivDelete, "dbeWindow"); + if (!dbeWindowPrivResType) + return; + + if (!dixRegisterPrivateOffset(dbeDrawableResType, + offsetof(PixmapRec, devPrivates))) + return; + + for (i = 0; i < screenInfo.numScreens; i++) + { + /* For each screen, set up DBE screen privates and init DIX and DDX + * interface. + */ + + pScreen = screenInfo.screens[i]; + + if (!(pDbeScreenPriv = malloc (sizeof (DbeScreenPrivRec)))) + { + /* If we can not alloc a window or screen private, + * then free any privates that we already alloc'ed and return + */ + + for (j = 0; j < i; j++) + { + free(dixLookupPrivate(&screenInfo.screens[j]->devPrivates, + dbeScreenPrivKey)); + dixSetPrivate(&screenInfo.screens[j]->devPrivates, + dbeScreenPrivKey, NULL); + } + return; + } + + dixSetPrivate(&pScreen->devPrivates, dbeScreenPrivKey, pDbeScreenPriv); + + /* Copy the resource types */ + pDbeScreenPriv->dbeDrawableResType = dbeDrawableResType; + pDbeScreenPriv->dbeWindowPrivResType = dbeWindowPrivResType; + + /* Copy the private indices */ + pDbeScreenPriv->dbeScreenPrivKey = dbeScreenPrivKey; + pDbeScreenPriv->dbeWindowPrivKey = dbeWindowPrivKey; + + { + /* We don't have DDX support for DBE anymore */ + +#ifndef DISABLE_MI_DBE_BY_DEFAULT + /* Setup DIX. */ + pDbeScreenPriv->SetupBackgroundPainter = DbeSetupBackgroundPainter; + + /* Setup DDX. */ + ddxInitSuccess = miDbeInit(pScreen, pDbeScreenPriv); + + /* DDX DBE initialization may have the side affect of + * reallocating pDbeScreenPriv, so we need to update it. + */ + pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen); + + if (ddxInitSuccess) + { + /* Wrap DestroyWindow. The DDX initialization function + * already wrapped PositionWindow for us. + */ + + pDbeScreenPriv->DestroyWindow = pScreen->DestroyWindow; + pScreen->DestroyWindow = DbeDestroyWindow; + } + else + { + /* DDX initialization failed. Stub the screen. */ + DbeStubScreen(pDbeScreenPriv, &nStubbedScreens); + } +#else + DbeStubScreen(pDbeScreenPriv, &nStubbedScreens); +#endif + + } + + } /* for (i = 0; i < screenInfo.numScreens; i++) */ + + + if (nStubbedScreens == screenInfo.numScreens) + { + /* All screens stubbed. Clean up and return. */ + + for (i = 0; i < screenInfo.numScreens; i++) + { + free(dixLookupPrivate(&screenInfo.screens[i]->devPrivates, + dbeScreenPrivKey)); + dixSetPrivate(&pScreen->devPrivates, dbeScreenPrivKey, NULL); + } + return; + } + + + /* Now add the extension. */ + extEntry = AddExtension(DBE_PROTOCOL_NAME, DbeNumberEvents, + DbeNumberErrors, ProcDbeDispatch, SProcDbeDispatch, + DbeResetProc, StandardMinorOpcode); + + dbeErrorBase = extEntry->errorBase; + +} /* DbeExtensionInit() */ + diff --git a/xorg-server/dbe/dbestruct.h b/xorg-server/dbe/dbestruct.h index 002ffbeb2..ba6b56d79 100644 --- a/xorg-server/dbe/dbestruct.h +++ b/xorg-server/dbe/dbestruct.h @@ -217,10 +217,6 @@ typedef struct _DbeScreenPrivRec ScreenPtr /*pScreen*/ ); - /* Device-specific private information. - */ - PrivateRec *devPrivates; - } DbeScreenPrivRec, *DbeScreenPrivPtr; #endif /* DBE_STRUCT_H */ diff --git a/xorg-server/render/render.c b/xorg-server/render/render.c index 9bbff1b6d..9aabcfb20 100644 --- a/xorg-server/render/render.c +++ b/xorg-server/render/render.c @@ -1,3363 +1,3370 @@ -/*
- *
- * Copyright © 2000 SuSE, Inc.
- *
- * Permission to use, copy, modify, distribute, and sell this software and its
- * documentation for any purpose is hereby granted without fee, provided that
- * the above copyright notice appear in all copies and that both that
- * copyright notice and this permission notice appear in supporting
- * documentation, and that the name of SuSE not be used in advertising or
- * publicity pertaining to distribution of the software without specific,
- * written prior permission. SuSE makes no representations about the
- * suitability of this software for any purpose. It is provided "as is"
- * without express or implied warranty.
- *
- * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
- * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 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 PERFORMANCE OF THIS SOFTWARE.
- *
- * Author: Keith Packard, SuSE, Inc.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include <X11/X.h>
-#include <X11/Xproto.h>
-#include "misc.h"
-#include "os.h"
-#include "dixstruct.h"
-#include "resource.h"
-#include "scrnintstr.h"
-#include "windowstr.h"
-#include "pixmapstr.h"
-#include "colormapst.h"
-#include "extnsionst.h"
-#include "servermd.h"
-#include <X11/extensions/render.h>
-#include <X11/extensions/renderproto.h>
-#include "picturestr.h"
-#include "glyphstr.h"
-#include <X11/Xfuncproto.h>
-#include "cursorstr.h"
-#include "xace.h"
-#include "protocol-versions.h"
-
-#if HAVE_STDINT_H
-#include <stdint.h>
-#elif !defined(UINT32_MAX)
-#define UINT32_MAX 0xffffffffU
-#endif
-
-static int ProcRenderQueryVersion (ClientPtr pClient);
-static int ProcRenderQueryPictFormats (ClientPtr pClient);
-static int ProcRenderQueryPictIndexValues (ClientPtr pClient);
-static int ProcRenderQueryDithers (ClientPtr pClient);
-static int ProcRenderCreatePicture (ClientPtr pClient);
-static int ProcRenderChangePicture (ClientPtr pClient);
-static int ProcRenderSetPictureClipRectangles (ClientPtr pClient);
-static int ProcRenderFreePicture (ClientPtr pClient);
-static int ProcRenderComposite (ClientPtr pClient);
-static int ProcRenderScale (ClientPtr pClient);
-static int ProcRenderTrapezoids (ClientPtr pClient);
-static int ProcRenderTriangles (ClientPtr pClient);
-static int ProcRenderTriStrip (ClientPtr pClient);
-static int ProcRenderTriFan (ClientPtr pClient);
-static int ProcRenderColorTrapezoids (ClientPtr pClient);
-static int ProcRenderColorTriangles (ClientPtr pClient);
-static int ProcRenderTransform (ClientPtr pClient);
-static int ProcRenderCreateGlyphSet (ClientPtr pClient);
-static int ProcRenderReferenceGlyphSet (ClientPtr pClient);
-static int ProcRenderFreeGlyphSet (ClientPtr pClient);
-static int ProcRenderAddGlyphs (ClientPtr pClient);
-static int ProcRenderAddGlyphsFromPicture (ClientPtr pClient);
-static int ProcRenderFreeGlyphs (ClientPtr pClient);
-static int ProcRenderCompositeGlyphs (ClientPtr pClient);
-static int ProcRenderFillRectangles (ClientPtr pClient);
-static int ProcRenderCreateCursor (ClientPtr pClient);
-static int ProcRenderSetPictureTransform (ClientPtr pClient);
-static int ProcRenderQueryFilters (ClientPtr pClient);
-static int ProcRenderSetPictureFilter (ClientPtr pClient);
-static int ProcRenderCreateAnimCursor (ClientPtr pClient);
-static int ProcRenderAddTraps (ClientPtr pClient);
-static int ProcRenderCreateSolidFill (ClientPtr pClient);
-static int ProcRenderCreateLinearGradient (ClientPtr pClient);
-static int ProcRenderCreateRadialGradient (ClientPtr pClient);
-static int ProcRenderCreateConicalGradient (ClientPtr pClient);
-
-static int ProcRenderDispatch (ClientPtr pClient);
-
-static int SProcRenderQueryVersion (ClientPtr pClient);
-static int SProcRenderQueryPictFormats (ClientPtr pClient);
-static int SProcRenderQueryPictIndexValues (ClientPtr pClient);
-static int SProcRenderQueryDithers (ClientPtr pClient);
-static int SProcRenderCreatePicture (ClientPtr pClient);
-static int SProcRenderChangePicture (ClientPtr pClient);
-static int SProcRenderSetPictureClipRectangles (ClientPtr pClient);
-static int SProcRenderFreePicture (ClientPtr pClient);
-static int SProcRenderComposite (ClientPtr pClient);
-static int SProcRenderScale (ClientPtr pClient);
-static int SProcRenderTrapezoids (ClientPtr pClient);
-static int SProcRenderTriangles (ClientPtr pClient);
-static int SProcRenderTriStrip (ClientPtr pClient);
-static int SProcRenderTriFan (ClientPtr pClient);
-static int SProcRenderColorTrapezoids (ClientPtr pClient);
-static int SProcRenderColorTriangles (ClientPtr pClient);
-static int SProcRenderTransform (ClientPtr pClient);
-static int SProcRenderCreateGlyphSet (ClientPtr pClient);
-static int SProcRenderReferenceGlyphSet (ClientPtr pClient);
-static int SProcRenderFreeGlyphSet (ClientPtr pClient);
-static int SProcRenderAddGlyphs (ClientPtr pClient);
-static int SProcRenderAddGlyphsFromPicture (ClientPtr pClient);
-static int SProcRenderFreeGlyphs (ClientPtr pClient);
-static int SProcRenderCompositeGlyphs (ClientPtr pClient);
-static int SProcRenderFillRectangles (ClientPtr pClient);
-static int SProcRenderCreateCursor (ClientPtr pClient);
-static int SProcRenderSetPictureTransform (ClientPtr pClient);
-static int SProcRenderQueryFilters (ClientPtr pClient);
-static int SProcRenderSetPictureFilter (ClientPtr pClient);
-static int SProcRenderCreateAnimCursor (ClientPtr pClient);
-static int SProcRenderAddTraps (ClientPtr pClient);
-static int SProcRenderCreateSolidFill (ClientPtr pClient);
-static int SProcRenderCreateLinearGradient (ClientPtr pClient);
-static int SProcRenderCreateRadialGradient (ClientPtr pClient);
-static int SProcRenderCreateConicalGradient (ClientPtr pClient);
-
-static int SProcRenderDispatch (ClientPtr pClient);
-
-int (*ProcRenderVector[RenderNumberRequests])(ClientPtr) = {
- ProcRenderQueryVersion,
- ProcRenderQueryPictFormats,
- ProcRenderQueryPictIndexValues,
- ProcRenderQueryDithers,
- ProcRenderCreatePicture,
- ProcRenderChangePicture,
- ProcRenderSetPictureClipRectangles,
- ProcRenderFreePicture,
- ProcRenderComposite,
- ProcRenderScale,
- ProcRenderTrapezoids,
- ProcRenderTriangles,
- ProcRenderTriStrip,
- ProcRenderTriFan,
- ProcRenderColorTrapezoids,
- ProcRenderColorTriangles,
- ProcRenderTransform,
- ProcRenderCreateGlyphSet,
- ProcRenderReferenceGlyphSet,
- ProcRenderFreeGlyphSet,
- ProcRenderAddGlyphs,
- ProcRenderAddGlyphsFromPicture,
- ProcRenderFreeGlyphs,
- ProcRenderCompositeGlyphs,
- ProcRenderCompositeGlyphs,
- ProcRenderCompositeGlyphs,
- ProcRenderFillRectangles,
- ProcRenderCreateCursor,
- ProcRenderSetPictureTransform,
- ProcRenderQueryFilters,
- ProcRenderSetPictureFilter,
- ProcRenderCreateAnimCursor,
- ProcRenderAddTraps,
- ProcRenderCreateSolidFill,
- ProcRenderCreateLinearGradient,
- ProcRenderCreateRadialGradient,
- ProcRenderCreateConicalGradient
-};
-
-int (*SProcRenderVector[RenderNumberRequests])(ClientPtr) = {
- SProcRenderQueryVersion,
- SProcRenderQueryPictFormats,
- SProcRenderQueryPictIndexValues,
- SProcRenderQueryDithers,
- SProcRenderCreatePicture,
- SProcRenderChangePicture,
- SProcRenderSetPictureClipRectangles,
- SProcRenderFreePicture,
- SProcRenderComposite,
- SProcRenderScale,
- SProcRenderTrapezoids,
- SProcRenderTriangles,
- SProcRenderTriStrip,
- SProcRenderTriFan,
- SProcRenderColorTrapezoids,
- SProcRenderColorTriangles,
- SProcRenderTransform,
- SProcRenderCreateGlyphSet,
- SProcRenderReferenceGlyphSet,
- SProcRenderFreeGlyphSet,
- SProcRenderAddGlyphs,
- SProcRenderAddGlyphsFromPicture,
- SProcRenderFreeGlyphs,
- SProcRenderCompositeGlyphs,
- SProcRenderCompositeGlyphs,
- SProcRenderCompositeGlyphs,
- SProcRenderFillRectangles,
- SProcRenderCreateCursor,
- SProcRenderSetPictureTransform,
- SProcRenderQueryFilters,
- SProcRenderSetPictureFilter,
- SProcRenderCreateAnimCursor,
- SProcRenderAddTraps,
- SProcRenderCreateSolidFill,
- SProcRenderCreateLinearGradient,
- SProcRenderCreateRadialGradient,
- SProcRenderCreateConicalGradient
-};
-
-int RenderErrBase;
-static int RenderClientPrivateKeyIndex;
-DevPrivateKey RenderClientPrivateKey = &RenderClientPrivateKeyIndex;
-
-typedef struct _RenderClient {
- int major_version;
- int minor_version;
-} RenderClientRec, *RenderClientPtr;
-
-#define GetRenderClient(pClient) ((RenderClientPtr)dixLookupPrivate(&(pClient)->devPrivates, RenderClientPrivateKey))
-
-static void
-RenderClientCallback (CallbackListPtr *list,
- pointer closure,
- pointer data)
-{
- NewClientInfoRec *clientinfo = (NewClientInfoRec *) data;
- ClientPtr pClient = clientinfo->client;
- RenderClientPtr pRenderClient = GetRenderClient (pClient);
-
- pRenderClient->major_version = 0;
- pRenderClient->minor_version = 0;
-}
-
-void
-RenderExtensionInit (void)
-{
- ExtensionEntry *extEntry;
-
- if (!PictureType)
- return;
- if (!PictureFinishInit ())
- return;
- if (!dixRequestPrivate(RenderClientPrivateKey, sizeof(RenderClientRec)))
- return;
- if (!AddCallback (&ClientStateCallback, RenderClientCallback, 0))
- return;
-
- extEntry = AddExtension (RENDER_NAME, 0, RenderNumberErrors,
- ProcRenderDispatch, SProcRenderDispatch,
- NULL, StandardMinorOpcode);
- if (!extEntry)
- return;
- RenderErrBase = extEntry->errorBase;
-}
-
-static int
-ProcRenderQueryVersion (ClientPtr client)
-{
- RenderClientPtr pRenderClient = GetRenderClient (client);
- xRenderQueryVersionReply rep;
- register int n;
- REQUEST(xRenderQueryVersionReq);
-
- pRenderClient->major_version = stuff->majorVersion;
- pRenderClient->minor_version = stuff->minorVersion;
-
- REQUEST_SIZE_MATCH(xRenderQueryVersionReq);
- memset(&rep, 0, sizeof(xRenderQueryVersionReply));
- rep.type = X_Reply;
- rep.length = 0;
- rep.sequenceNumber = client->sequence;
-
- if ((stuff->majorVersion * 1000 + stuff->minorVersion) <
- (SERVER_RENDER_MAJOR_VERSION * 1000 + SERVER_RENDER_MINOR_VERSION))
- {
- rep.majorVersion = stuff->majorVersion;
- rep.minorVersion = stuff->minorVersion;
- } else
- {
- rep.majorVersion = SERVER_RENDER_MAJOR_VERSION;
- rep.minorVersion = SERVER_RENDER_MINOR_VERSION;
- }
-
- if (client->swapped) {
- swaps(&rep.sequenceNumber, n);
- swapl(&rep.length, n);
- swapl(&rep.majorVersion, n);
- swapl(&rep.minorVersion, n);
- }
- WriteToClient(client, sizeof(xRenderQueryVersionReply), (char *)&rep);
- return Success;
-}
-
-static VisualPtr
-findVisual (ScreenPtr pScreen, VisualID vid)
-{
- VisualPtr pVisual;
- int v;
-
- for (v = 0; v < pScreen->numVisuals; v++)
- {
- pVisual = pScreen->visuals + v;
- if (pVisual->vid == vid)
- return pVisual;
- }
- return 0;
-}
-
-static int
-ProcRenderQueryPictFormats (ClientPtr client)
-{
- RenderClientPtr pRenderClient = GetRenderClient (client);
- xRenderQueryPictFormatsReply *reply;
- xPictScreen *pictScreen;
- xPictDepth *pictDepth;
- xPictVisual *pictVisual;
- xPictFormInfo *pictForm;
- CARD32 *pictSubpixel;
- ScreenPtr pScreen;
- VisualPtr pVisual;
- DepthPtr pDepth;
- int v, d;
- PictureScreenPtr ps;
- PictFormatPtr pFormat;
- int nformat;
- int ndepth;
- int nvisual;
- int rlength;
- int s;
- int n;
- int numScreens;
- int numSubpixel;
-/* REQUEST(xRenderQueryPictFormatsReq); */
-
- REQUEST_SIZE_MATCH(xRenderQueryPictFormatsReq);
-
-#ifdef PANORAMIX
- if (noPanoramiXExtension)
- numScreens = screenInfo.numScreens;
- else
- numScreens = ((xConnSetup *)ConnectionInfo)->numRoots;
-#else
- numScreens = screenInfo.numScreens;
-#endif
- ndepth = nformat = nvisual = 0;
- for (s = 0; s < numScreens; s++)
- {
- pScreen = screenInfo.screens[s];
- for (d = 0; d < pScreen->numDepths; d++)
- {
- pDepth = pScreen->allowedDepths + d;
- ++ndepth;
-
- for (v = 0; v < pDepth->numVids; v++)
- {
- pVisual = findVisual (pScreen, pDepth->vids[v]);
- if (pVisual && PictureMatchVisual (pScreen, pDepth->depth, pVisual))
- ++nvisual;
- }
- }
- ps = GetPictureScreenIfSet(pScreen);
- if (ps)
- nformat += ps->nformats;
- }
- if (pRenderClient->major_version == 0 && pRenderClient->minor_version < 6)
- numSubpixel = 0;
- else
- numSubpixel = numScreens;
-
- rlength = (sizeof (xRenderQueryPictFormatsReply) +
- nformat * sizeof (xPictFormInfo) +
- numScreens * sizeof (xPictScreen) +
- ndepth * sizeof (xPictDepth) +
- nvisual * sizeof (xPictVisual) +
- numSubpixel * sizeof (CARD32));
- reply = (xRenderQueryPictFormatsReply *) calloc(1, rlength);
- if (!reply)
- return BadAlloc;
- reply->type = X_Reply;
- reply->sequenceNumber = client->sequence;
- reply->length = bytes_to_int32(rlength - sizeof(xGenericReply));
- reply->numFormats = nformat;
- reply->numScreens = numScreens;
- reply->numDepths = ndepth;
- reply->numVisuals = nvisual;
- reply->numSubpixel = numSubpixel;
-
- pictForm = (xPictFormInfo *) (reply + 1);
-
- for (s = 0; s < numScreens; s++)
- {
- pScreen = screenInfo.screens[s];
- ps = GetPictureScreenIfSet(pScreen);
- if (ps)
- {
- for (nformat = 0, pFormat = ps->formats;
- nformat < ps->nformats;
- nformat++, pFormat++)
- {
- pictForm->id = pFormat->id;
- pictForm->type = pFormat->type;
- pictForm->depth = pFormat->depth;
- pictForm->direct.red = pFormat->direct.red;
- pictForm->direct.redMask = pFormat->direct.redMask;
- pictForm->direct.green = pFormat->direct.green;
- pictForm->direct.greenMask = pFormat->direct.greenMask;
- pictForm->direct.blue = pFormat->direct.blue;
- pictForm->direct.blueMask = pFormat->direct.blueMask;
- pictForm->direct.alpha = pFormat->direct.alpha;
- pictForm->direct.alphaMask = pFormat->direct.alphaMask;
- if (pFormat->type == PictTypeIndexed && pFormat->index.pColormap)
- pictForm->colormap = pFormat->index.pColormap->mid;
- else
- pictForm->colormap = None;
- if (client->swapped)
- {
- swapl (&pictForm->id, n);
- swaps (&pictForm->direct.red, n);
- swaps (&pictForm->direct.redMask, n);
- swaps (&pictForm->direct.green, n);
- swaps (&pictForm->direct.greenMask, n);
- swaps (&pictForm->direct.blue, n);
- swaps (&pictForm->direct.blueMask, n);
- swaps (&pictForm->direct.alpha, n);
- swaps (&pictForm->direct.alphaMask, n);
- swapl (&pictForm->colormap, n);
- }
- pictForm++;
- }
- }
- }
-
- pictScreen = (xPictScreen *) pictForm;
- for (s = 0; s < numScreens; s++)
- {
- pScreen = screenInfo.screens[s];
- pictDepth = (xPictDepth *) (pictScreen + 1);
- ndepth = 0;
- for (d = 0; d < pScreen->numDepths; d++)
- {
- pictVisual = (xPictVisual *) (pictDepth + 1);
- pDepth = pScreen->allowedDepths + d;
-
- nvisual = 0;
- for (v = 0; v < pDepth->numVids; v++)
- {
- pVisual = findVisual (pScreen, pDepth->vids[v]);
- if (pVisual && (pFormat = PictureMatchVisual (pScreen,
- pDepth->depth,
- pVisual)))
- {
- pictVisual->visual = pVisual->vid;
- pictVisual->format = pFormat->id;
- if (client->swapped)
- {
- swapl (&pictVisual->visual, n);
- swapl (&pictVisual->format, n);
- }
- pictVisual++;
- nvisual++;
- }
- }
- pictDepth->depth = pDepth->depth;
- pictDepth->nPictVisuals = nvisual;
- if (client->swapped)
- {
- swaps (&pictDepth->nPictVisuals, n);
- }
- ndepth++;
- pictDepth = (xPictDepth *) pictVisual;
- }
- pictScreen->nDepth = ndepth;
- ps = GetPictureScreenIfSet(pScreen);
- if (ps)
- pictScreen->fallback = ps->fallback->id;
- else
- pictScreen->fallback = 0;
- if (client->swapped)
- {
- swapl (&pictScreen->nDepth, n);
- swapl (&pictScreen->fallback, n);
- }
- pictScreen = (xPictScreen *) pictDepth;
- }
- pictSubpixel = (CARD32 *) pictScreen;
-
- for (s = 0; s < numSubpixel; s++)
- {
- pScreen = screenInfo.screens[s];
- ps = GetPictureScreenIfSet(pScreen);
- if (ps)
- *pictSubpixel = ps->subpixel;
- else
- *pictSubpixel = SubPixelUnknown;
- if (client->swapped)
- {
- swapl (pictSubpixel, n);
- }
- ++pictSubpixel;
- }
-
- if (client->swapped)
- {
- swaps (&reply->sequenceNumber, n);
- swapl (&reply->length, n);
- swapl (&reply->numFormats, n);
- swapl (&reply->numScreens, n);
- swapl (&reply->numDepths, n);
- swapl (&reply->numVisuals, n);
- swapl (&reply->numSubpixel, n);
- }
- WriteToClient(client, rlength, (char *) reply);
- free(reply);
- return Success;
-}
-
-static int
-ProcRenderQueryPictIndexValues (ClientPtr client)
-{
- PictFormatPtr pFormat;
- int rc, num;
- int rlength;
- int i, n;
- REQUEST(xRenderQueryPictIndexValuesReq);
- xRenderQueryPictIndexValuesReply *reply;
- xIndexValue *values;
-
- REQUEST_AT_LEAST_SIZE(xRenderQueryPictIndexValuesReq);
-
- rc = dixLookupResourceByType((pointer *)&pFormat, stuff->format,
- PictFormatType, client, DixReadAccess);
- if (rc != Success)
- return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc;
-
- if (pFormat->type != PictTypeIndexed)
- {
- client->errorValue = stuff->format;
- return BadMatch;
- }
- num = pFormat->index.nvalues;
- rlength = (sizeof (xRenderQueryPictIndexValuesReply) +
- num * sizeof(xIndexValue));
- reply = (xRenderQueryPictIndexValuesReply *) malloc(rlength);
- if (!reply)
- return BadAlloc;
-
- reply->type = X_Reply;
- reply->sequenceNumber = client->sequence;
- reply->length = bytes_to_int32(rlength - sizeof(xGenericReply));
- reply->numIndexValues = num;
-
- values = (xIndexValue *) (reply + 1);
-
- memcpy (reply + 1, pFormat->index.pValues, num * sizeof (xIndexValue));
-
- if (client->swapped)
- {
- for (i = 0; i < num; i++)
- {
- swapl (&values[i].pixel, n);
- swaps (&values[i].red, n);
- swaps (&values[i].green, n);
- swaps (&values[i].blue, n);
- swaps (&values[i].alpha, n);
- }
- swaps (&reply->sequenceNumber, n);
- swapl (&reply->length, n);
- swapl (&reply->numIndexValues, n);
- }
-
- WriteToClient(client, rlength, (char *) reply);
- free(reply);
- return Success;
-}
-
-static int
-ProcRenderQueryDithers (ClientPtr client)
-{
- return BadImplementation;
-}
-
-static int
-ProcRenderCreatePicture (ClientPtr client)
-{
- PicturePtr pPicture;
- DrawablePtr pDrawable;
- PictFormatPtr pFormat;
- int len, error, rc;
- REQUEST(xRenderCreatePictureReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderCreatePictureReq);
-
- LEGAL_NEW_RESOURCE(stuff->pid, client);
- rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
- DixReadAccess|DixAddAccess);
- if (rc != Success)
- return rc;
-
- rc = dixLookupResourceByType((pointer *)&pFormat, stuff->format,
- PictFormatType, client, DixReadAccess);
- if (rc != Success)
- return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc;
-
- if (pFormat->depth != pDrawable->depth)
- return BadMatch;
- len = client->req_len - bytes_to_int32(sizeof(xRenderCreatePictureReq));
- if (Ones(stuff->mask) != len)
- return BadLength;
-
- pPicture = CreatePicture (stuff->pid,
- pDrawable,
- pFormat,
- stuff->mask,
- (XID *) (stuff + 1),
- client,
- &error);
- if (!pPicture)
- return error;
- if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
- return BadAlloc;
- return Success;
-}
-
-static int
-ProcRenderChangePicture (ClientPtr client)
-{
- PicturePtr pPicture;
- REQUEST(xRenderChangePictureReq);
- int len;
-
- REQUEST_AT_LEAST_SIZE(xRenderChangePictureReq);
- VERIFY_PICTURE (pPicture, stuff->picture, client, DixSetAttrAccess);
-
- len = client->req_len - bytes_to_int32(sizeof(xRenderChangePictureReq));
- if (Ones(stuff->mask) != len)
- return BadLength;
-
- return ChangePicture (pPicture, stuff->mask, (XID *) (stuff + 1),
- (DevUnion *) 0, client);
-}
-
-static int
-ProcRenderSetPictureClipRectangles (ClientPtr client)
-{
- REQUEST(xRenderSetPictureClipRectanglesReq);
- PicturePtr pPicture;
- int nr;
-
- REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq);
- VERIFY_PICTURE (pPicture, stuff->picture, client, DixSetAttrAccess);
- if (!pPicture->pDrawable)
- return BadDrawable;
-
- nr = (client->req_len << 2) - sizeof(xRenderSetPictureClipRectanglesReq);
- if (nr & 4)
- return BadLength;
- nr >>= 3;
- return SetPictureClipRects (pPicture,
- stuff->xOrigin, stuff->yOrigin,
- nr, (xRectangle *) &stuff[1]);
-}
-
-static int
-ProcRenderFreePicture (ClientPtr client)
-{
- PicturePtr pPicture;
- REQUEST(xRenderFreePictureReq);
-
- REQUEST_SIZE_MATCH(xRenderFreePictureReq);
-
- VERIFY_PICTURE (pPicture, stuff->picture, client, DixDestroyAccess);
- FreeResource (stuff->picture, RT_NONE);
- return Success;
-}
-
-static Bool
-PictOpValid (CARD8 op)
-{
- if (/*PictOpMinimum <= op && */ op <= PictOpMaximum)
- return TRUE;
- if (PictOpDisjointMinimum <= op && op <= PictOpDisjointMaximum)
- return TRUE;
- if (PictOpConjointMinimum <= op && op <= PictOpConjointMaximum)
- return TRUE;
- if (PictOpBlendMinimum <= op && op <= PictOpBlendMaximum)
- return TRUE;
- return FALSE;
-}
-
-static int
-ProcRenderComposite (ClientPtr client)
-{
- PicturePtr pSrc, pMask, pDst;
- REQUEST(xRenderCompositeReq);
-
- REQUEST_SIZE_MATCH(xRenderCompositeReq);
- if (!PictOpValid (stuff->op))
- {
- client->errorValue = stuff->op;
- return BadValue;
- }
- VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess);
- if (!pDst->pDrawable)
- return BadDrawable;
- VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess);
- VERIFY_ALPHA (pMask, stuff->mask, client, DixReadAccess);
- if ((pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) ||
- (pMask && pMask->pDrawable && pDst->pDrawable->pScreen != pMask->pDrawable->pScreen))
- return BadMatch;
- CompositePicture (stuff->op,
- pSrc,
- pMask,
- pDst,
- stuff->xSrc,
- stuff->ySrc,
- stuff->xMask,
- stuff->yMask,
- stuff->xDst,
- stuff->yDst,
- stuff->width,
- stuff->height);
- return Success;
-}
-
-static int
-ProcRenderScale (ClientPtr client)
-{
- return BadImplementation;
-}
-
-static int
-ProcRenderTrapezoids (ClientPtr client)
-{
- int rc, ntraps;
- PicturePtr pSrc, pDst;
- PictFormatPtr pFormat;
- REQUEST(xRenderTrapezoidsReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq);
- if (!PictOpValid (stuff->op))
- {
- client->errorValue = stuff->op;
- return BadValue;
- }
- VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess);
- VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess);
- if (!pDst->pDrawable)
- return BadDrawable;
- if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen)
- return BadMatch;
- if (stuff->maskFormat)
- {
- rc = dixLookupResourceByType((pointer *)&pFormat, stuff->maskFormat,
- PictFormatType, client, DixReadAccess);
- if (rc != Success)
- return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc;
- }
- else
- pFormat = 0;
- ntraps = (client->req_len << 2) - sizeof (xRenderTrapezoidsReq);
- if (ntraps % sizeof (xTrapezoid))
- return BadLength;
- ntraps /= sizeof (xTrapezoid);
- if (ntraps)
- CompositeTrapezoids (stuff->op, pSrc, pDst, pFormat,
- stuff->xSrc, stuff->ySrc,
- ntraps, (xTrapezoid *) &stuff[1]);
- return Success;
-}
-
-static int
-ProcRenderTriangles (ClientPtr client)
-{
- int rc, ntris;
- PicturePtr pSrc, pDst;
- PictFormatPtr pFormat;
- REQUEST(xRenderTrianglesReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq);
- if (!PictOpValid (stuff->op))
- {
- client->errorValue = stuff->op;
- return BadValue;
- }
- VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess);
- VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess);
- if (!pDst->pDrawable)
- return BadDrawable;
- if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen)
- return BadMatch;
- if (stuff->maskFormat)
- {
- rc = dixLookupResourceByType((pointer *)&pFormat, stuff->maskFormat,
- PictFormatType, client, DixReadAccess);
- if (rc != Success)
- return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc;
- }
- else
- pFormat = 0;
- ntris = (client->req_len << 2) - sizeof (xRenderTrianglesReq);
- if (ntris % sizeof (xTriangle))
- return BadLength;
- ntris /= sizeof (xTriangle);
- if (ntris)
- CompositeTriangles (stuff->op, pSrc, pDst, pFormat,
- stuff->xSrc, stuff->ySrc,
- ntris, (xTriangle *) &stuff[1]);
- return Success;
-}
-
-static int
-ProcRenderTriStrip (ClientPtr client)
-{
- int rc, npoints;
- PicturePtr pSrc, pDst;
- PictFormatPtr pFormat;
- REQUEST(xRenderTrianglesReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq);
- if (!PictOpValid (stuff->op))
- {
- client->errorValue = stuff->op;
- return BadValue;
- }
- VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess);
- VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess);
- if (!pDst->pDrawable)
- return BadDrawable;
- if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen)
- return BadMatch;
- if (stuff->maskFormat)
- {
- rc = dixLookupResourceByType((pointer *)&pFormat, stuff->maskFormat,
- PictFormatType, client, DixReadAccess);
- if (rc != Success)
- return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc;
- }
- else
- pFormat = 0;
- npoints = ((client->req_len << 2) - sizeof (xRenderTriStripReq));
- if (npoints & 4)
- return(BadLength);
- npoints >>= 3;
- if (npoints >= 3)
- CompositeTriStrip (stuff->op, pSrc, pDst, pFormat,
- stuff->xSrc, stuff->ySrc,
- npoints, (xPointFixed *) &stuff[1]);
- return Success;
-}
-
-static int
-ProcRenderTriFan (ClientPtr client)
-{
- int rc, npoints;
- PicturePtr pSrc, pDst;
- PictFormatPtr pFormat;
- REQUEST(xRenderTrianglesReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq);
- if (!PictOpValid (stuff->op))
- {
- client->errorValue = stuff->op;
- return BadValue;
- }
- VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess);
- VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess);
- if (!pDst->pDrawable)
- return BadDrawable;
- if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen)
- return BadMatch;
- if (stuff->maskFormat)
- {
- rc = dixLookupResourceByType((pointer *)&pFormat, stuff->maskFormat,
- PictFormatType, client, DixReadAccess);
- if (rc != Success)
- return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc;
- }
- else
- pFormat = 0;
- npoints = ((client->req_len << 2) - sizeof (xRenderTriStripReq));
- if (npoints & 4)
- return(BadLength);
- npoints >>= 3;
- if (npoints >= 3)
- CompositeTriFan (stuff->op, pSrc, pDst, pFormat,
- stuff->xSrc, stuff->ySrc,
- npoints, (xPointFixed *) &stuff[1]);
- return Success;
-}
-
-static int
-ProcRenderColorTrapezoids (ClientPtr client)
-{
- return BadImplementation;
-}
-
-static int
-ProcRenderColorTriangles (ClientPtr client)
-{
- return BadImplementation;
-}
-
-static int
-ProcRenderTransform (ClientPtr client)
-{
- return BadImplementation;
-}
-
-static int
-ProcRenderCreateGlyphSet (ClientPtr client)
-{
- GlyphSetPtr glyphSet;
- PictFormatPtr format;
- int rc, f;
- REQUEST(xRenderCreateGlyphSetReq);
-
- REQUEST_SIZE_MATCH(xRenderCreateGlyphSetReq);
-
- LEGAL_NEW_RESOURCE(stuff->gsid, client);
- rc = dixLookupResourceByType((pointer *)&format, stuff->format,
- PictFormatType, client, DixReadAccess);
- if (rc != Success)
- return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc;
-
- switch (format->depth) {
- case 1:
- f = GlyphFormat1;
- break;
- case 4:
- f = GlyphFormat4;
- break;
- case 8:
- f = GlyphFormat8;
- break;
- case 16:
- f = GlyphFormat16;
- break;
- case 32:
- f = GlyphFormat32;
- break;
- default:
- return BadMatch;
- }
- if (format->type != PictTypeDirect)
- return BadMatch;
- glyphSet = AllocateGlyphSet (f, format);
- if (!glyphSet)
- return BadAlloc;
- /* security creation/labeling check */
- rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->gsid, GlyphSetType,
- glyphSet, RT_NONE, NULL, DixCreateAccess);
- if (rc != Success)
- return rc;
- if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet))
- return BadAlloc;
- return Success;
-}
-
-static int
-ProcRenderReferenceGlyphSet (ClientPtr client)
-{
- GlyphSetPtr glyphSet;
- int rc;
- REQUEST(xRenderReferenceGlyphSetReq);
-
- REQUEST_SIZE_MATCH(xRenderReferenceGlyphSetReq);
-
- LEGAL_NEW_RESOURCE(stuff->gsid, client);
-
- rc = dixLookupResourceByType((pointer *)&glyphSet, stuff->existing, GlyphSetType,
- client, DixGetAttrAccess);
- if (rc != Success)
- {
- client->errorValue = stuff->existing;
- return (rc == BadValue) ? RenderErrBase + BadGlyphSet : rc;
- }
- glyphSet->refcnt++;
- if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet))
- return BadAlloc;
- return Success;
-}
-
-#define NLOCALDELTA 64
-#define NLOCALGLYPH 256
-
-static int
-ProcRenderFreeGlyphSet (ClientPtr client)
-{
- GlyphSetPtr glyphSet;
- int rc;
- REQUEST(xRenderFreeGlyphSetReq);
-
- REQUEST_SIZE_MATCH(xRenderFreeGlyphSetReq);
- rc = dixLookupResourceByType((pointer *)&glyphSet, stuff->glyphset, GlyphSetType,
- client, DixDestroyAccess);
- if (rc != Success)
- {
- client->errorValue = stuff->glyphset;
- return (rc == BadValue) ? RenderErrBase + BadGlyphSet : rc;
- }
- FreeResource (stuff->glyphset, RT_NONE);
- return Success;
-}
-
-typedef struct _GlyphNew {
- Glyph id;
- GlyphPtr glyph;
- Bool found;
- unsigned char sha1[20];
-} GlyphNewRec, *GlyphNewPtr;
-
-#define NeedsComponent(f) (PICT_FORMAT_A(f) != 0 && PICT_FORMAT_RGB(f) != 0)
-
-static int
-ProcRenderAddGlyphs (ClientPtr client)
-{
- GlyphSetPtr glyphSet;
- REQUEST(xRenderAddGlyphsReq);
- GlyphNewRec glyphsLocal[NLOCALGLYPH];
- GlyphNewPtr glyphsBase, glyphs, glyph_new;
- int remain, nglyphs;
- CARD32 *gids;
- xGlyphInfo *gi;
- CARD8 *bits;
- unsigned int size;
- int err;
- int i, screen;
- PicturePtr pSrc = NULL, pDst = NULL;
- PixmapPtr pSrcPix = NULL, pDstPix = NULL;
- CARD32 component_alpha;
-
- REQUEST_AT_LEAST_SIZE(xRenderAddGlyphsReq);
- err = dixLookupResourceByType((pointer *)&glyphSet, stuff->glyphset, GlyphSetType,
- client, DixAddAccess);
- if (err != Success)
- {
- client->errorValue = stuff->glyphset;
- return (err == BadValue) ? RenderErrBase + BadGlyphSet : err;
- }
-
- err = BadAlloc;
- nglyphs = stuff->nglyphs;
- if (nglyphs > UINT32_MAX / sizeof(GlyphNewRec))
- return BadAlloc;
-
- component_alpha = NeedsComponent (glyphSet->format->format);
-
- if (nglyphs <= NLOCALGLYPH) {
- memset (glyphsLocal, 0, sizeof (glyphsLocal));
- glyphsBase = glyphsLocal;
- }
- else
- {
- glyphsBase = (GlyphNewPtr)calloc(nglyphs, sizeof (GlyphNewRec));
- if (!glyphsBase)
- return BadAlloc;
- }
-
- remain = (client->req_len << 2) - sizeof (xRenderAddGlyphsReq);
-
- glyphs = glyphsBase;
-
- gids = (CARD32 *) (stuff + 1);
- gi = (xGlyphInfo *) (gids + nglyphs);
- bits = (CARD8 *) (gi + nglyphs);
- remain -= (sizeof (CARD32) + sizeof (xGlyphInfo)) * nglyphs;
- for (i = 0; i < nglyphs; i++)
- {
- size_t padded_width;
- glyph_new = &glyphs[i];
-
- padded_width = PixmapBytePad (gi[i].width,
- glyphSet->format->depth);
-
- if (gi[i].height && padded_width > (UINT32_MAX - sizeof(GlyphRec))/gi[i].height)
- break;
-
- size = gi[i].height * padded_width;
- if (remain < size)
- break;
-
- err = HashGlyph (&gi[i], bits, size, glyph_new->sha1);
- if (err)
- goto bail;
-
- glyph_new->glyph = FindGlyphByHash (glyph_new->sha1,
- glyphSet->fdepth);
-
- if (glyph_new->glyph && glyph_new->glyph != DeletedGlyph)
- {
- glyph_new->found = TRUE;
- }
- else
- {
- GlyphPtr glyph;
-
- glyph_new->found = FALSE;
- glyph_new->glyph = glyph = AllocateGlyph (&gi[i], glyphSet->fdepth);
- if (! glyph)
- {
- err = BadAlloc;
- goto bail;
- }
-
- for (screen = 0; screen < screenInfo.numScreens; screen++)
- {
- int width = gi[i].width;
- int height = gi[i].height;
- int depth = glyphSet->format->depth;
- ScreenPtr pScreen;
- int error;
-
- /* Skip work if it's invisibly small anyway */
- if (!width || !height)
- break;
-
- pScreen = screenInfo.screens[screen];
- pSrcPix = GetScratchPixmapHeader (pScreen,
- width, height,
- depth, depth,
- -1, bits);
- if (! pSrcPix)
- {
- err = BadAlloc;
- goto bail;
- }
-
- pSrc = CreatePicture (0, &pSrcPix->drawable,
- glyphSet->format, 0, NULL,
- serverClient, &error);
- if (! pSrc)
- {
- err = BadAlloc;
- goto bail;
- }
-
- pDstPix = (pScreen->CreatePixmap) (pScreen,
- width, height, depth,
- CREATE_PIXMAP_USAGE_GLYPH_PICTURE);
-
- GlyphPicture (glyph)[screen] = pDst =
- CreatePicture (0, &pDstPix->drawable,
- glyphSet->format,
- CPComponentAlpha, &component_alpha,
- serverClient, &error);
-
- /* The picture takes a reference to the pixmap, so we
- drop ours. */
- (pScreen->DestroyPixmap) (pDstPix);
-
- if (! pDst)
- {
- err = BadAlloc;
- goto bail;
- }
-
- CompositePicture (PictOpSrc,
- pSrc,
- None,
- pDst,
- 0, 0,
- 0, 0,
- 0, 0,
- width, height);
-
- FreePicture ((pointer) pSrc, 0);
- pSrc = NULL;
- FreeScratchPixmapHeader (pSrcPix);
- pSrcPix = NULL;
- }
-
- memcpy (glyph_new->glyph->sha1, glyph_new->sha1, 20);
- }
-
- glyph_new->id = gids[i];
-
- if (size & 3)
- size += 4 - (size & 3);
- bits += size;
- remain -= size;
- }
- if (remain || i < nglyphs)
- {
- err = BadLength;
- goto bail;
- }
- if (!ResizeGlyphSet (glyphSet, nglyphs))
- {
- err = BadAlloc;
- goto bail;
- }
- for (i = 0; i < nglyphs; i++)
- AddGlyph (glyphSet, glyphs[i].glyph, glyphs[i].id);
-
- if (glyphsBase != glyphsLocal)
- free(glyphsBase);
- return Success;
-bail:
- if (pSrc)
- FreePicture ((pointer) pSrc, 0);
- if (pSrcPix)
- FreeScratchPixmapHeader (pSrcPix);
- for (i = 0; i < nglyphs; i++)
- if (glyphs[i].glyph && ! glyphs[i].found)
- free(glyphs[i].glyph);
- if (glyphsBase != glyphsLocal)
- free(glyphsBase);
- return err;
-}
-
-static int
-ProcRenderAddGlyphsFromPicture (ClientPtr client)
-{
- return BadImplementation;
-}
-
-static int
-ProcRenderFreeGlyphs (ClientPtr client)
-{
- REQUEST(xRenderFreeGlyphsReq);
- GlyphSetPtr glyphSet;
- int rc, nglyph;
- CARD32 *gids;
- CARD32 glyph;
-
- REQUEST_AT_LEAST_SIZE(xRenderFreeGlyphsReq);
- rc = dixLookupResourceByType((pointer *)&glyphSet, stuff->glyphset, GlyphSetType,
- client, DixRemoveAccess);
- if (rc != Success)
- {
- client->errorValue = stuff->glyphset;
- return (rc == BadValue) ? RenderErrBase + BadGlyphSet : rc;
- }
- nglyph = bytes_to_int32((client->req_len << 2) - sizeof (xRenderFreeGlyphsReq));
- gids = (CARD32 *) (stuff + 1);
- while (nglyph-- > 0)
- {
- glyph = *gids++;
- if (!DeleteGlyph (glyphSet, glyph))
- {
- client->errorValue = glyph;
- return RenderErrBase + BadGlyph;
- }
- }
- return Success;
-}
-
-static int
-ProcRenderCompositeGlyphs (ClientPtr client)
-{
- GlyphSetPtr glyphSet;
- GlyphSet gs;
- PicturePtr pSrc, pDst;
- PictFormatPtr pFormat;
- GlyphListRec listsLocal[NLOCALDELTA];
- GlyphListPtr lists, listsBase;
- GlyphPtr glyphsLocal[NLOCALGLYPH];
- Glyph glyph;
- GlyphPtr *glyphs, *glyphsBase;
- xGlyphElt *elt;
- CARD8 *buffer, *end;
- int nglyph;
- int nlist;
- int space;
- int size;
- int rc, n;
-
- REQUEST(xRenderCompositeGlyphsReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderCompositeGlyphsReq);
-
- switch (stuff->renderReqType) {
- default: size = 1; break;
- case X_RenderCompositeGlyphs16: size = 2; break;
- case X_RenderCompositeGlyphs32: size = 4; break;
- }
-
- if (!PictOpValid (stuff->op))
- {
- client->errorValue = stuff->op;
- return BadValue;
- }
- VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess);
- VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess);
- if (!pDst->pDrawable)
- return BadDrawable;
- if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen)
- return BadMatch;
- if (stuff->maskFormat)
- {
- rc = dixLookupResourceByType((pointer *)&pFormat, stuff->maskFormat,
- PictFormatType, client, DixReadAccess);
- if (rc != Success)
- return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc;
- }
- else
- pFormat = 0;
-
- rc = dixLookupResourceByType((pointer *)&glyphSet, stuff->glyphset,
- GlyphSetType, client, DixUseAccess);
- if (rc != Success)
- return (rc == BadValue) ? RenderErrBase + BadGlyphSet : rc;
-
- buffer = (CARD8 *) (stuff + 1);
- end = (CARD8 *) stuff + (client->req_len << 2);
- nglyph = 0;
- nlist = 0;
- while (buffer + sizeof (xGlyphElt) < end)
- {
- elt = (xGlyphElt *) buffer;
- buffer += sizeof (xGlyphElt);
-
- if (elt->len == 0xff)
- {
- buffer += 4;
- }
- else
- {
- nlist++;
- nglyph += elt->len;
- space = size * elt->len;
- if (space & 3)
- space += 4 - (space & 3);
- buffer += space;
- }
- }
- if (nglyph <= NLOCALGLYPH)
- glyphsBase = glyphsLocal;
- else
- {
- glyphsBase = (GlyphPtr *) malloc(nglyph * sizeof (GlyphPtr));
- if (!glyphsBase)
- return BadAlloc;
- }
- if (nlist <= NLOCALDELTA)
- listsBase = listsLocal;
- else
- {
- listsBase = (GlyphListPtr) malloc(nlist * sizeof (GlyphListRec));
- if (!listsBase)
- return BadAlloc;
- }
- buffer = (CARD8 *) (stuff + 1);
- glyphs = glyphsBase;
- lists = listsBase;
- while (buffer + sizeof (xGlyphElt) < end)
- {
- elt = (xGlyphElt *) buffer;
- buffer += sizeof (xGlyphElt);
-
- if (elt->len == 0xff)
- {
- if (buffer + sizeof (GlyphSet) < end)
- {
- memcpy(&gs, buffer, sizeof(GlyphSet));
- rc = dixLookupResourceByType((pointer *)&glyphSet, gs,
- GlyphSetType, client,
- DixUseAccess);
- if (rc != Success)
- {
- if (glyphsBase != glyphsLocal)
- free(glyphsBase);
- if (listsBase != listsLocal)
- free(listsBase);
- return (rc == BadValue) ? RenderErrBase + BadGlyphSet : rc;
- }
- }
- buffer += 4;
- }
- else
- {
- lists->xOff = elt->deltax;
- lists->yOff = elt->deltay;
- lists->format = glyphSet->format;
- lists->len = 0;
- n = elt->len;
- while (n--)
- {
- if (buffer + size <= end)
- {
- switch (size) {
- case 1:
- glyph = *((CARD8 *)buffer); break;
- case 2:
- glyph = *((CARD16 *)buffer); break;
- case 4:
- default:
- glyph = *((CARD32 *)buffer); break;
- }
- if ((*glyphs = FindGlyph (glyphSet, glyph)))
- {
- lists->len++;
- glyphs++;
- }
- }
- buffer += size;
- }
- space = size * elt->len;
- if (space & 3)
- buffer += 4 - (space & 3);
- lists++;
- }
- }
- if (buffer > end)
- return BadLength;
-
- CompositeGlyphs (stuff->op,
- pSrc,
- pDst,
- pFormat,
- stuff->xSrc,
- stuff->ySrc,
- nlist,
- listsBase,
- glyphsBase);
-
- if (glyphsBase != glyphsLocal)
- free(glyphsBase);
- if (listsBase != listsLocal)
- free(listsBase);
-
- return Success;
-}
-
-static int
-ProcRenderFillRectangles (ClientPtr client)
-{
- PicturePtr pDst;
- int things;
- REQUEST(xRenderFillRectanglesReq);
-
- REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq);
- if (!PictOpValid (stuff->op))
- {
- client->errorValue = stuff->op;
- return BadValue;
- }
- VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess);
- if (!pDst->pDrawable)
- return BadDrawable;
-
- things = (client->req_len << 2) - sizeof(xRenderFillRectanglesReq);
- if (things & 4)
- return(BadLength);
- things >>= 3;
-
- CompositeRects (stuff->op,
- pDst,
- &stuff->color,
- things,
- (xRectangle *) &stuff[1]);
-
- return Success;
-}
-
-static void
-RenderSetBit (unsigned char *line, int x, int bit)
-{
- unsigned char mask;
-
- if (screenInfo.bitmapBitOrder == LSBFirst)
- mask = (1 << (x & 7));
- else
- mask = (0x80 >> (x & 7));
- /* XXX assumes byte order is host byte order */
- line += (x >> 3);
- if (bit)
- *line |= mask;
- else
- *line &= ~mask;
-}
-
-#define DITHER_DIM 2
-
-static CARD32 orderedDither[DITHER_DIM][DITHER_DIM] = {
- { 1, 3, },
- { 4, 2, },
-};
-
-#define DITHER_SIZE ((sizeof orderedDither / sizeof orderedDither[0][0]) + 1)
-
-static int
-ProcRenderCreateCursor (ClientPtr client)
-{
- REQUEST(xRenderCreateCursorReq);
- PicturePtr pSrc;
- ScreenPtr pScreen;
- unsigned short width, height;
- CARD32 *argbbits, *argb;
- unsigned char *srcbits, *srcline;
- unsigned char *mskbits, *mskline;
- int stride;
- int x, y;
- int nbytes_mono;
- CursorMetricRec cm;
- CursorPtr pCursor;
- CARD32 twocolor[3];
- int rc, ncolor;
-
- REQUEST_SIZE_MATCH (xRenderCreateCursorReq);
- LEGAL_NEW_RESOURCE(stuff->cid, client);
-
- VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess);
- if (!pSrc->pDrawable)
- return BadDrawable;
- pScreen = pSrc->pDrawable->pScreen;
- width = pSrc->pDrawable->width;
- height = pSrc->pDrawable->height;
- if (height && width > UINT32_MAX/(height*sizeof(CARD32)))
- return BadAlloc;
- if ( stuff->x > width
- || stuff->y > height )
- return (BadMatch);
- argbbits = malloc(width * height * sizeof (CARD32));
- if (!argbbits)
- return (BadAlloc);
-
- stride = BitmapBytePad(width);
- nbytes_mono = stride*height;
- srcbits = calloc(1, nbytes_mono);
- if (!srcbits)
- {
- free(argbbits);
- return (BadAlloc);
- }
- mskbits = calloc(1, nbytes_mono);
- if (!mskbits)
- {
- free(argbbits);
- free(srcbits);
- return (BadAlloc);
- }
-
- if (pSrc->format == PICT_a8r8g8b8)
- {
- (*pScreen->GetImage) (pSrc->pDrawable,
- 0, 0, width, height, ZPixmap,
- 0xffffffff, (pointer) argbbits);
- }
- else
- {
- PixmapPtr pPixmap;
- PicturePtr pPicture;
- PictFormatPtr pFormat;
- int error;
-
- pFormat = PictureMatchFormat (pScreen, 32, PICT_a8r8g8b8);
- if (!pFormat)
- {
- free(argbbits);
- free(srcbits);
- free(mskbits);
- return (BadImplementation);
- }
- pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, 32,
- CREATE_PIXMAP_USAGE_SCRATCH);
- if (!pPixmap)
- {
- free(argbbits);
- free(srcbits);
- free(mskbits);
- return (BadAlloc);
- }
- pPicture = CreatePicture (0, &pPixmap->drawable, pFormat, 0, 0,
- client, &error);
- if (!pPicture)
- {
- free(argbbits);
- free(srcbits);
- free(mskbits);
- return error;
- }
- (*pScreen->DestroyPixmap) (pPixmap);
- CompositePicture (PictOpSrc,
- pSrc, 0, pPicture,
- 0, 0, 0, 0, 0, 0, width, height);
- (*pScreen->GetImage) (pPicture->pDrawable,
- 0, 0, width, height, ZPixmap,
- 0xffffffff, (pointer) argbbits);
- FreePicture (pPicture, 0);
- }
- /*
- * Check whether the cursor can be directly supported by
- * the core cursor code
- */
- ncolor = 0;
- argb = argbbits;
- for (y = 0; ncolor <= 2 && y < height; y++)
- {
- for (x = 0; ncolor <= 2 && x < width; x++)
- {
- CARD32 p = *argb++;
- CARD32 a = (p >> 24);
-
- if (a == 0) /* transparent */
- continue;
- if (a == 0xff) /* opaque */
- {
- int n;
- for (n = 0; n < ncolor; n++)
- if (p == twocolor[n])
- break;
- if (n == ncolor)
- twocolor[ncolor++] = p;
- }
- else
- ncolor = 3;
- }
- }
-
- /*
- * Convert argb image to two plane cursor
- */
- srcline = srcbits;
- mskline = mskbits;
- argb = argbbits;
- for (y = 0; y < height; y++)
- {
- for (x = 0; x < width; x++)
- {
- CARD32 p = *argb++;
-
- if (ncolor <= 2)
- {
- CARD32 a = ((p >> 24));
-
- RenderSetBit (mskline, x, a != 0);
- RenderSetBit (srcline, x, a != 0 && p == twocolor[0]);
- }
- else
- {
- CARD32 a = ((p >> 24) * DITHER_SIZE + 127) / 255;
- CARD32 i = ((CvtR8G8B8toY15(p) >> 7) * DITHER_SIZE + 127) / 255;
- CARD32 d = orderedDither[y&(DITHER_DIM-1)][x&(DITHER_DIM-1)];
- /* Set mask from dithered alpha value */
- RenderSetBit(mskline, x, a > d);
- /* Set src from dithered intensity value */
- RenderSetBit(srcline, x, a > d && i <= d);
- }
- }
- srcline += stride;
- mskline += stride;
- }
- /*
- * Dither to white and black if the cursor has more than two colors
- */
- if (ncolor > 2)
- {
- twocolor[0] = 0xff000000;
- twocolor[1] = 0xffffffff;
- }
- else
- {
- free(argbbits);
- argbbits = 0;
- }
-
-#define GetByte(p,s) (((p) >> (s)) & 0xff)
-#define GetColor(p,s) (GetByte(p,s) | (GetByte(p,s) << 8))
-
- cm.width = width;
- cm.height = height;
- cm.xhot = stuff->x;
- cm.yhot = stuff->y;
- rc = AllocARGBCursor(srcbits, mskbits, argbbits, &cm,
- GetColor(twocolor[0], 16),
- GetColor(twocolor[0], 8),
- GetColor(twocolor[0], 0),
- GetColor(twocolor[1], 16),
- GetColor(twocolor[1], 8),
- GetColor(twocolor[1], 0),
- &pCursor, client, stuff->cid);
- if (rc != Success)
- return rc;
- if (!AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor))
- return BadAlloc;
-
- return Success;
-}
-
-static int
-ProcRenderSetPictureTransform (ClientPtr client)
-{
- REQUEST(xRenderSetPictureTransformReq);
- PicturePtr pPicture;
-
- REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq);
- VERIFY_PICTURE (pPicture, stuff->picture, client, DixSetAttrAccess);
- return SetPictureTransform (pPicture, (PictTransform *) &stuff->transform);
-}
-
-static int
-ProcRenderQueryFilters (ClientPtr client)
-{
- REQUEST (xRenderQueryFiltersReq);
- DrawablePtr pDrawable;
- xRenderQueryFiltersReply *reply;
- int nbytesName;
- int nnames;
- ScreenPtr pScreen;
- PictureScreenPtr ps;
- int i, j, len, total_bytes, rc;
- INT16 *aliases;
- char *names;
-
- REQUEST_SIZE_MATCH(xRenderQueryFiltersReq);
- rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0,
- DixGetAttrAccess);
- if (rc != Success)
- return rc;
-
- pScreen = pDrawable->pScreen;
- nbytesName = 0;
- nnames = 0;
- ps = GetPictureScreenIfSet(pScreen);
- if (ps)
- {
- for (i = 0; i < ps->nfilters; i++)
- nbytesName += 1 + strlen (ps->filters[i].name);
- for (i = 0; i < ps->nfilterAliases; i++)
- nbytesName += 1 + strlen (ps->filterAliases[i].alias);
- nnames = ps->nfilters + ps->nfilterAliases;
- }
- len = ((nnames + 1) >> 1) + bytes_to_int32(nbytesName);
- total_bytes = sizeof (xRenderQueryFiltersReply) + (len << 2);
- reply = (xRenderQueryFiltersReply *) malloc(total_bytes);
- if (!reply)
- return BadAlloc;
- aliases = (INT16 *) (reply + 1);
- names = (char *) (aliases + ((nnames + 1) & ~1));
-
- reply->type = X_Reply;
- reply->sequenceNumber = client->sequence;
- reply->length = len;
- reply->numAliases = nnames;
- reply->numFilters = nnames;
- if (ps)
- {
-
- /* fill in alias values */
- for (i = 0; i < ps->nfilters; i++)
- aliases[i] = FilterAliasNone;
- for (i = 0; i < ps->nfilterAliases; i++)
- {
- for (j = 0; j < ps->nfilters; j++)
- if (ps->filterAliases[i].filter_id == ps->filters[j].id)
- break;
- if (j == ps->nfilters)
- {
- for (j = 0; j < ps->nfilterAliases; j++)
- if (ps->filterAliases[i].filter_id ==
- ps->filterAliases[j].alias_id)
- {
- break;
- }
- if (j == ps->nfilterAliases)
- j = FilterAliasNone;
- else
- j = j + ps->nfilters;
- }
- aliases[i + ps->nfilters] = j;
- }
-
- /* fill in filter names */
- for (i = 0; i < ps->nfilters; i++)
- {
- j = strlen (ps->filters[i].name);
- *names++ = j;
- strncpy (names, ps->filters[i].name, j);
- names += j;
- }
-
- /* fill in filter alias names */
- for (i = 0; i < ps->nfilterAliases; i++)
- {
- j = strlen (ps->filterAliases[i].alias);
- *names++ = j;
- strncpy (names, ps->filterAliases[i].alias, j);
- names += j;
- }
- }
-
- if (client->swapped)
- {
- register int n;
-
- for (i = 0; i < reply->numAliases; i++)
- {
- swaps (&aliases[i], n);
- }
- swaps(&reply->sequenceNumber, n);
- swapl(&reply->length, n);
- swapl(&reply->numAliases, n);
- swapl(&reply->numFilters, n);
- }
- WriteToClient(client, total_bytes, (char *) reply);
- free(reply);
-
- return Success;
-}
-
-static int
-ProcRenderSetPictureFilter (ClientPtr client)
-{
- REQUEST (xRenderSetPictureFilterReq);
- PicturePtr pPicture;
- int result;
- xFixed *params;
- int nparams;
- char *name;
-
- REQUEST_AT_LEAST_SIZE (xRenderSetPictureFilterReq);
- VERIFY_PICTURE (pPicture, stuff->picture, client, DixSetAttrAccess);
- name = (char *) (stuff + 1);
- params = (xFixed *) (name + pad_to_int32(stuff->nbytes));
- nparams = ((xFixed *) stuff + client->req_len) - params;
- result = SetPictureFilter (pPicture, name, stuff->nbytes, params, nparams);
- return result;
-}
-
-static int
-ProcRenderCreateAnimCursor (ClientPtr client)
-{
- REQUEST(xRenderCreateAnimCursorReq);
- CursorPtr *cursors;
- CARD32 *deltas;
- CursorPtr pCursor;
- int ncursor;
- xAnimCursorElt *elt;
- int i;
- int ret;
-
- REQUEST_AT_LEAST_SIZE(xRenderCreateAnimCursorReq);
- LEGAL_NEW_RESOURCE(stuff->cid, client);
- if (client->req_len & 1)
- return BadLength;
- ncursor = (client->req_len - (bytes_to_int32(sizeof(xRenderCreateAnimCursorReq)))) >> 1;
- cursors = malloc(ncursor * (sizeof (CursorPtr) + sizeof (CARD32)));
- if (!cursors)
- return BadAlloc;
- deltas = (CARD32 *) (cursors + ncursor);
- elt = (xAnimCursorElt *) (stuff + 1);
- for (i = 0; i < ncursor; i++)
- {
- ret = dixLookupResourceByType((pointer *)(cursors + i), elt->cursor,
- RT_CURSOR, client, DixReadAccess);
- if (ret != Success)
- {
- free(cursors);
- return (ret == BadValue) ? BadCursor : ret;
- }
- deltas[i] = elt->delay;
- elt++;
- }
- ret = AnimCursorCreate (cursors, deltas, ncursor, &pCursor, client,
- stuff->cid);
- free(cursors);
- if (ret != Success)
- return ret;
-
- if (AddResource (stuff->cid, RT_CURSOR, (pointer)pCursor))
- return Success;
- return BadAlloc;
-}
-
-static int
-ProcRenderAddTraps (ClientPtr client)
-{
- int ntraps;
- PicturePtr pPicture;
- REQUEST(xRenderAddTrapsReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderAddTrapsReq);
- VERIFY_PICTURE (pPicture, stuff->picture, client, DixWriteAccess);
- if (!pPicture->pDrawable)
- return BadDrawable;
- ntraps = (client->req_len << 2) - sizeof (xRenderAddTrapsReq);
- if (ntraps % sizeof (xTrap))
- return BadLength;
- ntraps /= sizeof (xTrap);
- if (ntraps)
- AddTraps (pPicture,
- stuff->xOff, stuff->yOff,
- ntraps, (xTrap *) &stuff[1]);
- return Success;
-}
-
-static int ProcRenderCreateSolidFill(ClientPtr client)
-{
- PicturePtr pPicture;
- int error = 0;
- REQUEST(xRenderCreateSolidFillReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderCreateSolidFillReq);
-
- LEGAL_NEW_RESOURCE(stuff->pid, client);
-
- pPicture = CreateSolidPicture(stuff->pid, &stuff->color, &error);
- if (!pPicture)
- return error;
- /* security creation/labeling check */
- error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType,
- pPicture, RT_NONE, NULL, DixCreateAccess);
- if (error != Success)
- return error;
- if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
- return BadAlloc;
- return Success;
-}
-
-static int ProcRenderCreateLinearGradient (ClientPtr client)
-{
- PicturePtr pPicture;
- int len;
- int error = 0;
- xFixed *stops;
- xRenderColor *colors;
- REQUEST(xRenderCreateLinearGradientReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderCreateLinearGradientReq);
-
- LEGAL_NEW_RESOURCE(stuff->pid, client);
-
- len = (client->req_len << 2) - sizeof(xRenderCreateLinearGradientReq);
- if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor)))
- return BadLength;
- if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor)))
- return BadLength;
-
- stops = (xFixed *)(stuff + 1);
- colors = (xRenderColor *)(stops + stuff->nStops);
-
- pPicture = CreateLinearGradientPicture (stuff->pid, &stuff->p1, &stuff->p2,
- stuff->nStops, stops, colors, &error);
- if (!pPicture)
- return error;
- /* security creation/labeling check */
- error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType,
- pPicture, RT_NONE, NULL, DixCreateAccess);
- if (error != Success)
- return error;
- if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
- return BadAlloc;
- return Success;
-}
-
-static int ProcRenderCreateRadialGradient (ClientPtr client)
-{
- PicturePtr pPicture;
- int len;
- int error = 0;
- xFixed *stops;
- xRenderColor *colors;
- REQUEST(xRenderCreateRadialGradientReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderCreateRadialGradientReq);
-
- LEGAL_NEW_RESOURCE(stuff->pid, client);
-
- len = (client->req_len << 2) - sizeof(xRenderCreateRadialGradientReq);
- if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor)))
- return BadLength;
-
- stops = (xFixed *)(stuff + 1);
- colors = (xRenderColor *)(stops + stuff->nStops);
-
- pPicture = CreateRadialGradientPicture (stuff->pid, &stuff->inner, &stuff->outer,
- stuff->inner_radius, stuff->outer_radius,
- stuff->nStops, stops, colors, &error);
- if (!pPicture)
- return error;
- /* security creation/labeling check */
- error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType,
- pPicture, RT_NONE, NULL, DixCreateAccess);
- if (error != Success)
- return error;
- if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
- return BadAlloc;
- return Success;
-}
-
-static int ProcRenderCreateConicalGradient (ClientPtr client)
-{
- PicturePtr pPicture;
- int len;
- int error = 0;
- xFixed *stops;
- xRenderColor *colors;
- REQUEST(xRenderCreateConicalGradientReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderCreateConicalGradientReq);
-
- LEGAL_NEW_RESOURCE(stuff->pid, client);
-
- len = (client->req_len << 2) - sizeof(xRenderCreateConicalGradientReq);
- if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor)))
- return BadLength;
-
- stops = (xFixed *)(stuff + 1);
- colors = (xRenderColor *)(stops + stuff->nStops);
-
- pPicture = CreateConicalGradientPicture (stuff->pid, &stuff->center, stuff->angle,
- stuff->nStops, stops, colors, &error);
- if (!pPicture)
- return error;
- /* security creation/labeling check */
- error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType,
- pPicture, RT_NONE, NULL, DixCreateAccess);
- if (error != Success)
- return error;
- if (!AddResource (stuff->pid, PictureType, (pointer)pPicture))
- return BadAlloc;
- return Success;
-}
-
-
-static int
-ProcRenderDispatch (ClientPtr client)
-{
- REQUEST(xReq);
-
- if (stuff->data < RenderNumberRequests)
- return (*ProcRenderVector[stuff->data]) (client);
- else
- return BadRequest;
-}
-
-static int
-SProcRenderQueryVersion (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderQueryVersionReq);
-
- swaps(&stuff->length, n);
- swapl(&stuff->majorVersion, n);
- swapl(&stuff->minorVersion, n);
- return (*ProcRenderVector[stuff->renderReqType])(client);
-}
-
-static int
-SProcRenderQueryPictFormats (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderQueryPictFormatsReq);
- swaps(&stuff->length, n);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderQueryPictIndexValues (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderQueryPictIndexValuesReq);
- swaps(&stuff->length, n);
- swapl(&stuff->format, n);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderQueryDithers (ClientPtr client)
-{
- return BadImplementation;
-}
-
-static int
-SProcRenderCreatePicture (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderCreatePictureReq);
- swaps(&stuff->length, n);
- swapl(&stuff->pid, n);
- swapl(&stuff->drawable, n);
- swapl(&stuff->format, n);
- swapl(&stuff->mask, n);
- SwapRestL(stuff);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderChangePicture (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderChangePictureReq);
- swaps(&stuff->length, n);
- swapl(&stuff->picture, n);
- swapl(&stuff->mask, n);
- SwapRestL(stuff);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderSetPictureClipRectangles (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderSetPictureClipRectanglesReq);
- swaps(&stuff->length, n);
- swapl(&stuff->picture, n);
- swaps(&stuff->xOrigin, n);
- swaps(&stuff->yOrigin, n);
- SwapRestS(stuff);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderFreePicture (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderFreePictureReq);
- swaps(&stuff->length, n);
- swapl(&stuff->picture, n);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderComposite (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderCompositeReq);
- swaps(&stuff->length, n);
- swapl(&stuff->src, n);
- swapl(&stuff->mask, n);
- swapl(&stuff->dst, n);
- swaps(&stuff->xSrc, n);
- swaps(&stuff->ySrc, n);
- swaps(&stuff->xMask, n);
- swaps(&stuff->yMask, n);
- swaps(&stuff->xDst, n);
- swaps(&stuff->yDst, n);
- swaps(&stuff->width, n);
- swaps(&stuff->height, n);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderScale (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderScaleReq);
- swaps(&stuff->length, n);
- swapl(&stuff->src, n);
- swapl(&stuff->dst, n);
- swapl(&stuff->colorScale, n);
- swapl(&stuff->alphaScale, n);
- swaps(&stuff->xSrc, n);
- swaps(&stuff->ySrc, n);
- swaps(&stuff->xDst, n);
- swaps(&stuff->yDst, n);
- swaps(&stuff->width, n);
- swaps(&stuff->height, n);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderTrapezoids (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderTrapezoidsReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq);
- swaps (&stuff->length, n);
- swapl (&stuff->src, n);
- swapl (&stuff->dst, n);
- swapl (&stuff->maskFormat, n);
- swaps (&stuff->xSrc, n);
- swaps (&stuff->ySrc, n);
- SwapRestL(stuff);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderTriangles (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderTrianglesReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq);
- swaps (&stuff->length, n);
- swapl (&stuff->src, n);
- swapl (&stuff->dst, n);
- swapl (&stuff->maskFormat, n);
- swaps (&stuff->xSrc, n);
- swaps (&stuff->ySrc, n);
- SwapRestL(stuff);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderTriStrip (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderTriStripReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderTriStripReq);
- swaps (&stuff->length, n);
- swapl (&stuff->src, n);
- swapl (&stuff->dst, n);
- swapl (&stuff->maskFormat, n);
- swaps (&stuff->xSrc, n);
- swaps (&stuff->ySrc, n);
- SwapRestL(stuff);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderTriFan (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderTriFanReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderTriFanReq);
- swaps (&stuff->length, n);
- swapl (&stuff->src, n);
- swapl (&stuff->dst, n);
- swapl (&stuff->maskFormat, n);
- swaps (&stuff->xSrc, n);
- swaps (&stuff->ySrc, n);
- SwapRestL(stuff);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderColorTrapezoids (ClientPtr client)
-{
- return BadImplementation;
-}
-
-static int
-SProcRenderColorTriangles (ClientPtr client)
-{
- return BadImplementation;
-}
-
-static int
-SProcRenderTransform (ClientPtr client)
-{
- return BadImplementation;
-}
-
-static int
-SProcRenderCreateGlyphSet (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderCreateGlyphSetReq);
- swaps(&stuff->length, n);
- swapl(&stuff->gsid, n);
- swapl(&stuff->format, n);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderReferenceGlyphSet (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderReferenceGlyphSetReq);
- swaps(&stuff->length, n);
- swapl(&stuff->gsid, n);
- swapl(&stuff->existing, n);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderFreeGlyphSet (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderFreeGlyphSetReq);
- swaps(&stuff->length, n);
- swapl(&stuff->glyphset, n);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderAddGlyphs (ClientPtr client)
-{
- register int n;
- register int i;
- CARD32 *gids;
- void *end;
- xGlyphInfo *gi;
- REQUEST(xRenderAddGlyphsReq);
- swaps(&stuff->length, n);
- swapl(&stuff->glyphset, n);
- swapl(&stuff->nglyphs, n);
- if (stuff->nglyphs & 0xe0000000)
- return BadLength;
- end = (CARD8 *) stuff + (client->req_len << 2);
- gids = (CARD32 *) (stuff + 1);
- gi = (xGlyphInfo *) (gids + stuff->nglyphs);
- if ((char *) end - (char *) (gids + stuff->nglyphs) < 0)
- return BadLength;
- if ((char *) end - (char *) (gi + stuff->nglyphs) < 0)
- return BadLength;
- for (i = 0; i < stuff->nglyphs; i++)
- {
- swapl (&gids[i], n);
- swaps (&gi[i].width, n);
- swaps (&gi[i].height, n);
- swaps (&gi[i].x, n);
- swaps (&gi[i].y, n);
- swaps (&gi[i].xOff, n);
- swaps (&gi[i].yOff, n);
- }
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderAddGlyphsFromPicture (ClientPtr client)
-{
- return BadImplementation;
-}
-
-static int
-SProcRenderFreeGlyphs (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderFreeGlyphsReq);
- swaps(&stuff->length, n);
- swapl(&stuff->glyphset, n);
- SwapRestL(stuff);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderCompositeGlyphs (ClientPtr client)
-{
- register int n;
- xGlyphElt *elt;
- CARD8 *buffer;
- CARD8 *end;
- int space;
- int i;
- int size;
-
- REQUEST(xRenderCompositeGlyphsReq);
-
- switch (stuff->renderReqType) {
- default: size = 1; break;
- case X_RenderCompositeGlyphs16: size = 2; break;
- case X_RenderCompositeGlyphs32: size = 4; break;
- }
-
- swaps(&stuff->length, n);
- swapl(&stuff->src, n);
- swapl(&stuff->dst, n);
- swapl(&stuff->maskFormat, n);
- swapl(&stuff->glyphset, n);
- swaps(&stuff->xSrc, n);
- swaps(&stuff->ySrc, n);
- buffer = (CARD8 *) (stuff + 1);
- end = (CARD8 *) stuff + (client->req_len << 2);
- while (buffer + sizeof (xGlyphElt) < end)
- {
- elt = (xGlyphElt *) buffer;
- buffer += sizeof (xGlyphElt);
-
- swaps (&elt->deltax, n);
- swaps (&elt->deltay, n);
-
- i = elt->len;
- if (i == 0xff)
- {
- swapl (buffer, n);
- buffer += 4;
- }
- else
- {
- space = size * i;
- switch (size) {
- case 1:
- buffer += i;
- break;
- case 2:
- while (i--)
- {
- swaps (buffer, n);
- buffer += 2;
- }
- break;
- case 4:
- while (i--)
- {
- swapl (buffer, n);
- buffer += 4;
- }
- break;
- }
- if (space & 3)
- buffer += 4 - (space & 3);
- }
- }
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderFillRectangles (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderFillRectanglesReq);
-
- REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq);
- swaps(&stuff->length, n);
- swapl(&stuff->dst, n);
- swaps(&stuff->color.red, n);
- swaps(&stuff->color.green, n);
- swaps(&stuff->color.blue, n);
- swaps(&stuff->color.alpha, n);
- SwapRestS(stuff);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderCreateCursor (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderCreateCursorReq);
- REQUEST_SIZE_MATCH (xRenderCreateCursorReq);
-
- swaps(&stuff->length, n);
- swapl(&stuff->cid, n);
- swapl(&stuff->src, n);
- swaps(&stuff->x, n);
- swaps(&stuff->y, n);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderSetPictureTransform (ClientPtr client)
-{
- register int n;
- REQUEST(xRenderSetPictureTransformReq);
- REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq);
-
- swaps(&stuff->length, n);
- swapl(&stuff->picture, n);
- swapl(&stuff->transform.matrix11, n);
- swapl(&stuff->transform.matrix12, n);
- swapl(&stuff->transform.matrix13, n);
- swapl(&stuff->transform.matrix21, n);
- swapl(&stuff->transform.matrix22, n);
- swapl(&stuff->transform.matrix23, n);
- swapl(&stuff->transform.matrix31, n);
- swapl(&stuff->transform.matrix32, n);
- swapl(&stuff->transform.matrix33, n);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderQueryFilters (ClientPtr client)
-{
- register int n;
- REQUEST (xRenderQueryFiltersReq);
- REQUEST_SIZE_MATCH (xRenderQueryFiltersReq);
-
- swaps(&stuff->length, n);
- swapl(&stuff->drawable, n);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderSetPictureFilter (ClientPtr client)
-{
- register int n;
- REQUEST (xRenderSetPictureFilterReq);
- REQUEST_AT_LEAST_SIZE (xRenderSetPictureFilterReq);
-
- swaps(&stuff->length, n);
- swapl(&stuff->picture, n);
- swaps(&stuff->nbytes, n);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderCreateAnimCursor (ClientPtr client)
-{
- register int n;
- REQUEST (xRenderCreateAnimCursorReq);
- REQUEST_AT_LEAST_SIZE (xRenderCreateAnimCursorReq);
-
- swaps(&stuff->length, n);
- swapl(&stuff->cid, n);
- SwapRestL(stuff);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderAddTraps (ClientPtr client)
-{
- register int n;
- REQUEST (xRenderAddTrapsReq);
- REQUEST_AT_LEAST_SIZE (xRenderAddTrapsReq);
-
- swaps(&stuff->length, n);
- swapl(&stuff->picture, n);
- swaps(&stuff->xOff, n);
- swaps(&stuff->yOff, n);
- SwapRestL(stuff);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderCreateSolidFill(ClientPtr client)
-{
- register int n;
- REQUEST (xRenderCreateSolidFillReq);
- REQUEST_AT_LEAST_SIZE (xRenderCreateSolidFillReq);
-
- swaps(&stuff->length, n);
- swapl(&stuff->pid, n);
- swaps(&stuff->color.alpha, n);
- swaps(&stuff->color.red, n);
- swaps(&stuff->color.green, n);
- swaps(&stuff->color.blue, n);
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static void swapStops(void *stuff, int num)
-{
- int i, n;
- CARD32 *stops;
- CARD16 *colors;
- stops = (CARD32 *)(stuff);
- for (i = 0; i < num; ++i) {
- swapl(stops, n);
- ++stops;
- }
- colors = (CARD16 *)(stops);
- for (i = 0; i < 4*num; ++i) {
- swaps(stops, n);
- ++stops;
- }
-}
-
-static int
-SProcRenderCreateLinearGradient (ClientPtr client)
-{
- register int n;
- int len;
- REQUEST (xRenderCreateLinearGradientReq);
- REQUEST_AT_LEAST_SIZE (xRenderCreateLinearGradientReq);
-
- swaps(&stuff->length, n);
- swapl(&stuff->pid, n);
- swapl(&stuff->p1.x, n);
- swapl(&stuff->p1.y, n);
- swapl(&stuff->p2.x, n);
- swapl(&stuff->p2.y, n);
- swapl(&stuff->nStops, n);
-
- len = (client->req_len << 2) - sizeof(xRenderCreateLinearGradientReq);
- if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor)))
- return BadLength;
- if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor)))
- return BadLength;
-
- swapStops(stuff+1, stuff->nStops);
-
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderCreateRadialGradient (ClientPtr client)
-{
- register int n;
- int len;
- REQUEST (xRenderCreateRadialGradientReq);
- REQUEST_AT_LEAST_SIZE (xRenderCreateRadialGradientReq);
-
- swaps(&stuff->length, n);
- swapl(&stuff->pid, n);
- swapl(&stuff->inner.x, n);
- swapl(&stuff->inner.y, n);
- swapl(&stuff->outer.x, n);
- swapl(&stuff->outer.y, n);
- swapl(&stuff->inner_radius, n);
- swapl(&stuff->outer_radius, n);
- swapl(&stuff->nStops, n);
-
- len = (client->req_len << 2) - sizeof(xRenderCreateRadialGradientReq);
- if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor)))
- return BadLength;
- if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor)))
- return BadLength;
-
- swapStops(stuff+1, stuff->nStops);
-
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderCreateConicalGradient (ClientPtr client)
-{
- register int n;
- int len;
- REQUEST (xRenderCreateConicalGradientReq);
- REQUEST_AT_LEAST_SIZE (xRenderCreateConicalGradientReq);
-
- swaps(&stuff->length, n);
- swapl(&stuff->pid, n);
- swapl(&stuff->center.x, n);
- swapl(&stuff->center.y, n);
- swapl(&stuff->angle, n);
- swapl(&stuff->nStops, n);
-
- len = (client->req_len << 2) - sizeof(xRenderCreateConicalGradientReq);
- if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor)))
- return BadLength;
- if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor)))
- return BadLength;
-
- swapStops(stuff+1, stuff->nStops);
-
- return (*ProcRenderVector[stuff->renderReqType]) (client);
-}
-
-static int
-SProcRenderDispatch (ClientPtr client)
-{
- REQUEST(xReq);
-
- if (stuff->data < RenderNumberRequests)
- return (*SProcRenderVector[stuff->data]) (client);
- else
- return BadRequest;
-}
-
-#ifdef PANORAMIX
-#include "panoramiX.h"
-#include "panoramiXsrv.h"
-
-#define VERIFY_XIN_PICTURE(pPicture, pid, client, mode) {\
- int rc = dixLookupResourceByType((pointer *)&(pPicture), pid,\
- XRT_PICTURE, client, mode);\
- if (rc != Success)\
- return (rc == BadValue) ? RenderErrBase + BadPicture : rc;\
-}
-
-#define VERIFY_XIN_ALPHA(pPicture, pid, client, mode) {\
- if (pid == None) \
- pPicture = 0; \
- else { \
- VERIFY_XIN_PICTURE(pPicture, pid, client, mode); \
- } \
-} \
-
-int (*PanoramiXSaveRenderVector[RenderNumberRequests])(ClientPtr);
-
-unsigned long XRT_PICTURE;
-
-static int
-PanoramiXRenderCreatePicture (ClientPtr client)
-{
- REQUEST(xRenderCreatePictureReq);
- PanoramiXRes *refDraw, *newPict;
- int result, j;
-
- REQUEST_AT_LEAST_SIZE(xRenderCreatePictureReq);
- result = dixLookupResourceByClass((pointer *)&refDraw, stuff->drawable,
- XRC_DRAWABLE, client, DixWriteAccess);
- if (result != Success)
- return (result == BadValue) ? BadDrawable : result;
- if(!(newPict = (PanoramiXRes *) malloc(sizeof(PanoramiXRes))))
- return BadAlloc;
- newPict->type = XRT_PICTURE;
- newPict->info[0].id = stuff->pid;
-
- if (refDraw->type == XRT_WINDOW &&
- stuff->drawable == WindowTable[0]->drawable.id)
- {
- newPict->u.pict.root = TRUE;
- }
- else
- newPict->u.pict.root = FALSE;
-
- for(j = 1; j < PanoramiXNumScreens; j++)
- newPict->info[j].id = FakeClientID(client->index);
-
- FOR_NSCREENS_BACKWARD(j) {
- stuff->pid = newPict->info[j].id;
- stuff->drawable = refDraw->info[j].id;
- result = (*PanoramiXSaveRenderVector[X_RenderCreatePicture]) (client);
- if(result != Success) break;
- }
-
- if (result == Success)
- AddResource(newPict->info[0].id, XRT_PICTURE, newPict);
- else
- free(newPict);
-
- return (result);
-}
-
-static int
-PanoramiXRenderChangePicture (ClientPtr client)
-{
- PanoramiXRes *pict;
- int result = Success, j;
- REQUEST(xRenderChangePictureReq);
-
- REQUEST_AT_LEAST_SIZE(xRenderChangePictureReq);
-
- VERIFY_XIN_PICTURE(pict, stuff->picture, client, DixWriteAccess);
-
- FOR_NSCREENS_BACKWARD(j) {
- stuff->picture = pict->info[j].id;
- result = (*PanoramiXSaveRenderVector[X_RenderChangePicture]) (client);
- if(result != Success) break;
- }
-
- return (result);
-}
-
-static int
-PanoramiXRenderSetPictureClipRectangles (ClientPtr client)
-{
- REQUEST(xRenderSetPictureClipRectanglesReq);
- int result = Success, j;
- PanoramiXRes *pict;
-
- REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq);
-
- VERIFY_XIN_PICTURE(pict, stuff->picture, client, DixWriteAccess);
-
- FOR_NSCREENS_BACKWARD(j) {
- stuff->picture = pict->info[j].id;
- result = (*PanoramiXSaveRenderVector[X_RenderSetPictureClipRectangles]) (client);
- if(result != Success) break;
- }
-
- return (result);
-}
-
-static int
-PanoramiXRenderSetPictureTransform (ClientPtr client)
-{
- REQUEST(xRenderSetPictureTransformReq);
- int result = Success, j;
- PanoramiXRes *pict;
-
- REQUEST_AT_LEAST_SIZE(xRenderSetPictureTransformReq);
-
- VERIFY_XIN_PICTURE(pict, stuff->picture, client, DixWriteAccess);
-
- FOR_NSCREENS_BACKWARD(j) {
- stuff->picture = pict->info[j].id;
- result = (*PanoramiXSaveRenderVector[X_RenderSetPictureTransform]) (client);
- if(result != Success) break;
- }
-
- return (result);
-}
-
-static int
-PanoramiXRenderSetPictureFilter (ClientPtr client)
-{
- REQUEST(xRenderSetPictureFilterReq);
- int result = Success, j;
- PanoramiXRes *pict;
-
- REQUEST_AT_LEAST_SIZE(xRenderSetPictureFilterReq);
-
- VERIFY_XIN_PICTURE(pict, stuff->picture, client, DixWriteAccess);
-
- FOR_NSCREENS_BACKWARD(j) {
- stuff->picture = pict->info[j].id;
- result = (*PanoramiXSaveRenderVector[X_RenderSetPictureFilter]) (client);
- if(result != Success) break;
- }
-
- return (result);
-}
-
-static int
-PanoramiXRenderFreePicture (ClientPtr client)
-{
- PanoramiXRes *pict;
- int result = Success, j;
- REQUEST(xRenderFreePictureReq);
-
- REQUEST_SIZE_MATCH(xRenderFreePictureReq);
-
- client->errorValue = stuff->picture;
-
- VERIFY_XIN_PICTURE(pict, stuff->picture, client, DixDestroyAccess);
-
-
- FOR_NSCREENS_BACKWARD(j) {
- stuff->picture = pict->info[j].id;
- result = (*PanoramiXSaveRenderVector[X_RenderFreePicture]) (client);
- if(result != Success) break;
- }
-
- /* Since ProcRenderFreePicture is using FreeResource, it will free
- our resource for us on the last pass through the loop above */
-
- return (result);
-}
-
-static int
-PanoramiXRenderComposite (ClientPtr client)
-{
- PanoramiXRes *src, *msk, *dst;
- int result = Success, j;
- xRenderCompositeReq orig;
- REQUEST(xRenderCompositeReq);
-
- REQUEST_SIZE_MATCH(xRenderCompositeReq);
-
- VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess);
- VERIFY_XIN_ALPHA (msk, stuff->mask, client, DixReadAccess);
- VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess);
-
- orig = *stuff;
-
- FOR_NSCREENS_FORWARD(j) {
- stuff->src = src->info[j].id;
- if (src->u.pict.root)
- {
- stuff->xSrc = orig.xSrc - panoramiXdataPtr[j].x;
- stuff->ySrc = orig.ySrc - panoramiXdataPtr[j].y;
- }
- stuff->dst = dst->info[j].id;
- if (dst->u.pict.root)
- {
- stuff->xDst = orig.xDst - panoramiXdataPtr[j].x;
- stuff->yDst = orig.yDst - panoramiXdataPtr[j].y;
- }
- if (msk)
- {
- stuff->mask = msk->info[j].id;
- if (msk->u.pict.root)
- {
- stuff->xMask = orig.xMask - panoramiXdataPtr[j].x;
- stuff->yMask = orig.yMask - panoramiXdataPtr[j].y;
- }
- }
- result = (*PanoramiXSaveRenderVector[X_RenderComposite]) (client);
- if(result != Success) break;
- }
-
- return result;
-}
-
-static int
-PanoramiXRenderCompositeGlyphs (ClientPtr client)
-{
- PanoramiXRes *src, *dst;
- int result = Success, j;
- REQUEST(xRenderCompositeGlyphsReq);
- xGlyphElt origElt, *elt;
- INT16 xSrc, ySrc;
-
- REQUEST_AT_LEAST_SIZE(xRenderCompositeGlyphsReq);
- VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess);
- VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess);
-
- if (client->req_len << 2 >= (sizeof (xRenderCompositeGlyphsReq) +
- sizeof (xGlyphElt)))
- {
- elt = (xGlyphElt *) (stuff + 1);
- origElt = *elt;
- xSrc = stuff->xSrc;
- ySrc = stuff->ySrc;
- FOR_NSCREENS_FORWARD(j) {
- stuff->src = src->info[j].id;
- if (src->u.pict.root)
- {
- stuff->xSrc = xSrc - panoramiXdataPtr[j].x;
- stuff->ySrc = ySrc - panoramiXdataPtr[j].y;
- }
- stuff->dst = dst->info[j].id;
- if (dst->u.pict.root)
- {
- elt->deltax = origElt.deltax - panoramiXdataPtr[j].x;
- elt->deltay = origElt.deltay - panoramiXdataPtr[j].y;
- }
- result = (*PanoramiXSaveRenderVector[stuff->renderReqType]) (client);
- if(result != Success) break;
- }
- }
-
- return result;
-}
-
-static int
-PanoramiXRenderFillRectangles (ClientPtr client)
-{
- PanoramiXRes *dst;
- int result = Success, j;
- REQUEST(xRenderFillRectanglesReq);
- char *extra;
- int extra_len;
-
- REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq);
- VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess);
- extra_len = (client->req_len << 2) - sizeof (xRenderFillRectanglesReq);
- if (extra_len &&
- (extra = (char *) malloc(extra_len)))
- {
- memcpy (extra, stuff + 1, extra_len);
- FOR_NSCREENS_FORWARD(j) {
- if (j) memcpy (stuff + 1, extra, extra_len);
- if (dst->u.pict.root)
- {
- int x_off = panoramiXdataPtr[j].x;
- int y_off = panoramiXdataPtr[j].y;
-
- if(x_off || y_off) {
- xRectangle *rects = (xRectangle *) (stuff + 1);
- int i = extra_len / sizeof (xRectangle);
-
- while (i--)
- {
- rects->x -= x_off;
- rects->y -= y_off;
- rects++;
- }
- }
- }
- stuff->dst = dst->info[j].id;
- result = (*PanoramiXSaveRenderVector[X_RenderFillRectangles]) (client);
- if(result != Success) break;
- }
- free(extra);
- }
-
- return result;
-}
-
-static int
-PanoramiXRenderTrapezoids(ClientPtr client)
-{
- PanoramiXRes *src, *dst;
- int result = Success, j;
- REQUEST(xRenderTrapezoidsReq);
- char *extra;
- int extra_len;
-
- REQUEST_AT_LEAST_SIZE (xRenderTrapezoidsReq);
-
- VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess);
- VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess);
-
- extra_len = (client->req_len << 2) - sizeof (xRenderTrapezoidsReq);
-
- if (extra_len &&
- (extra = (char *) malloc(extra_len))) {
- memcpy (extra, stuff + 1, extra_len);
-
- FOR_NSCREENS_FORWARD(j) {
- if (j) memcpy (stuff + 1, extra, extra_len);
- if (dst->u.pict.root) {
- int x_off = panoramiXdataPtr[j].x;
- int y_off = panoramiXdataPtr[j].y;
-
- if(x_off || y_off) {
- xTrapezoid *trap = (xTrapezoid *) (stuff + 1);
- int i = extra_len / sizeof (xTrapezoid);
-
- while (i--) {
- trap->top -= y_off;
- trap->bottom -= y_off;
- trap->left.p1.x -= x_off;
- trap->left.p1.y -= y_off;
- trap->left.p2.x -= x_off;
- trap->left.p2.y -= y_off;
- trap->right.p1.x -= x_off;
- trap->right.p1.y -= y_off;
- trap->right.p2.x -= x_off;
- trap->right.p2.y -= y_off;
- trap++;
- }
- }
- }
-
- stuff->src = src->info[j].id;
- stuff->dst = dst->info[j].id;
- result =
- (*PanoramiXSaveRenderVector[X_RenderTrapezoids]) (client);
-
- if(result != Success) break;
- }
-
- free(extra);
- }
-
- return result;
-}
-
-static int
-PanoramiXRenderTriangles(ClientPtr client)
-{
- PanoramiXRes *src, *dst;
- int result = Success, j;
- REQUEST(xRenderTrianglesReq);
- char *extra;
- int extra_len;
-
- REQUEST_AT_LEAST_SIZE (xRenderTrianglesReq);
-
- VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess);
- VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess);
-
- extra_len = (client->req_len << 2) - sizeof (xRenderTrianglesReq);
-
- if (extra_len &&
- (extra = (char *) malloc(extra_len))) {
- memcpy (extra, stuff + 1, extra_len);
-
- FOR_NSCREENS_FORWARD(j) {
- if (j) memcpy (stuff + 1, extra, extra_len);
- if (dst->u.pict.root) {
- int x_off = panoramiXdataPtr[j].x;
- int y_off = panoramiXdataPtr[j].y;
-
- if(x_off || y_off) {
- xTriangle *tri = (xTriangle *) (stuff + 1);
- int i = extra_len / sizeof (xTriangle);
-
- while (i--) {
- tri->p1.x -= x_off;
- tri->p1.y -= y_off;
- tri->p2.x -= x_off;
- tri->p2.y -= y_off;
- tri->p3.x -= x_off;
- tri->p3.y -= y_off;
- tri++;
- }
- }
- }
-
- stuff->src = src->info[j].id;
- stuff->dst = dst->info[j].id;
- result =
- (*PanoramiXSaveRenderVector[X_RenderTriangles]) (client);
-
- if(result != Success) break;
- }
-
- free(extra);
- }
-
- return result;
-}
-
-static int
-PanoramiXRenderTriStrip(ClientPtr client)
-{
- PanoramiXRes *src, *dst;
- int result = Success, j;
- REQUEST(xRenderTriStripReq);
- char *extra;
- int extra_len;
-
- REQUEST_AT_LEAST_SIZE (xRenderTriStripReq);
-
- VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess);
- VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess);
-
- extra_len = (client->req_len << 2) - sizeof (xRenderTriStripReq);
-
- if (extra_len &&
- (extra = (char *) malloc(extra_len))) {
- memcpy (extra, stuff + 1, extra_len);
-
- FOR_NSCREENS_FORWARD(j) {
- if (j) memcpy (stuff + 1, extra, extra_len);
- if (dst->u.pict.root) {
- int x_off = panoramiXdataPtr[j].x;
- int y_off = panoramiXdataPtr[j].y;
-
- if(x_off || y_off) {
- xPointFixed *fixed = (xPointFixed *) (stuff + 1);
- int i = extra_len / sizeof (xPointFixed);
-
- while (i--) {
- fixed->x -= x_off;
- fixed->y -= y_off;
- fixed++;
- }
- }
- }
-
- stuff->src = src->info[j].id;
- stuff->dst = dst->info[j].id;
- result =
- (*PanoramiXSaveRenderVector[X_RenderTriStrip]) (client);
-
- if(result != Success) break;
- }
-
- free(extra);
- }
-
- return result;
-}
-
-static int
-PanoramiXRenderTriFan(ClientPtr client)
-{
- PanoramiXRes *src, *dst;
- int result = Success, j;
- REQUEST(xRenderTriFanReq);
- char *extra;
- int extra_len;
-
- REQUEST_AT_LEAST_SIZE (xRenderTriFanReq);
-
- VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess);
- VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess);
-
- extra_len = (client->req_len << 2) - sizeof (xRenderTriFanReq);
-
- if (extra_len &&
- (extra = (char *) malloc(extra_len))) {
- memcpy (extra, stuff + 1, extra_len);
-
- FOR_NSCREENS_FORWARD(j) {
- if (j) memcpy (stuff + 1, extra, extra_len);
- if (dst->u.pict.root) {
- int x_off = panoramiXdataPtr[j].x;
- int y_off = panoramiXdataPtr[j].y;
-
- if(x_off || y_off) {
- xPointFixed *fixed = (xPointFixed *) (stuff + 1);
- int i = extra_len / sizeof (xPointFixed);
-
- while (i--) {
- fixed->x -= x_off;
- fixed->y -= y_off;
- fixed++;
- }
- }
- }
-
- stuff->src = src->info[j].id;
- stuff->dst = dst->info[j].id;
- result =
- (*PanoramiXSaveRenderVector[X_RenderTriFan]) (client);
-
- if(result != Success) break;
- }
-
- free(extra);
- }
-
- return result;
-}
-
-static int
-PanoramiXRenderAddTraps (ClientPtr client)
-{
- PanoramiXRes *picture;
- int result = Success, j;
- REQUEST(xRenderAddTrapsReq);
- char *extra;
- int extra_len;
- INT16 x_off, y_off;
-
- REQUEST_AT_LEAST_SIZE (xRenderAddTrapsReq);
- VERIFY_XIN_PICTURE (picture, stuff->picture, client, DixWriteAccess);
- extra_len = (client->req_len << 2) - sizeof (xRenderAddTrapsReq);
- if (extra_len &&
- (extra = (char *) malloc(extra_len)))
- {
- memcpy (extra, stuff + 1, extra_len);
- x_off = stuff->xOff;
- y_off = stuff->yOff;
- FOR_NSCREENS_FORWARD(j) {
- if (j) memcpy (stuff + 1, extra, extra_len);
- stuff->picture = picture->info[j].id;
-
- if (picture->u.pict.root)
- {
- stuff->xOff = x_off + panoramiXdataPtr[j].x;
- stuff->yOff = y_off + panoramiXdataPtr[j].y;
- }
- result = (*PanoramiXSaveRenderVector[X_RenderAddTraps]) (client);
- if(result != Success) break;
- }
- free(extra);
- }
-
- return result;
-}
-
-static int
-PanoramiXRenderCreateSolidFill (ClientPtr client)
-{
- REQUEST(xRenderCreateSolidFillReq);
- PanoramiXRes *newPict;
- int result = Success, j;
-
- REQUEST_AT_LEAST_SIZE(xRenderCreateSolidFillReq);
-
- if(!(newPict = (PanoramiXRes *) malloc(sizeof(PanoramiXRes))))
- return BadAlloc;
-
- newPict->type = XRT_PICTURE;
- newPict->info[0].id = stuff->pid;
- newPict->u.pict.root = FALSE;
-
- for(j = 1; j < PanoramiXNumScreens; j++)
- newPict->info[j].id = FakeClientID(client->index);
-
- FOR_NSCREENS_BACKWARD(j) {
- stuff->pid = newPict->info[j].id;
- result = (*PanoramiXSaveRenderVector[X_RenderCreateSolidFill]) (client);
- if(result != Success) break;
- }
-
- if (result == Success)
- AddResource(newPict->info[0].id, XRT_PICTURE, newPict);
- else
- free(newPict);
-
- return result;
-}
-
-static int
-PanoramiXRenderCreateLinearGradient (ClientPtr client)
-{
- REQUEST(xRenderCreateLinearGradientReq);
- PanoramiXRes *newPict;
- int result = Success, j;
-
- REQUEST_AT_LEAST_SIZE(xRenderCreateLinearGradientReq);
-
- if(!(newPict = (PanoramiXRes *) malloc(sizeof(PanoramiXRes))))
- return BadAlloc;
-
- newPict->type = XRT_PICTURE;
- newPict->info[0].id = stuff->pid;
- newPict->u.pict.root = FALSE;
-
- for(j = 1; j < PanoramiXNumScreens; j++)
- newPict->info[j].id = FakeClientID(client->index);
-
- FOR_NSCREENS_BACKWARD(j) {
- stuff->pid = newPict->info[j].id;
- result = (*PanoramiXSaveRenderVector[X_RenderCreateLinearGradient]) (client);
- if(result != Success) break;
- }
-
- if (result == Success)
- AddResource(newPict->info[0].id, XRT_PICTURE, newPict);
- else
- free(newPict);
-
- return result;
-}
-
-static int
-PanoramiXRenderCreateRadialGradient (ClientPtr client)
-{
- REQUEST(xRenderCreateRadialGradientReq);
- PanoramiXRes *newPict;
- int result = Success, j;
-
- REQUEST_AT_LEAST_SIZE(xRenderCreateRadialGradientReq);
-
- if(!(newPict = (PanoramiXRes *) malloc(sizeof(PanoramiXRes))))
- return BadAlloc;
-
- newPict->type = XRT_PICTURE;
- newPict->info[0].id = stuff->pid;
- newPict->u.pict.root = FALSE;
-
- for(j = 1; j < PanoramiXNumScreens; j++)
- newPict->info[j].id = FakeClientID(client->index);
-
- FOR_NSCREENS_BACKWARD(j) {
- stuff->pid = newPict->info[j].id;
- result = (*PanoramiXSaveRenderVector[X_RenderCreateRadialGradient]) (client);
- if(result != Success) break;
- }
-
- if (result == Success)
- AddResource(newPict->info[0].id, XRT_PICTURE, newPict);
- else
- free(newPict);
-
- return result;
-}
-
-static int
-PanoramiXRenderCreateConicalGradient (ClientPtr client)
-{
- REQUEST(xRenderCreateConicalGradientReq);
- PanoramiXRes *newPict;
- int result = Success, j;
-
- REQUEST_AT_LEAST_SIZE(xRenderCreateConicalGradientReq);
-
- if(!(newPict = (PanoramiXRes *) malloc(sizeof(PanoramiXRes))))
- return BadAlloc;
-
- newPict->type = XRT_PICTURE;
- newPict->info[0].id = stuff->pid;
- newPict->u.pict.root = FALSE;
-
- for(j = 1; j < PanoramiXNumScreens; j++)
- newPict->info[j].id = FakeClientID(client->index);
-
- FOR_NSCREENS_BACKWARD(j) {
- stuff->pid = newPict->info[j].id;
- result = (*PanoramiXSaveRenderVector[X_RenderCreateConicalGradient]) (client);
- if(result != Success) break;
- }
-
- if (result == Success)
- AddResource(newPict->info[0].id, XRT_PICTURE, newPict);
- else
- free(newPict);
-
- return result;
-}
-
-void
-PanoramiXRenderInit (void)
-{
- int i;
-
- XRT_PICTURE = CreateNewResourceType (XineramaDeleteResource,
- "XineramaPicture");
- for (i = 0; i < RenderNumberRequests; i++)
- PanoramiXSaveRenderVector[i] = ProcRenderVector[i];
- /*
- * Stuff in Xinerama aware request processing hooks
- */
- ProcRenderVector[X_RenderCreatePicture] = PanoramiXRenderCreatePicture;
- ProcRenderVector[X_RenderChangePicture] = PanoramiXRenderChangePicture;
- ProcRenderVector[X_RenderSetPictureTransform] = PanoramiXRenderSetPictureTransform;
- ProcRenderVector[X_RenderSetPictureFilter] = PanoramiXRenderSetPictureFilter;
- ProcRenderVector[X_RenderSetPictureClipRectangles] = PanoramiXRenderSetPictureClipRectangles;
- ProcRenderVector[X_RenderFreePicture] = PanoramiXRenderFreePicture;
- ProcRenderVector[X_RenderComposite] = PanoramiXRenderComposite;
- ProcRenderVector[X_RenderCompositeGlyphs8] = PanoramiXRenderCompositeGlyphs;
- ProcRenderVector[X_RenderCompositeGlyphs16] = PanoramiXRenderCompositeGlyphs;
- ProcRenderVector[X_RenderCompositeGlyphs32] = PanoramiXRenderCompositeGlyphs;
- ProcRenderVector[X_RenderFillRectangles] = PanoramiXRenderFillRectangles;
-
- ProcRenderVector[X_RenderTrapezoids] = PanoramiXRenderTrapezoids;
- ProcRenderVector[X_RenderTriangles] = PanoramiXRenderTriangles;
- ProcRenderVector[X_RenderTriStrip] = PanoramiXRenderTriStrip;
- ProcRenderVector[X_RenderTriFan] = PanoramiXRenderTriFan;
- ProcRenderVector[X_RenderAddTraps] = PanoramiXRenderAddTraps;
-
- ProcRenderVector[X_RenderCreateSolidFill] = PanoramiXRenderCreateSolidFill;
- ProcRenderVector[X_RenderCreateLinearGradient] = PanoramiXRenderCreateLinearGradient;
- ProcRenderVector[X_RenderCreateRadialGradient] = PanoramiXRenderCreateRadialGradient;
- ProcRenderVector[X_RenderCreateConicalGradient] = PanoramiXRenderCreateConicalGradient;
-}
-
-void
-PanoramiXRenderReset (void)
-{
- int i;
- for (i = 0; i < RenderNumberRequests; i++)
- ProcRenderVector[i] = PanoramiXSaveRenderVector[i];
-}
-
-#endif /* PANORAMIX */
+/* + * + * Copyright © 2000 SuSE, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of SuSE not be used in advertising or + * publicity pertaining to distribution of the software without specific, + * written prior permission. SuSE makes no representations about the + * suitability of this software for any purpose. It is provided "as is" + * without express or implied warranty. + * + * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE + * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 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 PERFORMANCE OF THIS SOFTWARE. + * + * Author: Keith Packard, SuSE, Inc. + */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include <X11/X.h> +#include <X11/Xproto.h> +#include "misc.h" +#include "os.h" +#include "dixstruct.h" +#include "resource.h" +#include "scrnintstr.h" +#include "windowstr.h" +#include "pixmapstr.h" +#include "colormapst.h" +#include "extnsionst.h" +#include "servermd.h" +#include <X11/extensions/render.h> +#include <X11/extensions/renderproto.h> +#include "picturestr.h" +#include "glyphstr.h" +#include <X11/Xfuncproto.h> +#include "cursorstr.h" +#include "xace.h" +#include "protocol-versions.h" + +#if HAVE_STDINT_H +#include <stdint.h> +#elif !defined(UINT32_MAX) +#define UINT32_MAX 0xffffffffU +#endif + +static int ProcRenderQueryVersion (ClientPtr pClient); +static int ProcRenderQueryPictFormats (ClientPtr pClient); +static int ProcRenderQueryPictIndexValues (ClientPtr pClient); +static int ProcRenderQueryDithers (ClientPtr pClient); +static int ProcRenderCreatePicture (ClientPtr pClient); +static int ProcRenderChangePicture (ClientPtr pClient); +static int ProcRenderSetPictureClipRectangles (ClientPtr pClient); +static int ProcRenderFreePicture (ClientPtr pClient); +static int ProcRenderComposite (ClientPtr pClient); +static int ProcRenderScale (ClientPtr pClient); +static int ProcRenderTrapezoids (ClientPtr pClient); +static int ProcRenderTriangles (ClientPtr pClient); +static int ProcRenderTriStrip (ClientPtr pClient); +static int ProcRenderTriFan (ClientPtr pClient); +static int ProcRenderColorTrapezoids (ClientPtr pClient); +static int ProcRenderColorTriangles (ClientPtr pClient); +static int ProcRenderTransform (ClientPtr pClient); +static int ProcRenderCreateGlyphSet (ClientPtr pClient); +static int ProcRenderReferenceGlyphSet (ClientPtr pClient); +static int ProcRenderFreeGlyphSet (ClientPtr pClient); +static int ProcRenderAddGlyphs (ClientPtr pClient); +static int ProcRenderAddGlyphsFromPicture (ClientPtr pClient); +static int ProcRenderFreeGlyphs (ClientPtr pClient); +static int ProcRenderCompositeGlyphs (ClientPtr pClient); +static int ProcRenderFillRectangles (ClientPtr pClient); +static int ProcRenderCreateCursor (ClientPtr pClient); +static int ProcRenderSetPictureTransform (ClientPtr pClient); +static int ProcRenderQueryFilters (ClientPtr pClient); +static int ProcRenderSetPictureFilter (ClientPtr pClient); +static int ProcRenderCreateAnimCursor (ClientPtr pClient); +static int ProcRenderAddTraps (ClientPtr pClient); +static int ProcRenderCreateSolidFill (ClientPtr pClient); +static int ProcRenderCreateLinearGradient (ClientPtr pClient); +static int ProcRenderCreateRadialGradient (ClientPtr pClient); +static int ProcRenderCreateConicalGradient (ClientPtr pClient); + +static int ProcRenderDispatch (ClientPtr pClient); + +static int SProcRenderQueryVersion (ClientPtr pClient); +static int SProcRenderQueryPictFormats (ClientPtr pClient); +static int SProcRenderQueryPictIndexValues (ClientPtr pClient); +static int SProcRenderQueryDithers (ClientPtr pClient); +static int SProcRenderCreatePicture (ClientPtr pClient); +static int SProcRenderChangePicture (ClientPtr pClient); +static int SProcRenderSetPictureClipRectangles (ClientPtr pClient); +static int SProcRenderFreePicture (ClientPtr pClient); +static int SProcRenderComposite (ClientPtr pClient); +static int SProcRenderScale (ClientPtr pClient); +static int SProcRenderTrapezoids (ClientPtr pClient); +static int SProcRenderTriangles (ClientPtr pClient); +static int SProcRenderTriStrip (ClientPtr pClient); +static int SProcRenderTriFan (ClientPtr pClient); +static int SProcRenderColorTrapezoids (ClientPtr pClient); +static int SProcRenderColorTriangles (ClientPtr pClient); +static int SProcRenderTransform (ClientPtr pClient); +static int SProcRenderCreateGlyphSet (ClientPtr pClient); +static int SProcRenderReferenceGlyphSet (ClientPtr pClient); +static int SProcRenderFreeGlyphSet (ClientPtr pClient); +static int SProcRenderAddGlyphs (ClientPtr pClient); +static int SProcRenderAddGlyphsFromPicture (ClientPtr pClient); +static int SProcRenderFreeGlyphs (ClientPtr pClient); +static int SProcRenderCompositeGlyphs (ClientPtr pClient); +static int SProcRenderFillRectangles (ClientPtr pClient); +static int SProcRenderCreateCursor (ClientPtr pClient); +static int SProcRenderSetPictureTransform (ClientPtr pClient); +static int SProcRenderQueryFilters (ClientPtr pClient); +static int SProcRenderSetPictureFilter (ClientPtr pClient); +static int SProcRenderCreateAnimCursor (ClientPtr pClient); +static int SProcRenderAddTraps (ClientPtr pClient); +static int SProcRenderCreateSolidFill (ClientPtr pClient); +static int SProcRenderCreateLinearGradient (ClientPtr pClient); +static int SProcRenderCreateRadialGradient (ClientPtr pClient); +static int SProcRenderCreateConicalGradient (ClientPtr pClient); + +static int SProcRenderDispatch (ClientPtr pClient); + +int (*ProcRenderVector[RenderNumberRequests])(ClientPtr) = { + ProcRenderQueryVersion, + ProcRenderQueryPictFormats, + ProcRenderQueryPictIndexValues, + ProcRenderQueryDithers, + ProcRenderCreatePicture, + ProcRenderChangePicture, + ProcRenderSetPictureClipRectangles, + ProcRenderFreePicture, + ProcRenderComposite, + ProcRenderScale, + ProcRenderTrapezoids, + ProcRenderTriangles, + ProcRenderTriStrip, + ProcRenderTriFan, + ProcRenderColorTrapezoids, + ProcRenderColorTriangles, + ProcRenderTransform, + ProcRenderCreateGlyphSet, + ProcRenderReferenceGlyphSet, + ProcRenderFreeGlyphSet, + ProcRenderAddGlyphs, + ProcRenderAddGlyphsFromPicture, + ProcRenderFreeGlyphs, + ProcRenderCompositeGlyphs, + ProcRenderCompositeGlyphs, + ProcRenderCompositeGlyphs, + ProcRenderFillRectangles, + ProcRenderCreateCursor, + ProcRenderSetPictureTransform, + ProcRenderQueryFilters, + ProcRenderSetPictureFilter, + ProcRenderCreateAnimCursor, + ProcRenderAddTraps, + ProcRenderCreateSolidFill, + ProcRenderCreateLinearGradient, + ProcRenderCreateRadialGradient, + ProcRenderCreateConicalGradient +}; + +int (*SProcRenderVector[RenderNumberRequests])(ClientPtr) = { + SProcRenderQueryVersion, + SProcRenderQueryPictFormats, + SProcRenderQueryPictIndexValues, + SProcRenderQueryDithers, + SProcRenderCreatePicture, + SProcRenderChangePicture, + SProcRenderSetPictureClipRectangles, + SProcRenderFreePicture, + SProcRenderComposite, + SProcRenderScale, + SProcRenderTrapezoids, + SProcRenderTriangles, + SProcRenderTriStrip, + SProcRenderTriFan, + SProcRenderColorTrapezoids, + SProcRenderColorTriangles, + SProcRenderTransform, + SProcRenderCreateGlyphSet, + SProcRenderReferenceGlyphSet, + SProcRenderFreeGlyphSet, + SProcRenderAddGlyphs, + SProcRenderAddGlyphsFromPicture, + SProcRenderFreeGlyphs, + SProcRenderCompositeGlyphs, + SProcRenderCompositeGlyphs, + SProcRenderCompositeGlyphs, + SProcRenderFillRectangles, + SProcRenderCreateCursor, + SProcRenderSetPictureTransform, + SProcRenderQueryFilters, + SProcRenderSetPictureFilter, + SProcRenderCreateAnimCursor, + SProcRenderAddTraps, + SProcRenderCreateSolidFill, + SProcRenderCreateLinearGradient, + SProcRenderCreateRadialGradient, + SProcRenderCreateConicalGradient +}; + +int RenderErrBase; +static int RenderClientPrivateKeyIndex; +DevPrivateKey RenderClientPrivateKey = &RenderClientPrivateKeyIndex; + +typedef struct _RenderClient { + int major_version; + int minor_version; +} RenderClientRec, *RenderClientPtr; + +#define GetRenderClient(pClient) ((RenderClientPtr)dixLookupPrivate(&(pClient)->devPrivates, RenderClientPrivateKey)) + +static void +RenderClientCallback (CallbackListPtr *list, + pointer closure, + pointer data) +{ + NewClientInfoRec *clientinfo = (NewClientInfoRec *) data; + ClientPtr pClient = clientinfo->client; + RenderClientPtr pRenderClient = GetRenderClient (pClient); + + pRenderClient->major_version = 0; + pRenderClient->minor_version = 0; +} + +void +RenderExtensionInit (void) +{ + ExtensionEntry *extEntry; + + if (!PictureType) + return; + if (!PictureFinishInit ()) + return; + if (!dixRequestPrivate(RenderClientPrivateKey, sizeof(RenderClientRec))) + return; + if (!AddCallback (&ClientStateCallback, RenderClientCallback, 0)) + return; + + extEntry = AddExtension (RENDER_NAME, 0, RenderNumberErrors, + ProcRenderDispatch, SProcRenderDispatch, + NULL, StandardMinorOpcode); + if (!extEntry) + return; + RenderErrBase = extEntry->errorBase; +} + +static int +ProcRenderQueryVersion (ClientPtr client) +{ + RenderClientPtr pRenderClient = GetRenderClient (client); + xRenderQueryVersionReply rep; + register int n; + REQUEST(xRenderQueryVersionReq); + + pRenderClient->major_version = stuff->majorVersion; + pRenderClient->minor_version = stuff->minorVersion; + + REQUEST_SIZE_MATCH(xRenderQueryVersionReq); + memset(&rep, 0, sizeof(xRenderQueryVersionReply)); + rep.type = X_Reply; + rep.length = 0; + rep.sequenceNumber = client->sequence; + + if ((stuff->majorVersion * 1000 + stuff->minorVersion) < + (SERVER_RENDER_MAJOR_VERSION * 1000 + SERVER_RENDER_MINOR_VERSION)) + { + rep.majorVersion = stuff->majorVersion; + rep.minorVersion = stuff->minorVersion; + } else + { + rep.majorVersion = SERVER_RENDER_MAJOR_VERSION; + rep.minorVersion = SERVER_RENDER_MINOR_VERSION; + } + + if (client->swapped) { + swaps(&rep.sequenceNumber, n); + swapl(&rep.length, n); + swapl(&rep.majorVersion, n); + swapl(&rep.minorVersion, n); + } + WriteToClient(client, sizeof(xRenderQueryVersionReply), (char *)&rep); + return Success; +} + +static VisualPtr +findVisual (ScreenPtr pScreen, VisualID vid) +{ + VisualPtr pVisual; + int v; + + for (v = 0; v < pScreen->numVisuals; v++) + { + pVisual = pScreen->visuals + v; + if (pVisual->vid == vid) + return pVisual; + } + return 0; +} + +static int +ProcRenderQueryPictFormats (ClientPtr client) +{ + RenderClientPtr pRenderClient = GetRenderClient (client); + xRenderQueryPictFormatsReply *reply; + xPictScreen *pictScreen; + xPictDepth *pictDepth; + xPictVisual *pictVisual; + xPictFormInfo *pictForm; + CARD32 *pictSubpixel; + ScreenPtr pScreen; + VisualPtr pVisual; + DepthPtr pDepth; + int v, d; + PictureScreenPtr ps; + PictFormatPtr pFormat; + int nformat; + int ndepth; + int nvisual; + int rlength; + int s; + int n; + int numScreens; + int numSubpixel; +/* REQUEST(xRenderQueryPictFormatsReq); */ + + REQUEST_SIZE_MATCH(xRenderQueryPictFormatsReq); + +#ifdef PANORAMIX + if (noPanoramiXExtension) + numScreens = screenInfo.numScreens; + else + numScreens = ((xConnSetup *)ConnectionInfo)->numRoots; +#else + numScreens = screenInfo.numScreens; +#endif + ndepth = nformat = nvisual = 0; + for (s = 0; s < numScreens; s++) + { + pScreen = screenInfo.screens[s]; + for (d = 0; d < pScreen->numDepths; d++) + { + pDepth = pScreen->allowedDepths + d; + ++ndepth; + + for (v = 0; v < pDepth->numVids; v++) + { + pVisual = findVisual (pScreen, pDepth->vids[v]); + if (pVisual && PictureMatchVisual (pScreen, pDepth->depth, pVisual)) + ++nvisual; + } + } + ps = GetPictureScreenIfSet(pScreen); + if (ps) + nformat += ps->nformats; + } + if (pRenderClient->major_version == 0 && pRenderClient->minor_version < 6) + numSubpixel = 0; + else + numSubpixel = numScreens; + + rlength = (sizeof (xRenderQueryPictFormatsReply) + + nformat * sizeof (xPictFormInfo) + + numScreens * sizeof (xPictScreen) + + ndepth * sizeof (xPictDepth) + + nvisual * sizeof (xPictVisual) + + numSubpixel * sizeof (CARD32)); + reply = (xRenderQueryPictFormatsReply *) calloc(1, rlength); + if (!reply) + return BadAlloc; + reply->type = X_Reply; + reply->sequenceNumber = client->sequence; + reply->length = bytes_to_int32(rlength - sizeof(xGenericReply)); + reply->numFormats = nformat; + reply->numScreens = numScreens; + reply->numDepths = ndepth; + reply->numVisuals = nvisual; + reply->numSubpixel = numSubpixel; + + pictForm = (xPictFormInfo *) (reply + 1); + + for (s = 0; s < numScreens; s++) + { + pScreen = screenInfo.screens[s]; + ps = GetPictureScreenIfSet(pScreen); + if (ps) + { + for (nformat = 0, pFormat = ps->formats; + nformat < ps->nformats; + nformat++, pFormat++) + { + pictForm->id = pFormat->id; + pictForm->type = pFormat->type; + pictForm->depth = pFormat->depth; + pictForm->direct.red = pFormat->direct.red; + pictForm->direct.redMask = pFormat->direct.redMask; + pictForm->direct.green = pFormat->direct.green; + pictForm->direct.greenMask = pFormat->direct.greenMask; + pictForm->direct.blue = pFormat->direct.blue; + pictForm->direct.blueMask = pFormat->direct.blueMask; + pictForm->direct.alpha = pFormat->direct.alpha; + pictForm->direct.alphaMask = pFormat->direct.alphaMask; + if (pFormat->type == PictTypeIndexed && pFormat->index.pColormap) + pictForm->colormap = pFormat->index.pColormap->mid; + else + pictForm->colormap = None; + if (client->swapped) + { + swapl (&pictForm->id, n); + swaps (&pictForm->direct.red, n); + swaps (&pictForm->direct.redMask, n); + swaps (&pictForm->direct.green, n); + swaps (&pictForm->direct.greenMask, n); + swaps (&pictForm->direct.blue, n); + swaps (&pictForm->direct.blueMask, n); + swaps (&pictForm->direct.alpha, n); + swaps (&pictForm->direct.alphaMask, n); + swapl (&pictForm->colormap, n); + } + pictForm++; + } + } + } + + pictScreen = (xPictScreen *) pictForm; + for (s = 0; s < numScreens; s++) + { + pScreen = screenInfo.screens[s]; + pictDepth = (xPictDepth *) (pictScreen + 1); + ndepth = 0; + for (d = 0; d < pScreen->numDepths; d++) + { + pictVisual = (xPictVisual *) (pictDepth + 1); + pDepth = pScreen->allowedDepths + d; + + nvisual = 0; + for (v = 0; v < pDepth->numVids; v++) + { + pVisual = findVisual (pScreen, pDepth->vids[v]); + if (pVisual && (pFormat = PictureMatchVisual (pScreen, + pDepth->depth, + pVisual))) + { + pictVisual->visual = pVisual->vid; + pictVisual->format = pFormat->id; + if (client->swapped) + { + swapl (&pictVisual->visual, n); + swapl (&pictVisual->format, n); + } + pictVisual++; + nvisual++; + } + } + pictDepth->depth = pDepth->depth; + pictDepth->nPictVisuals = nvisual; + if (client->swapped) + { + swaps (&pictDepth->nPictVisuals, n); + } + ndepth++; + pictDepth = (xPictDepth *) pictVisual; + } + pictScreen->nDepth = ndepth; + ps = GetPictureScreenIfSet(pScreen); + if (ps) + pictScreen->fallback = ps->fallback->id; + else + pictScreen->fallback = 0; + if (client->swapped) + { + swapl (&pictScreen->nDepth, n); + swapl (&pictScreen->fallback, n); + } + pictScreen = (xPictScreen *) pictDepth; + } + pictSubpixel = (CARD32 *) pictScreen; + + for (s = 0; s < numSubpixel; s++) + { + pScreen = screenInfo.screens[s]; + ps = GetPictureScreenIfSet(pScreen); + if (ps) + *pictSubpixel = ps->subpixel; + else + *pictSubpixel = SubPixelUnknown; + if (client->swapped) + { + swapl (pictSubpixel, n); + } + ++pictSubpixel; + } + + if (client->swapped) + { + swaps (&reply->sequenceNumber, n); + swapl (&reply->length, n); + swapl (&reply->numFormats, n); + swapl (&reply->numScreens, n); + swapl (&reply->numDepths, n); + swapl (&reply->numVisuals, n); + swapl (&reply->numSubpixel, n); + } + WriteToClient(client, rlength, (char *) reply); + free(reply); + return Success; +} + +static int +ProcRenderQueryPictIndexValues (ClientPtr client) +{ + PictFormatPtr pFormat; + int rc, num; + int rlength; + int i, n; + REQUEST(xRenderQueryPictIndexValuesReq); + xRenderQueryPictIndexValuesReply *reply; + xIndexValue *values; + + REQUEST_AT_LEAST_SIZE(xRenderQueryPictIndexValuesReq); + + rc = dixLookupResourceByType((pointer *)&pFormat, stuff->format, + PictFormatType, client, DixReadAccess); + if (rc != Success) + return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc; + + if (pFormat->type != PictTypeIndexed) + { + client->errorValue = stuff->format; + return BadMatch; + } + num = pFormat->index.nvalues; + rlength = (sizeof (xRenderQueryPictIndexValuesReply) + + num * sizeof(xIndexValue)); + reply = (xRenderQueryPictIndexValuesReply *) malloc(rlength); + if (!reply) + return BadAlloc; + + reply->type = X_Reply; + reply->sequenceNumber = client->sequence; + reply->length = bytes_to_int32(rlength - sizeof(xGenericReply)); + reply->numIndexValues = num; + + values = (xIndexValue *) (reply + 1); + + memcpy (reply + 1, pFormat->index.pValues, num * sizeof (xIndexValue)); + + if (client->swapped) + { + for (i = 0; i < num; i++) + { + swapl (&values[i].pixel, n); + swaps (&values[i].red, n); + swaps (&values[i].green, n); + swaps (&values[i].blue, n); + swaps (&values[i].alpha, n); + } + swaps (&reply->sequenceNumber, n); + swapl (&reply->length, n); + swapl (&reply->numIndexValues, n); + } + + WriteToClient(client, rlength, (char *) reply); + free(reply); + return Success; +} + +static int +ProcRenderQueryDithers (ClientPtr client) +{ + return BadImplementation; +} + +static int +ProcRenderCreatePicture (ClientPtr client) +{ + PicturePtr pPicture; + DrawablePtr pDrawable; + PictFormatPtr pFormat; + int len, error, rc; + REQUEST(xRenderCreatePictureReq); + + REQUEST_AT_LEAST_SIZE(xRenderCreatePictureReq); + + LEGAL_NEW_RESOURCE(stuff->pid, client); + rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0, + DixReadAccess|DixAddAccess); + if (rc != Success) + return rc; + + rc = dixLookupResourceByType((pointer *)&pFormat, stuff->format, + PictFormatType, client, DixReadAccess); + if (rc != Success) + return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc; + + if (pFormat->depth != pDrawable->depth) + return BadMatch; + len = client->req_len - bytes_to_int32(sizeof(xRenderCreatePictureReq)); + if (Ones(stuff->mask) != len) + return BadLength; + + pPicture = CreatePicture (stuff->pid, + pDrawable, + pFormat, + stuff->mask, + (XID *) (stuff + 1), + client, + &error); + if (!pPicture) + return error; + if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) + return BadAlloc; + return Success; +} + +static int +ProcRenderChangePicture (ClientPtr client) +{ + PicturePtr pPicture; + REQUEST(xRenderChangePictureReq); + int len; + + REQUEST_AT_LEAST_SIZE(xRenderChangePictureReq); + VERIFY_PICTURE (pPicture, stuff->picture, client, DixSetAttrAccess); + + len = client->req_len - bytes_to_int32(sizeof(xRenderChangePictureReq)); + if (Ones(stuff->mask) != len) + return BadLength; + + return ChangePicture (pPicture, stuff->mask, (XID *) (stuff + 1), + (DevUnion *) 0, client); +} + +static int +ProcRenderSetPictureClipRectangles (ClientPtr client) +{ + REQUEST(xRenderSetPictureClipRectanglesReq); + PicturePtr pPicture; + int nr; + + REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq); + VERIFY_PICTURE (pPicture, stuff->picture, client, DixSetAttrAccess); + if (!pPicture->pDrawable) + return BadDrawable; + + nr = (client->req_len << 2) - sizeof(xRenderSetPictureClipRectanglesReq); + if (nr & 4) + return BadLength; + nr >>= 3; + return SetPictureClipRects (pPicture, + stuff->xOrigin, stuff->yOrigin, + nr, (xRectangle *) &stuff[1]); +} + +static int +ProcRenderFreePicture (ClientPtr client) +{ + PicturePtr pPicture; + REQUEST(xRenderFreePictureReq); + + REQUEST_SIZE_MATCH(xRenderFreePictureReq); + + VERIFY_PICTURE (pPicture, stuff->picture, client, DixDestroyAccess); + FreeResource (stuff->picture, RT_NONE); + return Success; +} + +static Bool +PictOpValid (CARD8 op) +{ + if (/*PictOpMinimum <= op && */ op <= PictOpMaximum) + return TRUE; + if (PictOpDisjointMinimum <= op && op <= PictOpDisjointMaximum) + return TRUE; + if (PictOpConjointMinimum <= op && op <= PictOpConjointMaximum) + return TRUE; + if (PictOpBlendMinimum <= op && op <= PictOpBlendMaximum) + return TRUE; + return FALSE; +} + +static int +ProcRenderComposite (ClientPtr client) +{ + PicturePtr pSrc, pMask, pDst; + REQUEST(xRenderCompositeReq); + + REQUEST_SIZE_MATCH(xRenderCompositeReq); + if (!PictOpValid (stuff->op)) + { + client->errorValue = stuff->op; + return BadValue; + } + VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess); + if (!pDst->pDrawable) + return BadDrawable; + VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess); + VERIFY_ALPHA (pMask, stuff->mask, client, DixReadAccess); + if ((pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) || + (pMask && pMask->pDrawable && pDst->pDrawable->pScreen != pMask->pDrawable->pScreen)) + return BadMatch; + CompositePicture (stuff->op, + pSrc, + pMask, + pDst, + stuff->xSrc, + stuff->ySrc, + stuff->xMask, + stuff->yMask, + stuff->xDst, + stuff->yDst, + stuff->width, + stuff->height); + return Success; +} + +static int +ProcRenderScale (ClientPtr client) +{ + return BadImplementation; +} + +static int +ProcRenderTrapezoids (ClientPtr client) +{ + int rc, ntraps; + PicturePtr pSrc, pDst; + PictFormatPtr pFormat; + REQUEST(xRenderTrapezoidsReq); + + REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq); + if (!PictOpValid (stuff->op)) + { + client->errorValue = stuff->op; + return BadValue; + } + VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess); + VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess); + if (!pDst->pDrawable) + return BadDrawable; + if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) + return BadMatch; + if (stuff->maskFormat) + { + rc = dixLookupResourceByType((pointer *)&pFormat, stuff->maskFormat, + PictFormatType, client, DixReadAccess); + if (rc != Success) + return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc; + } + else + pFormat = 0; + ntraps = (client->req_len << 2) - sizeof (xRenderTrapezoidsReq); + if (ntraps % sizeof (xTrapezoid)) + return BadLength; + ntraps /= sizeof (xTrapezoid); + if (ntraps) + CompositeTrapezoids (stuff->op, pSrc, pDst, pFormat, + stuff->xSrc, stuff->ySrc, + ntraps, (xTrapezoid *) &stuff[1]); + return Success; +} + +static int +ProcRenderTriangles (ClientPtr client) +{ + int rc, ntris; + PicturePtr pSrc, pDst; + PictFormatPtr pFormat; + REQUEST(xRenderTrianglesReq); + + REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); + if (!PictOpValid (stuff->op)) + { + client->errorValue = stuff->op; + return BadValue; + } + VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess); + VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess); + if (!pDst->pDrawable) + return BadDrawable; + if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) + return BadMatch; + if (stuff->maskFormat) + { + rc = dixLookupResourceByType((pointer *)&pFormat, stuff->maskFormat, + PictFormatType, client, DixReadAccess); + if (rc != Success) + return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc; + } + else + pFormat = 0; + ntris = (client->req_len << 2) - sizeof (xRenderTrianglesReq); + if (ntris % sizeof (xTriangle)) + return BadLength; + ntris /= sizeof (xTriangle); + if (ntris) + CompositeTriangles (stuff->op, pSrc, pDst, pFormat, + stuff->xSrc, stuff->ySrc, + ntris, (xTriangle *) &stuff[1]); + return Success; +} + +static int +ProcRenderTriStrip (ClientPtr client) +{ + int rc, npoints; + PicturePtr pSrc, pDst; + PictFormatPtr pFormat; + REQUEST(xRenderTrianglesReq); + + REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); + if (!PictOpValid (stuff->op)) + { + client->errorValue = stuff->op; + return BadValue; + } + VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess); + VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess); + if (!pDst->pDrawable) + return BadDrawable; + if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) + return BadMatch; + if (stuff->maskFormat) + { + rc = dixLookupResourceByType((pointer *)&pFormat, stuff->maskFormat, + PictFormatType, client, DixReadAccess); + if (rc != Success) + return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc; + } + else + pFormat = 0; + npoints = ((client->req_len << 2) - sizeof (xRenderTriStripReq)); + if (npoints & 4) + return(BadLength); + npoints >>= 3; + if (npoints >= 3) + CompositeTriStrip (stuff->op, pSrc, pDst, pFormat, + stuff->xSrc, stuff->ySrc, + npoints, (xPointFixed *) &stuff[1]); + return Success; +} + +static int +ProcRenderTriFan (ClientPtr client) +{ + int rc, npoints; + PicturePtr pSrc, pDst; + PictFormatPtr pFormat; + REQUEST(xRenderTrianglesReq); + + REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); + if (!PictOpValid (stuff->op)) + { + client->errorValue = stuff->op; + return BadValue; + } + VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess); + VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess); + if (!pDst->pDrawable) + return BadDrawable; + if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) + return BadMatch; + if (stuff->maskFormat) + { + rc = dixLookupResourceByType((pointer *)&pFormat, stuff->maskFormat, + PictFormatType, client, DixReadAccess); + if (rc != Success) + return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc; + } + else + pFormat = 0; + npoints = ((client->req_len << 2) - sizeof (xRenderTriStripReq)); + if (npoints & 4) + return(BadLength); + npoints >>= 3; + if (npoints >= 3) + CompositeTriFan (stuff->op, pSrc, pDst, pFormat, + stuff->xSrc, stuff->ySrc, + npoints, (xPointFixed *) &stuff[1]); + return Success; +} + +static int +ProcRenderColorTrapezoids (ClientPtr client) +{ + return BadImplementation; +} + +static int +ProcRenderColorTriangles (ClientPtr client) +{ + return BadImplementation; +} + +static int +ProcRenderTransform (ClientPtr client) +{ + return BadImplementation; +} + +static int +ProcRenderCreateGlyphSet (ClientPtr client) +{ + GlyphSetPtr glyphSet; + PictFormatPtr format; + int rc, f; + REQUEST(xRenderCreateGlyphSetReq); + + REQUEST_SIZE_MATCH(xRenderCreateGlyphSetReq); + + LEGAL_NEW_RESOURCE(stuff->gsid, client); + rc = dixLookupResourceByType((pointer *)&format, stuff->format, + PictFormatType, client, DixReadAccess); + if (rc != Success) + return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc; + + switch (format->depth) { + case 1: + f = GlyphFormat1; + break; + case 4: + f = GlyphFormat4; + break; + case 8: + f = GlyphFormat8; + break; + case 16: + f = GlyphFormat16; + break; + case 32: + f = GlyphFormat32; + break; + default: + return BadMatch; + } + if (format->type != PictTypeDirect) + return BadMatch; + glyphSet = AllocateGlyphSet (f, format); + if (!glyphSet) + return BadAlloc; + /* security creation/labeling check */ + rc = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->gsid, GlyphSetType, + glyphSet, RT_NONE, NULL, DixCreateAccess); + if (rc != Success) + return rc; + if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet)) + return BadAlloc; + return Success; +} + +static int +ProcRenderReferenceGlyphSet (ClientPtr client) +{ + GlyphSetPtr glyphSet; + int rc; + REQUEST(xRenderReferenceGlyphSetReq); + + REQUEST_SIZE_MATCH(xRenderReferenceGlyphSetReq); + + LEGAL_NEW_RESOURCE(stuff->gsid, client); + + rc = dixLookupResourceByType((pointer *)&glyphSet, stuff->existing, GlyphSetType, + client, DixGetAttrAccess); + if (rc != Success) + { + client->errorValue = stuff->existing; + return (rc == BadValue) ? RenderErrBase + BadGlyphSet : rc; + } + glyphSet->refcnt++; + if (!AddResource (stuff->gsid, GlyphSetType, (pointer)glyphSet)) + return BadAlloc; + return Success; +} + +#define NLOCALDELTA 64 +#define NLOCALGLYPH 256 + +static int +ProcRenderFreeGlyphSet (ClientPtr client) +{ + GlyphSetPtr glyphSet; + int rc; + REQUEST(xRenderFreeGlyphSetReq); + + REQUEST_SIZE_MATCH(xRenderFreeGlyphSetReq); + rc = dixLookupResourceByType((pointer *)&glyphSet, stuff->glyphset, GlyphSetType, + client, DixDestroyAccess); + if (rc != Success) + { + client->errorValue = stuff->glyphset; + return (rc == BadValue) ? RenderErrBase + BadGlyphSet : rc; + } + FreeResource (stuff->glyphset, RT_NONE); + return Success; +} + +typedef struct _GlyphNew { + Glyph id; + GlyphPtr glyph; + Bool found; + unsigned char sha1[20]; +} GlyphNewRec, *GlyphNewPtr; + +#define NeedsComponent(f) (PICT_FORMAT_A(f) != 0 && PICT_FORMAT_RGB(f) != 0) + +static int +ProcRenderAddGlyphs (ClientPtr client) +{ + GlyphSetPtr glyphSet; + REQUEST(xRenderAddGlyphsReq); + GlyphNewRec glyphsLocal[NLOCALGLYPH]; + GlyphNewPtr glyphsBase, glyphs, glyph_new; + int remain, nglyphs; + CARD32 *gids; + xGlyphInfo *gi; + CARD8 *bits; + unsigned int size; + int err; + int i, screen; + PicturePtr pSrc = NULL, pDst = NULL; + PixmapPtr pSrcPix = NULL, pDstPix = NULL; + CARD32 component_alpha; + + REQUEST_AT_LEAST_SIZE(xRenderAddGlyphsReq); + err = dixLookupResourceByType((pointer *)&glyphSet, stuff->glyphset, GlyphSetType, + client, DixAddAccess); + if (err != Success) + { + client->errorValue = stuff->glyphset; + return (err == BadValue) ? RenderErrBase + BadGlyphSet : err; + } + + err = BadAlloc; + nglyphs = stuff->nglyphs; + if (nglyphs > UINT32_MAX / sizeof(GlyphNewRec)) + return BadAlloc; + + component_alpha = NeedsComponent (glyphSet->format->format); + + if (nglyphs <= NLOCALGLYPH) { + memset (glyphsLocal, 0, sizeof (glyphsLocal)); + glyphsBase = glyphsLocal; + } + else + { + glyphsBase = (GlyphNewPtr)calloc(nglyphs, sizeof (GlyphNewRec)); + if (!glyphsBase) + return BadAlloc; + } + + remain = (client->req_len << 2) - sizeof (xRenderAddGlyphsReq); + + glyphs = glyphsBase; + + gids = (CARD32 *) (stuff + 1); + gi = (xGlyphInfo *) (gids + nglyphs); + bits = (CARD8 *) (gi + nglyphs); + remain -= (sizeof (CARD32) + sizeof (xGlyphInfo)) * nglyphs; + for (i = 0; i < nglyphs; i++) + { + size_t padded_width; + glyph_new = &glyphs[i]; + + padded_width = PixmapBytePad (gi[i].width, + glyphSet->format->depth); + + if (gi[i].height && padded_width > (UINT32_MAX - sizeof(GlyphRec))/gi[i].height) + break; + + size = gi[i].height * padded_width; + if (remain < size) + break; + + err = HashGlyph (&gi[i], bits, size, glyph_new->sha1); + if (err) + goto bail; + + glyph_new->glyph = FindGlyphByHash (glyph_new->sha1, + glyphSet->fdepth); + + if (glyph_new->glyph && glyph_new->glyph != DeletedGlyph) + { + glyph_new->found = TRUE; + } + else + { + GlyphPtr glyph; + + glyph_new->found = FALSE; + glyph_new->glyph = glyph = AllocateGlyph (&gi[i], glyphSet->fdepth); + if (! glyph) + { + err = BadAlloc; + goto bail; + } + + for (screen = 0; screen < screenInfo.numScreens; screen++) + { + int width = gi[i].width; + int height = gi[i].height; + int depth = glyphSet->format->depth; + ScreenPtr pScreen; + int error; + + /* Skip work if it's invisibly small anyway */ + if (!width || !height) + break; + + pScreen = screenInfo.screens[screen]; + pSrcPix = GetScratchPixmapHeader (pScreen, + width, height, + depth, depth, + -1, bits); + if (! pSrcPix) + { + err = BadAlloc; + goto bail; + } + + pSrc = CreatePicture (0, &pSrcPix->drawable, + glyphSet->format, 0, NULL, + serverClient, &error); + if (! pSrc) + { + err = BadAlloc; + goto bail; + } + + pDstPix = (pScreen->CreatePixmap) (pScreen, + width, height, depth, + CREATE_PIXMAP_USAGE_GLYPH_PICTURE); + + if (!pDstPix) + { + err = BadAlloc; + goto bail; + } + + GlyphPicture (glyph)[screen] = pDst = + CreatePicture (0, &pDstPix->drawable, + glyphSet->format, + CPComponentAlpha, &component_alpha, + serverClient, &error); + + /* The picture takes a reference to the pixmap, so we + drop ours. */ + (pScreen->DestroyPixmap) (pDstPix); + pDstPix = NULL; + + if (! pDst) + { + err = BadAlloc; + goto bail; + } + + CompositePicture (PictOpSrc, + pSrc, + None, + pDst, + 0, 0, + 0, 0, + 0, 0, + width, height); + + FreePicture ((pointer) pSrc, 0); + pSrc = NULL; + FreeScratchPixmapHeader (pSrcPix); + pSrcPix = NULL; + } + + memcpy (glyph_new->glyph->sha1, glyph_new->sha1, 20); + } + + glyph_new->id = gids[i]; + + if (size & 3) + size += 4 - (size & 3); + bits += size; + remain -= size; + } + if (remain || i < nglyphs) + { + err = BadLength; + goto bail; + } + if (!ResizeGlyphSet (glyphSet, nglyphs)) + { + err = BadAlloc; + goto bail; + } + for (i = 0; i < nglyphs; i++) + AddGlyph (glyphSet, glyphs[i].glyph, glyphs[i].id); + + if (glyphsBase != glyphsLocal) + free(glyphsBase); + return Success; +bail: + if (pSrc) + FreePicture ((pointer) pSrc, 0); + if (pSrcPix) + FreeScratchPixmapHeader (pSrcPix); + for (i = 0; i < nglyphs; i++) + if (glyphs[i].glyph && ! glyphs[i].found) + free(glyphs[i].glyph); + if (glyphsBase != glyphsLocal) + free(glyphsBase); + return err; +} + +static int +ProcRenderAddGlyphsFromPicture (ClientPtr client) +{ + return BadImplementation; +} + +static int +ProcRenderFreeGlyphs (ClientPtr client) +{ + REQUEST(xRenderFreeGlyphsReq); + GlyphSetPtr glyphSet; + int rc, nglyph; + CARD32 *gids; + CARD32 glyph; + + REQUEST_AT_LEAST_SIZE(xRenderFreeGlyphsReq); + rc = dixLookupResourceByType((pointer *)&glyphSet, stuff->glyphset, GlyphSetType, + client, DixRemoveAccess); + if (rc != Success) + { + client->errorValue = stuff->glyphset; + return (rc == BadValue) ? RenderErrBase + BadGlyphSet : rc; + } + nglyph = bytes_to_int32((client->req_len << 2) - sizeof (xRenderFreeGlyphsReq)); + gids = (CARD32 *) (stuff + 1); + while (nglyph-- > 0) + { + glyph = *gids++; + if (!DeleteGlyph (glyphSet, glyph)) + { + client->errorValue = glyph; + return RenderErrBase + BadGlyph; + } + } + return Success; +} + +static int +ProcRenderCompositeGlyphs (ClientPtr client) +{ + GlyphSetPtr glyphSet; + GlyphSet gs; + PicturePtr pSrc, pDst; + PictFormatPtr pFormat; + GlyphListRec listsLocal[NLOCALDELTA]; + GlyphListPtr lists, listsBase; + GlyphPtr glyphsLocal[NLOCALGLYPH]; + Glyph glyph; + GlyphPtr *glyphs, *glyphsBase; + xGlyphElt *elt; + CARD8 *buffer, *end; + int nglyph; + int nlist; + int space; + int size; + int rc, n; + + REQUEST(xRenderCompositeGlyphsReq); + + REQUEST_AT_LEAST_SIZE(xRenderCompositeGlyphsReq); + + switch (stuff->renderReqType) { + default: size = 1; break; + case X_RenderCompositeGlyphs16: size = 2; break; + case X_RenderCompositeGlyphs32: size = 4; break; + } + + if (!PictOpValid (stuff->op)) + { + client->errorValue = stuff->op; + return BadValue; + } + VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess); + VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess); + if (!pDst->pDrawable) + return BadDrawable; + if (pSrc->pDrawable && pSrc->pDrawable->pScreen != pDst->pDrawable->pScreen) + return BadMatch; + if (stuff->maskFormat) + { + rc = dixLookupResourceByType((pointer *)&pFormat, stuff->maskFormat, + PictFormatType, client, DixReadAccess); + if (rc != Success) + return (rc == BadValue) ? RenderErrBase + BadPictFormat : rc; + } + else + pFormat = 0; + + rc = dixLookupResourceByType((pointer *)&glyphSet, stuff->glyphset, + GlyphSetType, client, DixUseAccess); + if (rc != Success) + return (rc == BadValue) ? RenderErrBase + BadGlyphSet : rc; + + buffer = (CARD8 *) (stuff + 1); + end = (CARD8 *) stuff + (client->req_len << 2); + nglyph = 0; + nlist = 0; + while (buffer + sizeof (xGlyphElt) < end) + { + elt = (xGlyphElt *) buffer; + buffer += sizeof (xGlyphElt); + + if (elt->len == 0xff) + { + buffer += 4; + } + else + { + nlist++; + nglyph += elt->len; + space = size * elt->len; + if (space & 3) + space += 4 - (space & 3); + buffer += space; + } + } + if (nglyph <= NLOCALGLYPH) + glyphsBase = glyphsLocal; + else + { + glyphsBase = (GlyphPtr *) malloc(nglyph * sizeof (GlyphPtr)); + if (!glyphsBase) + return BadAlloc; + } + if (nlist <= NLOCALDELTA) + listsBase = listsLocal; + else + { + listsBase = (GlyphListPtr) malloc(nlist * sizeof (GlyphListRec)); + if (!listsBase) + return BadAlloc; + } + buffer = (CARD8 *) (stuff + 1); + glyphs = glyphsBase; + lists = listsBase; + while (buffer + sizeof (xGlyphElt) < end) + { + elt = (xGlyphElt *) buffer; + buffer += sizeof (xGlyphElt); + + if (elt->len == 0xff) + { + if (buffer + sizeof (GlyphSet) < end) + { + memcpy(&gs, buffer, sizeof(GlyphSet)); + rc = dixLookupResourceByType((pointer *)&glyphSet, gs, + GlyphSetType, client, + DixUseAccess); + if (rc != Success) + { + if (glyphsBase != glyphsLocal) + free(glyphsBase); + if (listsBase != listsLocal) + free(listsBase); + return (rc == BadValue) ? RenderErrBase + BadGlyphSet : rc; + } + } + buffer += 4; + } + else + { + lists->xOff = elt->deltax; + lists->yOff = elt->deltay; + lists->format = glyphSet->format; + lists->len = 0; + n = elt->len; + while (n--) + { + if (buffer + size <= end) + { + switch (size) { + case 1: + glyph = *((CARD8 *)buffer); break; + case 2: + glyph = *((CARD16 *)buffer); break; + case 4: + default: + glyph = *((CARD32 *)buffer); break; + } + if ((*glyphs = FindGlyph (glyphSet, glyph))) + { + lists->len++; + glyphs++; + } + } + buffer += size; + } + space = size * elt->len; + if (space & 3) + buffer += 4 - (space & 3); + lists++; + } + } + if (buffer > end) + return BadLength; + + CompositeGlyphs (stuff->op, + pSrc, + pDst, + pFormat, + stuff->xSrc, + stuff->ySrc, + nlist, + listsBase, + glyphsBase); + + if (glyphsBase != glyphsLocal) + free(glyphsBase); + if (listsBase != listsLocal) + free(listsBase); + + return Success; +} + +static int +ProcRenderFillRectangles (ClientPtr client) +{ + PicturePtr pDst; + int things; + REQUEST(xRenderFillRectanglesReq); + + REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq); + if (!PictOpValid (stuff->op)) + { + client->errorValue = stuff->op; + return BadValue; + } + VERIFY_PICTURE (pDst, stuff->dst, client, DixWriteAccess); + if (!pDst->pDrawable) + return BadDrawable; + + things = (client->req_len << 2) - sizeof(xRenderFillRectanglesReq); + if (things & 4) + return(BadLength); + things >>= 3; + + CompositeRects (stuff->op, + pDst, + &stuff->color, + things, + (xRectangle *) &stuff[1]); + + return Success; +} + +static void +RenderSetBit (unsigned char *line, int x, int bit) +{ + unsigned char mask; + + if (screenInfo.bitmapBitOrder == LSBFirst) + mask = (1 << (x & 7)); + else + mask = (0x80 >> (x & 7)); + /* XXX assumes byte order is host byte order */ + line += (x >> 3); + if (bit) + *line |= mask; + else + *line &= ~mask; +} + +#define DITHER_DIM 2 + +static CARD32 orderedDither[DITHER_DIM][DITHER_DIM] = { + { 1, 3, }, + { 4, 2, }, +}; + +#define DITHER_SIZE ((sizeof orderedDither / sizeof orderedDither[0][0]) + 1) + +static int +ProcRenderCreateCursor (ClientPtr client) +{ + REQUEST(xRenderCreateCursorReq); + PicturePtr pSrc; + ScreenPtr pScreen; + unsigned short width, height; + CARD32 *argbbits, *argb; + unsigned char *srcbits, *srcline; + unsigned char *mskbits, *mskline; + int stride; + int x, y; + int nbytes_mono; + CursorMetricRec cm; + CursorPtr pCursor; + CARD32 twocolor[3]; + int rc, ncolor; + + REQUEST_SIZE_MATCH (xRenderCreateCursorReq); + LEGAL_NEW_RESOURCE(stuff->cid, client); + + VERIFY_PICTURE (pSrc, stuff->src, client, DixReadAccess); + if (!pSrc->pDrawable) + return BadDrawable; + pScreen = pSrc->pDrawable->pScreen; + width = pSrc->pDrawable->width; + height = pSrc->pDrawable->height; + if (height && width > UINT32_MAX/(height*sizeof(CARD32))) + return BadAlloc; + if ( stuff->x > width + || stuff->y > height ) + return (BadMatch); + argbbits = malloc(width * height * sizeof (CARD32)); + if (!argbbits) + return (BadAlloc); + + stride = BitmapBytePad(width); + nbytes_mono = stride*height; + srcbits = calloc(1, nbytes_mono); + if (!srcbits) + { + free(argbbits); + return (BadAlloc); + } + mskbits = calloc(1, nbytes_mono); + if (!mskbits) + { + free(argbbits); + free(srcbits); + return (BadAlloc); + } + + if (pSrc->format == PICT_a8r8g8b8) + { + (*pScreen->GetImage) (pSrc->pDrawable, + 0, 0, width, height, ZPixmap, + 0xffffffff, (pointer) argbbits); + } + else + { + PixmapPtr pPixmap; + PicturePtr pPicture; + PictFormatPtr pFormat; + int error; + + pFormat = PictureMatchFormat (pScreen, 32, PICT_a8r8g8b8); + if (!pFormat) + { + free(argbbits); + free(srcbits); + free(mskbits); + return (BadImplementation); + } + pPixmap = (*pScreen->CreatePixmap) (pScreen, width, height, 32, + CREATE_PIXMAP_USAGE_SCRATCH); + if (!pPixmap) + { + free(argbbits); + free(srcbits); + free(mskbits); + return (BadAlloc); + } + pPicture = CreatePicture (0, &pPixmap->drawable, pFormat, 0, 0, + client, &error); + if (!pPicture) + { + free(argbbits); + free(srcbits); + free(mskbits); + return error; + } + (*pScreen->DestroyPixmap) (pPixmap); + CompositePicture (PictOpSrc, + pSrc, 0, pPicture, + 0, 0, 0, 0, 0, 0, width, height); + (*pScreen->GetImage) (pPicture->pDrawable, + 0, 0, width, height, ZPixmap, + 0xffffffff, (pointer) argbbits); + FreePicture (pPicture, 0); + } + /* + * Check whether the cursor can be directly supported by + * the core cursor code + */ + ncolor = 0; + argb = argbbits; + for (y = 0; ncolor <= 2 && y < height; y++) + { + for (x = 0; ncolor <= 2 && x < width; x++) + { + CARD32 p = *argb++; + CARD32 a = (p >> 24); + + if (a == 0) /* transparent */ + continue; + if (a == 0xff) /* opaque */ + { + int n; + for (n = 0; n < ncolor; n++) + if (p == twocolor[n]) + break; + if (n == ncolor) + twocolor[ncolor++] = p; + } + else + ncolor = 3; + } + } + + /* + * Convert argb image to two plane cursor + */ + srcline = srcbits; + mskline = mskbits; + argb = argbbits; + for (y = 0; y < height; y++) + { + for (x = 0; x < width; x++) + { + CARD32 p = *argb++; + + if (ncolor <= 2) + { + CARD32 a = ((p >> 24)); + + RenderSetBit (mskline, x, a != 0); + RenderSetBit (srcline, x, a != 0 && p == twocolor[0]); + } + else + { + CARD32 a = ((p >> 24) * DITHER_SIZE + 127) / 255; + CARD32 i = ((CvtR8G8B8toY15(p) >> 7) * DITHER_SIZE + 127) / 255; + CARD32 d = orderedDither[y&(DITHER_DIM-1)][x&(DITHER_DIM-1)]; + /* Set mask from dithered alpha value */ + RenderSetBit(mskline, x, a > d); + /* Set src from dithered intensity value */ + RenderSetBit(srcline, x, a > d && i <= d); + } + } + srcline += stride; + mskline += stride; + } + /* + * Dither to white and black if the cursor has more than two colors + */ + if (ncolor > 2) + { + twocolor[0] = 0xff000000; + twocolor[1] = 0xffffffff; + } + else + { + free(argbbits); + argbbits = 0; + } + +#define GetByte(p,s) (((p) >> (s)) & 0xff) +#define GetColor(p,s) (GetByte(p,s) | (GetByte(p,s) << 8)) + + cm.width = width; + cm.height = height; + cm.xhot = stuff->x; + cm.yhot = stuff->y; + rc = AllocARGBCursor(srcbits, mskbits, argbbits, &cm, + GetColor(twocolor[0], 16), + GetColor(twocolor[0], 8), + GetColor(twocolor[0], 0), + GetColor(twocolor[1], 16), + GetColor(twocolor[1], 8), + GetColor(twocolor[1], 0), + &pCursor, client, stuff->cid); + if (rc != Success) + return rc; + if (!AddResource(stuff->cid, RT_CURSOR, (pointer)pCursor)) + return BadAlloc; + + return Success; +} + +static int +ProcRenderSetPictureTransform (ClientPtr client) +{ + REQUEST(xRenderSetPictureTransformReq); + PicturePtr pPicture; + + REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq); + VERIFY_PICTURE (pPicture, stuff->picture, client, DixSetAttrAccess); + return SetPictureTransform (pPicture, (PictTransform *) &stuff->transform); +} + +static int +ProcRenderQueryFilters (ClientPtr client) +{ + REQUEST (xRenderQueryFiltersReq); + DrawablePtr pDrawable; + xRenderQueryFiltersReply *reply; + int nbytesName; + int nnames; + ScreenPtr pScreen; + PictureScreenPtr ps; + int i, j, len, total_bytes, rc; + INT16 *aliases; + char *names; + + REQUEST_SIZE_MATCH(xRenderQueryFiltersReq); + rc = dixLookupDrawable(&pDrawable, stuff->drawable, client, 0, + DixGetAttrAccess); + if (rc != Success) + return rc; + + pScreen = pDrawable->pScreen; + nbytesName = 0; + nnames = 0; + ps = GetPictureScreenIfSet(pScreen); + if (ps) + { + for (i = 0; i < ps->nfilters; i++) + nbytesName += 1 + strlen (ps->filters[i].name); + for (i = 0; i < ps->nfilterAliases; i++) + nbytesName += 1 + strlen (ps->filterAliases[i].alias); + nnames = ps->nfilters + ps->nfilterAliases; + } + len = ((nnames + 1) >> 1) + bytes_to_int32(nbytesName); + total_bytes = sizeof (xRenderQueryFiltersReply) + (len << 2); + reply = (xRenderQueryFiltersReply *) malloc(total_bytes); + if (!reply) + return BadAlloc; + aliases = (INT16 *) (reply + 1); + names = (char *) (aliases + ((nnames + 1) & ~1)); + + reply->type = X_Reply; + reply->sequenceNumber = client->sequence; + reply->length = len; + reply->numAliases = nnames; + reply->numFilters = nnames; + if (ps) + { + + /* fill in alias values */ + for (i = 0; i < ps->nfilters; i++) + aliases[i] = FilterAliasNone; + for (i = 0; i < ps->nfilterAliases; i++) + { + for (j = 0; j < ps->nfilters; j++) + if (ps->filterAliases[i].filter_id == ps->filters[j].id) + break; + if (j == ps->nfilters) + { + for (j = 0; j < ps->nfilterAliases; j++) + if (ps->filterAliases[i].filter_id == + ps->filterAliases[j].alias_id) + { + break; + } + if (j == ps->nfilterAliases) + j = FilterAliasNone; + else + j = j + ps->nfilters; + } + aliases[i + ps->nfilters] = j; + } + + /* fill in filter names */ + for (i = 0; i < ps->nfilters; i++) + { + j = strlen (ps->filters[i].name); + *names++ = j; + strncpy (names, ps->filters[i].name, j); + names += j; + } + + /* fill in filter alias names */ + for (i = 0; i < ps->nfilterAliases; i++) + { + j = strlen (ps->filterAliases[i].alias); + *names++ = j; + strncpy (names, ps->filterAliases[i].alias, j); + names += j; + } + } + + if (client->swapped) + { + register int n; + + for (i = 0; i < reply->numAliases; i++) + { + swaps (&aliases[i], n); + } + swaps(&reply->sequenceNumber, n); + swapl(&reply->length, n); + swapl(&reply->numAliases, n); + swapl(&reply->numFilters, n); + } + WriteToClient(client, total_bytes, (char *) reply); + free(reply); + + return Success; +} + +static int +ProcRenderSetPictureFilter (ClientPtr client) +{ + REQUEST (xRenderSetPictureFilterReq); + PicturePtr pPicture; + int result; + xFixed *params; + int nparams; + char *name; + + REQUEST_AT_LEAST_SIZE (xRenderSetPictureFilterReq); + VERIFY_PICTURE (pPicture, stuff->picture, client, DixSetAttrAccess); + name = (char *) (stuff + 1); + params = (xFixed *) (name + pad_to_int32(stuff->nbytes)); + nparams = ((xFixed *) stuff + client->req_len) - params; + result = SetPictureFilter (pPicture, name, stuff->nbytes, params, nparams); + return result; +} + +static int +ProcRenderCreateAnimCursor (ClientPtr client) +{ + REQUEST(xRenderCreateAnimCursorReq); + CursorPtr *cursors; + CARD32 *deltas; + CursorPtr pCursor; + int ncursor; + xAnimCursorElt *elt; + int i; + int ret; + + REQUEST_AT_LEAST_SIZE(xRenderCreateAnimCursorReq); + LEGAL_NEW_RESOURCE(stuff->cid, client); + if (client->req_len & 1) + return BadLength; + ncursor = (client->req_len - (bytes_to_int32(sizeof(xRenderCreateAnimCursorReq)))) >> 1; + cursors = malloc(ncursor * (sizeof (CursorPtr) + sizeof (CARD32))); + if (!cursors) + return BadAlloc; + deltas = (CARD32 *) (cursors + ncursor); + elt = (xAnimCursorElt *) (stuff + 1); + for (i = 0; i < ncursor; i++) + { + ret = dixLookupResourceByType((pointer *)(cursors + i), elt->cursor, + RT_CURSOR, client, DixReadAccess); + if (ret != Success) + { + free(cursors); + return (ret == BadValue) ? BadCursor : ret; + } + deltas[i] = elt->delay; + elt++; + } + ret = AnimCursorCreate (cursors, deltas, ncursor, &pCursor, client, + stuff->cid); + free(cursors); + if (ret != Success) + return ret; + + if (AddResource (stuff->cid, RT_CURSOR, (pointer)pCursor)) + return Success; + return BadAlloc; +} + +static int +ProcRenderAddTraps (ClientPtr client) +{ + int ntraps; + PicturePtr pPicture; + REQUEST(xRenderAddTrapsReq); + + REQUEST_AT_LEAST_SIZE(xRenderAddTrapsReq); + VERIFY_PICTURE (pPicture, stuff->picture, client, DixWriteAccess); + if (!pPicture->pDrawable) + return BadDrawable; + ntraps = (client->req_len << 2) - sizeof (xRenderAddTrapsReq); + if (ntraps % sizeof (xTrap)) + return BadLength; + ntraps /= sizeof (xTrap); + if (ntraps) + AddTraps (pPicture, + stuff->xOff, stuff->yOff, + ntraps, (xTrap *) &stuff[1]); + return Success; +} + +static int ProcRenderCreateSolidFill(ClientPtr client) +{ + PicturePtr pPicture; + int error = 0; + REQUEST(xRenderCreateSolidFillReq); + + REQUEST_AT_LEAST_SIZE(xRenderCreateSolidFillReq); + + LEGAL_NEW_RESOURCE(stuff->pid, client); + + pPicture = CreateSolidPicture(stuff->pid, &stuff->color, &error); + if (!pPicture) + return error; + /* security creation/labeling check */ + error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType, + pPicture, RT_NONE, NULL, DixCreateAccess); + if (error != Success) + return error; + if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) + return BadAlloc; + return Success; +} + +static int ProcRenderCreateLinearGradient (ClientPtr client) +{ + PicturePtr pPicture; + int len; + int error = 0; + xFixed *stops; + xRenderColor *colors; + REQUEST(xRenderCreateLinearGradientReq); + + REQUEST_AT_LEAST_SIZE(xRenderCreateLinearGradientReq); + + LEGAL_NEW_RESOURCE(stuff->pid, client); + + len = (client->req_len << 2) - sizeof(xRenderCreateLinearGradientReq); + if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor))) + return BadLength; + if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) + return BadLength; + + stops = (xFixed *)(stuff + 1); + colors = (xRenderColor *)(stops + stuff->nStops); + + pPicture = CreateLinearGradientPicture (stuff->pid, &stuff->p1, &stuff->p2, + stuff->nStops, stops, colors, &error); + if (!pPicture) + return error; + /* security creation/labeling check */ + error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType, + pPicture, RT_NONE, NULL, DixCreateAccess); + if (error != Success) + return error; + if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) + return BadAlloc; + return Success; +} + +static int ProcRenderCreateRadialGradient (ClientPtr client) +{ + PicturePtr pPicture; + int len; + int error = 0; + xFixed *stops; + xRenderColor *colors; + REQUEST(xRenderCreateRadialGradientReq); + + REQUEST_AT_LEAST_SIZE(xRenderCreateRadialGradientReq); + + LEGAL_NEW_RESOURCE(stuff->pid, client); + + len = (client->req_len << 2) - sizeof(xRenderCreateRadialGradientReq); + if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) + return BadLength; + + stops = (xFixed *)(stuff + 1); + colors = (xRenderColor *)(stops + stuff->nStops); + + pPicture = CreateRadialGradientPicture (stuff->pid, &stuff->inner, &stuff->outer, + stuff->inner_radius, stuff->outer_radius, + stuff->nStops, stops, colors, &error); + if (!pPicture) + return error; + /* security creation/labeling check */ + error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType, + pPicture, RT_NONE, NULL, DixCreateAccess); + if (error != Success) + return error; + if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) + return BadAlloc; + return Success; +} + +static int ProcRenderCreateConicalGradient (ClientPtr client) +{ + PicturePtr pPicture; + int len; + int error = 0; + xFixed *stops; + xRenderColor *colors; + REQUEST(xRenderCreateConicalGradientReq); + + REQUEST_AT_LEAST_SIZE(xRenderCreateConicalGradientReq); + + LEGAL_NEW_RESOURCE(stuff->pid, client); + + len = (client->req_len << 2) - sizeof(xRenderCreateConicalGradientReq); + if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) + return BadLength; + + stops = (xFixed *)(stuff + 1); + colors = (xRenderColor *)(stops + stuff->nStops); + + pPicture = CreateConicalGradientPicture (stuff->pid, &stuff->center, stuff->angle, + stuff->nStops, stops, colors, &error); + if (!pPicture) + return error; + /* security creation/labeling check */ + error = XaceHook(XACE_RESOURCE_ACCESS, client, stuff->pid, PictureType, + pPicture, RT_NONE, NULL, DixCreateAccess); + if (error != Success) + return error; + if (!AddResource (stuff->pid, PictureType, (pointer)pPicture)) + return BadAlloc; + return Success; +} + + +static int +ProcRenderDispatch (ClientPtr client) +{ + REQUEST(xReq); + + if (stuff->data < RenderNumberRequests) + return (*ProcRenderVector[stuff->data]) (client); + else + return BadRequest; +} + +static int +SProcRenderQueryVersion (ClientPtr client) +{ + register int n; + REQUEST(xRenderQueryVersionReq); + + swaps(&stuff->length, n); + swapl(&stuff->majorVersion, n); + swapl(&stuff->minorVersion, n); + return (*ProcRenderVector[stuff->renderReqType])(client); +} + +static int +SProcRenderQueryPictFormats (ClientPtr client) +{ + register int n; + REQUEST(xRenderQueryPictFormatsReq); + swaps(&stuff->length, n); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderQueryPictIndexValues (ClientPtr client) +{ + register int n; + REQUEST(xRenderQueryPictIndexValuesReq); + swaps(&stuff->length, n); + swapl(&stuff->format, n); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderQueryDithers (ClientPtr client) +{ + return BadImplementation; +} + +static int +SProcRenderCreatePicture (ClientPtr client) +{ + register int n; + REQUEST(xRenderCreatePictureReq); + swaps(&stuff->length, n); + swapl(&stuff->pid, n); + swapl(&stuff->drawable, n); + swapl(&stuff->format, n); + swapl(&stuff->mask, n); + SwapRestL(stuff); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderChangePicture (ClientPtr client) +{ + register int n; + REQUEST(xRenderChangePictureReq); + swaps(&stuff->length, n); + swapl(&stuff->picture, n); + swapl(&stuff->mask, n); + SwapRestL(stuff); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderSetPictureClipRectangles (ClientPtr client) +{ + register int n; + REQUEST(xRenderSetPictureClipRectanglesReq); + swaps(&stuff->length, n); + swapl(&stuff->picture, n); + swaps(&stuff->xOrigin, n); + swaps(&stuff->yOrigin, n); + SwapRestS(stuff); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderFreePicture (ClientPtr client) +{ + register int n; + REQUEST(xRenderFreePictureReq); + swaps(&stuff->length, n); + swapl(&stuff->picture, n); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderComposite (ClientPtr client) +{ + register int n; + REQUEST(xRenderCompositeReq); + swaps(&stuff->length, n); + swapl(&stuff->src, n); + swapl(&stuff->mask, n); + swapl(&stuff->dst, n); + swaps(&stuff->xSrc, n); + swaps(&stuff->ySrc, n); + swaps(&stuff->xMask, n); + swaps(&stuff->yMask, n); + swaps(&stuff->xDst, n); + swaps(&stuff->yDst, n); + swaps(&stuff->width, n); + swaps(&stuff->height, n); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderScale (ClientPtr client) +{ + register int n; + REQUEST(xRenderScaleReq); + swaps(&stuff->length, n); + swapl(&stuff->src, n); + swapl(&stuff->dst, n); + swapl(&stuff->colorScale, n); + swapl(&stuff->alphaScale, n); + swaps(&stuff->xSrc, n); + swaps(&stuff->ySrc, n); + swaps(&stuff->xDst, n); + swaps(&stuff->yDst, n); + swaps(&stuff->width, n); + swaps(&stuff->height, n); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderTrapezoids (ClientPtr client) +{ + register int n; + REQUEST(xRenderTrapezoidsReq); + + REQUEST_AT_LEAST_SIZE(xRenderTrapezoidsReq); + swaps (&stuff->length, n); + swapl (&stuff->src, n); + swapl (&stuff->dst, n); + swapl (&stuff->maskFormat, n); + swaps (&stuff->xSrc, n); + swaps (&stuff->ySrc, n); + SwapRestL(stuff); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderTriangles (ClientPtr client) +{ + register int n; + REQUEST(xRenderTrianglesReq); + + REQUEST_AT_LEAST_SIZE(xRenderTrianglesReq); + swaps (&stuff->length, n); + swapl (&stuff->src, n); + swapl (&stuff->dst, n); + swapl (&stuff->maskFormat, n); + swaps (&stuff->xSrc, n); + swaps (&stuff->ySrc, n); + SwapRestL(stuff); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderTriStrip (ClientPtr client) +{ + register int n; + REQUEST(xRenderTriStripReq); + + REQUEST_AT_LEAST_SIZE(xRenderTriStripReq); + swaps (&stuff->length, n); + swapl (&stuff->src, n); + swapl (&stuff->dst, n); + swapl (&stuff->maskFormat, n); + swaps (&stuff->xSrc, n); + swaps (&stuff->ySrc, n); + SwapRestL(stuff); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderTriFan (ClientPtr client) +{ + register int n; + REQUEST(xRenderTriFanReq); + + REQUEST_AT_LEAST_SIZE(xRenderTriFanReq); + swaps (&stuff->length, n); + swapl (&stuff->src, n); + swapl (&stuff->dst, n); + swapl (&stuff->maskFormat, n); + swaps (&stuff->xSrc, n); + swaps (&stuff->ySrc, n); + SwapRestL(stuff); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderColorTrapezoids (ClientPtr client) +{ + return BadImplementation; +} + +static int +SProcRenderColorTriangles (ClientPtr client) +{ + return BadImplementation; +} + +static int +SProcRenderTransform (ClientPtr client) +{ + return BadImplementation; +} + +static int +SProcRenderCreateGlyphSet (ClientPtr client) +{ + register int n; + REQUEST(xRenderCreateGlyphSetReq); + swaps(&stuff->length, n); + swapl(&stuff->gsid, n); + swapl(&stuff->format, n); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderReferenceGlyphSet (ClientPtr client) +{ + register int n; + REQUEST(xRenderReferenceGlyphSetReq); + swaps(&stuff->length, n); + swapl(&stuff->gsid, n); + swapl(&stuff->existing, n); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderFreeGlyphSet (ClientPtr client) +{ + register int n; + REQUEST(xRenderFreeGlyphSetReq); + swaps(&stuff->length, n); + swapl(&stuff->glyphset, n); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderAddGlyphs (ClientPtr client) +{ + register int n; + register int i; + CARD32 *gids; + void *end; + xGlyphInfo *gi; + REQUEST(xRenderAddGlyphsReq); + swaps(&stuff->length, n); + swapl(&stuff->glyphset, n); + swapl(&stuff->nglyphs, n); + if (stuff->nglyphs & 0xe0000000) + return BadLength; + end = (CARD8 *) stuff + (client->req_len << 2); + gids = (CARD32 *) (stuff + 1); + gi = (xGlyphInfo *) (gids + stuff->nglyphs); + if ((char *) end - (char *) (gids + stuff->nglyphs) < 0) + return BadLength; + if ((char *) end - (char *) (gi + stuff->nglyphs) < 0) + return BadLength; + for (i = 0; i < stuff->nglyphs; i++) + { + swapl (&gids[i], n); + swaps (&gi[i].width, n); + swaps (&gi[i].height, n); + swaps (&gi[i].x, n); + swaps (&gi[i].y, n); + swaps (&gi[i].xOff, n); + swaps (&gi[i].yOff, n); + } + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderAddGlyphsFromPicture (ClientPtr client) +{ + return BadImplementation; +} + +static int +SProcRenderFreeGlyphs (ClientPtr client) +{ + register int n; + REQUEST(xRenderFreeGlyphsReq); + swaps(&stuff->length, n); + swapl(&stuff->glyphset, n); + SwapRestL(stuff); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderCompositeGlyphs (ClientPtr client) +{ + register int n; + xGlyphElt *elt; + CARD8 *buffer; + CARD8 *end; + int space; + int i; + int size; + + REQUEST(xRenderCompositeGlyphsReq); + + switch (stuff->renderReqType) { + default: size = 1; break; + case X_RenderCompositeGlyphs16: size = 2; break; + case X_RenderCompositeGlyphs32: size = 4; break; + } + + swaps(&stuff->length, n); + swapl(&stuff->src, n); + swapl(&stuff->dst, n); + swapl(&stuff->maskFormat, n); + swapl(&stuff->glyphset, n); + swaps(&stuff->xSrc, n); + swaps(&stuff->ySrc, n); + buffer = (CARD8 *) (stuff + 1); + end = (CARD8 *) stuff + (client->req_len << 2); + while (buffer + sizeof (xGlyphElt) < end) + { + elt = (xGlyphElt *) buffer; + buffer += sizeof (xGlyphElt); + + swaps (&elt->deltax, n); + swaps (&elt->deltay, n); + + i = elt->len; + if (i == 0xff) + { + swapl (buffer, n); + buffer += 4; + } + else + { + space = size * i; + switch (size) { + case 1: + buffer += i; + break; + case 2: + while (i--) + { + swaps (buffer, n); + buffer += 2; + } + break; + case 4: + while (i--) + { + swapl (buffer, n); + buffer += 4; + } + break; + } + if (space & 3) + buffer += 4 - (space & 3); + } + } + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderFillRectangles (ClientPtr client) +{ + register int n; + REQUEST(xRenderFillRectanglesReq); + + REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq); + swaps(&stuff->length, n); + swapl(&stuff->dst, n); + swaps(&stuff->color.red, n); + swaps(&stuff->color.green, n); + swaps(&stuff->color.blue, n); + swaps(&stuff->color.alpha, n); + SwapRestS(stuff); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderCreateCursor (ClientPtr client) +{ + register int n; + REQUEST(xRenderCreateCursorReq); + REQUEST_SIZE_MATCH (xRenderCreateCursorReq); + + swaps(&stuff->length, n); + swapl(&stuff->cid, n); + swapl(&stuff->src, n); + swaps(&stuff->x, n); + swaps(&stuff->y, n); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderSetPictureTransform (ClientPtr client) +{ + register int n; + REQUEST(xRenderSetPictureTransformReq); + REQUEST_SIZE_MATCH(xRenderSetPictureTransformReq); + + swaps(&stuff->length, n); + swapl(&stuff->picture, n); + swapl(&stuff->transform.matrix11, n); + swapl(&stuff->transform.matrix12, n); + swapl(&stuff->transform.matrix13, n); + swapl(&stuff->transform.matrix21, n); + swapl(&stuff->transform.matrix22, n); + swapl(&stuff->transform.matrix23, n); + swapl(&stuff->transform.matrix31, n); + swapl(&stuff->transform.matrix32, n); + swapl(&stuff->transform.matrix33, n); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderQueryFilters (ClientPtr client) +{ + register int n; + REQUEST (xRenderQueryFiltersReq); + REQUEST_SIZE_MATCH (xRenderQueryFiltersReq); + + swaps(&stuff->length, n); + swapl(&stuff->drawable, n); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderSetPictureFilter (ClientPtr client) +{ + register int n; + REQUEST (xRenderSetPictureFilterReq); + REQUEST_AT_LEAST_SIZE (xRenderSetPictureFilterReq); + + swaps(&stuff->length, n); + swapl(&stuff->picture, n); + swaps(&stuff->nbytes, n); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderCreateAnimCursor (ClientPtr client) +{ + register int n; + REQUEST (xRenderCreateAnimCursorReq); + REQUEST_AT_LEAST_SIZE (xRenderCreateAnimCursorReq); + + swaps(&stuff->length, n); + swapl(&stuff->cid, n); + SwapRestL(stuff); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderAddTraps (ClientPtr client) +{ + register int n; + REQUEST (xRenderAddTrapsReq); + REQUEST_AT_LEAST_SIZE (xRenderAddTrapsReq); + + swaps(&stuff->length, n); + swapl(&stuff->picture, n); + swaps(&stuff->xOff, n); + swaps(&stuff->yOff, n); + SwapRestL(stuff); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderCreateSolidFill(ClientPtr client) +{ + register int n; + REQUEST (xRenderCreateSolidFillReq); + REQUEST_AT_LEAST_SIZE (xRenderCreateSolidFillReq); + + swaps(&stuff->length, n); + swapl(&stuff->pid, n); + swaps(&stuff->color.alpha, n); + swaps(&stuff->color.red, n); + swaps(&stuff->color.green, n); + swaps(&stuff->color.blue, n); + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static void swapStops(void *stuff, int num) +{ + int i, n; + CARD32 *stops; + CARD16 *colors; + stops = (CARD32 *)(stuff); + for (i = 0; i < num; ++i) { + swapl(stops, n); + ++stops; + } + colors = (CARD16 *)(stops); + for (i = 0; i < 4*num; ++i) { + swaps(stops, n); + ++stops; + } +} + +static int +SProcRenderCreateLinearGradient (ClientPtr client) +{ + register int n; + int len; + REQUEST (xRenderCreateLinearGradientReq); + REQUEST_AT_LEAST_SIZE (xRenderCreateLinearGradientReq); + + swaps(&stuff->length, n); + swapl(&stuff->pid, n); + swapl(&stuff->p1.x, n); + swapl(&stuff->p1.y, n); + swapl(&stuff->p2.x, n); + swapl(&stuff->p2.y, n); + swapl(&stuff->nStops, n); + + len = (client->req_len << 2) - sizeof(xRenderCreateLinearGradientReq); + if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor))) + return BadLength; + if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) + return BadLength; + + swapStops(stuff+1, stuff->nStops); + + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderCreateRadialGradient (ClientPtr client) +{ + register int n; + int len; + REQUEST (xRenderCreateRadialGradientReq); + REQUEST_AT_LEAST_SIZE (xRenderCreateRadialGradientReq); + + swaps(&stuff->length, n); + swapl(&stuff->pid, n); + swapl(&stuff->inner.x, n); + swapl(&stuff->inner.y, n); + swapl(&stuff->outer.x, n); + swapl(&stuff->outer.y, n); + swapl(&stuff->inner_radius, n); + swapl(&stuff->outer_radius, n); + swapl(&stuff->nStops, n); + + len = (client->req_len << 2) - sizeof(xRenderCreateRadialGradientReq); + if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor))) + return BadLength; + if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) + return BadLength; + + swapStops(stuff+1, stuff->nStops); + + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderCreateConicalGradient (ClientPtr client) +{ + register int n; + int len; + REQUEST (xRenderCreateConicalGradientReq); + REQUEST_AT_LEAST_SIZE (xRenderCreateConicalGradientReq); + + swaps(&stuff->length, n); + swapl(&stuff->pid, n); + swapl(&stuff->center.x, n); + swapl(&stuff->center.y, n); + swapl(&stuff->angle, n); + swapl(&stuff->nStops, n); + + len = (client->req_len << 2) - sizeof(xRenderCreateConicalGradientReq); + if (stuff->nStops > UINT32_MAX/(sizeof(xFixed) + sizeof(xRenderColor))) + return BadLength; + if (len != stuff->nStops*(sizeof(xFixed) + sizeof(xRenderColor))) + return BadLength; + + swapStops(stuff+1, stuff->nStops); + + return (*ProcRenderVector[stuff->renderReqType]) (client); +} + +static int +SProcRenderDispatch (ClientPtr client) +{ + REQUEST(xReq); + + if (stuff->data < RenderNumberRequests) + return (*SProcRenderVector[stuff->data]) (client); + else + return BadRequest; +} + +#ifdef PANORAMIX +#include "panoramiX.h" +#include "panoramiXsrv.h" + +#define VERIFY_XIN_PICTURE(pPicture, pid, client, mode) {\ + int rc = dixLookupResourceByType((pointer *)&(pPicture), pid,\ + XRT_PICTURE, client, mode);\ + if (rc != Success)\ + return (rc == BadValue) ? RenderErrBase + BadPicture : rc;\ +} + +#define VERIFY_XIN_ALPHA(pPicture, pid, client, mode) {\ + if (pid == None) \ + pPicture = 0; \ + else { \ + VERIFY_XIN_PICTURE(pPicture, pid, client, mode); \ + } \ +} \ + +int (*PanoramiXSaveRenderVector[RenderNumberRequests])(ClientPtr); + +unsigned long XRT_PICTURE; + +static int +PanoramiXRenderCreatePicture (ClientPtr client) +{ + REQUEST(xRenderCreatePictureReq); + PanoramiXRes *refDraw, *newPict; + int result, j; + + REQUEST_AT_LEAST_SIZE(xRenderCreatePictureReq); + result = dixLookupResourceByClass((pointer *)&refDraw, stuff->drawable, + XRC_DRAWABLE, client, DixWriteAccess); + if (result != Success) + return (result == BadValue) ? BadDrawable : result; + if(!(newPict = (PanoramiXRes *) malloc(sizeof(PanoramiXRes)))) + return BadAlloc; + newPict->type = XRT_PICTURE; + newPict->info[0].id = stuff->pid; + + if (refDraw->type == XRT_WINDOW && + stuff->drawable == WindowTable[0]->drawable.id) + { + newPict->u.pict.root = TRUE; + } + else + newPict->u.pict.root = FALSE; + + for(j = 1; j < PanoramiXNumScreens; j++) + newPict->info[j].id = FakeClientID(client->index); + + FOR_NSCREENS_BACKWARD(j) { + stuff->pid = newPict->info[j].id; + stuff->drawable = refDraw->info[j].id; + result = (*PanoramiXSaveRenderVector[X_RenderCreatePicture]) (client); + if(result != Success) break; + } + + if (result == Success) + AddResource(newPict->info[0].id, XRT_PICTURE, newPict); + else + free(newPict); + + return (result); +} + +static int +PanoramiXRenderChangePicture (ClientPtr client) +{ + PanoramiXRes *pict; + int result = Success, j; + REQUEST(xRenderChangePictureReq); + + REQUEST_AT_LEAST_SIZE(xRenderChangePictureReq); + + VERIFY_XIN_PICTURE(pict, stuff->picture, client, DixWriteAccess); + + FOR_NSCREENS_BACKWARD(j) { + stuff->picture = pict->info[j].id; + result = (*PanoramiXSaveRenderVector[X_RenderChangePicture]) (client); + if(result != Success) break; + } + + return (result); +} + +static int +PanoramiXRenderSetPictureClipRectangles (ClientPtr client) +{ + REQUEST(xRenderSetPictureClipRectanglesReq); + int result = Success, j; + PanoramiXRes *pict; + + REQUEST_AT_LEAST_SIZE(xRenderSetPictureClipRectanglesReq); + + VERIFY_XIN_PICTURE(pict, stuff->picture, client, DixWriteAccess); + + FOR_NSCREENS_BACKWARD(j) { + stuff->picture = pict->info[j].id; + result = (*PanoramiXSaveRenderVector[X_RenderSetPictureClipRectangles]) (client); + if(result != Success) break; + } + + return (result); +} + +static int +PanoramiXRenderSetPictureTransform (ClientPtr client) +{ + REQUEST(xRenderSetPictureTransformReq); + int result = Success, j; + PanoramiXRes *pict; + + REQUEST_AT_LEAST_SIZE(xRenderSetPictureTransformReq); + + VERIFY_XIN_PICTURE(pict, stuff->picture, client, DixWriteAccess); + + FOR_NSCREENS_BACKWARD(j) { + stuff->picture = pict->info[j].id; + result = (*PanoramiXSaveRenderVector[X_RenderSetPictureTransform]) (client); + if(result != Success) break; + } + + return (result); +} + +static int +PanoramiXRenderSetPictureFilter (ClientPtr client) +{ + REQUEST(xRenderSetPictureFilterReq); + int result = Success, j; + PanoramiXRes *pict; + + REQUEST_AT_LEAST_SIZE(xRenderSetPictureFilterReq); + + VERIFY_XIN_PICTURE(pict, stuff->picture, client, DixWriteAccess); + + FOR_NSCREENS_BACKWARD(j) { + stuff->picture = pict->info[j].id; + result = (*PanoramiXSaveRenderVector[X_RenderSetPictureFilter]) (client); + if(result != Success) break; + } + + return (result); +} + +static int +PanoramiXRenderFreePicture (ClientPtr client) +{ + PanoramiXRes *pict; + int result = Success, j; + REQUEST(xRenderFreePictureReq); + + REQUEST_SIZE_MATCH(xRenderFreePictureReq); + + client->errorValue = stuff->picture; + + VERIFY_XIN_PICTURE(pict, stuff->picture, client, DixDestroyAccess); + + + FOR_NSCREENS_BACKWARD(j) { + stuff->picture = pict->info[j].id; + result = (*PanoramiXSaveRenderVector[X_RenderFreePicture]) (client); + if(result != Success) break; + } + + /* Since ProcRenderFreePicture is using FreeResource, it will free + our resource for us on the last pass through the loop above */ + + return (result); +} + +static int +PanoramiXRenderComposite (ClientPtr client) +{ + PanoramiXRes *src, *msk, *dst; + int result = Success, j; + xRenderCompositeReq orig; + REQUEST(xRenderCompositeReq); + + REQUEST_SIZE_MATCH(xRenderCompositeReq); + + VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess); + VERIFY_XIN_ALPHA (msk, stuff->mask, client, DixReadAccess); + VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess); + + orig = *stuff; + + FOR_NSCREENS_FORWARD(j) { + stuff->src = src->info[j].id; + if (src->u.pict.root) + { + stuff->xSrc = orig.xSrc - panoramiXdataPtr[j].x; + stuff->ySrc = orig.ySrc - panoramiXdataPtr[j].y; + } + stuff->dst = dst->info[j].id; + if (dst->u.pict.root) + { + stuff->xDst = orig.xDst - panoramiXdataPtr[j].x; + stuff->yDst = orig.yDst - panoramiXdataPtr[j].y; + } + if (msk) + { + stuff->mask = msk->info[j].id; + if (msk->u.pict.root) + { + stuff->xMask = orig.xMask - panoramiXdataPtr[j].x; + stuff->yMask = orig.yMask - panoramiXdataPtr[j].y; + } + } + result = (*PanoramiXSaveRenderVector[X_RenderComposite]) (client); + if(result != Success) break; + } + + return result; +} + +static int +PanoramiXRenderCompositeGlyphs (ClientPtr client) +{ + PanoramiXRes *src, *dst; + int result = Success, j; + REQUEST(xRenderCompositeGlyphsReq); + xGlyphElt origElt, *elt; + INT16 xSrc, ySrc; + + REQUEST_AT_LEAST_SIZE(xRenderCompositeGlyphsReq); + VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess); + VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess); + + if (client->req_len << 2 >= (sizeof (xRenderCompositeGlyphsReq) + + sizeof (xGlyphElt))) + { + elt = (xGlyphElt *) (stuff + 1); + origElt = *elt; + xSrc = stuff->xSrc; + ySrc = stuff->ySrc; + FOR_NSCREENS_FORWARD(j) { + stuff->src = src->info[j].id; + if (src->u.pict.root) + { + stuff->xSrc = xSrc - panoramiXdataPtr[j].x; + stuff->ySrc = ySrc - panoramiXdataPtr[j].y; + } + stuff->dst = dst->info[j].id; + if (dst->u.pict.root) + { + elt->deltax = origElt.deltax - panoramiXdataPtr[j].x; + elt->deltay = origElt.deltay - panoramiXdataPtr[j].y; + } + result = (*PanoramiXSaveRenderVector[stuff->renderReqType]) (client); + if(result != Success) break; + } + } + + return result; +} + +static int +PanoramiXRenderFillRectangles (ClientPtr client) +{ + PanoramiXRes *dst; + int result = Success, j; + REQUEST(xRenderFillRectanglesReq); + char *extra; + int extra_len; + + REQUEST_AT_LEAST_SIZE (xRenderFillRectanglesReq); + VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess); + extra_len = (client->req_len << 2) - sizeof (xRenderFillRectanglesReq); + if (extra_len && + (extra = (char *) malloc(extra_len))) + { + memcpy (extra, stuff + 1, extra_len); + FOR_NSCREENS_FORWARD(j) { + if (j) memcpy (stuff + 1, extra, extra_len); + if (dst->u.pict.root) + { + int x_off = panoramiXdataPtr[j].x; + int y_off = panoramiXdataPtr[j].y; + + if(x_off || y_off) { + xRectangle *rects = (xRectangle *) (stuff + 1); + int i = extra_len / sizeof (xRectangle); + + while (i--) + { + rects->x -= x_off; + rects->y -= y_off; + rects++; + } + } + } + stuff->dst = dst->info[j].id; + result = (*PanoramiXSaveRenderVector[X_RenderFillRectangles]) (client); + if(result != Success) break; + } + free(extra); + } + + return result; +} + +static int +PanoramiXRenderTrapezoids(ClientPtr client) +{ + PanoramiXRes *src, *dst; + int result = Success, j; + REQUEST(xRenderTrapezoidsReq); + char *extra; + int extra_len; + + REQUEST_AT_LEAST_SIZE (xRenderTrapezoidsReq); + + VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess); + VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess); + + extra_len = (client->req_len << 2) - sizeof (xRenderTrapezoidsReq); + + if (extra_len && + (extra = (char *) malloc(extra_len))) { + memcpy (extra, stuff + 1, extra_len); + + FOR_NSCREENS_FORWARD(j) { + if (j) memcpy (stuff + 1, extra, extra_len); + if (dst->u.pict.root) { + int x_off = panoramiXdataPtr[j].x; + int y_off = panoramiXdataPtr[j].y; + + if(x_off || y_off) { + xTrapezoid *trap = (xTrapezoid *) (stuff + 1); + int i = extra_len / sizeof (xTrapezoid); + + while (i--) { + trap->top -= y_off; + trap->bottom -= y_off; + trap->left.p1.x -= x_off; + trap->left.p1.y -= y_off; + trap->left.p2.x -= x_off; + trap->left.p2.y -= y_off; + trap->right.p1.x -= x_off; + trap->right.p1.y -= y_off; + trap->right.p2.x -= x_off; + trap->right.p2.y -= y_off; + trap++; + } + } + } + + stuff->src = src->info[j].id; + stuff->dst = dst->info[j].id; + result = + (*PanoramiXSaveRenderVector[X_RenderTrapezoids]) (client); + + if(result != Success) break; + } + + free(extra); + } + + return result; +} + +static int +PanoramiXRenderTriangles(ClientPtr client) +{ + PanoramiXRes *src, *dst; + int result = Success, j; + REQUEST(xRenderTrianglesReq); + char *extra; + int extra_len; + + REQUEST_AT_LEAST_SIZE (xRenderTrianglesReq); + + VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess); + VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess); + + extra_len = (client->req_len << 2) - sizeof (xRenderTrianglesReq); + + if (extra_len && + (extra = (char *) malloc(extra_len))) { + memcpy (extra, stuff + 1, extra_len); + + FOR_NSCREENS_FORWARD(j) { + if (j) memcpy (stuff + 1, extra, extra_len); + if (dst->u.pict.root) { + int x_off = panoramiXdataPtr[j].x; + int y_off = panoramiXdataPtr[j].y; + + if(x_off || y_off) { + xTriangle *tri = (xTriangle *) (stuff + 1); + int i = extra_len / sizeof (xTriangle); + + while (i--) { + tri->p1.x -= x_off; + tri->p1.y -= y_off; + tri->p2.x -= x_off; + tri->p2.y -= y_off; + tri->p3.x -= x_off; + tri->p3.y -= y_off; + tri++; + } + } + } + + stuff->src = src->info[j].id; + stuff->dst = dst->info[j].id; + result = + (*PanoramiXSaveRenderVector[X_RenderTriangles]) (client); + + if(result != Success) break; + } + + free(extra); + } + + return result; +} + +static int +PanoramiXRenderTriStrip(ClientPtr client) +{ + PanoramiXRes *src, *dst; + int result = Success, j; + REQUEST(xRenderTriStripReq); + char *extra; + int extra_len; + + REQUEST_AT_LEAST_SIZE (xRenderTriStripReq); + + VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess); + VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess); + + extra_len = (client->req_len << 2) - sizeof (xRenderTriStripReq); + + if (extra_len && + (extra = (char *) malloc(extra_len))) { + memcpy (extra, stuff + 1, extra_len); + + FOR_NSCREENS_FORWARD(j) { + if (j) memcpy (stuff + 1, extra, extra_len); + if (dst->u.pict.root) { + int x_off = panoramiXdataPtr[j].x; + int y_off = panoramiXdataPtr[j].y; + + if(x_off || y_off) { + xPointFixed *fixed = (xPointFixed *) (stuff + 1); + int i = extra_len / sizeof (xPointFixed); + + while (i--) { + fixed->x -= x_off; + fixed->y -= y_off; + fixed++; + } + } + } + + stuff->src = src->info[j].id; + stuff->dst = dst->info[j].id; + result = + (*PanoramiXSaveRenderVector[X_RenderTriStrip]) (client); + + if(result != Success) break; + } + + free(extra); + } + + return result; +} + +static int +PanoramiXRenderTriFan(ClientPtr client) +{ + PanoramiXRes *src, *dst; + int result = Success, j; + REQUEST(xRenderTriFanReq); + char *extra; + int extra_len; + + REQUEST_AT_LEAST_SIZE (xRenderTriFanReq); + + VERIFY_XIN_PICTURE (src, stuff->src, client, DixReadAccess); + VERIFY_XIN_PICTURE (dst, stuff->dst, client, DixWriteAccess); + + extra_len = (client->req_len << 2) - sizeof (xRenderTriFanReq); + + if (extra_len && + (extra = (char *) malloc(extra_len))) { + memcpy (extra, stuff + 1, extra_len); + + FOR_NSCREENS_FORWARD(j) { + if (j) memcpy (stuff + 1, extra, extra_len); + if (dst->u.pict.root) { + int x_off = panoramiXdataPtr[j].x; + int y_off = panoramiXdataPtr[j].y; + + if(x_off || y_off) { + xPointFixed *fixed = (xPointFixed *) (stuff + 1); + int i = extra_len / sizeof (xPointFixed); + + while (i--) { + fixed->x -= x_off; + fixed->y -= y_off; + fixed++; + } + } + } + + stuff->src = src->info[j].id; + stuff->dst = dst->info[j].id; + result = + (*PanoramiXSaveRenderVector[X_RenderTriFan]) (client); + + if(result != Success) break; + } + + free(extra); + } + + return result; +} + +static int +PanoramiXRenderAddTraps (ClientPtr client) +{ + PanoramiXRes *picture; + int result = Success, j; + REQUEST(xRenderAddTrapsReq); + char *extra; + int extra_len; + INT16 x_off, y_off; + + REQUEST_AT_LEAST_SIZE (xRenderAddTrapsReq); + VERIFY_XIN_PICTURE (picture, stuff->picture, client, DixWriteAccess); + extra_len = (client->req_len << 2) - sizeof (xRenderAddTrapsReq); + if (extra_len && + (extra = (char *) malloc(extra_len))) + { + memcpy (extra, stuff + 1, extra_len); + x_off = stuff->xOff; + y_off = stuff->yOff; + FOR_NSCREENS_FORWARD(j) { + if (j) memcpy (stuff + 1, extra, extra_len); + stuff->picture = picture->info[j].id; + + if (picture->u.pict.root) + { + stuff->xOff = x_off + panoramiXdataPtr[j].x; + stuff->yOff = y_off + panoramiXdataPtr[j].y; + } + result = (*PanoramiXSaveRenderVector[X_RenderAddTraps]) (client); + if(result != Success) break; + } + free(extra); + } + + return result; +} + +static int +PanoramiXRenderCreateSolidFill (ClientPtr client) +{ + REQUEST(xRenderCreateSolidFillReq); + PanoramiXRes *newPict; + int result = Success, j; + + REQUEST_AT_LEAST_SIZE(xRenderCreateSolidFillReq); + + if(!(newPict = (PanoramiXRes *) malloc(sizeof(PanoramiXRes)))) + return BadAlloc; + + newPict->type = XRT_PICTURE; + newPict->info[0].id = stuff->pid; + newPict->u.pict.root = FALSE; + + for(j = 1; j < PanoramiXNumScreens; j++) + newPict->info[j].id = FakeClientID(client->index); + + FOR_NSCREENS_BACKWARD(j) { + stuff->pid = newPict->info[j].id; + result = (*PanoramiXSaveRenderVector[X_RenderCreateSolidFill]) (client); + if(result != Success) break; + } + + if (result == Success) + AddResource(newPict->info[0].id, XRT_PICTURE, newPict); + else + free(newPict); + + return result; +} + +static int +PanoramiXRenderCreateLinearGradient (ClientPtr client) +{ + REQUEST(xRenderCreateLinearGradientReq); + PanoramiXRes *newPict; + int result = Success, j; + + REQUEST_AT_LEAST_SIZE(xRenderCreateLinearGradientReq); + + if(!(newPict = (PanoramiXRes *) malloc(sizeof(PanoramiXRes)))) + return BadAlloc; + + newPict->type = XRT_PICTURE; + newPict->info[0].id = stuff->pid; + newPict->u.pict.root = FALSE; + + for(j = 1; j < PanoramiXNumScreens; j++) + newPict->info[j].id = FakeClientID(client->index); + + FOR_NSCREENS_BACKWARD(j) { + stuff->pid = newPict->info[j].id; + result = (*PanoramiXSaveRenderVector[X_RenderCreateLinearGradient]) (client); + if(result != Success) break; + } + + if (result == Success) + AddResource(newPict->info[0].id, XRT_PICTURE, newPict); + else + free(newPict); + + return result; +} + +static int +PanoramiXRenderCreateRadialGradient (ClientPtr client) +{ + REQUEST(xRenderCreateRadialGradientReq); + PanoramiXRes *newPict; + int result = Success, j; + + REQUEST_AT_LEAST_SIZE(xRenderCreateRadialGradientReq); + + if(!(newPict = (PanoramiXRes *) malloc(sizeof(PanoramiXRes)))) + return BadAlloc; + + newPict->type = XRT_PICTURE; + newPict->info[0].id = stuff->pid; + newPict->u.pict.root = FALSE; + + for(j = 1; j < PanoramiXNumScreens; j++) + newPict->info[j].id = FakeClientID(client->index); + + FOR_NSCREENS_BACKWARD(j) { + stuff->pid = newPict->info[j].id; + result = (*PanoramiXSaveRenderVector[X_RenderCreateRadialGradient]) (client); + if(result != Success) break; + } + + if (result == Success) + AddResource(newPict->info[0].id, XRT_PICTURE, newPict); + else + free(newPict); + + return result; +} + +static int +PanoramiXRenderCreateConicalGradient (ClientPtr client) +{ + REQUEST(xRenderCreateConicalGradientReq); + PanoramiXRes *newPict; + int result = Success, j; + + REQUEST_AT_LEAST_SIZE(xRenderCreateConicalGradientReq); + + if(!(newPict = (PanoramiXRes *) malloc(sizeof(PanoramiXRes)))) + return BadAlloc; + + newPict->type = XRT_PICTURE; + newPict->info[0].id = stuff->pid; + newPict->u.pict.root = FALSE; + + for(j = 1; j < PanoramiXNumScreens; j++) + newPict->info[j].id = FakeClientID(client->index); + + FOR_NSCREENS_BACKWARD(j) { + stuff->pid = newPict->info[j].id; + result = (*PanoramiXSaveRenderVector[X_RenderCreateConicalGradient]) (client); + if(result != Success) break; + } + + if (result == Success) + AddResource(newPict->info[0].id, XRT_PICTURE, newPict); + else + free(newPict); + + return result; +} + +void +PanoramiXRenderInit (void) +{ + int i; + + XRT_PICTURE = CreateNewResourceType (XineramaDeleteResource, + "XineramaPicture"); + for (i = 0; i < RenderNumberRequests; i++) + PanoramiXSaveRenderVector[i] = ProcRenderVector[i]; + /* + * Stuff in Xinerama aware request processing hooks + */ + ProcRenderVector[X_RenderCreatePicture] = PanoramiXRenderCreatePicture; + ProcRenderVector[X_RenderChangePicture] = PanoramiXRenderChangePicture; + ProcRenderVector[X_RenderSetPictureTransform] = PanoramiXRenderSetPictureTransform; + ProcRenderVector[X_RenderSetPictureFilter] = PanoramiXRenderSetPictureFilter; + ProcRenderVector[X_RenderSetPictureClipRectangles] = PanoramiXRenderSetPictureClipRectangles; + ProcRenderVector[X_RenderFreePicture] = PanoramiXRenderFreePicture; + ProcRenderVector[X_RenderComposite] = PanoramiXRenderComposite; + ProcRenderVector[X_RenderCompositeGlyphs8] = PanoramiXRenderCompositeGlyphs; + ProcRenderVector[X_RenderCompositeGlyphs16] = PanoramiXRenderCompositeGlyphs; + ProcRenderVector[X_RenderCompositeGlyphs32] = PanoramiXRenderCompositeGlyphs; + ProcRenderVector[X_RenderFillRectangles] = PanoramiXRenderFillRectangles; + + ProcRenderVector[X_RenderTrapezoids] = PanoramiXRenderTrapezoids; + ProcRenderVector[X_RenderTriangles] = PanoramiXRenderTriangles; + ProcRenderVector[X_RenderTriStrip] = PanoramiXRenderTriStrip; + ProcRenderVector[X_RenderTriFan] = PanoramiXRenderTriFan; + ProcRenderVector[X_RenderAddTraps] = PanoramiXRenderAddTraps; + + ProcRenderVector[X_RenderCreateSolidFill] = PanoramiXRenderCreateSolidFill; + ProcRenderVector[X_RenderCreateLinearGradient] = PanoramiXRenderCreateLinearGradient; + ProcRenderVector[X_RenderCreateRadialGradient] = PanoramiXRenderCreateRadialGradient; + ProcRenderVector[X_RenderCreateConicalGradient] = PanoramiXRenderCreateConicalGradient; +} + +void +PanoramiXRenderReset (void) +{ + int i; + for (i = 0; i < RenderNumberRequests; i++) + ProcRenderVector[i] = PanoramiXSaveRenderVector[i]; +} + +#endif /* PANORAMIX */ |