[Mesa-dev] [PATCH kmscube 2/4] Pass struct drm to init_gbm()

Christian Gmeiner christian.gmeiner at gmail.com
Thu Apr 5 14:29:28 UTC 2018


2018-04-05 15:44 GMT+02:00 Thierry Reding <thierry.reding at gmail.com>:
> From: Thierry Reding <treding at nvidia.com>
>
> This helps cut down on the number of parameters that we need to pass
> around. Subsequent patches will also add more data to struct drm that
> init_gbm() needs to access, so passing in the struct make sure these
> will be available.
>
> Based on work by Lucas Stach <l.stach at pengutronix.de>.
>
> Signed-off-by: Thierry Reding <treding at nvidia.com>

Reviewed-by: Christian Gmeiner <christian.gmeiner at gmail.com>

> ---
>  common.c  | 22 +++++++++++-----------
>  common.h  |  4 ++--
>  kmscube.c |  3 +--
>  3 files changed, 14 insertions(+), 15 deletions(-)
>
> diff --git a/common.c b/common.c
> index faecd4215039..3dcd9bd3d8f4 100644
> --- a/common.c
> +++ b/common.c
> @@ -30,6 +30,7 @@
>  #include <string.h>
>
>  #include "common.h"
> +#include "drm-common.h"
>
>  static struct gbm gbm;
>
> @@ -40,25 +41,24 @@ gbm_surface_create_with_modifiers(struct gbm_device *gbm,
>                                    const uint64_t *modifiers,
>                                    const unsigned int count);
>
> -const struct gbm * init_gbm(int drm_fd, int w, int h, uint64_t modifier)
> +const struct gbm * init_gbm(const struct drm *drm, uint64_t modifier)
>  {

Just an idea:
To keep the diffstat smaller it could may help to create local vars like

    int w = drm->mode->hdisplay;
    int h = drm->mode->vdisplay;

> -       gbm.dev = gbm_create_device(drm_fd);
> +       gbm.dev = gbm_create_device(drm->fd);
>         gbm.format = GBM_FORMAT_XRGB8888;
>
>         if (gbm_surface_create_with_modifiers) {
> -               gbm.surface = gbm_surface_create_with_modifiers(gbm.dev, w, h,
> -                                                               gbm.format,
> -                                                               &modifier, 1);
> -
> +               gbm.surface = gbm_surface_create_with_modifiers(gbm.dev,
> +                               drm->mode->hdisplay, drm->mode->vdisplay,
> +                               gbm.format, &modifier, 1);
>         } else {
>                 if (modifier != DRM_FORMAT_MOD_LINEAR) {
>                         fprintf(stderr, "Modifiers requested but support isn't available\n");
>                         return NULL;
>                 }
> -               gbm.surface = gbm_surface_create(gbm.dev, w, h,
> -                                               gbm.format,
> -                                               GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
>
> +               gbm.surface = gbm_surface_create(gbm.dev, drm->mode->hdisplay,
> +                               drm->mode->vdisplay, gbm.format,
> +                               GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
>         }
>
>         if (!gbm.surface) {
> @@ -66,8 +66,8 @@ const struct gbm * init_gbm(int drm_fd, int w, int h, uint64_t modifier)
>                 return NULL;
>         }
>
> -       gbm.width = w;
> -       gbm.height = h;
> +       gbm.width = drm->mode->hdisplay;
> +       gbm.height = drm->mode->vdisplay;
>
>         return &gbm;
>  }
> diff --git a/common.h b/common.h
> index 898010dd546f..8ff1ed3a6aa3 100644
> --- a/common.h
> +++ b/common.h
> @@ -83,8 +83,8 @@ struct gbm {
>         int width, height;
>  };
>
> -const struct gbm * init_gbm(int drm_fd, int w, int h, uint64_t modifier);
> -
> +struct drm;
> +const struct gbm *init_gbm(const struct drm *drm, uint64_t modifier);
>
>  struct egl {
>         EGLDisplay display;
> diff --git a/kmscube.c b/kmscube.c
> index 87a4205ddc20..b05e57df7faf 100644
> --- a/kmscube.c
> +++ b/kmscube.c
> @@ -130,8 +130,7 @@ int main(int argc, char *argv[])
>                 return -1;
>         }
>
> -       gbm = init_gbm(drm->fd, drm->mode->hdisplay, drm->mode->vdisplay,
> -                       modifier);
> +       gbm = init_gbm(drm, modifier);
>         if (!gbm) {
>                 printf("failed to initialize GBM\n");
>                 return -1;
> --
> 2.16.3
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev

-- 
greets
--
Christian Gmeiner, MSc

https://christian-gmeiner.info


More information about the mesa-dev mailing list