[Mesa-dev] [PATCH 1/3] gbm: Added new funtions to match dri format and usage.
Zhigang Gong
zhigang.gong at gmail.com
Sat Dec 17 18:32:24 PST 2011
To map GBM format and usage to corresponding dri format
and usage are common functions. For the convinent of
future extension, pull out the code and create two
separated functions. Slightly change the sequence of
the gbm_bo creation, before allocate a buffer, we check
whether the input parameters are valid and if not, we
return NULL directly. And if we fail to create image,
we need to free the allocated buffer.
Signed-off-by: Zhigang Gong <zhigang.gong at linux.intel.com>
---
src/gbm/backends/dri/gbm_dri.c | 64 +++++++++++++++++++++++++---------------
src/gbm/main/gbm.h | 4 ++
2 files changed, 44 insertions(+), 24 deletions(-)
diff --git a/src/gbm/backends/dri/gbm_dri.c b/src/gbm/backends/dri/gbm_dri.c
index 9de8cb6..e44e5c6 100644
--- a/src/gbm/backends/dri/gbm_dri.c
+++ b/src/gbm/backends/dri/gbm_dri.c
@@ -215,20 +215,44 @@ 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)
@@ -292,7 +316,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)
@@ -302,29 +331,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 05d2292..a994451 100644
--- a/src/gbm/main/gbm.h
+++ b/src/gbm/main/gbm.h
@@ -59,6 +59,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.3.1
More information about the mesa-dev
mailing list