Skip to content

Commit

Permalink
hw/nxagent: Backport latest devPrivates ABI from X.org.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunweaver committed Nov 21, 2017
1 parent 56e01e8 commit 5ae81d1
Show file tree
Hide file tree
Showing 32 changed files with 368 additions and 441 deletions.
206 changes: 102 additions & 104 deletions nx-X11/programs/Xserver/Xext/shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ in this Software without prior written authorization from The Open Group.
#include "gcstruct.h"
#include "extnsionst.h"
#include "servermd.h"
#include "shmint.h"
#define _XSHM_SERVER_
#include <X11/extensions/shmstr.h>
#include <nx-X11/Xfuncproto.h>

#include "protocol-versions.h"
Expand All @@ -61,14 +61,11 @@ in this Software without prior written authorization from The Open Group.
#include "panoramiXsrv.h"
#endif

typedef struct _ShmDesc {
struct _ShmDesc *next;
int shmid;
int refcnt;
char *addr;
Bool writable;
unsigned long size;
} ShmDescRec, *ShmDescPtr;
typedef struct _ShmScrPrivateRec {
CloseScreenProcPtr CloseScreen;
ShmFuncsPtr shmFuncs;
DestroyPixmapProcPtr destroyPixmap;
} ShmScrPrivateRec;

static void miShmPutImage(XSHM_PUT_IMAGE_ARGS);
static void fbShmPutImage(XSHM_PUT_IMAGE_ARGS);
Expand Down Expand Up @@ -108,15 +105,16 @@ int BadShmSegCode;
RESTYPE ShmSegType;
static ShmDescPtr Shmsegs;
static Bool sharedPixmaps;
static int pixmapFormat;
static int shmPixFormat[MAXSCREENS];
static ShmFuncsPtr shmFuncs[MAXSCREENS];
static DestroyPixmapProcPtr destroyPixmap[MAXSCREENS];
#ifdef PIXPRIV
static int shmPixmapPrivate;
#endif
static ShmFuncs miFuncs = {NULL, miShmPutImage};
static ShmFuncs fbFuncs = {fbShmCreatePixmap, fbShmPutImage};
static DevPrivateKeyRec shmScrPrivateKeyRec;

#define shmScrPrivateKey (&shmScrPrivateKeyRec)
static DevPrivateKeyRec shmPixmapPrivateKeyRec;

#define shmPixmapPrivateKey (&shmPixmapPrivateKeyRec)
static ShmFuncs miFuncs = { NULL, miShmPutImage };
static ShmFuncs fbFuncs = { fbShmCreatePixmap, fbShmPutImage };

#define ShmGetScreenPriv(s) ((ShmScrPrivateRec *)dixLookupPrivate(&(s)->devPrivates, shmScrPrivateKey))

#define VERIFY_SHMSEG(shmseg,shmdesc,client) \
{ \
Expand Down Expand Up @@ -204,42 +202,28 @@ ShmExtensionInit(void)
}
#endif

if (!ShmRegisterPrivates())
return;

sharedPixmaps = xFalse;
pixmapFormat = 0;
{
sharedPixmaps = xTrue;
pixmapFormat = shmPixFormat[0];
for (i = 0; i < screenInfo.numScreens; i++)
{
if (!shmFuncs[i])
shmFuncs[i] = &miFuncs;
if (!shmFuncs[i]->CreatePixmap)
sharedPixmaps = xFalse;
if (shmPixFormat[i] && (shmPixFormat[i] != pixmapFormat))
{
sharedPixmaps = xFalse;
pixmapFormat = 0;
sharedPixmaps = xTrue;
for (i = 0; i < screenInfo.numScreens; i++) {
ShmScrPrivateRec *screen_priv =
ShmInitScreenPriv(screenInfo.screens[i]);
if (!screen_priv->shmFuncs)
screen_priv->shmFuncs = &miFuncs;
if (!screen_priv->shmFuncs->CreatePixmap)
sharedPixmaps = xFalse;
}
}
if (!pixmapFormat)
pixmapFormat = ZPixmap;
if (sharedPixmaps)
{
for (i = 0; i < screenInfo.numScreens; i++)
{
destroyPixmap[i] = screenInfo.screens[i]->DestroyPixmap;
screenInfo.screens[i]->DestroyPixmap = ShmDestroyPixmap;
}
#ifdef PIXPRIV
shmPixmapPrivate = AllocatePixmapPrivateIndex();
for (i = 0; i < screenInfo.numScreens; i++)
{
if (!AllocatePixmapPrivate(screenInfo.screens[i],
shmPixmapPrivate, 0))
return;
}
#endif
}
if (sharedPixmaps)
for (i = 0; i < screenInfo.numScreens; i++) {
ShmScrPrivateRec *screen_priv =
ShmGetScreenPriv(screenInfo.screens[i]);
screen_priv->destroyPixmap =
screenInfo.screens[i]->DestroyPixmap;
screenInfo.screens[i]->DestroyPixmap = ShmDestroyPixmap;
}
}
ShmSegType = CreateNewResourceType(ShmDetachSegment);
if (ShmSegType &&
Expand All @@ -255,76 +239,87 @@ ShmExtensionInit(void)
}
#endif /* NXAGENT_SERVER */

/*ARGSUSED*/
static void
ShmResetProc (extEntry)
ExtensionEntry *extEntry;
static Bool
ShmCloseScreen(ScreenPtr pScreen)
{
int i;
ShmScrPrivateRec *screen_priv = ShmGetScreenPriv(pScreen);

for (i = 0; i < MAXSCREENS; i++)
{
shmFuncs[i] = (ShmFuncsPtr)NULL;
shmPixFormat[i] = 0;
pScreen->CloseScreen = screen_priv->CloseScreen;
dixSetPrivate(&pScreen->devPrivates, shmScrPrivateKey, NULL);
free(screen_priv);
return (*pScreen->CloseScreen) (pScreen);
}

static ShmScrPrivateRec *
ShmInitScreenPriv(ScreenPtr pScreen)
{
ShmScrPrivateRec *screen_priv = ShmGetScreenPriv(pScreen);

if (!screen_priv) {
screen_priv = calloc(1, sizeof(ShmScrPrivateRec));
screen_priv->CloseScreen = pScreen->CloseScreen;
dixSetPrivate(&pScreen->devPrivates, shmScrPrivateKey, screen_priv);
pScreen->CloseScreen = ShmCloseScreen;
}
return screen_priv;
}

void
ShmRegisterFuncs(
ScreenPtr pScreen,
ShmFuncsPtr funcs)
static Bool
ShmRegisterPrivates(void)
{
shmFuncs[pScreen->myNum] = funcs;
if (!dixRegisterPrivateKey(&shmScrPrivateKeyRec, PRIVATE_SCREEN, 0))
return FALSE;
if (!dixRegisterPrivateKey(&shmPixmapPrivateKeyRec, PRIVATE_PIXMAP, 0))
return FALSE;
return TRUE;
}

/*ARGSUSED*/ static void
ShmResetProc(ExtensionEntry * extEntry)
{
int i;

for (i = 0; i < screenInfo.numScreens; i++)
ShmRegisterFuncs(screenInfo.screens[i], NULL);
}

void
ShmSetPixmapFormat(
ShmRegisterFuncs(
ScreenPtr pScreen,
int format)
ShmFuncsPtr funcs)
{
shmPixFormat[pScreen->myNum] = format;
if (!ShmRegisterPrivates())
return;
ShmInitScreenPriv(pScreen)->shmFuncs = funcs;
}

static Bool
ShmDestroyPixmap (PixmapPtr pPixmap)
{
ScreenPtr pScreen = pPixmap->drawable.pScreen;
ShmScrPrivateRec *screen_priv = ShmGetScreenPriv(pScreen);
void *shmdesc = NULL;
Bool ret;

if (pPixmap->refcnt == 1)
{
ShmDescPtr shmdesc;
#ifdef PIXPRIV
shmdesc = (ShmDescPtr) pPixmap->devPrivates[shmPixmapPrivate].ptr;
#else
char *base = (char *) pPixmap->devPrivate.ptr;

if (base != (void *) (pPixmap + 1))
{
for (shmdesc = Shmsegs; shmdesc; shmdesc = shmdesc->next)
{
if (shmdesc->addr <= base && base <= shmdesc->addr + shmdesc->size)
break;
}
}
else
shmdesc = 0;
#endif
if (shmdesc)
ShmDetachSegment ((void *) shmdesc, pPixmap->drawable.id);
}

pScreen->DestroyPixmap = destroyPixmap[pScreen->myNum];
shmdesc = dixLookupPrivate(&pPixmap->devPrivates, shmPixmapPrivateKey);

pScreen->DestroyPixmap = screen_priv->destroyPixmap;
ret = (*pScreen->DestroyPixmap) (pPixmap);
destroyPixmap[pScreen->myNum] = pScreen->DestroyPixmap;
screen_priv->destroyPixmap = pScreen->DestroyPixmap;
pScreen->DestroyPixmap = ShmDestroyPixmap;

if (shmdesc)
ShmDetachSegment ((void *) shmdesc, pPixmap->drawable.id);

return ret;
}

void
ShmRegisterFbFuncs(pScreen)
ScreenPtr pScreen;
{
shmFuncs[pScreen->myNum] = &fbFuncs;
ShmRegisterFuncs(pScreen, &fbFuncs);
}

static int
Expand All @@ -339,7 +334,6 @@ ProcShmQueryVersion(client)
rep.length = 0;
rep.sequenceNumber = client->sequence;
rep.sharedPixmaps = sharedPixmaps;
rep.pixmapFormat = pixmapFormat;
rep.majorVersion = SERVER_SHM_MAJOR_VERSION;
rep.minorVersion = SERVER_SHM_MINOR_VERSION;
rep.uid = geteuid();
Expand Down Expand Up @@ -777,16 +771,17 @@ ProcPanoramiXShmCreatePixmap(
result = (client->noClientException);

FOR_NSCREENS(j) {
ShmScrPrivateRec *screen_priv;

pScreen = screenInfo.screens[j];

pMap = (*shmFuncs[j]->CreatePixmap)(pScreen,
screen_priv = ShmGetScreenPriv(pScreen);
pMap = (*screen_priv->shmFuncs->CreatePixmap)(pScreen,
stuff->width, stuff->height, stuff->depth,
shmdesc->addr + stuff->offset);

if (pMap) {
#ifdef PIXPRIV
pMap->devPrivates[shmPixmapPrivate].ptr = (void *) shmdesc;
#endif
dixSetPrivate(&pMap->devPrivates, shmPixmapPrivateKey, shmdesc);
shmdesc->refcnt++;
pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
pMap->drawable.id = newPix->info[j].id;
Expand Down Expand Up @@ -824,8 +819,9 @@ ProcShmPutImage(client)
register DrawablePtr pDraw;
long length;
ShmDescPtr shmdesc;
REQUEST(xShmPutImageReq);
ShmScrPrivateRec *screen_priv;

REQUEST(xShmPutImageReq);
REQUEST_SIZE_MATCH(xShmPutImageReq);
VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, pGC, client);
VERIFY_SHMPTR(stuff->shmseg, stuff->offset, FALSE, shmdesc, client);
Expand Down Expand Up @@ -902,7 +898,8 @@ ProcShmPutImage(client)
shmdesc->addr + stuff->offset +
(stuff->srcY * length));
else
(*shmFuncs[pDraw->pScreen->myNum]->PutImage)(
screen_priv = ShmGetScreenPriv(pDraw->pScreen);
(*screen_priv->shmFuncs->PutImage)(
pDraw, pGC, stuff->depth, stuff->format,
stuff->totalWidth, stuff->totalHeight,
stuff->srcX, stuff->srcY,
Expand Down Expand Up @@ -1074,6 +1071,8 @@ ProcShmCreatePixmap(client)
DepthPtr pDepth;
register int i;
ShmDescPtr shmdesc;
ShmScrPrivateRec *screen_priv;

REQUEST(xShmCreatePixmapReq);
unsigned int width, height, depth;
unsigned long size;
Expand Down Expand Up @@ -1118,15 +1117,14 @@ ProcShmCreatePixmap(client)
}

VERIFY_SHMSIZE(shmdesc, stuff->offset, size, client);
pMap = (*shmFuncs[pDraw->pScreen->myNum]->CreatePixmap)(
screen_priv = ShmGetScreenPriv(pDraw->pScreen);
pMap = (*screen_priv->shmFuncs->CreatePixmap)(
pDraw->pScreen, stuff->width,
stuff->height, stuff->depth,
shmdesc->addr + stuff->offset);
if (pMap)
{
#ifdef PIXPRIV
pMap->devPrivates[shmPixmapPrivate].ptr = (void *) shmdesc;
#endif
dixSetPrivate(&pMap->devPrivates, shmPixmapPrivateKey, shmdesc);
shmdesc->refcnt++;
pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
pMap->drawable.id = stuff->pid;
Expand Down
44 changes: 39 additions & 5 deletions nx-X11/programs/Xserver/Xext/shmint.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,54 @@
#ifndef _SHMINT_H_
#define _SHMINT_H_

#define _XSHM_SERVER_
#include <X11/extensions/shmstr.h>
#include <X11/extensions/shmproto.h>

#include "screenint.h"
#include "pixmap.h"
#include "gc.h"

void
ShmRegisterFuncs(ScreenPtr pScreen, ShmFuncsPtr funcs);
#define XSHM_PUT_IMAGE_ARGS \
DrawablePtr /* dst */, \
GCPtr /* pGC */, \
int /* depth */, \
unsigned int /* format */, \
int /* w */, \
int /* h */, \
int /* sx */, \
int /* sy */, \
int /* sw */, \
int /* sh */, \
int /* dx */, \
int /* dy */, \
char * /* data */

#define XSHM_CREATE_PIXMAP_ARGS \
ScreenPtr /* pScreen */, \
int /* width */, \
int /* height */, \
int /* depth */, \
char * /* addr */

typedef struct _ShmFuncs {
PixmapPtr (*CreatePixmap) (XSHM_CREATE_PIXMAP_ARGS);
void (*PutImage) (XSHM_PUT_IMAGE_ARGS);
} ShmFuncs, *ShmFuncsPtr;

typedef struct _ShmDesc {
struct _ShmDesc *next;
int shmid;
int refcnt;
char *addr;
Bool writable;
unsigned long size;
} ShmDescRec, *ShmDescPtr;

void
ShmSetPixmapFormat(ScreenPtr pScreen, int format);
ShmRegisterFuncs(ScreenPtr pScreen, ShmFuncsPtr funcs);

void
ShmRegisterFbFuncs(ScreenPtr pScreen);



#endif /* _SHMINT_H_ */
Loading

0 comments on commit 5ae81d1

Please sign in to comment.