[PATCH 02/14] screen: split out screen init code.

walter harms wharms at bfs.de
Thu Jun 14 07:57:26 PDT 2012



Am 14.06.2012 16:43, schrieb Dave Airlie:
> From: Dave Airlie <airlied at redhat.com>
> 
> This is a precursor for reusing this code to init gpu screens.
> 
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  dix/dispatch.c |   44 +++++++++++++++++++++++++++-----------------
>  1 file changed, 27 insertions(+), 17 deletions(-)
> 
> diff --git a/dix/dispatch.c b/dix/dispatch.c
> index b88f974..5448298 100644
> --- a/dix/dispatch.c
> +++ b/dix/dispatch.c
> @@ -3724,27 +3724,11 @@ with its screen number, a pointer to its ScreenRec, argc, and argv.
>  
>  */
>  
> -int
> -AddScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
> -                           int /*argc */ ,
> -                           char **      /*argv */
> -          ), int argc, char **argv)
> +static int init_screen(ScreenPtr pScreen, int i)
>  {
> -
> -    int i;
>      int scanlinepad, format, depth, bitsPerPixel, j, k;
> -    ScreenPtr pScreen;
> -
> -    i = screenInfo.numScreens;
> -    if (i == MAXSCREENS)
> -        return -1;
> -
> -    pScreen = (ScreenPtr) calloc(1, sizeof(ScreenRec));
> -    if (!pScreen)
> -        return -1;
>  
>      if (!dixAllocatePrivates(&pScreen->devPrivates, PRIVATE_SCREEN)) {
> -        free(pScreen);
>          return -1;
>      }
>      pScreen->myNum = i;
> @@ -3782,7 +3766,33 @@ AddScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
>              PixmapWidthPaddingInfo[depth].notPower2 = 0;
>          }
>      }
> +    return 0;
> +}
> +
> +int
> +AddScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
> +                           int /*argc */ ,
> +                           char **      /*argv */
> +          ), int argc, char **argv)
> +{
>  
> +    int i;
> +    ScreenPtr pScreen;
> +    Bool ret;
> +
> +    i = screenInfo.numScreens;
> +    if (i == MAXSCREENS)
> +        return -1;
> +

	is it better to return -2 here ?
	you can still check via if (AddScreen < 0) but you can
	see the difference between running out-of-screens (bad)
	and out-of-memory (panic).

	just my to 2 cents,
	re,
 	wh

> +    pScreen = (ScreenPtr) calloc(1, sizeof(ScreenRec));
> +    if (!pScreen)
> +        return -1;
> +
> +    ret = init_screen(pScreen, i);
> +    if (ret) {
> +        free(pScreen);
> +        return ret;
> +    }
>      /* This is where screen specific stuff gets initialized.  Load the
>         screen structure, call the hardware, whatever.
>         This is also where the default colormap should be allocated and


More information about the xorg-devel mailing list