summaryrefslogtreecommitdiff
path: root/xserver/Xext/xvmain.c
diff options
context:
space:
mode:
Diffstat (limited to 'xserver/Xext/xvmain.c')
-rw-r--r--xserver/Xext/xvmain.c95
1 files changed, 31 insertions, 64 deletions
diff --git a/xserver/Xext/xvmain.c b/xserver/Xext/xvmain.c
index 0abf190dc..c9b11d4bb 100644
--- a/xserver/Xext/xvmain.c
+++ b/xserver/Xext/xvmain.c
@@ -327,36 +327,24 @@ XvGetRTPort(void)
return XvRTPort;
}
-static Bool
-XvDestroyPixmap(PixmapPtr pPix)
+static void
+XvStopAdaptors(DrawablePtr pDrawable)
{
- Bool status;
- ScreenPtr pScreen;
- XvScreenPtr pxvs;
- XvAdaptorPtr pa;
- int na;
- XvPortPtr pp;
- int np;
-
- pScreen = pPix->drawable.pScreen;
-
- SCREEN_PROLOGUE(pScreen, DestroyPixmap);
-
- pxvs = (XvScreenPtr) dixLookupPrivate(&pScreen->devPrivates, XvScreenKey);
+ ScreenPtr pScreen = pDrawable->pScreen;
+ XvScreenPtr pxvs = dixLookupPrivate(&pScreen->devPrivates, XvScreenKey);
+ XvAdaptorPtr pa = pxvs->pAdaptors;
+ int na = pxvs->nAdaptors;
/* CHECK TO SEE IF THIS PORT IS IN USE */
-
- pa = pxvs->pAdaptors;
- na = pxvs->nAdaptors;
while (na--) {
- np = pa->nPorts;
- pp = pa->pPorts;
+ XvPortPtr pp = pa->pPorts;
+ int np = pa->nPorts;
while (np--) {
- if (pp->pDraw == (DrawablePtr) pPix) {
- XvdiSendVideoNotify(pp, pp->pDraw, XvPreempted);
+ if (pp->pDraw == pDrawable) {
+ XvdiSendVideoNotify(pp, pDrawable, XvPreempted);
- (void) (*pp->pAdaptor->ddStopVideo) (pp, pp->pDraw);
+ (void) (*pp->pAdaptor->ddStopVideo) (pp, pDrawable);
pp->pDraw = NULL;
pp->client = NULL;
@@ -366,9 +354,19 @@ XvDestroyPixmap(PixmapPtr pPix)
}
pa++;
}
+}
- status = (*pScreen->DestroyPixmap) (pPix);
+static Bool
+XvDestroyPixmap(PixmapPtr pPix)
+{
+ ScreenPtr pScreen = pPix->drawable.pScreen;
+ Bool status;
+ if (pPix->refcnt == 1)
+ XvStopAdaptors(&pPix->drawable);
+
+ SCREEN_PROLOGUE(pScreen, DestroyPixmap);
+ status = (*pScreen->DestroyPixmap) (pPix);
SCREEN_EPILOGUE(pScreen, DestroyPixmap, XvDestroyPixmap);
return status;
@@ -378,45 +376,13 @@ XvDestroyPixmap(PixmapPtr pPix)
static Bool
XvDestroyWindow(WindowPtr pWin)
{
+ ScreenPtr pScreen = pWin->drawable.pScreen;
Bool status;
- ScreenPtr pScreen;
- XvScreenPtr pxvs;
- XvAdaptorPtr pa;
- int na;
- XvPortPtr pp;
- int np;
- pScreen = pWin->drawable.pScreen;
+ XvStopAdaptors(&pWin->drawable);
SCREEN_PROLOGUE(pScreen, DestroyWindow);
-
- pxvs = (XvScreenPtr) dixLookupPrivate(&pScreen->devPrivates, XvScreenKey);
-
- /* CHECK TO SEE IF THIS PORT IS IN USE */
-
- pa = pxvs->pAdaptors;
- na = pxvs->nAdaptors;
- while (na--) {
- np = pa->nPorts;
- pp = pa->pPorts;
-
- while (np--) {
- if (pp->pDraw == (DrawablePtr) pWin) {
- XvdiSendVideoNotify(pp, pp->pDraw, XvPreempted);
-
- (void) (*pp->pAdaptor->ddStopVideo) (pp, pp->pDraw);
-
- pp->pDraw = NULL;
- pp->client = NULL;
- pp->time = currentTime;
- }
- pp++;
- }
- pa++;
- }
-
status = (*pScreen->DestroyWindow) (pWin);
-
SCREEN_EPILOGUE(pScreen, DestroyWindow, XvDestroyWindow);
return status;
@@ -834,10 +800,9 @@ XvdiSelectVideoNotify(ClientPtr client, DrawablePtr pDraw, BOOL onoff)
if (!(tpn = malloc(sizeof(XvVideoNotifyRec))))
return BadAlloc;
tpn->next = NULL;
- if (!AddResource(pDraw->id, XvRTVideoNotifyList, tpn)) {
- free(tpn);
+ tpn->client = NULL;
+ if (!AddResource(pDraw->id, XvRTVideoNotifyList, tpn))
return BadAlloc;
- }
}
else {
/* LOOK TO SEE IF ENTRY ALREADY EXISTS */
@@ -878,7 +843,8 @@ XvdiSelectVideoNotify(ClientPtr client, DrawablePtr pDraw, BOOL onoff)
tpn->client = NULL;
tpn->id = FakeClientID(client->index);
- AddResource(tpn->id, XvRTVideoNotify, tpn);
+ if (!AddResource(tpn->id, XvRTVideoNotify, tpn))
+ return BadAlloc;
tpn->client = client;
return Success;
@@ -927,7 +893,8 @@ XvdiSelectPortNotify(ClientPtr client, XvPortPtr pPort, BOOL onoff)
tpn->client = client;
tpn->id = FakeClientID(client->index);
- AddResource(tpn->id, XvRTPortNotify, tpn);
+ if (!AddResource(tpn->id, XvRTPortNotify, tpn))
+ return BadAlloc;
return Success;
@@ -1102,7 +1069,7 @@ XvFillColorKey(DrawablePtr pDraw, CARD32 key, RegionPtr region)
(void) ChangeGC(NullClient, gc, GCForeground | GCSubwindowMode, pval);
ValidateGC(pDraw, gc);
- rects = malloc(nbox * sizeof(xRectangle));
+ rects = xallocarray(nbox, sizeof(xRectangle));
if (rects) {
for (i = 0; i < nbox; i++, pbox++) {
rects[i].x = pbox->x1 - pDraw->x;