Commit 21c3d20f authored by Mike Gabriel's avatar Mike Gabriel

[render] Split out filter finding from filter setting.

Backported from X.org: commit acda790e430b2a18c7c35379f6e538f3d01ff221 Author: Keith Packard <keithp@keithp.com> Date: Fri Mar 14 13:46:30 2008 -0700 [render] Split out filter finding from filter setting. 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. Backport to nx-libs: Mike Gabriel <mike.gabriel@das-netzwerkteam.de>
parent e3838817
...@@ -482,7 +482,12 @@ PictFilterPtr ...@@ -482,7 +482,12 @@ PictFilterPtr
PictureFindFilter (ScreenPtr pScreen, char *name, int len); PictureFindFilter (ScreenPtr pScreen, char *name, int len);
int 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 Bool
PictureFinishInit (void); PictureFinishInit (void);
......
...@@ -215,21 +215,30 @@ PictureFindFilter (ScreenPtr pScreen, char *name, int len) ...@@ -215,21 +215,30 @@ PictureFindFilter (ScreenPtr pScreen, char *name, int len)
} }
static Bool static Bool
convolutionFilterValidateParams (PicturePtr pPicture, convolutionFilterValidateParams (ScreenPtr pScreen,
int filter, int filter,
xFixed *params, xFixed *params,
int nparams) int nparams,
int* width,
int* height)
{ {
int w, h;
if (nparams < 3) if (nparams < 3)
return FALSE; return FALSE;
if (xFixedFrac (params[0]) || xFixedFrac (params[1])) if (xFixedFrac (params[0]) || xFixedFrac (params[1]))
return FALSE; return FALSE;
w = xFixedToInt (params[0]);
h = xFixedToInt (params[1]);
nparams -= 2; nparams -= 2;
if ((xFixedToInt (params[0]) * xFixedToInt (params[1])) > nparams) if (w * h > nparams)
return FALSE; return FALSE;
*width = w;
*height = h;
return TRUE; return TRUE;
} }
...@@ -271,10 +280,8 @@ PictureResetFilters (ScreenPtr pScreen) ...@@ -271,10 +280,8 @@ PictureResetFilters (ScreenPtr pScreen)
int int
SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int nparams) SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int nparams)
{ {
ScreenPtr pScreen;
PictFilterPtr pFilter; PictFilterPtr pFilter;
xFixed *new_params; ScreenPtr pScreen;
int i;
if (pPicture->pDrawable) { if (pPicture->pDrawable) {
pScreen = pPicture->pDrawable->pScreen; pScreen = pPicture->pDrawable->pScreen;
...@@ -288,7 +295,7 @@ SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int ...@@ -288,7 +295,7 @@ SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int
if (!pFilter) if (!pFilter)
return BadName; return BadName;
if (!pPicture->pDrawable) { if (pPicture->pDrawable == NULL) {
int s; int s;
/* For source pictures, the picture isn't tied to a screen. So, ensure /* For source pictures, the picture isn't tied to a screen. So, ensure
...@@ -303,8 +310,25 @@ SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int ...@@ -303,8 +310,25 @@ SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int
} }
} }
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->ValidateParams) { if (pFilter->ValidateParams) {
if (!(*pFilter->ValidateParams) (pPicture, pFilter->id, params, nparams)) int width, height;
if (!(*pFilter->ValidateParams) (pScreen, pFilter->id, params, nparams, &width, &height))
return BadMatch; return BadMatch;
} }
else if (nparams) { else if (nparams) {
...@@ -312,7 +336,7 @@ SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int ...@@ -312,7 +336,7 @@ SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int
} }
if (nparams != pPicture->filter_nparams) { if (nparams != pPicture->filter_nparams) {
new_params = xalloc (nparams * sizeof (xFixed)); xFixed *new_params = xalloc (nparams * sizeof (xFixed));
if (!new_params && nparams) if (!new_params && nparams)
return BadAlloc; return BadAlloc;
...@@ -324,8 +348,9 @@ SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int ...@@ -324,8 +348,9 @@ SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int
pPicture->filter_params[i] = params[i]; pPicture->filter_params[i] = params[i];
pPicture->filter = pFilter->id; pPicture->filter = pFilter->id;
if (pPicture->pDrawable) { if (pPicture->pDrawable)
PictureScreenPtr ps = GetPictureScreen (pScreen); {
PictureScreenPtr ps = GetPictureScreen(pScreen);
int result; int result;
result = (*ps->ChangePictureFilter) (pPicture, pPicture->filter, result = (*ps->ChangePictureFilter) (pPicture, pPicture->filter,
...@@ -335,5 +360,5 @@ SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int ...@@ -335,5 +360,5 @@ SetPictureFilter (PicturePtr pPicture, char *name, int len, xFixed *params, int
} }
pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT; pPicture->serialNumber |= GC_CHANGE_SERIAL_BIT;
return Success; return ;
} }
...@@ -168,12 +168,14 @@ typedef struct _Picture { ...@@ -168,12 +168,14 @@ typedef struct _Picture {
SourcePictPtr pSourcePict; SourcePictPtr pSourcePict;
} PictureRec; } PictureRec;
typedef Bool (*PictFilterValidateParamsProcPtr) (PicturePtr pPicture, int id, typedef Bool (*PictFilterValidateParamsProcPtr) (ScreenPtr pScreen, int id,
xFixed *params, int nparams); xFixed *params, int nparams,
int *width, int *height);
typedef struct { typedef struct {
char *name; char *name;
int id; int id;
PictFilterValidateParamsProcPtr ValidateParams; PictFilterValidateParamsProcPtr ValidateParams;
int width, height;
} PictFilterRec, *PictFilterPtr; } PictFilterRec, *PictFilterPtr;
#define PictFilterNearest 0 #define PictFilterNearest 0
...@@ -457,7 +459,12 @@ PictFilterPtr ...@@ -457,7 +459,12 @@ PictFilterPtr
PictureFindFilter (ScreenPtr pScreen, char *name, int len); PictureFindFilter (ScreenPtr pScreen, char *name, int len);
int 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 Bool
PictureFinishInit (void); PictureFinishInit (void);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment