OSDN Git Service

minigbm: Resolve format based on BO usage flags
[android-x86/external-minigbm.git] / helpers.c
index e9d2836..806c152 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 (bo->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);
        }
 
@@ -501,21 +515,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
@@ -523,8 +528,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)