Re: [Mesa-dev] [PATCH 1/2] gbm: Introduce a helper function for printing GBM format names.

2018-11-06 Thread Daniel Stone
Hi,

On Tue, 6 Nov 2018 at 13:11, Eric Engestrom  wrote:
> On Friday, 2018-11-02 14:40:49 -0700, Eric Anholt wrote:
> > +GBM_EXPORT char *
> > +gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc *desc)
> > +{
>
> Actually, This won't work with the two GBM_BO_FORMAT_{X,A}RGB; you
> should add them as a special case here, something like:
>
>   if (gbm_format == GBM_BO_FORMAT_XRGB)
>  return "XRGB";
>
>   if (gbm_format == GBM_BO_FORMAT_ARGB)
>  return "ARGB";
>
> followed by your desc->name code.

Perhaps better would be to just lift gbm_format_canonicalize() from
src/gbm/backends/dri/gbm_dri.c and use it at function entry.

Cheers,
Daniel
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 1/2] gbm: Introduce a helper function for printing GBM format names.

2018-11-06 Thread Eric Engestrom
On Friday, 2018-11-02 14:40:49 -0700, Eric Anholt wrote:
> This requires that the caller make a little (stack) allocation to store
> the string.
> ---
>  src/gbm/main/gbm.c | 18 ++
>  src/gbm/main/gbm.h |  6 ++
>  2 files changed, 24 insertions(+)
> 
> diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
> index 0bf2922bacdd..174f62ad797f 100644
> --- a/src/gbm/main/gbm.c
> +++ b/src/gbm/main/gbm.c
> @@ -695,3 +695,21 @@ gbm_surface_has_free_buffers(struct gbm_surface *surf)
>  {
> return surf->gbm->surface_has_free_buffers(surf);
>  }
> +
> +/**
> + * Returns a string representing the fourcc format name.
> + *
> + * \param desc Caller-provided storage for the format name string.
> + * \return String containing the fourcc of the format.
> + */
> +GBM_EXPORT char *
> +gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc *desc)
> +{

Actually, This won't work with the two GBM_BO_FORMAT_{X,A}RGB; you
should add them as a special case here, something like:

  if (gbm_format == GBM_BO_FORMAT_XRGB)
 return "XRGB";

  if (gbm_format == GBM_BO_FORMAT_ARGB)
 return "ARGB";

followed by your desc->name code.

> +   desc->name[0] = gbm_format;
> +   desc->name[1] = gbm_format >> 8;
> +   desc->name[2] = gbm_format >> 16;
> +   desc->name[3] = gbm_format >> 24;
> +   desc->name[4] = 0;
> +
> +   return desc->name;
> +}
> diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
> index e95f9e34960b..9b5288710a5b 100644
> --- a/src/gbm/main/gbm.h
> +++ b/src/gbm/main/gbm.h
> @@ -190,6 +190,9 @@ enum gbm_bo_format {
>  #define GBM_FORMAT_YUV444__gbm_fourcc_code('Y', 'U', '2', '4') /* 
> non-subsampled Cb (1) and Cr (2) planes */
>  #define GBM_FORMAT_YVU444__gbm_fourcc_code('Y', 'V', '2', '4') /* 
> non-subsampled Cr (1) and Cb (2) planes */
>  
> +struct gbm_format_name_desc {
> +   char name[5];
> +};
>  
>  /**
>   * Flags to indicate the intended use for the buffer - these are passed into
> @@ -399,6 +402,9 @@ gbm_surface_has_free_buffers(struct gbm_surface *surface);
>  void
>  gbm_surface_destroy(struct gbm_surface *surface);
>  
> +char *
> +gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc *desc);
> +
>  #ifdef __cplusplus
>  }
>  #endif
> -- 
> 2.19.1
> 
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 1/2] gbm: Introduce a helper function for printing GBM format names.

2018-11-02 Thread Eric Anholt
This requires that the caller make a little (stack) allocation to store
the string.
---
 src/gbm/main/gbm.c | 18 ++
 src/gbm/main/gbm.h |  6 ++
 2 files changed, 24 insertions(+)

diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c
index 0bf2922bacdd..174f62ad797f 100644
--- a/src/gbm/main/gbm.c
+++ b/src/gbm/main/gbm.c
@@ -695,3 +695,21 @@ gbm_surface_has_free_buffers(struct gbm_surface *surf)
 {
return surf->gbm->surface_has_free_buffers(surf);
 }
+
+/**
+ * Returns a string representing the fourcc format name.
+ *
+ * \param desc Caller-provided storage for the format name string.
+ * \return String containing the fourcc of the format.
+ */
+GBM_EXPORT char *
+gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc *desc)
+{
+   desc->name[0] = gbm_format;
+   desc->name[1] = gbm_format >> 8;
+   desc->name[2] = gbm_format >> 16;
+   desc->name[3] = gbm_format >> 24;
+   desc->name[4] = 0;
+
+   return desc->name;
+}
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index e95f9e34960b..9b5288710a5b 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -190,6 +190,9 @@ enum gbm_bo_format {
 #define GBM_FORMAT_YUV444  __gbm_fourcc_code('Y', 'U', '2', '4') /* 
non-subsampled Cb (1) and Cr (2) planes */
 #define GBM_FORMAT_YVU444  __gbm_fourcc_code('Y', 'V', '2', '4') /* 
non-subsampled Cr (1) and Cb (2) planes */
 
+struct gbm_format_name_desc {
+   char name[5];
+};
 
 /**
  * Flags to indicate the intended use for the buffer - these are passed into
@@ -399,6 +402,9 @@ gbm_surface_has_free_buffers(struct gbm_surface *surface);
 void
 gbm_surface_destroy(struct gbm_surface *surface);
 
+char *
+gbm_format_get_name(uint32_t gbm_format, struct gbm_format_name_desc *desc);
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.19.1

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev