[Mesa-dev] [PATCH 05/11] gbm: Pull out FourCC <-> DRIimage format table
Rather than duplicated (yet asymmetric) open-coded tables, pull them out to a common structure. Signed-off-by: Daniel Stone --- src/gbm/Makefile.am| 1 + src/gbm/backends/dri/gbm_dri.c | 105 ++--- 2 files changed, 46 insertions(+), 60 deletions(-) diff --git a/src/gbm/Makefile.am b/src/gbm/Makefile.am index 60b0924506..de8396000b 100644 --- a/src/gbm/Makefile.am +++ b/src/gbm/Makefile.am @@ -5,6 +5,7 @@ pkgconfig_DATA = main/gbm.pc AM_CFLAGS = \ -I$(top_srcdir)/include \ + -I$(top_srcdir)/src \ -I$(top_srcdir)/src/loader \ -I$(top_srcdir)/src/gbm/main \ $(DLOPEN_CFLAGS) \ diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c index 84f37d4cf5..3cdd7d505c 100644 --- a/src/gbm/backends/dri/gbm_dri.c +++ b/src/gbm/backends/dri/gbm_dri.c @@ -48,6 +48,7 @@ #include "gbmint.h" #include "loader.h" +#include "util/macros.h" /* For importing wl_buffer */ #if HAVE_WAYLAND_PLATFORM @@ -550,6 +551,48 @@ dri_screen_create_sw(struct gbm_dri_device *dri) return dri_screen_create_swrast(dri); } +static const struct { + uint32_t gbm_format; + int dri_image_format; +} gbm_to_dri_image_formats[] = { + { GBM_FORMAT_R8, __DRI_IMAGE_FORMAT_R8 }, + { GBM_FORMAT_GR88, __DRI_IMAGE_FORMAT_GR88 }, + { GBM_FORMAT_RGB565, __DRI_IMAGE_FORMAT_RGB565 }, + { GBM_FORMAT_XRGB, __DRI_IMAGE_FORMAT_XRGB }, + { GBM_FORMAT_ARGB, __DRI_IMAGE_FORMAT_ARGB }, + { GBM_FORMAT_XBGR, __DRI_IMAGE_FORMAT_XBGR }, + { GBM_FORMAT_ABGR, __DRI_IMAGE_FORMAT_ABGR }, + { GBM_FORMAT_XRGB2101010, __DRI_IMAGE_FORMAT_XRGB2101010 }, + { GBM_FORMAT_ARGB2101010, __DRI_IMAGE_FORMAT_ARGB2101010 }, +}; + +static int +gbm_format_to_dri_format(uint32_t gbm_format) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(gbm_to_dri_image_formats); i++) { + if (gbm_to_dri_image_formats[i].gbm_format == gbm_format) + return gbm_to_dri_image_formats[i].dri_image_format; + } + + return 0; +} + +static uint32_t +gbm_dri_to_gbm_format(int dri_format) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(gbm_to_dri_image_formats); i++) { + if (gbm_to_dri_image_formats[i].dri_image_format == dri_format) + return gbm_to_dri_image_formats[i].gbm_format; + } + + return 0; +} + + static int gbm_dri_is_format_supported(struct gbm_device *gbm, uint32_t format, @@ -795,35 +838,6 @@ gbm_dri_bo_destroy(struct gbm_bo *_bo) free(bo); } -static uint32_t -gbm_dri_to_gbm_format(uint32_t dri_format) -{ - uint32_t ret = 0; - - switch (dri_format) { - case __DRI_IMAGE_FORMAT_RGB565: - ret = GBM_FORMAT_RGB565; - break; - case __DRI_IMAGE_FORMAT_XRGB: - ret = GBM_FORMAT_XRGB; - break; - case __DRI_IMAGE_FORMAT_ARGB: - ret = GBM_FORMAT_ARGB; - break; - case __DRI_IMAGE_FORMAT_XBGR: - ret = GBM_FORMAT_XBGR; - break; - case __DRI_IMAGE_FORMAT_ABGR: - ret = GBM_FORMAT_ABGR; - break; - default: - ret = 0; - break; - } - - return ret; -} - static struct gbm_bo * gbm_dri_bo_import(struct gbm_device *gbm, uint32_t type, void *buffer, uint32_t usage) @@ -1126,37 +1140,8 @@ gbm_dri_bo_create(struct gbm_device *gbm, bo->base.height = height; bo->base.format = format; - switch (format) { - case GBM_FORMAT_R8: - dri_format = __DRI_IMAGE_FORMAT_R8; - break; - case GBM_FORMAT_GR88: - dri_format = __DRI_IMAGE_FORMAT_GR88; - break; - case GBM_FORMAT_RGB565: - dri_format = __DRI_IMAGE_FORMAT_RGB565; - break; - case GBM_FORMAT_XRGB: - case GBM_BO_FORMAT_XRGB: - dri_format = __DRI_IMAGE_FORMAT_XRGB; - break; - case GBM_FORMAT_ARGB: - case GBM_BO_FORMAT_ARGB: - dri_format = __DRI_IMAGE_FORMAT_ARGB; - break; - case GBM_FORMAT_ABGR: - dri_format = __DRI_IMAGE_FORMAT_ABGR; - break; - case GBM_FORMAT_XBGR: - dri_format = __DRI_IMAGE_FORMAT_XBGR; - break; - case GBM_FORMAT_ARGB2101010: - dri_format = __DRI_IMAGE_FORMAT_ARGB2101010; - break; - case GBM_FORMAT_XRGB2101010: - dri_format = __DRI_IMAGE_FORMAT_XRGB2101010; - break; - default: + dri_format = gbm_format_to_dri_format(format); + if (dri_format == 0) { errno = EINVAL; goto failed; } -- 2.13.0 ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 05/11] gbm: Pull out FourCC <-> DRIimage format table
Am Freitag, den 16.06.2017, 18:14 +0100 schrieb Daniel Stone: > Rather than duplicated (yet asymmetric) open-coded tables, pull them out > to a common structure. > > Signed-off-by: Daniel Stone > --- > src/gbm/Makefile.am| 1 + > src/gbm/backends/dri/gbm_dri.c | 105 > ++--- > 2 files changed, 46 insertions(+), 60 deletions(-) > > diff --git a/src/gbm/Makefile.am b/src/gbm/Makefile.am > index 60b0924506..de8396000b 100644 > --- a/src/gbm/Makefile.am > +++ b/src/gbm/Makefile.am > @@ -5,6 +5,7 @@ pkgconfig_DATA = main/gbm.pc > > AM_CFLAGS = \ > -I$(top_srcdir)/include \ > + -I$(top_srcdir)/src \ > -I$(top_srcdir)/src/loader \ > -I$(top_srcdir)/src/gbm/main \ > $(DLOPEN_CFLAGS) \ > diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c > index 84f37d4cf5..3cdd7d505c 100644 > --- a/src/gbm/backends/dri/gbm_dri.c > +++ b/src/gbm/backends/dri/gbm_dri.c > @@ -48,6 +48,7 @@ > > #include "gbmint.h" > #include "loader.h" > +#include "util/macros.h" > > /* For importing wl_buffer */ > #if HAVE_WAYLAND_PLATFORM > @@ -550,6 +551,48 @@ dri_screen_create_sw(struct gbm_dri_device *dri) > return dri_screen_create_swrast(dri); > } > > +static const struct { > + uint32_t gbm_format; > + int dri_image_format; > +} gbm_to_dri_image_formats[] = { > + { GBM_FORMAT_R8, __DRI_IMAGE_FORMAT_R8 }, > + { GBM_FORMAT_GR88, __DRI_IMAGE_FORMAT_GR88 }, > + { GBM_FORMAT_RGB565, __DRI_IMAGE_FORMAT_RGB565 }, > + { GBM_FORMAT_XRGB, __DRI_IMAGE_FORMAT_XRGB }, > + { GBM_FORMAT_ARGB, __DRI_IMAGE_FORMAT_ARGB }, > + { GBM_FORMAT_XBGR, __DRI_IMAGE_FORMAT_XBGR }, > + { GBM_FORMAT_ABGR, __DRI_IMAGE_FORMAT_ABGR }, > + { GBM_FORMAT_XRGB2101010, __DRI_IMAGE_FORMAT_XRGB2101010 }, > + { GBM_FORMAT_ARGB2101010, __DRI_IMAGE_FORMAT_ARGB2101010 }, > +}; This drops the GBM_BO_FORMAT_XRGB and GBM_BO_FORMAT_ARGB handling present in the gbm_dri_bo_import() conversion function. I'm not sure if/how this is still in-use, but I would prefer to keep those for the sake of backwards compatibility. Regards, Lucas > + > +static int > +gbm_format_to_dri_format(uint32_t gbm_format) > +{ > + int i; > + > + for (i = 0; i < ARRAY_SIZE(gbm_to_dri_image_formats); i++) { > + if (gbm_to_dri_image_formats[i].gbm_format == gbm_format) > + return gbm_to_dri_image_formats[i].dri_image_format; > + } > + > + return 0; > +} > + > +static uint32_t > +gbm_dri_to_gbm_format(int dri_format) > +{ > + int i; > + > + for (i = 0; i < ARRAY_SIZE(gbm_to_dri_image_formats); i++) { > + if (gbm_to_dri_image_formats[i].dri_image_format == dri_format) > + return gbm_to_dri_image_formats[i].gbm_format; > + } > + > + return 0; > +} > + > + > static int > gbm_dri_is_format_supported(struct gbm_device *gbm, > uint32_t format, > @@ -795,35 +838,6 @@ gbm_dri_bo_destroy(struct gbm_bo *_bo) > free(bo); > } > > -static uint32_t > -gbm_dri_to_gbm_format(uint32_t dri_format) > -{ > - uint32_t ret = 0; > - > - switch (dri_format) { > - case __DRI_IMAGE_FORMAT_RGB565: > - ret = GBM_FORMAT_RGB565; > - break; > - case __DRI_IMAGE_FORMAT_XRGB: > - ret = GBM_FORMAT_XRGB; > - break; > - case __DRI_IMAGE_FORMAT_ARGB: > - ret = GBM_FORMAT_ARGB; > - break; > - case __DRI_IMAGE_FORMAT_XBGR: > - ret = GBM_FORMAT_XBGR; > - break; > - case __DRI_IMAGE_FORMAT_ABGR: > - ret = GBM_FORMAT_ABGR; > - break; > - default: > - ret = 0; > - break; > - } > - > - return ret; > -} > - > static struct gbm_bo * > gbm_dri_bo_import(struct gbm_device *gbm, >uint32_t type, void *buffer, uint32_t usage) > @@ -1126,37 +1140,8 @@ gbm_dri_bo_create(struct gbm_device *gbm, > bo->base.height = height; > bo->base.format = format; > > - switch (format) { > - case GBM_FORMAT_R8: > - dri_format = __DRI_IMAGE_FORMAT_R8; > - break; > - case GBM_FORMAT_GR88: > - dri_format = __DRI_IMAGE_FORMAT_GR88; > - break; > - case GBM_FORMAT_RGB565: > - dri_format = __DRI_IMAGE_FORMAT_RGB565; > - break; > - case GBM_FORMAT_XRGB: > - case GBM_BO_FORMAT_XRGB: > - dri_format = __DRI_IMAGE_FORMAT_XRGB; > - break; > - case GBM_FORMAT_ARGB: > - case GBM_BO_FORMAT_ARGB: > - dri_format = __DRI_IMAGE_FORMAT_ARGB; > - break; > - case GBM_FORMAT_ABGR: > - dri_format = __DRI_IMAGE_FORMAT_ABGR; > - break; > - case GBM_FORMAT_XBGR: > - dri_format = __DRI_IMAGE_FORMAT_XBGR; > - break; > - case GBM_FORMAT_ARGB2101010: > - dri_format = __DRI_IMAGE_FORMAT_ARGB2101010; > - break; > - case GBM_FORMAT_XRGB2101010: > - dri_format = __DRI_IMAGE_FORMAT_XRGB2101010; > - break; > - default: > + dri_format = gbm_format_to_dri_format(form
Re: [Mesa-dev] [PATCH 05/11] gbm: Pull out FourCC <-> DRIimage format table
On 28 June 2017 at 16:02, Lucas Stach wrote: > Am Freitag, den 16.06.2017, 18:14 +0100 schrieb Daniel Stone: >> Rather than duplicated (yet asymmetric) open-coded tables, pull them out >> to a common structure. >> >> Signed-off-by: Daniel Stone >> --- >> src/gbm/Makefile.am| 1 + >> src/gbm/backends/dri/gbm_dri.c | 105 >> ++--- >> 2 files changed, 46 insertions(+), 60 deletions(-) >> >> diff --git a/src/gbm/Makefile.am b/src/gbm/Makefile.am >> index 60b0924506..de8396000b 100644 >> --- a/src/gbm/Makefile.am >> +++ b/src/gbm/Makefile.am >> @@ -5,6 +5,7 @@ pkgconfig_DATA = main/gbm.pc >> >> AM_CFLAGS = \ >> -I$(top_srcdir)/include \ >> + -I$(top_srcdir)/src \ >> -I$(top_srcdir)/src/loader \ >> -I$(top_srcdir)/src/gbm/main \ >> $(DLOPEN_CFLAGS) \ >> diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c >> index 84f37d4cf5..3cdd7d505c 100644 >> --- a/src/gbm/backends/dri/gbm_dri.c >> +++ b/src/gbm/backends/dri/gbm_dri.c >> @@ -48,6 +48,7 @@ >> >> #include "gbmint.h" >> #include "loader.h" >> +#include "util/macros.h" >> >> /* For importing wl_buffer */ >> #if HAVE_WAYLAND_PLATFORM >> @@ -550,6 +551,48 @@ dri_screen_create_sw(struct gbm_dri_device *dri) >> return dri_screen_create_swrast(dri); >> } >> >> +static const struct { >> + uint32_t gbm_format; >> + int dri_image_format; >> +} gbm_to_dri_image_formats[] = { >> + { GBM_FORMAT_R8, __DRI_IMAGE_FORMAT_R8 }, >> + { GBM_FORMAT_GR88, __DRI_IMAGE_FORMAT_GR88 }, >> + { GBM_FORMAT_RGB565, __DRI_IMAGE_FORMAT_RGB565 }, >> + { GBM_FORMAT_XRGB, __DRI_IMAGE_FORMAT_XRGB }, >> + { GBM_FORMAT_ARGB, __DRI_IMAGE_FORMAT_ARGB }, >> + { GBM_FORMAT_XBGR, __DRI_IMAGE_FORMAT_XBGR }, >> + { GBM_FORMAT_ABGR, __DRI_IMAGE_FORMAT_ABGR }, >> + { GBM_FORMAT_XRGB2101010, __DRI_IMAGE_FORMAT_XRGB2101010 }, >> + { GBM_FORMAT_ARGB2101010, __DRI_IMAGE_FORMAT_ARGB2101010 }, >> +}; > > This drops the GBM_BO_FORMAT_XRGB and GBM_BO_FORMAT_ARGB > handling present in the gbm_dri_bo_import() conversion function. I'm not > sure if/how this is still in-use, but I would prefer to keep those for > the sake of backwards compatibility. > I think it's good idea to keep support for GBM_BO_FORMAT_*. We could even static inline a helper that converts them to GBM_FORMAT_... ;-) -Emil ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev
Re: [Mesa-dev] [PATCH 05/11] gbm: Pull out FourCC <-> DRIimage format table
On Friday, 2017-06-16 18:14:28 +0100, Daniel Stone wrote: > Rather than duplicated (yet asymmetric) open-coded tables, pull them out > to a common structure. > > Signed-off-by: Daniel Stone > --- > src/gbm/Makefile.am| 1 + > src/gbm/backends/dri/gbm_dri.c | 105 > ++--- > 2 files changed, 46 insertions(+), 60 deletions(-) > > diff --git a/src/gbm/Makefile.am b/src/gbm/Makefile.am > index 60b0924506..de8396000b 100644 > --- a/src/gbm/Makefile.am > +++ b/src/gbm/Makefile.am > @@ -5,6 +5,7 @@ pkgconfig_DATA = main/gbm.pc > > AM_CFLAGS = \ > -I$(top_srcdir)/include \ > + -I$(top_srcdir)/src \ > -I$(top_srcdir)/src/loader \ > -I$(top_srcdir)/src/gbm/main \ > $(DLOPEN_CFLAGS) \ > diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c > index 84f37d4cf5..3cdd7d505c 100644 > --- a/src/gbm/backends/dri/gbm_dri.c > +++ b/src/gbm/backends/dri/gbm_dri.c > @@ -48,6 +48,7 @@ > > #include "gbmint.h" > #include "loader.h" > +#include "util/macros.h" > > /* For importing wl_buffer */ > #if HAVE_WAYLAND_PLATFORM > @@ -550,6 +551,48 @@ dri_screen_create_sw(struct gbm_dri_device *dri) > return dri_screen_create_swrast(dri); > } > > +static const struct { > + uint32_t gbm_format; > + int dri_image_format; > +} gbm_to_dri_image_formats[] = { > + { GBM_FORMAT_R8, __DRI_IMAGE_FORMAT_R8 }, > + { GBM_FORMAT_GR88, __DRI_IMAGE_FORMAT_GR88 }, > + { GBM_FORMAT_RGB565, __DRI_IMAGE_FORMAT_RGB565 }, > + { GBM_FORMAT_XRGB, __DRI_IMAGE_FORMAT_XRGB }, > + { GBM_FORMAT_ARGB, __DRI_IMAGE_FORMAT_ARGB }, > + { GBM_FORMAT_XBGR, __DRI_IMAGE_FORMAT_XBGR }, > + { GBM_FORMAT_ABGR, __DRI_IMAGE_FORMAT_ABGR }, > + { GBM_FORMAT_XRGB2101010, __DRI_IMAGE_FORMAT_XRGB2101010 }, > + { GBM_FORMAT_ARGB2101010, __DRI_IMAGE_FORMAT_ARGB2101010 }, > +}; > + > +static int > +gbm_format_to_dri_format(uint32_t gbm_format) > +{ > + int i; > + > + for (i = 0; i < ARRAY_SIZE(gbm_to_dri_image_formats); i++) { > + if (gbm_to_dri_image_formats[i].gbm_format == gbm_format) > + return gbm_to_dri_image_formats[i].dri_image_format; > + } > + > + return 0; > +} > + > +static uint32_t > +gbm_dri_to_gbm_format(int dri_format) > +{ > + int i; > + > + for (i = 0; i < ARRAY_SIZE(gbm_to_dri_image_formats); i++) { > + if (gbm_to_dri_image_formats[i].dri_image_format == dri_format) > + return gbm_to_dri_image_formats[i].gbm_format; > + } > + > + return 0; > +} > + This is doing a linear search, which is fine, but this is one situation where I like macros; you can make it constant-time by just having a file with: X(GBM_FORMAT_..., __DRI_IMAGE_FORMAT_...) and in these two functions have a switch with: #define X(gbm, dri) case gbm: return dri; and #define X(gbm, dri) case dri: return gbm; It's a small list, so it doesn't really matter, and anyway it might as well be a follow-up patch (happy to volunteer :P), so this and patches 1-3 are: Reviewed-by: Eric Engestrom I'll try and review the rest tomorrow. Cheers, Eric ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev