gbm: Set errno on errors
This should give the caller some information of what called the error. For the gbm_bo_import() case, for instance, it is possible to know if the import is not supported or the error was caused by an invalid parameter. Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
This commit is contained in:
parent
aa91fe1c09
commit
49964fa28b
|
@ -30,6 +30,7 @@
|
|||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -353,8 +354,10 @@ gbm_dri_bo_write(struct gbm_bo *_bo, const void *buf, size_t count)
|
|||
{
|
||||
struct gbm_dri_bo *bo = gbm_dri_bo(_bo);
|
||||
|
||||
if (bo->image != NULL)
|
||||
if (bo->image != NULL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(bo->map, buf, count);
|
||||
|
||||
|
@ -432,8 +435,10 @@ gbm_dri_bo_import(struct gbm_device *gbm,
|
|||
int gbm_format;
|
||||
|
||||
/* Required for query image WIDTH & HEIGHT */
|
||||
if (dri->image->base.version < 4)
|
||||
if (dri->image->base.version < 4) {
|
||||
errno = ENOSYS;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
#if HAVE_WAYLAND_PLATFORM
|
||||
|
@ -441,12 +446,16 @@ gbm_dri_bo_import(struct gbm_device *gbm,
|
|||
{
|
||||
struct wl_drm_buffer *wb;
|
||||
|
||||
if (!dri->wl_drm)
|
||||
if (!dri->wl_drm) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wb = wayland_drm_buffer_get(dri->wl_drm, (struct wl_resource *) buffer);
|
||||
if (!wb)
|
||||
if (!wb) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
image = dri->image->dupImage(wb->driver_buffer, NULL);
|
||||
|
||||
|
@ -473,15 +482,19 @@ gbm_dri_bo_import(struct gbm_device *gbm,
|
|||
case GBM_BO_IMPORT_EGL_IMAGE:
|
||||
{
|
||||
int dri_format;
|
||||
if (dri->lookup_image == NULL)
|
||||
if (dri->lookup_image == NULL) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
image = dri->lookup_image(dri->screen, buffer, dri->lookup_user_data);
|
||||
image = dri->image->dupImage(image, NULL);
|
||||
dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_FORMAT, &dri_format);
|
||||
gbm_format = gbm_dri_to_gbm_format(dri_format);
|
||||
if (gbm_format == 0)
|
||||
if (gbm_format == 0) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -502,6 +515,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
|
|||
}
|
||||
|
||||
default:
|
||||
errno = ENOSYS;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -518,6 +532,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
|
|||
dri_use |= __DRI_IMAGE_USE_CURSOR;
|
||||
if (dri->image->base.version >= 2 &&
|
||||
!dri->image->validateUsage(bo->image, dri_use)) {
|
||||
errno = EINVAL;
|
||||
free(bo);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -549,10 +564,14 @@ create_dumb(struct gbm_device *gbm,
|
|||
struct drm_mode_destroy_dumb destroy_arg;
|
||||
int ret;
|
||||
|
||||
if (!(usage & GBM_BO_USE_CURSOR_64X64))
|
||||
if (!(usage & GBM_BO_USE_CURSOR_64X64)) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
if (format != GBM_FORMAT_ARGB8888)
|
||||
}
|
||||
if (format != GBM_FORMAT_ARGB8888) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bo = calloc(1, sizeof *bo);
|
||||
if (bo == NULL)
|
||||
|
@ -643,6 +662,7 @@ gbm_dri_bo_create(struct gbm_device *gbm,
|
|||
dri_format = __DRI_IMAGE_FORMAT_XRGB2101010;
|
||||
break;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
goto failed;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "gbm.h"
|
||||
#include "gbmint.h"
|
||||
|
@ -109,7 +110,7 @@ _gbm_mesa_get_device(int fd)
|
|||
int i;
|
||||
|
||||
if (fd < 0 || fstat(fd, &buf) < 0 || !S_ISCHR(buf.st_mode)) {
|
||||
fprintf(stderr, "_gbm_mesa_get_device: invalid fd: %d\n", fd);
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -145,7 +146,7 @@ gbm_create_device(int fd)
|
|||
struct stat buf;
|
||||
|
||||
if (fd < 0 || fstat(fd, &buf) < 0 || !S_ISCHR(buf.st_mode)) {
|
||||
fprintf(stderr, "gbm_create_device: invalid fd: %d\n", fd);
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -258,7 +259,7 @@ gbm_bo_get_fd(struct gbm_bo *bo)
|
|||
* \param bo The buffer object
|
||||
* \param buf The data to write
|
||||
* \param count The number of bytes to write
|
||||
* \return Returns -1 on error, 0 otherwise
|
||||
* \return Returns 0 on success, otherwise -1 is returned an errno set
|
||||
*/
|
||||
GBM_EXPORT int
|
||||
gbm_bo_write(struct gbm_bo *bo, const void *buf, size_t count)
|
||||
|
@ -332,7 +333,7 @@ gbm_bo_destroy(struct gbm_bo *bo)
|
|||
*
|
||||
* \return A newly allocated buffer that should be freed with gbm_bo_destroy()
|
||||
* when no longer needed. If an error occurs during allocation %NULL will be
|
||||
* returned.
|
||||
* returned and errno set.
|
||||
*
|
||||
* \sa enum gbm_bo_format for the list of formats
|
||||
* \sa enum gbm_bo_flags for the list of usage flags
|
||||
|
@ -342,12 +343,16 @@ gbm_bo_create(struct gbm_device *gbm,
|
|||
uint32_t width, uint32_t height,
|
||||
uint32_t format, uint32_t usage)
|
||||
{
|
||||
if (width == 0 || height == 0)
|
||||
if (width == 0 || height == 0) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (usage & GBM_BO_USE_CURSOR_64X64 &&
|
||||
(width != 64 || height != 64))
|
||||
(width != 64 || height != 64)) {
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return gbm->bo_create(gbm, width, height, format, usage);
|
||||
}
|
||||
|
@ -373,7 +378,8 @@ gbm_bo_create(struct gbm_device *gbm,
|
|||
* \param usage The union of the usage flags for this buffer
|
||||
*
|
||||
* \return A newly allocated buffer object that should be freed with
|
||||
* gbm_bo_destroy() when no longer needed.
|
||||
* gbm_bo_destroy() when no longer needed. On error, %NULL is returned
|
||||
* and errno is set.
|
||||
*
|
||||
* \sa enum gbm_bo_flags for the list of usage flags
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue