#include <errno.h>
#include <i915_drm.h>
+#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
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;
*/
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 &&
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
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;
}
}
if (addr == MAP_FAILED) {
- fprintf(stderr, "drv: i915 GEM mmap failed\n");
+ drv_log("i915 GEM mmap failed\n");
return addr;
}
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;
}