[RFC xserver 14/16] modesetting: Get supported formats/modifiers for scanout
Daniel Stone
daniels at collabora.com
Thu Jun 8 18:43:40 UTC 2017
From: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
Retrieve IN_FORMATS property
Signed-off-by: Louis-Francis Ratté-Boulianne <lfrb at collabora.com>
Signed-off-by: Daniel Stone <daniels at collabora.com>
---
hw/xfree86/drivers/modesetting/drmmode_display.c | 161 +++++++++++++++++++++--
hw/xfree86/drivers/modesetting/drmmode_display.h | 9 ++
2 files changed, 160 insertions(+), 10 deletions(-)
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.c b/hw/xfree86/drivers/modesetting/drmmode_display.c
index 958cfc2c7..18a515d76 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.c
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.c
@@ -54,6 +54,69 @@ static Bool drmmode_xf86crtc_resize(ScrnInfoPtr scrn, int width, int height);
static PixmapPtr drmmode_create_pixmap_header(ScreenPtr pScreen, int width, int height,
int depth, int bitsPerPixel, int devKind,
void *pPixData);
+
+struct drm_format_modifier {
+ /* Bitmask of formats in get_plane format list this info applies to. The
+ * offset allows a sliding window of which 64 formats (bits).
+ *
+ * Some examples:
+ * In today's world with < 65 formats, and formats 0, and 2 are
+ * supported
+ * 0x0000000000000005
+ * ^-offset = 0, formats = 5
+ *
+ * If the number formats grew to 128, and formats 98-102 are
+ * supported with the modifier:
+ *
+ * 0x0000003c00000000 0000000000000000
+ * ^
+ * |__offset = 64, formats = 0x3c00000000
+ *
+ */
+ uint64_t formats;
+ uint32_t offset;
+ uint32_t pad;
+
+ /* This modifier can be used with the format for this plane. */
+ uint64_t modifier;
+} __attribute__ ((__packed__));
+
+struct drm_format_modifier_blob {
+#define FORMAT_BLOB_CURRENT 1
+ /* Version of this blob format */
+ uint32_t version;
+
+ /* Flags */
+ uint32_t flags;
+
+ /* Number of fourcc formats supported */
+ uint32_t count_formats;
+
+ /* Where in this blob the formats exist (in bytes) */
+ uint32_t formats_offset;
+
+ /* Number of drm_format_modifiers */
+ uint32_t count_modifiers;
+
+ /* Where in this blob the modifiers exist (in bytes) */
+ uint32_t modifiers_offset;
+
+ /* u32 formats[] */
+ /* struct drm_format_modifier modifiers[] */
+} __attribute__ ((__packed__));
+
+static inline uint32_t *
+formats_ptr(struct drm_format_modifier_blob *blob)
+{
+ return (uint32_t *)(((char *)blob) + blob->formats_offset);
+}
+
+static inline struct drm_format_modifier *
+modifiers_ptr(struct drm_format_modifier_blob *blob)
+{
+ return (struct drm_format_modifier *)(((char *)blob) + blob->modifiers_offset);
+}
+
static Bool
drmmode_zaphod_string_matches(ScrnInfoPtr scrn, const char *s, char *output_name)
{
@@ -1544,15 +1607,79 @@ is_plane_assigned(ScrnInfoPtr scrn, int plane_id)
return FALSE;
}
+/**
+ * Populates the formats array, and the modifiers of each format for a drm_plane.
+ */
+static Bool
+populate_format_modifiers(xf86CrtcPtr crtc, const drmModePlane *kplane,
+ uint32_t blob_id)
+{
+ drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+ drmmode_ptr drmmode = drmmode_crtc->drmmode;
+ unsigned i, j;
+ drmModePropertyBlobRes *blob;
+ struct drm_format_modifier_blob *fmt_mod_blob;
+ uint32_t *blob_formats;
+ struct drm_format_modifier *blob_modifiers;
+
+ blob = drmModeGetPropertyBlob(drmmode->fd, blob_id);
+ if (!blob)
+ return FALSE;
+
+ fmt_mod_blob = blob->data;
+ blob_formats = formats_ptr(fmt_mod_blob);
+ blob_modifiers = modifiers_ptr(fmt_mod_blob);
+
+ assert(drmmode_crtc->count_formats == fmt_mod_blob->count_formats);
+
+ for (i = 0; i < fmt_mod_blob->count_formats; i++) {
+ uint32_t count_modifiers = 0;
+ uint64_t *modifiers = NULL;
+
+ for (j = 0; j < fmt_mod_blob->count_modifiers; j++) {
+ struct drm_format_modifier *mod = &blob_modifiers[j];
+
+ if ((i < mod->offset) || (i > mod->offset + 64))
+ continue;
+ if (!(mod->formats & (1 << (i - mod->offset))))
+ continue;
+
+ count_modifiers++;
+ modifiers = realloc(modifiers, count_modifiers * sizeof(modifiers[0]));
+ if (!modifiers) {
+ drmModeFreePropertyBlob(blob);
+ return FALSE;
+ }
+ modifiers[count_modifiers - 1] = mod->modifier;
+ }
+
+ drmmode_crtc->formats[i].format = blob_formats[i];
+ drmmode_crtc->formats[i].modifiers = modifiers;
+ drmmode_crtc->formats[i].count_modifiers = count_modifiers;
+ }
+
+ drmModeFreePropertyBlob(blob);
+
+ return TRUE;
+}
+
+#define SELECT_BEST() \
+ best_plane = plane_id; \
+ best_kplane = kplane; \
+ blob_id = drmmode_prop_get_value(&tmp_props[DRMMODE_PLANE_IN_FORMATS], \
+ props, 0); \
+ drmmode_prop_info_copy(drmmode_crtc->props_plane, tmp_props, \
+ DRMMODE_PLANE__COUNT, 1);
+
static void
drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
{
drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
drmmode_ptr drmmode = drmmode_crtc->drmmode;
drmModePlaneRes *kplane_res;
- drmModePlane *kplane;
+ drmModePlane *kplane, *best_kplane = NULL;
drmModeObjectProperties *props;
- uint32_t i, type;
+ uint32_t i, type, blob_id;
int current_crtc, best_plane = 0;
static drmmode_prop_enum_info_rec plane_type_enums[] = {
@@ -1574,6 +1701,7 @@ drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
},
[DRMMODE_PLANE_FB_ID] = { .name = "FB_ID", },
[DRMMODE_PLANE_CRTC_ID] = { .name = "CRTC_ID", },
+ [DRMMODE_PLANE_IN_FORMATS] = { .name = "IN_FORMATS", },
[DRMMODE_PLANE_SRC_X] = { .name = "SRC_X", },
[DRMMODE_PLANE_SRC_Y] = { .name = "SRC_Y", },
};
@@ -1606,13 +1734,13 @@ drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
}
plane_id = kplane->plane_id;
- drmModeFreePlane(kplane);
props = drmModeObjectGetProperties(drmmode->fd, plane_id,
DRM_MODE_OBJECT_PLANE);
if (!props) {
xf86DrvMsg(drmmode->scrn->scrnIndex, X_ERROR,
"couldn't get plane properties\n");
+ drmModeFreePlane(kplane);
continue;
}
@@ -1622,6 +1750,7 @@ drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
type = drmmode_prop_get_value(&tmp_props[DRMMODE_PLANE_TYPE],
props, DRMMODE_PLANE_TYPE__COUNT);
if (type != DRMMODE_PLANE_TYPE_PRIMARY) {
+ drmModeFreePlane(kplane);
drmModeFreeObjectProperties(props);
continue;
}
@@ -1630,25 +1759,37 @@ drmmode_crtc_create_planes(xf86CrtcPtr crtc, int num)
current_crtc = drmmode_prop_get_value(&tmp_props[DRMMODE_PLANE_CRTC_ID],
props, 0);
if (current_crtc == drmmode_crtc->mode_crtc->crtc_id) {
- if (best_plane)
+ if (best_plane) {
+ drmModeFreePlane(best_kplane);
drmmode_prop_info_free(drmmode_crtc->props_plane, DRMMODE_PLANE__COUNT);
- best_plane = plane_id;
- drmmode_prop_info_copy(drmmode_crtc->props_plane, tmp_props,
- DRMMODE_PLANE__COUNT, 1);
+ }
+ SELECT_BEST();
drmModeFreeObjectProperties(props);
break;
}
if (!best_plane) {
- best_plane = plane_id;
- drmmode_prop_info_copy(drmmode_crtc->props_plane, tmp_props,
- DRMMODE_PLANE__COUNT, 1);
+ SELECT_BEST();
+ } else {
+ drmModeFreePlane(kplane);
}
drmModeFreeObjectProperties(props);
}
drmmode_crtc->plane_id = best_plane;
+ if (best_kplane) {
+ drmmode_crtc->count_formats = best_kplane->count_formats;
+ drmmode_crtc->formats = calloc(sizeof(drmmode_format_rec),
+ best_kplane->count_formats);
+ if (blob_id) {
+ populate_format_modifiers(crtc, best_kplane, blob_id);
+ } else {
+ for (i = 0; i < best_kplane->count_formats; i++)
+ drmmode_crtc->formats[i].format = best_kplane->formats[i];
+ }
+ drmModeFreePlane(best_kplane);
+ }
drmmode_prop_info_free(tmp_props, DRMMODE_PLANE__COUNT);
drmModeFreePlaneResources(kplane_res);
diff --git a/hw/xfree86/drivers/modesetting/drmmode_display.h b/hw/xfree86/drivers/modesetting/drmmode_display.h
index cb7e27d1e..39cc17660 100644
--- a/hw/xfree86/drivers/modesetting/drmmode_display.h
+++ b/hw/xfree86/drivers/modesetting/drmmode_display.h
@@ -39,6 +39,7 @@ struct gbm_device;
enum drmmode_plane_property {
DRMMODE_PLANE_TYPE = 0,
DRMMODE_PLANE_FB_ID,
+ DRMMODE_PLANE_IN_FORMATS,
DRMMODE_PLANE_CRTC_ID,
DRMMODE_PLANE_SRC_X,
DRMMODE_PLANE_SRC_Y,
@@ -143,6 +144,12 @@ typedef struct {
} drmmode_mode_rec, *drmmode_mode_ptr;
typedef struct {
+ uint32_t format;
+ uint32_t count_modifiers;
+ uint64_t *modifiers;
+} drmmode_format_rec, *drmmode_format_ptr;
+
+typedef struct {
drmmode_ptr drmmode;
drmModeCrtcPtr mode_crtc;
uint32_t vblank_pipe;
@@ -155,6 +162,8 @@ typedef struct {
drmmode_prop_info_rec props_plane[DRMMODE_PLANE__COUNT];
uint32_t plane_id;
drmmode_mode_ptr current_mode;
+ uint32_t count_formats;
+ drmmode_format_rec *formats;
drmmode_bo rotate_bo;
unsigned rotate_fb_id;
--
2.13.0
More information about the xorg-devel
mailing list