[Mesa-dev] [PATCH 5/5] st/dri: implement the GL interop DRI extension

Michel Dänzer michel at daenzer.net
Sat Mar 5 09:08:28 UTC 2016


On 04.03.2016 04:46, Marek Olšák wrote:
> 
> @@ -1417,6 +1422,254 @@ static const __DRIrobustnessExtension dri2Robustness = {
>     .base = { __DRI2_ROBUSTNESS, 1 }
>  };
>  
> +#define offset_after(type, ptr, member) \
> +   offsetof(type, member) + sizeof(ptr->member)
> +
> +static int
> +dri2_interop_query_device_info(__DRIcontext *_ctx,
> +                               mesa_glinterop_device_info *out)
> +{
> +   struct pipe_screen *screen = dri_context(_ctx)->st->pipe->screen;
> +
> +   if (out->size < offset_after(mesa_glinterop_device_info, out, device_id))
> +      return MESA_GLINTEROP_INVALID_VALUE;
> +
> +   out->pci_segment_group = screen->get_param(screen, PIPE_CAP_PCI_GROUP);
> +   out->pci_bus = screen->get_param(screen, PIPE_CAP_PCI_BUS);
> +   out->pci_device = screen->get_param(screen, PIPE_CAP_PCI_DEVICE);
> +   out->pci_function = screen->get_param(screen, PIPE_CAP_PCI_FUNCTION);
> +
> +   out->vendor_id = screen->get_param(screen, PIPE_CAP_VENDOR_ID);
> +   out->device_id = screen->get_param(screen, PIPE_CAP_DEVICE_ID);
> +
> +   return MESA_GLINTEROP_SUCCESS;
> +}

With the struct size based scheme, callees need to set out->size to the
amount of data they actually write. (And callers need to check that
callees actually wrote all the fields they need, which should probably
also be documented prominently)


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer


More information about the mesa-dev mailing list