2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
* midispcur.c
|
|
|
|
*
|
|
|
|
* machine independent cursor display routines
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 1989, 1998 The Open Group
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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 THE
|
|
|
|
OPEN GROUP 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 Open Group 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 Open Group.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#include <X11/X.h>
|
|
|
|
#include "misc.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "cursorstr.h"
|
|
|
|
#include "windowstr.h"
|
|
|
|
#include "regionstr.h"
|
|
|
|
#include "dixstruct.h"
|
|
|
|
#include "scrnintstr.h"
|
|
|
|
#include "servermd.h"
|
|
|
|
#include "mipointer.h"
|
|
|
|
#include "misprite.h"
|
|
|
|
#include "gcstruct.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#include "picturestr.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#include "inputstr.h"
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
/* per-screen private data */
|
2010-12-05 08:36:02 -07:00
|
|
|
static DevPrivateKeyRec miDCScreenKeyRec;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
#define miDCScreenKey (&miDCScreenKeyRec)
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
static DevScreenPrivateKeyRec miDCDeviceKeyRec;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
#define miDCDeviceKey (&miDCDeviceKeyRec)
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
static Bool miDCCloseScreen(ScreenPtr pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
/* per device private data */
|
2006-11-26 11:13:41 -07:00
|
|
|
typedef struct {
|
2012-06-10 07:21:05 -06:00
|
|
|
GCPtr pSourceGC, pMaskGC;
|
|
|
|
GCPtr pSaveGC, pRestoreGC;
|
|
|
|
PixmapPtr pSave;
|
|
|
|
PicturePtr pRootPicture;
|
2009-09-06 13:44:18 -06:00
|
|
|
} miDCBufferRec, *miDCBufferPtr;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
#define miGetDCDevice(dev, screen) \
|
2009-09-06 13:44:18 -06:00
|
|
|
((DevHasCursor(dev)) ? \
|
2011-11-05 07:32:40 -06:00
|
|
|
(miDCBufferPtr)dixLookupScreenPrivate(&dev->devPrivates, miDCDeviceKey, screen) : \
|
|
|
|
(miDCBufferPtr)dixLookupScreenPrivate(&GetMaster(dev, MASTER_POINTER)->devPrivates, miDCDeviceKey, screen))
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2015-09-16 13:10:19 -06:00
|
|
|
/*
|
2014-09-27 11:52:59 -06:00
|
|
|
* The core pointer buffer will point to the index of the virtual pointer
|
2015-09-16 13:10:19 -06:00
|
|
|
* in the pCursorBuffers array.
|
2009-09-06 13:44:18 -06:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2012-06-10 07:21:05 -06:00
|
|
|
CloseScreenProcPtr CloseScreen;
|
|
|
|
PixmapPtr sourceBits; /* source bits */
|
|
|
|
PixmapPtr maskBits; /* mask bits */
|
|
|
|
PicturePtr pPicture;
|
2013-06-07 11:28:45 -06:00
|
|
|
CursorPtr pCursor;
|
|
|
|
} miDCScreenRec, *miDCScreenPtr;
|
|
|
|
|
|
|
|
#define miGetDCScreen(s) ((miDCScreenPtr)(dixLookupPrivate(&(s)->devPrivates, miDCScreenKey)))
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-07-27 13:02:24 -06:00
|
|
|
Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCInitialize(ScreenPtr pScreen, miPointerScreenFuncPtr screenFuncs)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCScreenPtr pScreenPriv;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2011-11-05 07:32:40 -06:00
|
|
|
if (!dixRegisterPrivateKey(&miDCScreenKeyRec, PRIVATE_SCREEN, 0) ||
|
2012-06-10 07:21:05 -06:00
|
|
|
!dixRegisterScreenPrivateKey(&miDCDeviceKeyRec, pScreen, PRIVATE_DEVICE,
|
|
|
|
0))
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
pScreenPriv = calloc(1, sizeof(miDCScreenRec));
|
2010-12-05 08:36:02 -07:00
|
|
|
if (!pScreenPriv)
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
pScreenPriv->CloseScreen = pScreen->CloseScreen;
|
|
|
|
pScreen->CloseScreen = miDCCloseScreen;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2008-11-02 08:26:08 -07:00
|
|
|
dixSetPrivate(&pScreen->devPrivates, miDCScreenKey, pScreenPriv);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!miSpriteInitialize(pScreen, screenFuncs)) {
|
2014-09-27 11:52:59 -06:00
|
|
|
free((void *) pScreenPriv);
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
static void
|
|
|
|
miDCSwitchScreenCursor(ScreenPtr pScreen, CursorPtr pCursor, PixmapPtr sourceBits, PixmapPtr maskBits, PicturePtr pPicture)
|
|
|
|
{
|
|
|
|
miDCScreenPtr pScreenPriv = dixLookupPrivate(&pScreen->devPrivates, miDCScreenKey);
|
|
|
|
|
|
|
|
if (pScreenPriv->sourceBits)
|
|
|
|
(*pScreen->DestroyPixmap)(pScreenPriv->sourceBits);
|
|
|
|
pScreenPriv->sourceBits = sourceBits;
|
|
|
|
|
|
|
|
if (pScreenPriv->maskBits)
|
|
|
|
(*pScreen->DestroyPixmap)(pScreenPriv->maskBits);
|
|
|
|
pScreenPriv->maskBits = maskBits;
|
|
|
|
|
|
|
|
if (pScreenPriv->pPicture)
|
|
|
|
FreePicture(pScreenPriv->pPicture, 0);
|
|
|
|
pScreenPriv->pPicture = pPicture;
|
|
|
|
|
|
|
|
pScreenPriv->pCursor = pCursor;
|
|
|
|
}
|
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
static Bool
|
2013-06-07 11:28:45 -06:00
|
|
|
miDCCloseScreen(ScreenPtr pScreen)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCScreenPtr pScreenPriv;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
pScreenPriv = (miDCScreenPtr) dixLookupPrivate(&pScreen->devPrivates,
|
|
|
|
miDCScreenKey);
|
2006-11-26 11:13:41 -07:00
|
|
|
pScreen->CloseScreen = pScreenPriv->CloseScreen;
|
2013-06-07 11:28:45 -06:00
|
|
|
|
|
|
|
miDCSwitchScreenCursor(pScreen, NULL, NULL, NULL, NULL);
|
2014-09-27 11:52:59 -06:00
|
|
|
free((void *) pScreenPriv);
|
2013-06-07 11:28:45 -06:00
|
|
|
return (*pScreen->CloseScreen) (pScreen);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCRealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define EnsurePicture(picture,draw,win) (picture || miDCMakePicture(&picture,draw,win))
|
|
|
|
|
|
|
|
static PicturePtr
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCMakePicture(PicturePtr * ppPicture, DrawablePtr pDraw, WindowPtr pWin)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
PictFormatPtr pFormat;
|
|
|
|
XID subwindow_mode = IncludeInferiors;
|
|
|
|
PicturePtr pPicture;
|
|
|
|
int error;
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
pFormat = PictureWindowFormat(pWin);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!pFormat)
|
2012-06-10 07:21:05 -06:00
|
|
|
return 0;
|
|
|
|
pPicture = CreatePicture(0, pDraw, pFormat,
|
|
|
|
CPSubwindowMode, &subwindow_mode,
|
|
|
|
serverClient, &error);
|
2006-11-26 11:13:41 -07:00
|
|
|
*ppPicture = pPicture;
|
|
|
|
return pPicture;
|
|
|
|
}
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
static Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCRealize(ScreenPtr pScreen, CursorPtr pCursor)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
miDCScreenPtr pScreenPriv = dixLookupPrivate(&pScreen->devPrivates, miDCScreenKey);
|
2012-06-10 07:21:05 -06:00
|
|
|
GCPtr pGC;
|
|
|
|
ChangeGCVal gcvals;
|
2013-06-07 11:28:45 -06:00
|
|
|
PixmapPtr sourceBits, maskBits;
|
|
|
|
|
|
|
|
if (pScreenPriv->pCursor == pCursor)
|
|
|
|
return TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pCursor->bits->argb) {
|
|
|
|
PixmapPtr pPixmap;
|
|
|
|
PictFormatPtr pFormat;
|
|
|
|
int error;
|
2013-06-07 11:28:45 -06:00
|
|
|
PicturePtr pPicture;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
pFormat = PictureMatchFormat(pScreen, 32, PICT_a8r8g8b8);
|
2013-06-07 11:28:45 -06:00
|
|
|
if (!pFormat)
|
|
|
|
return FALSE;
|
2012-06-10 07:21:05 -06:00
|
|
|
|
|
|
|
pPixmap = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width,
|
|
|
|
pCursor->bits->height, 32,
|
|
|
|
CREATE_PIXMAP_USAGE_SCRATCH);
|
2013-06-07 11:28:45 -06:00
|
|
|
if (!pPixmap)
|
|
|
|
return FALSE;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
pGC = GetScratchGC(32, pScreen);
|
|
|
|
if (!pGC) {
|
|
|
|
(*pScreen->DestroyPixmap) (pPixmap);
|
2013-06-07 11:28:45 -06:00
|
|
|
return FALSE;
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
ValidateGC(&pPixmap->drawable, pGC);
|
|
|
|
(*pGC->ops->PutImage) (&pPixmap->drawable, pGC, 32,
|
|
|
|
0, 0, pCursor->bits->width,
|
|
|
|
pCursor->bits->height,
|
|
|
|
0, ZPixmap, (char *) pCursor->bits->argb);
|
|
|
|
FreeScratchGC(pGC);
|
2013-06-07 11:28:45 -06:00
|
|
|
pPicture = CreatePicture(0, &pPixmap->drawable,
|
|
|
|
pFormat, 0, 0, serverClient, &error);
|
2006-11-26 11:13:41 -07:00
|
|
|
(*pScreen->DestroyPixmap) (pPixmap);
|
2013-06-07 11:28:45 -06:00
|
|
|
if (!pPicture)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
miDCSwitchScreenCursor(pScreen, pCursor, NULL, NULL, pPicture);
|
|
|
|
return TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2016-05-29 06:02:34 -06:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
sourceBits = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width,
|
|
|
|
pCursor->bits->height, 1, 0);
|
|
|
|
if (!sourceBits)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
maskBits = (*pScreen->CreatePixmap) (pScreen, pCursor->bits->width,
|
|
|
|
pCursor->bits->height, 1, 0);
|
|
|
|
if (!maskBits) {
|
|
|
|
(*pScreen->DestroyPixmap) (sourceBits);
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create the two sets of bits, clipping as appropriate */
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
pGC = GetScratchGC(1, pScreen);
|
|
|
|
if (!pGC) {
|
2013-06-07 11:28:45 -06:00
|
|
|
(*pScreen->DestroyPixmap) (sourceBits);
|
|
|
|
(*pScreen->DestroyPixmap) (maskBits);
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
ValidateGC((DrawablePtr) sourceBits, pGC);
|
|
|
|
(*pGC->ops->PutImage) ((DrawablePtr) sourceBits, pGC, 1,
|
2012-06-10 07:21:05 -06:00
|
|
|
0, 0, pCursor->bits->width, pCursor->bits->height,
|
|
|
|
0, XYPixmap, (char *) pCursor->bits->source);
|
2010-12-05 08:36:02 -07:00
|
|
|
gcvals.val = GXand;
|
2012-06-10 07:21:05 -06:00
|
|
|
ChangeGC(NullClient, pGC, GCFunction, &gcvals);
|
2013-06-07 11:28:45 -06:00
|
|
|
ValidateGC((DrawablePtr) sourceBits, pGC);
|
|
|
|
(*pGC->ops->PutImage) ((DrawablePtr) sourceBits, pGC, 1,
|
2012-06-10 07:21:05 -06:00
|
|
|
0, 0, pCursor->bits->width, pCursor->bits->height,
|
|
|
|
0, XYPixmap, (char *) pCursor->bits->mask);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* mask bits -- pCursor->mask & ~pCursor->source */
|
2010-12-05 08:36:02 -07:00
|
|
|
gcvals.val = GXcopy;
|
2012-06-10 07:21:05 -06:00
|
|
|
ChangeGC(NullClient, pGC, GCFunction, &gcvals);
|
2013-06-07 11:28:45 -06:00
|
|
|
ValidateGC((DrawablePtr) maskBits, pGC);
|
|
|
|
(*pGC->ops->PutImage) ((DrawablePtr) maskBits, pGC, 1,
|
2012-06-10 07:21:05 -06:00
|
|
|
0, 0, pCursor->bits->width, pCursor->bits->height,
|
|
|
|
0, XYPixmap, (char *) pCursor->bits->mask);
|
2010-12-05 08:36:02 -07:00
|
|
|
gcvals.val = GXandInverted;
|
2012-06-10 07:21:05 -06:00
|
|
|
ChangeGC(NullClient, pGC, GCFunction, &gcvals);
|
2013-06-07 11:28:45 -06:00
|
|
|
ValidateGC((DrawablePtr) maskBits, pGC);
|
|
|
|
(*pGC->ops->PutImage) ((DrawablePtr) maskBits, pGC, 1,
|
2012-06-10 07:21:05 -06:00
|
|
|
0, 0, pCursor->bits->width, pCursor->bits->height,
|
|
|
|
0, XYPixmap, (char *) pCursor->bits->source);
|
|
|
|
FreeScratchGC(pGC);
|
2013-06-07 11:28:45 -06:00
|
|
|
|
|
|
|
miDCSwitchScreenCursor(pScreen, pCursor, sourceBits, maskBits, NULL);
|
|
|
|
return TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCUnrealizeCursor(ScreenPtr pScreen, CursorPtr pCursor)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
miDCScreenPtr pScreenPriv = dixLookupPrivate(&pScreen->devPrivates, miDCScreenKey);
|
|
|
|
|
|
|
|
if (pCursor == pScreenPriv->pCursor)
|
|
|
|
miDCSwitchScreenCursor(pScreen, NULL, NULL, NULL, NULL);
|
2006-11-26 11:13:41 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCPutBits(DrawablePtr pDrawable,
|
|
|
|
GCPtr sourceGC,
|
|
|
|
GCPtr maskGC,
|
|
|
|
int x_org,
|
|
|
|
int y_org,
|
|
|
|
unsigned w, unsigned h, unsigned long source, unsigned long mask)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
miDCScreenPtr pScreenPriv = dixLookupPrivate(&pDrawable->pScreen->devPrivates, miDCScreenKey);
|
2010-12-05 08:36:02 -07:00
|
|
|
ChangeGCVal gcval;
|
2012-06-10 07:21:05 -06:00
|
|
|
int x, y;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (sourceGC->fgPixel != source) {
|
|
|
|
gcval.val = source;
|
|
|
|
ChangeGC(NullClient, sourceGC, GCForeground, &gcval);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
if (sourceGC->serialNumber != pDrawable->serialNumber)
|
2012-06-10 07:21:05 -06:00
|
|
|
ValidateGC(pDrawable, sourceGC);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (sourceGC->miTranslate) {
|
2006-11-26 11:13:41 -07:00
|
|
|
x = pDrawable->x + x_org;
|
|
|
|
y = pDrawable->y + y_org;
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
2006-11-26 11:13:41 -07:00
|
|
|
x = x_org;
|
|
|
|
y = y_org;
|
|
|
|
}
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
(*sourceGC->ops->PushPixels) (sourceGC, pScreenPriv->sourceBits, pDrawable, w, h,
|
2012-06-10 07:21:05 -06:00
|
|
|
x, y);
|
|
|
|
if (maskGC->fgPixel != mask) {
|
|
|
|
gcval.val = mask;
|
|
|
|
ChangeGC(NullClient, maskGC, GCForeground, &gcval);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
if (maskGC->serialNumber != pDrawable->serialNumber)
|
2012-06-10 07:21:05 -06:00
|
|
|
ValidateGC(pDrawable, maskGC);
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (maskGC->miTranslate) {
|
2006-11-26 11:13:41 -07:00
|
|
|
x = pDrawable->x + x_org;
|
|
|
|
y = pDrawable->y + y_org;
|
2012-06-10 07:21:05 -06:00
|
|
|
}
|
|
|
|
else {
|
2006-11-26 11:13:41 -07:00
|
|
|
x = x_org;
|
|
|
|
y = y_org;
|
|
|
|
}
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
(*maskGC->ops->PushPixels) (maskGC, pScreenPriv->maskBits, pDrawable, w, h, x, y);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static GCPtr
|
2010-07-27 13:02:24 -06:00
|
|
|
miDCMakeGC(WindowPtr pWin)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
GCPtr pGC;
|
2012-06-10 07:21:05 -06:00
|
|
|
int status;
|
|
|
|
XID gcvals[2];
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
gcvals[0] = IncludeInferiors;
|
|
|
|
gcvals[1] = FALSE;
|
2012-06-10 07:21:05 -06:00
|
|
|
pGC = CreateGC((DrawablePtr) pWin,
|
|
|
|
GCSubwindowMode | GCGraphicsExposures, gcvals, &status,
|
|
|
|
(XID) 0, serverClient);
|
2006-11-26 11:13:41 -07:00
|
|
|
return pGC;
|
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCPutUpCursor(DeviceIntPtr pDev, ScreenPtr pScreen, CursorPtr pCursor,
|
|
|
|
int x, int y, unsigned long source, unsigned long mask)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
miDCScreenPtr pScreenPriv = dixLookupPrivate(&pScreen->devPrivates, miDCScreenKey);
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCBufferPtr pBuffer;
|
|
|
|
WindowPtr pWin;
|
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
if (!miDCRealize(pScreen, pCursor))
|
|
|
|
return FALSE;
|
2011-11-05 07:32:40 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
pWin = pScreen->root;
|
|
|
|
pBuffer = miGetDCDevice(pDev, pScreen);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2013-06-07 11:28:45 -06:00
|
|
|
if (pScreenPriv->pPicture) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!EnsurePicture(pBuffer->pRootPicture, &pWin->drawable, pWin))
|
|
|
|
return FALSE;
|
|
|
|
CompositePicture(PictOpOver,
|
2013-06-07 11:28:45 -06:00
|
|
|
pScreenPriv->pPicture,
|
2012-06-10 07:21:05 -06:00
|
|
|
NULL,
|
|
|
|
pBuffer->pRootPicture,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
x, y, pCursor->bits->width, pCursor->bits->height);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-07 11:28:45 -06:00
|
|
|
miDCPutBits((DrawablePtr) pWin,
|
2012-06-10 07:21:05 -06:00
|
|
|
pBuffer->pSourceGC, pBuffer->pMaskGC,
|
|
|
|
x, y, pCursor->bits->width, pCursor->bits->height,
|
|
|
|
source, mask);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCSaveUnderCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
|
|
|
|
int x, int y, int w, int h)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCBufferPtr pBuffer;
|
|
|
|
PixmapPtr pSave;
|
|
|
|
WindowPtr pWin;
|
|
|
|
GCPtr pGC;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
pBuffer = miGetDCDevice(pDev, pScreen);
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
pSave = pBuffer->pSave;
|
2010-12-05 08:36:02 -07:00
|
|
|
pWin = pScreen->root;
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!pSave || pSave->drawable.width < w || pSave->drawable.height < h) {
|
|
|
|
if (pSave)
|
|
|
|
(*pScreen->DestroyPixmap) (pSave);
|
|
|
|
pBuffer->pSave = pSave =
|
|
|
|
(*pScreen->CreatePixmap) (pScreen, w, h, pScreen->rootDepth, 0);
|
|
|
|
if (!pSave)
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
pGC = pBuffer->pSaveGC;
|
2006-11-26 11:13:41 -07:00
|
|
|
if (pSave->drawable.serialNumber != pGC->serialNumber)
|
2012-06-10 07:21:05 -06:00
|
|
|
ValidateGC((DrawablePtr) pSave, pGC);
|
2006-11-26 11:13:41 -07:00
|
|
|
(*pGC->ops->CopyArea) ((DrawablePtr) pWin, (DrawablePtr) pSave, pGC,
|
2012-06-10 07:21:05 -06:00
|
|
|
x, y, w, h, 0, 0);
|
2006-11-26 11:13:41 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCRestoreUnderCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
|
|
|
|
int x, int y, int w, int h)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCBufferPtr pBuffer;
|
|
|
|
PixmapPtr pSave;
|
|
|
|
WindowPtr pWin;
|
|
|
|
GCPtr pGC;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
pBuffer = miGetDCDevice(pDev, pScreen);
|
2009-09-06 13:44:18 -06:00
|
|
|
pSave = pBuffer->pSave;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
pWin = pScreen->root;
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!pSave)
|
2012-06-10 07:21:05 -06:00
|
|
|
return FALSE;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2009-09-06 13:44:18 -06:00
|
|
|
pGC = pBuffer->pRestoreGC;
|
2006-11-26 11:13:41 -07:00
|
|
|
if (pWin->drawable.serialNumber != pGC->serialNumber)
|
2012-06-10 07:21:05 -06:00
|
|
|
ValidateGC((DrawablePtr) pWin, pGC);
|
2006-11-26 11:13:41 -07:00
|
|
|
(*pGC->ops->CopyArea) ((DrawablePtr) pSave, (DrawablePtr) pWin, pGC,
|
2012-06-10 07:21:05 -06:00
|
|
|
0, 0, w, h, x, y);
|
2006-11-26 11:13:41 -07:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
Bool
|
2009-09-06 13:44:18 -06:00
|
|
|
miDCDeviceInitialize(DeviceIntPtr pDev, ScreenPtr pScreen)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCBufferPtr pBuffer;
|
|
|
|
WindowPtr pWin;
|
|
|
|
int i;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
if (!DevHasCursor(pDev))
|
|
|
|
return TRUE;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < screenInfo.numScreens; i++) {
|
2010-07-27 13:02:24 -06:00
|
|
|
pScreen = screenInfo.screens[i];
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
pBuffer = calloc(1, sizeof(miDCBufferRec));
|
2010-07-27 13:02:24 -06:00
|
|
|
if (!pBuffer)
|
|
|
|
goto failure;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
dixSetScreenPrivate(&pDev->devPrivates, miDCDeviceKey, pScreen,
|
|
|
|
pBuffer);
|
2010-12-05 08:36:02 -07:00
|
|
|
pWin = pScreen->root;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
pBuffer->pSourceGC = miDCMakeGC(pWin);
|
|
|
|
if (!pBuffer->pSourceGC)
|
|
|
|
goto failure;
|
|
|
|
|
|
|
|
pBuffer->pMaskGC = miDCMakeGC(pWin);
|
|
|
|
if (!pBuffer->pMaskGC)
|
|
|
|
goto failure;
|
|
|
|
|
|
|
|
pBuffer->pSaveGC = miDCMakeGC(pWin);
|
|
|
|
if (!pBuffer->pSaveGC)
|
|
|
|
goto failure;
|
|
|
|
|
|
|
|
pBuffer->pRestoreGC = miDCMakeGC(pWin);
|
|
|
|
if (!pBuffer->pRestoreGC)
|
|
|
|
goto failure;
|
|
|
|
|
|
|
|
pBuffer->pRootPicture = NULL;
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
/* (re)allocated lazily depending on the cursor size */
|
|
|
|
pBuffer->pSave = NULL;
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
|
|
|
|
return TRUE;
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
failure:
|
2010-07-27 13:02:24 -06:00
|
|
|
|
|
|
|
miDCDeviceCleanup(pDev, pScreen);
|
|
|
|
|
|
|
|
return FALSE;
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
void
|
2009-09-06 13:44:18 -06:00
|
|
|
miDCDeviceCleanup(DeviceIntPtr pDev, ScreenPtr pScreen)
|
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
miDCBufferPtr pBuffer;
|
|
|
|
int i;
|
2009-09-06 13:44:18 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (DevHasCursor(pDev)) {
|
|
|
|
for (i = 0; i < screenInfo.numScreens; i++) {
|
2010-07-27 13:02:24 -06:00
|
|
|
pScreen = screenInfo.screens[i];
|
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
pBuffer = miGetDCDevice(pDev, pScreen);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pBuffer) {
|
|
|
|
if (pBuffer->pSourceGC)
|
|
|
|
FreeGC(pBuffer->pSourceGC, (GContext) 0);
|
|
|
|
if (pBuffer->pMaskGC)
|
|
|
|
FreeGC(pBuffer->pMaskGC, (GContext) 0);
|
|
|
|
if (pBuffer->pSaveGC)
|
|
|
|
FreeGC(pBuffer->pSaveGC, (GContext) 0);
|
|
|
|
if (pBuffer->pRestoreGC)
|
|
|
|
FreeGC(pBuffer->pRestoreGC, (GContext) 0);
|
2010-12-05 08:36:02 -07:00
|
|
|
|
|
|
|
/* If a pRootPicture was allocated for a root window, it
|
|
|
|
* is freed when that root window is destroyed, so don't
|
|
|
|
* free it again here. */
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (pBuffer->pSave)
|
|
|
|
(*pScreen->DestroyPixmap) (pBuffer->pSave);
|
2010-07-27 13:02:24 -06:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
free(pBuffer);
|
2012-06-10 07:21:05 -06:00
|
|
|
dixSetScreenPrivate(&pDev->devPrivates, miDCDeviceKey, pScreen,
|
|
|
|
NULL);
|
2010-07-27 13:02:24 -06:00
|
|
|
}
|
|
|
|
}
|
2009-09-06 13:44:18 -06:00
|
|
|
}
|
|
|
|
}
|