[PATCHv3] xfree86: use screen privates for Xv offscreen images.

Jamey Sharp jamey at minilop.net
Mon Apr 26 12:56:21 PDT 2010


This replaces a globally-allocated array that depended on MAXSCREENS.

Signed-off-by: Jamey Sharp <jamey at minilop.net>
---
On Mon, Apr 26, 2010 at 12:06 PM, Aaron Plattner <aplattner at nvidia.com> wrote:
> Ah, okay, I didn't realize there was an ordering problem there.  It's
> kind of weird that clients are allowed to do that, but given that,
> calling dixRequestPrivate each time seems okay.  It might be nice to
> have a comment to that effect in xf86XVRegisterOffscreenImages.

Good point. Here's one.

Tiago, if you happen to get this version into your tree before Keith
pulls it, cool; else, oh well, it's just a comment.

 hw/xfree86/common/xf86xv.c |   27 ++++++++++++++++++---------
 1 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index bdcc4fc..2cc2f60 100644
--- a/hw/xfree86/common/xf86xv.c
+++ b/hw/xfree86/common/xf86xv.c
@@ -186,7 +186,9 @@ typedef struct {
    int num;
 } OffscreenImageRec;
 
-static OffscreenImageRec OffscreenImages[MAXSCREENS];
+static int OffscreenPrivateKeyIndex;
+static DevPrivateKey OffscreenPrivateKey = &OffscreenPrivateKeyIndex;
+#define GetOffscreenImage(pScreen) ((OffscreenImageRec *) dixLookupPrivate(&(pScreen)->devPrivates, OffscreenPrivateKey))
 
 Bool
 xf86XVRegisterOffscreenImages(
@@ -194,9 +196,18 @@ xf86XVRegisterOffscreenImages(
     XF86OffscreenImagePtr images,
     int num
 ){
-    OffscreenImages[pScreen->myNum].num = num;
-    OffscreenImages[pScreen->myNum].images = images;
-
+    OffscreenImageRec *OffscreenImage;
+    /* This function may be called before xf86XVScreenInit, so there's
+     * no better place than this to call dixRequestPrivate to ensure we
+     * have space reserved. After the first call it is a no-op. */
+    if(!dixRequestPrivate(OffscreenPrivateKey, sizeof(OffscreenImageRec)) ||
+       !(OffscreenImage = GetOffscreenImage(pScreen)))
+        /* Every X.org driver assumes this function always succeeds, so
+         * just die on allocation failure. */
+        FatalError("Could not allocate private storage for XV offscreen images.\n");
+
+    OffscreenImage->num = num;
+    OffscreenImage->images = images;
     return TRUE;
 }
 
@@ -205,8 +216,9 @@ xf86XVQueryOffscreenImages(
    ScreenPtr pScreen,
    int *num
 ){
-   *num = OffscreenImages[pScreen->myNum].num;
-   return OffscreenImages[pScreen->myNum].images;
+    OffscreenImageRec *OffscreenImage = GetOffscreenImage(pScreen);
+    *num = OffscreenImage->num;
+    return OffscreenImage->images;
 }
 
 
@@ -1177,9 +1189,6 @@ xf86XVCloseScreen(int i, ScreenPtr pScreen)
   XvAdaptorPtr pa;
   int c;
 
-  /* Clear offscreen images */
-  memset(&OffscreenImages[pScreen->myNum], 0, sizeof(OffscreenImages[0]));
-
   if(!ScreenPriv) return TRUE;
 
   if(ScreenPriv->videoGC) {
-- 
1.7.0



More information about the xorg-devel mailing list