[PATCHv2] Use screen privates for Xv offscreen images.

Jamey Sharp jamey at minilop.net
Thu Apr 22 21:41:00 PDT 2010


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

Signed-off-by: Jamey Sharp <jamey at minilop.net>
---

On Thu, Apr 22, 2010 at 11:29 AM, Vignatti Tiago (Nokia-D/Helsinki) <tiago.vignatti at nokia.com> wrote:
> On Thu, Apr 22, 2010 at 07:42:56PM +0200, Vignatti Tiago (Nokia-D/Helsinki) wrote:
>> PS: there's a bug in your xv patch that I'm trying to track down now.
>
> Haven't had time to see this today, Jamey. But the problem is that
> xf86XVRegisterOffscreenImages is being called before ScreenPriv be allocated
> (done after, inside xf86XVScreenInit).

So it is. Oops. Apparently I don't have any hardware that tests this
code. How about this version instead? I've at least read the callers
more carefully now.

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

diff --git a/hw/xfree86/common/xf86xv.c b/hw/xfree86/common/xf86xv.c
index bdcc4fc..1503502 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,15 @@ xf86XVRegisterOffscreenImages(
     XF86OffscreenImagePtr images,
     int num
 ){
-    OffscreenImages[pScreen->myNum].num = num;
-    OffscreenImages[pScreen->myNum].images = images;
-
+    OffscreenImageRec *OffscreenImage;
+    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 +213,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 +1186,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