OSDN Git Service

minigbm: Make sure no mappings remain when closing a GEM handle
[android-x86/external-minigbm.git] / helpers.c
index 9a665ce..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);
        }
 
@@ -277,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;
@@ -296,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)