[Mesa-dev] [PATCH v2] wayland-drm: static inline wayland_drm_buffer_get

Eric Engestrom eric.engestrom at imgtec.com
Mon Oct 30 12:02:54 UTC 2017


On Tuesday, 2017-10-24 17:14:20 +0100, Emil Velikov wrote:
> From: Emil Velikov <emil.velikov at collabora.com>
> 
> The function is effectively a direct function call into
> libwayland-server.so.
> 
> Thus GBM no longer depends on the wayland-drm static library, making the
> build more straight forward. And the resulting binary is a bit smaller.
> 
> Note: we need to move struct wayland_drm_callbacks further up,
> otherwise we'll get an error since the type is incomplete.
> 
> v2: Rebase, beef-up commit message, update meson, move struct
> wayland_drm_callbacks.
> 
> Cc: Dylan Baker <dylan at pnwbakers.com>
> Cc: Daniel Stone <daniels at collabora.com>
> Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
> Reviewed-by: Daniel Stone <daniels at collabora.com> (v1)
> ---
> Dylan can you check the meson bits? Can one say to meson, build object X 
> while only using the depA CFLAGS? It seems to me that it currently links 
> against depA even when you don't want it to.

I'm not sure I understand what you're asking: you want to include
wayland-drm.h's path in libgbm's CFLAGS but not link libgbm against
libwayland_drm?

That looks like what's already happening here:
libgbm has `include_directories('../egl/wayland/wayland-drm')`, and you
removed libwayland_drm from `link_with:`

I haven't tested your patch, but it looks correct to me.

> 
>  src/Makefile.am                           |  2 +-
>  src/egl/wayland/wayland-drm/wayland-drm.c | 26 -----------------
>  src/egl/wayland/wayland-drm/wayland-drm.h | 48 +++++++++++++++++++++++--------
>  src/gbm/Makefile.am                       |  2 +-
>  src/gbm/meson.build                       |  4 +--
>  5 files changed, 39 insertions(+), 43 deletions(-)
> 
> diff --git a/src/Makefile.am b/src/Makefile.am
> index 5ef2d4f55ea..20e90c3d0b8 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -64,7 +64,7 @@ endif
>  # include only conditionally ?
>  SUBDIRS += compiler
>  
> -## Optionally required by GBM, EGL
> +## Optionally required by EGL
>  if HAVE_PLATFORM_WAYLAND
>  SUBDIRS += egl/wayland/wayland-drm
>  endif
> diff --git a/src/egl/wayland/wayland-drm/wayland-drm.c b/src/egl/wayland/wayland-drm/wayland-drm.c
> index 73dfba9600e..81f6f528527 100644
> --- a/src/egl/wayland/wayland-drm/wayland-drm.c
> +++ b/src/egl/wayland/wayland-drm/wayland-drm.c
> @@ -39,19 +39,6 @@
>  
>  #define MIN(x,y) (((x)<(y))?(x):(y))
>  
> -struct wl_drm {
> -	struct wl_display *display;
> -	struct wl_global *wl_drm_global;
> -
> -	void *user_data;
> -	char *device_name;
> -        uint32_t flags;
> -
> -	struct wayland_drm_callbacks callbacks;
> -
> -        struct wl_buffer_interface buffer_interface;
> -};
> -
>  static void
>  destroy_buffer(struct wl_resource *resource)
>  {
> @@ -244,19 +231,6 @@ bind_drm(struct wl_client *client, void *data, uint32_t version, uint32_t id)
>             wl_resource_post_event(resource, WL_DRM_CAPABILITIES, capabilities);
>  }
>  
> -struct wl_drm_buffer *
> -wayland_drm_buffer_get(struct wl_drm *drm, struct wl_resource *resource)
> -{
> -	if (resource == NULL)
> -		return NULL;
> -
> -        if (wl_resource_instance_of(resource, &wl_buffer_interface,
> -                                    &drm->buffer_interface))
> -		return wl_resource_get_user_data(resource);
> -        else
> -		return NULL;
> -}
> -
>  struct wl_drm *
>  wayland_drm_init(struct wl_display *display, char *device_name,
>                   const struct wayland_drm_callbacks *callbacks, void *user_data,
> diff --git a/src/egl/wayland/wayland-drm/wayland-drm.h b/src/egl/wayland/wayland-drm/wayland-drm.h
> index 111383ff1d6..36e5bf042a7 100644
> --- a/src/egl/wayland/wayland-drm/wayland-drm.h
> +++ b/src/egl/wayland/wayland-drm/wayland-drm.h
> @@ -4,8 +4,31 @@
>  #include <wayland-server.h>
>  
>  struct wl_display;
> -struct wl_drm;
>  struct wl_resource;
> +struct wl_drm_buffer;
> +
> +struct wayland_drm_callbacks {
> +	int (*authenticate)(void *user_data, uint32_t id);
> +
> +	void (*reference_buffer)(void *user_data, uint32_t name, int fd,
> +                                 struct wl_drm_buffer *buffer);
> +
> +	void (*release_buffer)(void *user_data, struct wl_drm_buffer *buffer);
> +};
> +
> +
> +struct wl_drm {
> +	struct wl_display *display;
> +	struct wl_global *wl_drm_global;
> +
> +	void *user_data;
> +	char *device_name;
> +	uint32_t flags;
> +
> +	struct wayland_drm_callbacks callbacks;
> +
> +	struct wl_buffer_interface buffer_interface;
> +};
>  
>  struct wl_drm_buffer {
>  	struct wl_resource *resource;
> @@ -18,19 +41,20 @@ struct wl_drm_buffer {
>  	void *driver_buffer;
>  };
>  
> -struct wayland_drm_callbacks {
> -	int (*authenticate)(void *user_data, uint32_t id);
> -
> -        void (*reference_buffer)(void *user_data, uint32_t name, int fd,
> -                                 struct wl_drm_buffer *buffer);
> -
> -	void (*release_buffer)(void *user_data, struct wl_drm_buffer *buffer);
> -};
> -
>  enum { WAYLAND_DRM_PRIME = 0x01 };
>  
> -struct wl_drm_buffer *
> -wayland_drm_buffer_get(struct wl_drm *drm, struct wl_resource *resource);
> +static inline struct wl_drm_buffer *
> +wayland_drm_buffer_get(struct wl_drm *drm, struct wl_resource *resource)
> +{
> +	if (resource == NULL)
> +		return NULL;
> +
> +	if (wl_resource_instance_of(resource, &wl_buffer_interface,
> +	                            &drm->buffer_interface))
> +		return wl_resource_get_user_data(resource);
> +	else
> +		return NULL;
> +}
>  
>  struct wl_drm *
>  wayland_drm_init(struct wl_display *display, char *device_name,
> diff --git a/src/gbm/Makefile.am b/src/gbm/Makefile.am
> index 805208a3ca9..088ff3a309a 100644
> --- a/src/gbm/Makefile.am
> +++ b/src/gbm/Makefile.am
> @@ -32,7 +32,7 @@ libgbm_la_LIBADD = \
>  
>  if HAVE_PLATFORM_WAYLAND
>  AM_CFLAGS += $(WAYLAND_SERVER_CFLAGS)
> -libgbm_la_LIBADD += $(top_builddir)/src/egl/wayland/wayland-drm/libwayland-drm.la $(WAYLAND_SERVER_LIBS)
> +libgbm_la_LIBADD += $(WAYLAND_SERVER_LIBS)
>  endif
>  
>  if HAVE_DRI2
> diff --git a/src/gbm/meson.build b/src/gbm/meson.build
> index 1bb3c94c387..f977bff235e 100644
> --- a/src/gbm/meson.build
> +++ b/src/gbm/meson.build
> @@ -29,7 +29,6 @@ files_gbm = files(
>  )
>  deps_gbm = []
>  args_gbm = []
> -links_gbm = []
>  deps_gbm = []
>  
>  if with_dri2
> @@ -39,7 +38,6 @@ if with_dri2
>  endif
>  if with_platform_wayland
>    deps_gbm += dep_wayland_server
> -  links_gbm += libwayland_drm
>  endif
>  
>  # TODO: wayland support (requires egl)
> @@ -52,7 +50,7 @@ libgbm = shared_library(
>      include_directories('../egl/wayland/wayland-drm')],
>    c_args : args_gbm,
>    link_args : [ld_args_gc_sections],
> -  link_with : [links_gbm, libloader, libmesa_util, libxmlconfig],
> +  link_with : [libloader, libmesa_util, libxmlconfig],
>    dependencies : [deps_gbm, dep_dl],
>    version : '1.0',
>    install : true,
> -- 
> 2.14.1
> 


More information about the mesa-dev mailing list