[PATCH xserver] dri2: Pass a ScreenPtr through to the driver's AuthMagic function. (v3)

Kristian Høgsberg hoegsberg at gmail.com
Fri Jun 29 06:23:07 PDT 2012


On Fri, Jun 29, 2012 at 03:24:15PM +1000, Christopher James Halse Rogers wrote:
> xwayland drivers need access to their screen private data to authenticate.
> Now that drivers no longer have direct access to the global screen arrays,
> this needs to be passed in as function context.
> 
> v2: Don't break ABI
> v3: Paint the bikeshed blue; drop fd from AuthMagic2ProcPtr prototype
> 
> Cherry-picked from master, with the subsequent fixup commit sqashed in,
> and modified to apply to the v6 DRI2InfoRec structure.

Thanks, pushed to the xwayland-1.12 branch.

Kristian

> Signed-off-by: Christopher James Halse Rogers <christopher.halse.rogers at canonical.com>
> ---
>  hw/xfree86/dri2/dri2.c |   50 ++++++++++++++++++++++++++++++++++++++++--------
>  hw/xfree86/dri2/dri2.h |   11 +++++++++++
>  2 files changed, 53 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
> index 591ff3a..b08618a 100644
> --- a/hw/xfree86/dri2/dri2.c
> +++ b/hw/xfree86/dri2/dri2.c
> @@ -48,6 +48,8 @@
>  
>  #include "xf86.h"
>  
> +#include "xf86Priv.h"
> +
>  CARD8 dri2_major;               /* version of DRI2 supported by DDX */
>  CARD8 dri2_minor;
>  
> @@ -104,7 +106,8 @@ typedef struct _DRI2Screen {
>      DRI2ScheduleSwapProcPtr ScheduleSwap;
>      DRI2GetMSCProcPtr GetMSC;
>      DRI2ScheduleWaitMSCProcPtr ScheduleWaitMSC;
> -    DRI2AuthMagicProcPtr AuthMagic;
> +    DRI2AuthMagic2ProcPtr AuthMagic;
> +    DRI2AuthMagicProcPtr LegacyAuthMagic;
>      DRI2ReuseBufferNotifyProcPtr ReuseBufferNotify;
>      DRI2SwapLimitValidateProcPtr SwapLimitValidate;
>  
> @@ -1109,12 +1112,22 @@ DRI2Connect(ScreenPtr pScreen, unsigned int driverType, int *fd,
>      return TRUE;
>  }
>  
> +static Bool
> +DRI2AuthMagic (ScreenPtr pScreen, uint32_t magic)
> +{
> +    DRI2ScreenPtr ds = DRI2GetScreen(pScreen);
> +    if (ds == NULL)
> +        return -EINVAL;
> +
> +    return (*ds->LegacyAuthMagic) (ds->fd, magic);
> +}
> +
>  Bool
>  DRI2Authenticate(ScreenPtr pScreen, uint32_t magic)
>  {
>      DRI2ScreenPtr ds = DRI2GetScreen(pScreen);
>  
> -    if (ds == NULL || (*ds->AuthMagic) (ds->fd, magic))
> +    if (ds == NULL || (*ds->AuthMagic) (pScreen, magic))
>          return FALSE;
>  
>      return TRUE;
> @@ -1200,9 +1213,23 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
>      else {
>          cur_minor = 1;
>      }
> -
> +    
> +    /* 
> +     * Hack: Gate this on xorgWayland rather than info->version.
> +     * This API is introduced in 1.13 with version 8, but we only support
> +     * version 6. This allows us to upstream xwayland DDX support in a way
> +     * that's source-compatible.
> +     *
> +     * If a driver is built without xwayland support, we'll die before we get
> +     * here. If a driver is built with xwayland support, it'll support
> +     * AuthMagic2, or crash; we don't care about xwayland ABI yet.
> +     */
> +    if (xorgWayland) {
> +        ds->AuthMagic = info->AuthMagic2;
> +    }
> +    
>      if (info->version >= 5) {
> -        ds->AuthMagic = info->AuthMagic;
> +        ds->LegacyAuthMagic = info->AuthMagic;
>      }
>  
>      if (info->version >= 6) {
> @@ -1212,14 +1239,21 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
>  
>      /*
>       * if the driver doesn't provide an AuthMagic function or the info struct
> -     * version is too low, it relies on the old method (using libdrm) or fail
> +     * version is too low, call through LegacyAuthMagic
>       */
> -    if (!ds->AuthMagic)
> +    if (!ds->AuthMagic) {
> +        ds->AuthMagic = DRI2AuthMagic;
> +        /*
> +         * If the driver doesn't provide an AuthMagic function
> +         * it relies on the old method (using libdrm) or fails
> +         */
> +        if (!ds->LegacyAuthMagic)
>  #ifdef WITH_LIBDRM
> -        ds->AuthMagic = drmAuthMagic;
> +            ds->LegacyAuthMagic = drmAuthMagic;
>  #else
> -        goto err_out;
> +            goto err_out;
>  #endif
> +    }
>  
>      /* Initialize minor if needed and set to minimum provied by DDX */
>      if (!dri2_minor || dri2_minor > cur_minor)
> diff --git a/hw/xfree86/dri2/dri2.h b/hw/xfree86/dri2/dri2.h
> index 00b3668..cec9634 100644
> --- a/hw/xfree86/dri2/dri2.h
> +++ b/hw/xfree86/dri2/dri2.h
> @@ -64,6 +64,7 @@ typedef void (*DRI2CopyRegionProcPtr) (DrawablePtr pDraw,
>                                         DRI2BufferPtr pSrcBuffer);
>  typedef void (*DRI2WaitProcPtr) (WindowPtr pWin, unsigned int sequence);
>  typedef int (*DRI2AuthMagicProcPtr) (int fd, uint32_t magic);
> +typedef int (*DRI2AuthMagic2ProcPtr) (ScreenPtr pScreen, uint32_t magic);
>  
>  /**
>   * Schedule a buffer swap
> @@ -211,6 +212,16 @@ typedef struct {
>  
>      DRI2ReuseBufferNotifyProcPtr ReuseBufferNotify;
>      DRI2SwapLimitValidateProcPtr SwapLimitValidate;
> +
> +    /* added in version 8 AND in xwayland branch */
> +    /* 
> +     * MERGE NOTE: when merging xwayland to master, the commit adding this
> +     * is unnecessary, but it's slightly different in master.
> +     */
> +    /* AuthMagic callback which passes extra context */
> +    /* If this is NULL the AuthMagic callback is used */
> +    /* If this is non-NULL the AuthMagic callback is ignored */
> +    DRI2AuthMagic2ProcPtr AuthMagic2;
>  } DRI2InfoRec, *DRI2InfoPtr;
>  
>  extern _X_EXPORT int DRI2EventBase;
> -- 
> 1.7.10.4
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list