To prepare for RandR using filters in transforms, split out
code paths so that the RandR code can validate the filter name and
parameters during the transform set operation so that use of the filter
later will not have unreportable errors.
---
 render/filter.c     |   57 +++++++++++++++++++++++++++++++++++---------------
 render/picturestr.h |    9 ++++++-
 2 files changed, 47 insertions(+), 19 deletions(-)

diff --git a/render/filter.c b/render/filter.c
index aa3eb1a..e499fc4 100644
--- a/render/filter.c
+++ b/render/filter.c
@@ -213,7 +213,7 @@ PictureFindFilter (ScreenPtr pScreen, char *name, int len)
 }
 
 static Bool
-convolutionFilterValidateParams (PicturePtr pPicture,
+convolutionFilterValidateParams (ScreenPtr pScreen,
                                  int      filter,
                                  xFixed           *params,
                                  int      nparams)
@@ -270,29 +270,51 @@ int
 SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, 
int nparams)
 {
     PictFilterPtr      pFilter;
-    xFixed             *new_params;
-    int                        i, s, result;
+    ScreenPtr          pScreen;
 
-    pFilter = PictureFindFilter (screenInfo.screens[0], name, len);
+    if (pPicture->pDrawable != NULL)
+       pScreen = pPicture->pDrawable->pScreen;
+    else
+       pScreen = screenInfo.screens[0];
+
+    pFilter = PictureFindFilter (pScreen, name, len);
+
+    if (!pFilter)
+       return BadName;
 
-    if (pPicture->pDrawable == NULL) {
+    if (pPicture->pDrawable == NULL)
+    {
+       int s;
        /* For source pictures, the picture isn't tied to a screen.  So, ensure
         * that all screens can handle a filter we set for the picture.
         */
-       for (s = 0; s < screenInfo.numScreens; s++) {
-           if (PictureFindFilter (screenInfo.screens[s], name, len)->id !=
-               pFilter->id)
-           {
+       for (s = 1; s < screenInfo.numScreens; s++)
+       {
+           PictFilterPtr   pScreenFilter;
+           pScreenFilter = PictureFindFilter (screenInfo.screens[s],
+                                              name, len);
+           if (!pScreenFilter || pScreenFilter->id != pFilter->id)
                return BadMatch;
-           }
        }
     }
+    return SetPicturePictFilter (pPicture, pFilter, params, nparams);
+}
+
+int
+SetPicturePictFilter (PicturePtr pPicture, PictFilterPtr pFilter,
+                     xFixed *params, int nparams)
+{
+    ScreenPtr  pScreen;
+    int                i;
+
+    if (pPicture->pDrawable)
+       pScreen = pPicture->pDrawable->pScreen;
+    else
+       pScreen = screenInfo.screens[0];
 
-    if (!pFilter)
-       return BadName;
     if (pFilter->ValidateParams)
     {
-       if (!(*pFilter->ValidateParams) (pPicture, pFilter->id, params, 
nparams))
+       if (!(*pFilter->ValidateParams) (pScreen, pFilter->id, params, nparams))
            return BadMatch;
     }
     else if (nparams)
@@ -300,7 +322,7 @@ SetPictureFilter (PicturePtr pPicture, char *name, int len, 
xFixed *params, int
 
     if (nparams != pPicture->filter_nparams)
     {
-       new_params = xalloc (nparams * sizeof (xFixed));
+       xFixed *new_params = xalloc (nparams * sizeof (xFixed));
        if (!new_params && nparams)
            return BadAlloc;
        xfree (pPicture->filter_params);
@@ -311,9 +333,10 @@ SetPictureFilter (PicturePtr pPicture, char *name, int 
len, xFixed *params, int
        pPicture->filter_params[i] = params[i];
     pPicture->filter = pFilter->id;
 
-    if (pPicture->pDrawable) {
-       ScreenPtr pScreen = pPicture->pDrawable->pScreen;
-       PictureScreenPtr ps = GetPictureScreen(pScreen);
+    if (pPicture->pDrawable)
+    {
+       PictureScreenPtr    ps = GetPictureScreen(pScreen);
+       int                 result;
 
        result = (*ps->ChangePictureFilter) (pPicture, pPicture->filter,
                                             params, nparams);
diff --git a/render/picturestr.h b/render/picturestr.h
index 93d86bd..8a926ce 100644
--- a/render/picturestr.h
+++ b/render/picturestr.h
@@ -184,7 +184,7 @@ typedef struct _Picture {
     SourcePictPtr   pSourcePict;
 } PictureRec;
 
-typedef Bool (*PictFilterValidateParamsProcPtr) (PicturePtr pPicture, int id,
+typedef Bool (*PictFilterValidateParamsProcPtr) (ScreenPtr pScreen, int id,
                                                 xFixed *params, int nparams);
 typedef struct {
     char                           *name;
@@ -473,7 +473,12 @@ PictFilterPtr
 PictureFindFilter (ScreenPtr pScreen, char *name, int len);
 
 int
-SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, 
int nparams);
+SetPicturePictFilter (PicturePtr pPicture, PictFilterPtr pFilter,
+                     xFixed *params, int nparams);
+
+int
+SetPictureFilter (PicturePtr pPicture, char *name, int len,
+                 xFixed *params, int nparams);
 
 Bool
 PictureFinishInit (void);
-- 
1.5.6.5

_______________________________________________
xorg mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/xorg

Reply via email to