gbm: doc fixes
[mesa.git] / src / gbm / main / gbm.c
index ad5208ca13607aa48dd1771eea7dbd339a830bb6..a464f3c33fef5c9810930e9bb45af58cb39678cb 100644 (file)
@@ -25,8 +25,6 @@
  *    Benjamin Franzke <benjaminfranzke@googlemail.com>
  */
 
-#define _BSD_SOURCE
-
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -36,6 +34,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include "gbm.h"
 #include "gbmint.h"
@@ -109,7 +108,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 +144,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;
    }
 
@@ -233,7 +232,7 @@ gbm_bo_get_handle(struct gbm_bo *bo)
 /** Get a DMA-BUF file descriptor for the buffer object
  *
  * This function creates a DMA-BUF (also known as PRIME) file descriptor
- * handle for the buffer object.  Eeach call to gbm_bo_get_fd() returns a new
+ * handle for the buffer object.  Each call to gbm_bo_get_fd() returns a new
  * file descriptor and the caller is responsible for closing the file
  * descriptor.
 
@@ -250,15 +249,15 @@ gbm_bo_get_fd(struct gbm_bo *bo)
 /** Write data into the buffer object
  *
  * If the buffer object was created with the GBM_BO_USE_WRITE flag,
- * this function can used to write data into the buffer object.  The
- * data is copied directly into the object and it's the responsiblity
+ * this function can be used to write data into the buffer object.  The
+ * data is copied directly into the object and it's the responsibility
  * of the caller to make sure the data represents valid pixel data,
  * according to the width, height, stride and format of the buffer object.
  *
  * \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 +331,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 +341,10 @@ gbm_bo_create(struct gbm_device *gbm,
               uint32_t width, uint32_t height,
               uint32_t format, uint32_t usage)
 {
-   if (width == 0 || height == 0)
-      return NULL;
-
-   if (usage & GBM_BO_USE_CURSOR_64X64 &&
-       (width != 64 || height != 64))
+   if (width == 0 || height == 0) {
+      errno = EINVAL;
       return NULL;
+   }
 
    return gbm->bo_create(gbm, width, height, format, usage);
 }
@@ -362,8 +359,9 @@ gbm_bo_create(struct gbm_device *gbm,
  *
  *   GBM_BO_IMPORT_WL_BUFFER
  *   GBM_BO_IMPORT_EGL_IMAGE
+ *   GBM_BO_IMPORT_FD
  *
- * The the gbm bo shares the underlying pixels but its life-time is
+ * The gbm bo shares the underlying pixels but its life-time is
  * independent of the foreign object.
  *
  * \param gbm The gbm device returned from gbm_create_device()
@@ -372,7 +370,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
  */
@@ -383,6 +382,59 @@ gbm_bo_import(struct gbm_device *gbm,
    return gbm->bo_import(gbm, type, buffer, usage);
 }
 
+/**
+ * Map a region of a gbm buffer object for cpu access
+ *
+ * This function maps a region of a gbm bo for cpu read and/or write
+ * access.
+ *
+ * \param bo The buffer object
+ * \param x The X (top left origin) starting position of the mapped region for
+ * the buffer
+ * \param y The Y (top left origin) starting position of the mapped region for
+ * the buffer
+ * \param width The width of the mapped region for the buffer
+ * \param height The height of the mapped region for the buffer
+ * \param flags The union of the GBM_BO_TRANSFER_* flags for this buffer
+ * \param stride Ptr for returned stride in bytes of the mapped region
+ * \param map_data Returned opaque ptr for the mapped region
+ *
+ * \return Address of the mapped buffer that should be unmapped with
+ * gbm_bo_unmap() when no longer needed. On error, %NULL is returned
+ * and errno is set.
+ *
+ * \sa enum gbm_bo_transfer_flags for the list of flags
+ */
+GBM_EXPORT void *
+gbm_bo_map(struct gbm_bo *bo,
+              uint32_t x, uint32_t y,
+              uint32_t width, uint32_t height,
+              uint32_t flags, uint32_t *stride, void **map_data)
+{
+   if (!bo || width == 0 || height == 0 || !stride || !map_data) {
+      errno = EINVAL;
+      return NULL;
+   }
+
+   return bo->gbm->bo_map(bo, x, y, width, height,
+                          flags, stride, map_data);
+}
+
+/**
+ * Unmap a previously mapped region of a gbm buffer object
+ *
+ * This function unmaps a region of a gbm bo for cpu read and/or write
+ * access.
+ *
+ * \param bo The buffer object
+ * \param map_data opaque ptr returned from prior gbm_bo_map
+ */
+GBM_EXPORT void
+gbm_bo_unmap(struct gbm_bo *bo, void *map_data)
+{
+   bo->gbm->bo_unmap(bo, map_data);
+}
+
 /**
  * Allocate a surface object
  *