OSDN Git Service

minigbm: Make sure no mappings remain when closing a GEM handle
[android-x86/external-minigbm.git] / helpers.c
index 3022a08..238563d 100644 (file)
--- a/helpers.c
+++ b/helpers.c
@@ -47,6 +47,7 @@ static uint32_t bpp_from_format(uint32_t format, size_t plane)
                return 8;
 
        case DRM_FORMAT_NV12:
+       case DRM_FORMAT_NV21:
                return (plane == 0) ? 8 : 4;
 
        case DRM_FORMAT_ABGR1555:
@@ -139,16 +140,26 @@ int drv_bo_from_format(struct bo *bo, uint32_t stride, uint32_t aligned_height,
 
        num_planes = drv_num_planes_from_format(format);
        assert(num_planes);
-       bo->total_size = 0;
+
+       /*
+        * HAL_PIXEL_FORMAT_YV12 requires that (see <system/graphics.h>):
+        *  - the aligned height is same as the buffer's height.
+        *  - the chroma stride is 16 bytes aligned, i.e., the luma's strides
+        *    is 32 bytes aligned.
+        */
+       if (format == DRM_FORMAT_YVU420_ANDROID) {
+               assert(aligned_height == bo->height);
+               assert(stride == ALIGN(stride, 32));
+       }
 
        for (p = 0; p < num_planes; p++) {
                bo->strides[p] = subsample_stride(stride, format, p);
-               bo->sizes[p] = drv_size_from_format(format, bo->strides[p], bo->height, p);
+               bo->sizes[p] = drv_size_from_format(format, bo->strides[p], aligned_height, p);
                bo->offsets[p] = offset;
                offset += bo->sizes[p];
-               bo->total_size += drv_size_from_format(format, bo->strides[p], aligned_height, p);
        }
 
+       bo->total_size = offset;
        return 0;
 }
 
@@ -168,6 +179,9 @@ int drv_dumb_bo_create(struct bo *bo, uint32_t width, uint32_t height, uint32_t
                 * Android requires.
                 */
                aligned_width = ALIGN(width, 32);
+       }
+
+       if (format == DRM_FORMAT_YVU420_ANDROID || format == DRM_FORMAT_YVU420) {
                aligned_height = 3 * DIV_ROUND_UP(height, 2);
        }
 
@@ -202,8 +216,7 @@ int drv_dumb_bo_destroy(struct bo *bo)
 
        ret = drmIoctl(bo->drv->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
        if (ret) {
-               fprintf(stderr, "drv: DRM_IOCTL_MODE_DESTROY_DUMB failed "
-                               "(handle=%x)\n",
+               fprintf(stderr, "drv: DRM_IOCTL_MODE_DESTROY_DUMB failed (handle=%x)\n",
                        bo->handles[0].u32);
                return ret;
        }
@@ -230,8 +243,7 @@ int drv_gem_bo_destroy(struct bo *bo)
 
                ret = drmIoctl(bo->drv->fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
                if (ret) {
-                       fprintf(stderr, "drv: DRM_IOCTL_GEM_CLOSE failed "
-                                       "(handle=%x) error %d\n",
+                       fprintf(stderr, "drv: DRM_IOCTL_GEM_CLOSE failed (handle=%x) error %d\n",
                                bo->handles[plane].u32, ret);
                        error = ret;
                }
@@ -253,8 +265,7 @@ int drv_prime_bo_import(struct bo *bo, struct drv_import_fd_data *data)
                ret = drmIoctl(bo->drv->fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &prime_handle);
 
                if (ret) {
-                       fprintf(stderr, "drv: DRM_IOCTL_PRIME_FD_TO_HANDLE "
-                                       "failed (fd=%u)\n",
+                       fprintf(stderr, "drv: DRM_IOCTL_PRIME_FD_TO_HANDLE failed (fd=%u)\n",
                                prime_handle.fd);
 
                        /*
@@ -280,7 +291,7 @@ int drv_prime_bo_import(struct bo *bo, struct drv_import_fd_data *data)
        return 0;
 }
 
-void *drv_dumb_bo_map(struct bo *bo, struct map_info *data, size_t plane)
+void *drv_dumb_bo_map(struct bo *bo, struct map_info *data, size_t plane, int prot)
 {
        int ret;
        size_t i;
@@ -299,8 +310,7 @@ void *drv_dumb_bo_map(struct bo *bo, struct map_info *data, size_t plane)
                if (bo->handles[i].u32 == bo->handles[plane].u32)
                        data->length += bo->sizes[i];
 
-       return mmap(0, data->length, PROT_READ | PROT_WRITE, MAP_SHARED, bo->drv->fd,
-                   map_dumb.offset);
+       return mmap(0, data->length, prot, MAP_SHARED, bo->drv->fd, map_dumb.offset);
 }
 
 uintptr_t drv_get_reference_count(struct driver *drv, struct bo *bo, size_t plane)
@@ -504,21 +514,12 @@ out:
        return items;
 }
 
-int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats, uint32_t num_formats)
+int drv_modify_linear_combinations(struct driver *drv)
 {
-       int ret;
        uint32_t i, j, num_items;
        struct kms_item *items;
        struct combination *combo;
-       struct format_metadata metadata;
 
-       metadata.tiling = 0;
-       metadata.priority = 1;
-       metadata.modifier = DRM_FORMAT_MOD_NONE;
-
-       ret = drv_add_combinations(drv, formats, num_formats, &metadata, BO_COMMON_USE_MASK);
-       if (ret)
-               return ret;
        /*
         * All current drivers can scanout linear XRGB8888/ARGB8888 as a primary
         * plane and as a cursor. Some drivers don't support
@@ -526,8 +527,10 @@ int drv_add_linear_combinations(struct driver *drv, const uint32_t *formats, uin
         * kernel disregards the alpha component of ARGB unless it's an overlay
         * plane.
         */
-       drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
-       drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &metadata, BO_USE_CURSOR | BO_USE_SCANOUT);
+       drv_modify_combination(drv, DRM_FORMAT_XRGB8888, &LINEAR_METADATA,
+                              BO_USE_CURSOR | BO_USE_SCANOUT);
+       drv_modify_combination(drv, DRM_FORMAT_ARGB8888, &LINEAR_METADATA,
+                              BO_USE_CURSOR | BO_USE_SCANOUT);
 
        items = drv_query_kms(drv, &num_items);
        if (!items || !num_items)