[Mesa-dev] [PATCH 1/2] gbm: Use a separate function to check format and usage.
zhigang.gong at linux.intel.com
zhigang.gong at linux.intel.com
Mon Feb 13 23:53:17 PST 2012
From: Zhigang Gong <zhigang.gong at linux.intel.com>
To extent gbm to support more formats and usages, it's better
to do the format and usage matching in a seprated function.
Also fixed a memory leak at gbm_dri_bo_create, if failed to
create a DRI image, before return NULL, we need to free
bo.
Signed-off-by: Zhigang Gong <zhigang.gong at linux.intel.com>
---
src/gbm/backends/dri/gbm_dri.c | 61 ++++++++++++++++++++++++---------------
src/gbm/main/gbm.h | 4 ++
2 files changed, 41 insertions(+), 24 deletions(-)
diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index ddd153a..7932d12 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -215,20 +215,41 @@ free_screen:
}
static int
-gbm_dri_is_format_supported(struct gbm_device *gbm,
- enum gbm_bo_format format,
- uint32_t usage)
+gbm_dri_match_format(enum gbm_bo_format format, int *dri_format)
{
switch (format) {
case GBM_BO_FORMAT_XRGB8888:
+ *dri_format = __DRI_IMAGE_FORMAT_XRGB8888;
break;
case GBM_BO_FORMAT_ARGB8888:
- if (usage & GBM_BO_USE_SCANOUT)
- return 0;
+ *dri_format = __DRI_IMAGE_FORMAT_ARGB8888;
break;
default:
- return 0;
+ return -1;
}
+ return 0;
+}
+
+static void
+gbm_dri_match_usage(enum gbm_bo_flags usage, unsigned int *dri_use) {
+ if (usage & GBM_BO_USE_SCANOUT)
+ *dri_use |= __DRI_IMAGE_USE_SCANOUT;
+ if (usage & GBM_BO_USE_CURSOR_64X64)
+ *dri_use |= __DRI_IMAGE_USE_CURSOR; }
+
+static int
+gbm_dri_is_format_supported(struct gbm_device *gbm,
+ enum gbm_bo_format format,
+ uint32_t usage) {
+ int dri_format = 0;
+
+ if (gbm_dri_match_format(format, &dri_format)
+ || (usage & ~GBM_BO_USE_VALID_FLAGS)
+ || ((usage & GBM_BO_USE_SCANOUT)
+ && (format == GBM_BO_FORMAT_ARGB8888))
+ || ((usage & GBM_BO_USE_CURSOR_64X64)
+ && (usage & GBM_BO_USE_RENDERING)))
+ return 0;
if (usage & GBM_BO_USE_CURSOR_64X64 &&
usage & GBM_BO_USE_RENDERING)
@@ -303,7 +324,12 @@ gbm_dri_bo_create(struct gbm_device *gbm,
struct gbm_dri_device *dri = gbm_dri_device(gbm);
struct gbm_dri_bo *bo;
int dri_format;
- unsigned dri_use = 0;
+ unsigned int dri_use = 0;
+
+ if (gbm_dri_match_format(format, &dri_format) != 0)
+ return NULL;
+ if (usage & ~GBM_BO_USE_VALID_FLAGS)
+ return NULL;
bo = calloc(1, sizeof *bo);
if (bo == NULL)
@@ -313,29 +339,16 @@ gbm_dri_bo_create(struct gbm_device *gbm,
bo->base.base.width = width;
bo->base.base.height = height;
- switch (format) {
- case GBM_BO_FORMAT_XRGB8888:
- dri_format = __DRI_IMAGE_FORMAT_XRGB8888;
- break;
- case GBM_BO_FORMAT_ARGB8888:
- dri_format = __DRI_IMAGE_FORMAT_ARGB8888;
- break;
- default:
- return NULL;
- }
-
- if (usage & GBM_BO_USE_SCANOUT)
- dri_use |= __DRI_IMAGE_USE_SCANOUT;
- if (usage & GBM_BO_USE_CURSOR_64X64)
- dri_use |= __DRI_IMAGE_USE_CURSOR;
-
+ gbm_dri_match_usage(usage, &dri_use);
bo->image =
dri->image->createImage(dri->screen,
width, height,
dri_format, dri_use,
bo);
- if (bo->image == NULL)
+ if (bo->image == NULL) {
+ free(bo);
return NULL;
+ }
dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE,
&bo->base.base.handle.s32);
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h
index c4ae51d..ec64b94 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -100,6 +100,10 @@ enum gbm_bo_flags {
GBM_BO_USE_RENDERING = (1 << 2),
};
+#define GBM_BO_USE_VALID_FLAGS (GBM_BO_USE_SCANOUT \
+ | GBM_BO_USE_CURSOR_64X64 \
+ | GBM_BO_USE_RENDERING)
+
int
gbm_device_get_fd(struct gbm_device *gbm);
--
1.7.4.4
More information about the mesa-dev
mailing list