OSDN Git Service

minigbm: Consolidate format info in new struct planar_layout
[android-x86/external-minigbm.git] / i915.c
diff --git a/i915.c b/i915.c
index da22dc5..fc877cb 100644 (file)
--- a/i915.c
+++ b/i915.c
@@ -8,6 +8,7 @@
 
 #include <errno.h>
 #include <i915_drm.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/mman.h>
@@ -49,6 +50,31 @@ static uint32_t i915_get_gen(int device_id)
        return 4;
 }
 
+/*
+ * We allow allocation of ARGB formats for SCANOUT if the corresponding XRGB
+ * formats supports it. It's up to the caller (chrome ozone) to ultimately not
+ * scan out ARGB if the display controller only supports XRGB, but we'll allow
+ * the allocation of the bo here.
+ */
+static bool format_compatible(const struct combination *combo, uint32_t format)
+{
+       if (combo->format == format)
+               return true;
+
+       switch (format) {
+       case DRM_FORMAT_XRGB8888:
+               return combo->format == DRM_FORMAT_ARGB8888;
+       case DRM_FORMAT_XBGR8888:
+               return combo->format == DRM_FORMAT_ABGR8888;
+       case DRM_FORMAT_RGBX8888:
+               return combo->format == DRM_FORMAT_RGBA8888;
+       case DRM_FORMAT_BGRX8888:
+               return combo->format == DRM_FORMAT_BGRA8888;
+       default:
+               return false;
+       }
+}
+
 static int i915_add_kms_item(struct driver *drv, const struct kms_item *item)
 {
        uint32_t i;
@@ -60,7 +86,7 @@ static int i915_add_kms_item(struct driver *drv, const struct kms_item *item)
         */
        for (i = 0; i < drv_array_size(drv->combos); i++) {
                combo = (struct combination *)drv_array_at_idx(drv->combos, i);
-               if (combo->format != item->format)
+               if (!format_compatible(combo, item->format))
                        continue;
 
                if (item->modifier == DRM_FORMAT_MOD_LINEAR &&
@@ -255,7 +281,7 @@ static int i915_init(struct driver *drv)
        get_param.value = &device_id;
        ret = drmIoctl(drv->fd, DRM_IOCTL_I915_GETPARAM, &get_param);
        if (ret) {
-               fprintf(stderr, "drv: Failed to get I915_PARAM_CHIPSET_ID\n");
+               drv_log("Failed to get I915_PARAM_CHIPSET_ID\n");
                free(i915);
                return -EINVAL;
        }
@@ -267,7 +293,7 @@ static int i915_init(struct driver *drv)
        get_param.value = &i915->has_llc;
        ret = drmIoctl(drv->fd, DRM_IOCTL_I915_GETPARAM, &get_param);
        if (ret) {
-               fprintf(stderr, "drv: Failed to get I915_PARAM_HAS_LLC\n");
+               drv_log("Failed to get I915_PARAM_HAS_LLC\n");
                free(i915);
                return -EINVAL;
        }
@@ -349,8 +375,7 @@ static int i915_bo_create_for_modifier(struct bo *bo, uint32_t width, uint32_t h
 
        ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_CREATE, &gem_create);
        if (ret) {
-               fprintf(stderr, "drv: DRM_IOCTL_I915_GEM_CREATE failed (size=%llu)\n",
-                       gem_create.size);
+               drv_log("DRM_IOCTL_I915_GEM_CREATE failed (size=%llu)\n", gem_create.size);
                return ret;
        }
 
@@ -369,7 +394,7 @@ static int i915_bo_create_for_modifier(struct bo *bo, uint32_t width, uint32_t h
                gem_close.handle = bo->handles[0].u32;
                drmIoctl(bo->drv->fd, DRM_IOCTL_GEM_CLOSE, &gem_close);
 
-               fprintf(stderr, "drv: DRM_IOCTL_I915_GEM_SET_TILING failed with %d", errno);
+               drv_log("DRM_IOCTL_I915_GEM_SET_TILING failed with %d\n", errno);
                return -errno;
        }
 
@@ -425,7 +450,7 @@ static int i915_bo_import(struct bo *bo, struct drv_import_fd_data *data)
        ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_GET_TILING, &gem_get_tiling);
        if (ret) {
                drv_gem_bo_destroy(bo);
-               fprintf(stderr, "drv: DRM_IOCTL_I915_GEM_GET_TILING failed.");
+               drv_log("DRM_IOCTL_I915_GEM_GET_TILING failed.\n");
                return ret;
        }
 
@@ -451,7 +476,7 @@ static void *i915_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint32_t
 
                ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_MMAP, &gem_map);
                if (ret) {
-                       fprintf(stderr, "drv: DRM_IOCTL_I915_GEM_MMAP failed\n");
+                       drv_log("DRM_IOCTL_I915_GEM_MMAP failed\n");
                        return MAP_FAILED;
                }
 
@@ -464,7 +489,7 @@ static void *i915_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint32_t
 
                ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_MMAP_GTT, &gem_map);
                if (ret) {
-                       fprintf(stderr, "drv: DRM_IOCTL_I915_GEM_MMAP_GTT failed\n");
+                       drv_log("DRM_IOCTL_I915_GEM_MMAP_GTT failed\n");
                        return MAP_FAILED;
                }
 
@@ -473,7 +498,7 @@ static void *i915_bo_map(struct bo *bo, struct vma *vma, size_t plane, uint32_t
        }
 
        if (addr == MAP_FAILED) {
-               fprintf(stderr, "drv: i915 GEM mmap failed\n");
+               drv_log("i915 GEM mmap failed\n");
                return addr;
        }
 
@@ -500,7 +525,7 @@ static int i915_bo_invalidate(struct bo *bo, struct mapping *mapping)
 
        ret = drmIoctl(bo->drv->fd, DRM_IOCTL_I915_GEM_SET_DOMAIN, &set_domain);
        if (ret) {
-               fprintf(stderr, "drv: DRM_IOCTL_I915_GEM_SET_DOMAIN with %d\n", ret);
+               drv_log("DRM_IOCTL_I915_GEM_SET_DOMAIN with %d\n", ret);
                return ret;
        }