static int kms_plane_probe(struct kms_plane *plane) { struct kms_device *device = plane->device; drmModeObjectPropertiesPtr props; drmModePlane *p; unsigned int i; p = drmModeGetPlane(device->fd, plane->id); if (!p) return -ENODEV; /* TODO: allow dynamic assignment to CRTCs */ if (p->crtc_id == 0) { for (i = 0; i < device->num_crtcs; i++) { if (p->possible_crtcs & (1 << i)) { p->crtc_id = device->crtcs[i]->id; break; } } } for (i = 0; i < device->num_crtcs; i++) { if (device->crtcs[i]->id == p->crtc_id) { plane->crtc = device->crtcs[i]; break; } } plane->formats = calloc(p->count_formats, sizeof(uint32_t)); if (!plane->formats) return -ENOMEM; for (i = 0; i < p->count_formats; i++) plane->formats[i] = p->formats[i]; plane->num_formats = p->count_formats; drmModeFreePlane(p); props = drmModeObjectGetProperties(device->fd, plane->id, DRM_MODE_OBJECT_PLANE); if (!props) return -ENODEV; for (i = 0; i < props->count_props; i++) { drmModePropertyPtr prop; prop = drmModeGetProperty(device->fd, props->props[i]); if (prop) { if (strcmp(prop->name, "type") == 0) plane->type = props->prop_values[i]; drmModeFreeProperty(prop); } } drmModeFreeObjectProperties(props); return 0; }
int drm_object_create_properties(struct mp_log *log, int fd, struct drm_object *object) { object->props = drmModeObjectGetProperties(fd, object->id, object->type); if (object->props) { object->props_info = talloc_zero_size(NULL, object->props->count_props * sizeof(object->props_info)); if (object->props_info) { for (int i = 0; i < object->props->count_props; i++) object->props_info[i] = drmModeGetProperty(fd, object->props->props[i]); } else { mp_err(log, "Out of memory\n"); goto fail; } } else { mp_err(log, "Failed to retrieve properties for object id %d\n", object->id); goto fail; } return 0; fail: drm_object_free_properties(object); return -1; }
static void find_crtc_properties (MetaMonitorManagerKms *manager_kms, MetaCRTC *meta_crtc) { MetaCRTCKms *crtc_kms; drmModeObjectPropertiesPtr props; size_t i; crtc_kms = meta_crtc->driver_private; props = drmModeObjectGetProperties (manager_kms->fd, meta_crtc->crtc_id, DRM_MODE_OBJECT_CRTC); if (!props) return; for (i = 0; i < props->count_props; i++) { drmModePropertyPtr prop = drmModeGetProperty (manager_kms->fd, props->props[i]); if (!prop) continue; if ((prop->flags & DRM_MODE_PROP_ENUM) && strcmp (prop->name, "underscan") == 0) crtc_kms->underscan_prop_id = prop->prop_id; else if ((prop->flags & DRM_MODE_PROP_RANGE) && strcmp (prop->name, "underscan hborder") == 0) crtc_kms->underscan_hborder_prop_id = prop->prop_id; else if ((prop->flags & DRM_MODE_PROP_RANGE) && strcmp (prop->name, "underscan vborder") == 0) crtc_kms->underscan_vborder_prop_id = prop->prop_id; drmModeFreeProperty (prop); } }
static int drm_plane_type(int drm_fd, int plane_id) { drmModeObjectPropertiesPtr props; drmModePropertyPtr prop; int plane_type = -EINVAL; int i; props = drmModeObjectGetProperties(drm_fd, plane_id, DRM_MODE_OBJECT_PLANE); if (!props) return -ENODEV; for (i = 0; i < props->count_props && plane_type == -EINVAL; i++) { prop = drmModeGetProperty(drm_fd, props->props[i]); if (prop) { if (strcmp(prop->name, "type") == 0) plane_type = props->prop_values[i]; drmModeFreeProperty(prop); } } drmModeFreeObjectProperties(props); return plane_type; }
static void fill_obj_props(int fd, uint32_t id, int type, int num_props, const char **prop_names, uint32_t *prop_ids) { drmModeObjectPropertiesPtr props; int i, j; props = drmModeObjectGetProperties(fd, id, type); igt_assert(props); for (i = 0; i < props->count_props; i++) { drmModePropertyPtr prop = drmModeGetProperty(fd, props->props[i]); for (j = 0; j < num_props; j++) { if (strcmp(prop->name, prop_names[j]) != 0) continue; prop_ids[j] = props->props[i]; break; } drmModeFreeProperty(prop); } drmModeFreeObjectProperties(props); }
static void populate_crtc_props(int fd, struct my_crtc *c) { drmModeObjectPropertiesPtr props; uint32_t i; props = drmModeObjectGetProperties(fd, c->base.crtc_id, DRM_MODE_OBJECT_CRTC); if (!props) return; for (i = 0; i < props->count_props; i++) { drmModePropertyPtr prop; prop = drmModeGetProperty(fd, props->props[i]); if (!prop) continue; printf("crtc prop %s %u\n", prop->name, prop->prop_id); // if (!strcmp(prop->name, "MODE")) // c->prop.mode = prop->prop_id; // else if (!strcmp(prop->name, "CONNECTOR_IDS")) // c->prop.connector_ids = prop->prop_id; drmModeFreeProperty(prop); } drmModeFreeObjectProperties(props); }
static void crtc_commit_legacy(struct kms_atomic_crtc_state *crtc, struct kms_atomic_plane_state *plane, enum kms_atomic_check_relax relax) { drmModeObjectPropertiesPtr props; uint32_t *connectors; int num_connectors = 0; int i; if (!crtc->active) { do_or_die(drmModeSetCrtc(crtc->state->desc->fd, crtc->obj, 0, 0, 0, NULL, 0, NULL)); return; } connectors = calloc(crtc->state->num_connectors, sizeof(*connectors)); igt_assert(connectors); igt_assert_neq_u32(crtc->mode.id, 0); for (i = 0; i < crtc->state->num_connectors; i++) { struct kms_atomic_connector_state *connector = &crtc->state->connectors[i]; if (connector->crtc_id != crtc->obj) continue; connectors[num_connectors++] = connector->obj; } do_or_die(drmModeSetCrtc(crtc->state->desc->fd, crtc->obj, plane->fb_id, plane->src_x >> 16, plane->src_y >> 16, (num_connectors) ? connectors : NULL, num_connectors, crtc->mode.data)); /* When doing a legacy commit, the core may update MODE_ID to be a new * blob implicitly created by the legacy request. Hence we backfill * the value in the state object to ensure they match. */ props = drmModeObjectGetProperties(crtc->state->desc->fd, crtc->obj, DRM_MODE_OBJECT_CRTC); igt_assert(props); for (i = 0; i < props->count_props; i++) { if (props->props[i] != crtc->state->desc->props_crtc[CRTC_MODE_ID]) continue; crtc->mode.id = props->prop_values[i]; break; } drmModeFreeObjectProperties(props); crtc_check_current_state(crtc, plane, relax); plane_check_current_state(plane, relax); }
static void init_crtc_rotations (MetaMonitorManager *manager, MetaCRTC *crtc, unsigned int idx) { MetaMonitorManagerKms *manager_kms = META_MONITOR_MANAGER_KMS (manager); drmModeObjectPropertiesPtr props; drmModePlaneRes *planes; drmModePlane *drm_plane; MetaCRTCKms *crtc_kms; unsigned int i; crtc_kms = crtc->driver_private; planes = drmModeGetPlaneResources(manager_kms->fd); if (planes == NULL) return; for (i = 0; i < planes->count_planes; i++) { drmModePropertyPtr prop; drm_plane = drmModeGetPlane (manager_kms->fd, planes->planes[i]); if (!drm_plane) continue; if ((drm_plane->possible_crtcs & (1 << idx))) { props = drmModeObjectGetProperties (manager_kms->fd, drm_plane->plane_id, DRM_MODE_OBJECT_PLANE); if (props && is_primary_plane (manager, props)) { int rotation_idx; crtc_kms->primary_plane_id = drm_plane->plane_id; rotation_idx = find_property_index (manager, props, "rotation", &prop); if (rotation_idx >= 0) { crtc_kms->rotation_prop_id = props->props[rotation_idx]; parse_transforms (manager, prop, crtc); drmModeFreeProperty (prop); } } if (props) drmModeFreeObjectProperties (props); } drmModeFreePlane (drm_plane); } drmModeFreePlaneResources (planes); }
/* Pick a plane.. something that at a minimum can be connected to * the chosen crtc, but prefer primary plane. * * Seems like there is some room for a drmModeObjectGetNamedProperty() * type helper in libdrm.. */ static int get_plane_id(void) { drmModePlaneResPtr plane_resources; uint32_t i, j; int ret = -EINVAL; int found_primary = 0; plane_resources = drmModeGetPlaneResources(drm.fd); if (!plane_resources) { printf("drmModeGetPlaneResources failed: %s\n", strerror(errno)); return -1; } for (i = 0; (i < plane_resources->count_planes) && !found_primary; i++) { uint32_t id = plane_resources->planes[i]; drmModePlanePtr plane = drmModeGetPlane(drm.fd, id); if (!plane) { printf("drmModeGetPlane(%u) failed: %s\n", id, strerror(errno)); continue; } if (plane->possible_crtcs & (1 << drm.crtc_index)) { drmModeObjectPropertiesPtr props = drmModeObjectGetProperties(drm.fd, id, DRM_MODE_OBJECT_PLANE); /* primary or not, this plane is good enough to use: */ ret = id; for (j = 0; j < props->count_props; j++) { drmModePropertyPtr p = drmModeGetProperty(drm.fd, props->props[j]); if ((strcmp(p->name, "type") == 0) && (props->prop_values[j] == DRM_PLANE_TYPE_PRIMARY)) { /* found our primary plane, lets use that: */ found_primary = 1; } drmModeFreeProperty(p); } drmModeFreeObjectProperties(props); } drmModeFreePlane(plane); } drmModeFreePlaneResources(plane_resources); return ret; }
static bool GetProperties(int fd, uint32_t id, uint32_t type, struct drm_object *object) { drmModeObjectPropertiesPtr props = drmModeObjectGetProperties(fd, id, type); if (!props) return false; object->id = id; object->type = type; object->props = props; object->props_info = new drmModePropertyPtr[props->count_props]; for (uint32_t i = 0; i < props->count_props; i++) object->props_info[i] = drmModeGetProperty(fd, props->props[i]); return true; }
void DrmObject::refresh_props() { auto props = drmModeObjectGetProperties(card().fd(), this->id(), this->object_type()); if (props == nullptr) return; for (unsigned i = 0; i < props->count_props; ++i) { uint32_t prop_id = props->props[i]; uint64_t prop_value = props->prop_values[i]; m_prop_values[prop_id] = prop_value; } drmModeFreeObjectProperties(props); }
static void plane_get_current_state(struct kms_atomic_plane_state *plane) { struct kms_atomic_desc *desc = plane->state->desc; drmModeObjectPropertiesPtr props; int i; props = drmModeObjectGetProperties(desc->fd, plane->obj, DRM_MODE_OBJECT_PLANE); igt_assert(props); for (i = 0; i < props->count_props; i++) { uint32_t *prop_ids = desc->props_plane; if (props->props[i] == prop_ids[PLANE_CRTC_ID]) plane->crtc_id = props->prop_values[i]; else if (props->props[i] == prop_ids[PLANE_FB_ID]) plane->fb_id = props->prop_values[i]; else if (props->props[i] == prop_ids[PLANE_CRTC_X]) plane->crtc_x = props->prop_values[i]; else if (props->props[i] == prop_ids[PLANE_CRTC_Y]) plane->crtc_y = props->prop_values[i]; else if (props->props[i] == prop_ids[PLANE_CRTC_W]) plane->crtc_w = props->prop_values[i]; else if (props->props[i] == prop_ids[PLANE_CRTC_H]) plane->crtc_h = props->prop_values[i]; else if (props->props[i] == prop_ids[PLANE_SRC_X]) plane->src_x = props->prop_values[i]; else if (props->props[i] == prop_ids[PLANE_SRC_Y]) plane->src_y = props->prop_values[i]; else if (props->props[i] == prop_ids[PLANE_SRC_W]) plane->src_w = props->prop_values[i]; else if (props->props[i] == prop_ids[PLANE_SRC_H]) plane->src_h = props->prop_values[i]; else if (props->props[i] == prop_ids[PLANE_TYPE]) { int j; for (j = 0; j < ARRAY_SIZE(desc->props_plane_type); j++) { if (props->prop_values[i] == desc->props_plane_type[j]) { plane->type = j; break; } } } } drmModeFreeObjectProperties(props); }
static void listObjectProperties(uint32_t id, uint32_t type) { unsigned int i; drmModeObjectPropertiesPtr props; props = drmModeObjectGetProperties(fd, id, type); if (!props) { printf("\tNo properties: %s.\n", strerror(errno)); return; } for (i = 0; i < props->count_props; i++) dump_prop(props->props[i], props->prop_values[i]); drmModeFreeObjectProperties(props); }
static uint64_t drm_plane_type(drmModePlane *plane) { int i,j; /* The property values and their names are stored in different arrays, so we * access them simultaneously here. * We are interested in OVERLAY planes only, that's type 0 or DRM_PLANE_TYPE_OVERLAY * (see /usr/xf86drmMode.h for definition). */ drmModeObjectPropertiesPtr props = drmModeObjectGetProperties(drm.fd, plane->plane_id, DRM_MODE_OBJECT_PLANE); for (j = 0; j < props->count_props; j++) { /* found the type property */ if ( !strcmp(drmModeGetProperty(drm.fd, props->props[j])->name, "type")) return (props->prop_values[j]); } return (0); }
static void populate_plane_props(int fd, struct my_plane *p) { drmModeObjectPropertiesPtr props; uint32_t i; props = drmModeObjectGetProperties(fd, p->base.plane_id, DRM_MODE_OBJECT_PLANE); if (!props) return; for (i = 0; i < props->count_props; i++) { drmModePropertyPtr prop; prop = drmModeGetProperty(fd, props->props[i]); if (!prop) continue; printf("plane prop %s %u\n", prop->name, prop->prop_id); if (!strcmp(prop->name, "SRC_X")) p->prop.src_x = prop->prop_id; else if (!strcmp(prop->name, "SRC_Y")) p->prop.src_y = prop->prop_id; else if (!strcmp(prop->name, "SRC_W")) p->prop.src_w = prop->prop_id; else if (!strcmp(prop->name, "SRC_H")) p->prop.src_h = prop->prop_id; else if (!strcmp(prop->name, "CRTC_X")) p->prop.crtc_x = prop->prop_id; else if (!strcmp(prop->name, "CRTC_Y")) p->prop.crtc_y = prop->prop_id; else if (!strcmp(prop->name, "CRTC_W")) p->prop.crtc_w = prop->prop_id; else if (!strcmp(prop->name, "CRTC_H")) p->prop.crtc_h = prop->prop_id; else if (!strcmp(prop->name, "FB_ID")) p->prop.fb = prop->prop_id; else if (!strcmp(prop->name, "CRTC_ID")) p->prop.crtc = prop->prop_id; drmModeFreeProperty(prop); } drmModeFreeObjectProperties(props); }
static void connector_get_current_state(struct kms_atomic_connector_state *connector) { drmModeObjectPropertiesPtr props; int i; props = drmModeObjectGetProperties(connector->state->desc->fd, connector->obj, DRM_MODE_OBJECT_CONNECTOR); igt_assert(props); for (i = 0; i < props->count_props; i++) { uint32_t *prop_ids = connector->state->desc->props_connector; if (props->props[i] == prop_ids[CONNECTOR_CRTC_ID]) connector->crtc_id = props->prop_values[i]; } drmModeFreeObjectProperties(props); }
bool DrmPlane::initProps() { m_propsNames = { QByteArrayLiteral("type"), QByteArrayLiteral("SRC_X"), QByteArrayLiteral("SRC_Y"), QByteArrayLiteral("SRC_W"), QByteArrayLiteral("SRC_H"), QByteArrayLiteral("CRTC_X"), QByteArrayLiteral("CRTC_Y"), QByteArrayLiteral("CRTC_W"), QByteArrayLiteral("CRTC_H"), QByteArrayLiteral("FB_ID"), QByteArrayLiteral("CRTC_ID"), }; QVector<QByteArray> typeNames = { QByteArrayLiteral("Primary"), QByteArrayLiteral("Cursor"), QByteArrayLiteral("Overlay"), }; drmModeObjectProperties *properties = drmModeObjectGetProperties(m_fd, m_id, DRM_MODE_OBJECT_PLANE); if (!properties){ qCWarning(KWIN_DRM) << "Failed to get properties for plane " << m_id ; return false; } int propCount = int(PropertyIndex::Count); for (int j = 0; j < propCount; ++j) { if (j == int(PropertyIndex::Type)) { initProp(j, properties, typeNames); } else { initProp(j, properties); } } drmModeFreeObjectProperties(properties); return true; }
static uint32_t get_plane_prop_id(uint32_t obj_id, const char *name) { int i,j; drmModePlaneRes *plane_resources; drmModePlane *plane; drmModeObjectProperties *props; drmModePropertyRes **props_info; char format_str[5]; plane_resources = drmModeGetPlaneResources(drm.fd); for (i = 0; i < plane_resources->count_planes; i++) { plane = drmModeGetPlane(drm.fd, plane_resources->planes[i]); if (plane->plane_id != obj_id) continue; /* TODO: Improvement. We get all the properties of the * plane and info about the properties. * We should have done this already... * This implementation must be improved. */ props = drmModeObjectGetProperties(drm.fd, plane->plane_id, DRM_MODE_OBJECT_PLANE); props_info = malloc(props->count_props * sizeof *props_info); for (j = 0; j < props->count_props; ++j) props_info[j] = drmModeGetProperty(drm.fd, props->props[j]); /* We look for the prop_id we need */ for (j = 0; j < props->count_props; j++) { if (!strcmp(props_info[j]->name, name)) return props_info[j]->prop_id; } RARCH_ERR ("DRM: plane %d fb property ID with name %s not found\n", plane->plane_id, name); } return (0); }
static void crtc_get_current_state(struct kms_atomic_crtc_state *crtc) { drmModeObjectPropertiesPtr props; int i; props = drmModeObjectGetProperties(crtc->state->desc->fd, crtc->obj, DRM_MODE_OBJECT_CRTC); igt_assert(props); for (i = 0; i < props->count_props; i++) { uint32_t *prop_ids = crtc->state->desc->props_crtc; if (props->props[i] == prop_ids[CRTC_MODE_ID]) { drmModePropertyBlobPtr blob; crtc->mode.id = props->prop_values[i]; if (!crtc->mode.id) { crtc->mode.len = 0; continue; } blob = drmModeGetPropertyBlob(crtc->state->desc->fd, crtc->mode.id); igt_assert(blob); igt_assert_eq_u32(blob->length, sizeof(struct drm_mode_modeinfo)); if (!crtc->mode.data || memcmp(crtc->mode.data, blob->data, blob->length) != 0) crtc->mode.data = blob->data; crtc->mode.len = blob->length; } else if (props->props[i] == prop_ids[CRTC_ACTIVE]) { crtc->active = props->prop_values[i]; } } drmModeFreeObjectProperties(props); }
int DrmResources::GetProperty(uint32_t obj_id, uint32_t obj_type, const char *prop_name, DrmProperty *property) { drmModeObjectPropertiesPtr props; props = drmModeObjectGetProperties(fd_, obj_id, obj_type); if (!props) { ALOGE("Failed to get properties for %d/%x", obj_id, obj_type); return -ENODEV; } bool found = false; for (int i = 0; !found && (size_t)i < props->count_props; ++i) { drmModePropertyPtr p = drmModeGetProperty(fd_, props->props[i]); if (!strcmp(p->name, prop_name)) { property->Init(p, props->prop_values[i]); found = true; } drmModeFreeProperty(p); } drmModeFreeObjectProperties(props); return found ? 0 : -ENOENT; }
bool CDRMUtils::GetConnector() { for(auto i = 0; i < m_drm_resources->count_connectors; i++) { m_connector->connector = drmModeGetConnector(m_fd, m_drm_resources->connectors[i]); if(m_connector->connector->connection == DRM_MODE_CONNECTED) { CLog::Log(LOGDEBUG, "CDRMUtils::%s - found connector: %d", __FUNCTION__, m_connector->connector->connector_id); break; } drmModeFreeConnector(m_connector->connector); m_connector->connector = nullptr; } if(!m_connector->connector) { CLog::Log(LOGERROR, "CDRMUtils::%s - could not get connector: %s", __FUNCTION__, strerror(errno)); return false; } m_connector->props = drmModeObjectGetProperties(m_fd, m_connector->connector->connector_id, DRM_MODE_OBJECT_CONNECTOR); if (!m_connector->props) { CLog::Log(LOGERROR, "CDRMUtils::%s - could not get connector %u properties: %s", __FUNCTION__, m_connector->connector->connector_id, strerror(errno)); return false; } m_connector->props_info = new drmModePropertyPtr[m_connector->props->count_props]; for (uint32_t i = 0; i < m_connector->props->count_props; i++) { m_connector->props_info[i] = drmModeGetProperty(m_fd, m_connector->props->props[i]); } return true; }
bool CDRMUtils::GetCrtc() { for(auto i = 0; i < m_drm_resources->count_crtcs; i++) { m_crtc->crtc = drmModeGetCrtc(m_fd, m_drm_resources->crtcs[i]); if(m_crtc->crtc->crtc_id == m_encoder->encoder->crtc_id) { CLog::Log(LOGDEBUG, "CDRMUtils::%s - found crtc: %d", __FUNCTION__, m_crtc->crtc->crtc_id); m_crtc_index = i; break; } drmModeFreeCrtc(m_crtc->crtc); m_crtc->crtc = nullptr; } if(!m_crtc->crtc) { CLog::Log(LOGERROR, "CDRMUtils::%s - could not get crtc: %s", __FUNCTION__, strerror(errno)); return false; } m_crtc->props = drmModeObjectGetProperties(m_fd, m_crtc->crtc->crtc_id, DRM_MODE_OBJECT_CRTC); if (!m_crtc->props) { CLog::Log(LOGERROR, "CDRMUtils::%s - could not get crtc %u properties: %s", __FUNCTION__, m_crtc->crtc->crtc_id, strerror(errno)); return false; } m_crtc->props_info = new drmModePropertyPtr[m_crtc->props->count_props]; for (uint32_t i = 0; i < m_crtc->props->count_props; i++) { m_crtc->props_info[i] = drmModeGetProperty(m_fd, m_crtc->props->props[i]); } return true; }
static void fill_obj_prop_map(int fd, uint32_t id, int type, const char *name, int num_enums, const char **enum_names, uint64_t *enum_ids) { drmModeObjectPropertiesPtr props; int i, j, k; props = drmModeObjectGetProperties(fd, id, type); igt_assert(props); for (i = 0; i < props->count_props; i++) { drmModePropertyPtr prop = drmModeGetProperty(fd, props->props[i]); igt_assert(prop); if (strcmp(prop->name, name) != 0) { drmModeFreeProperty(prop); continue; } for (j = 0; j < prop->count_enums; j++) { struct drm_mode_property_enum *e = &prop->enums[j]; for (k = 0; k < num_enums; k++) { if (strcmp(e->name, enum_names[k]) != 0) continue; enum_ids[k] = e->value; break; } } drmModeFreeProperty(prop); } }
bool CDRMUtils::GetPlanes() { drmModePlaneResPtr plane_resources; uint32_t primary_plane_id = 0; uint32_t overlay_plane_id = 0; uint32_t fourcc = 0; plane_resources = drmModeGetPlaneResources(m_fd); if (!plane_resources) { CLog::Log(LOGERROR, "CDRMUtils::%s - drmModeGetPlaneResources failed: %s", __FUNCTION__, strerror(errno)); return false; } for (uint32_t i = 0; i < plane_resources->count_planes; i++) { uint32_t id = plane_resources->planes[i]; drmModePlanePtr plane = drmModeGetPlane(m_fd, id); if (!plane) { CLog::Log(LOGERROR, "CDRMUtils::%s - drmModeGetPlane(%u) failed: %s", __FUNCTION__, id, strerror(errno)); continue; } if (plane->possible_crtcs & (1 << m_crtc_index)) { drmModeObjectPropertiesPtr props = drmModeObjectGetProperties(m_fd, id, DRM_MODE_OBJECT_PLANE); for (uint32_t j = 0; j < props->count_props; j++) { drmModePropertyPtr p = drmModeGetProperty(m_fd, props->props[j]); if ((strcmp(p->name, "type") == 0) && (props->prop_values[j] == DRM_PLANE_TYPE_PRIMARY) && (primary_plane_id == 0)) { CLog::Log(LOGDEBUG, "CDRMUtils::%s - found primary plane: %u", __FUNCTION__, id); primary_plane_id = id; } else if ((strcmp(p->name, "type") == 0) && (props->prop_values[j] == DRM_PLANE_TYPE_OVERLAY) && (overlay_plane_id == 0)) { CLog::Log(LOGDEBUG, "CDRMUtils::%s - found overlay plane: %u", __FUNCTION__, id); overlay_plane_id = id; } drmModeFreeProperty(p); } drmModeFreeObjectProperties(props); } drmModeFreePlane(plane); } drmModeFreePlaneResources(plane_resources); // primary plane m_primary_plane->plane = drmModeGetPlane(m_fd, primary_plane_id); if (!m_primary_plane->plane) { CLog::Log(LOGERROR, "CDRMUtils::%s - could not get primary plane %u: %s", __FUNCTION__, primary_plane_id, strerror(errno)); return false; } if (!GetProperties(m_fd, primary_plane_id, DRM_MODE_OBJECT_PLANE, m_primary_plane)) { CLog::Log(LOGERROR, "CDRMUtils::%s - could not get primary plane %u properties: %s", __FUNCTION__, primary_plane_id, strerror(errno)); return false; } for (uint32_t i = 0; i < m_primary_plane->plane->count_formats; i++) { /* we want an alpha layer so break if we find one */ if (m_primary_plane->plane->formats[i] == DRM_FORMAT_XRGB8888) { fourcc = DRM_FORMAT_XRGB8888; m_primary_plane->format = fourcc; } else if (m_primary_plane->plane->formats[i] == DRM_FORMAT_ARGB8888) { fourcc = DRM_FORMAT_ARGB8888; m_primary_plane->format = fourcc; break; } } if (fourcc == 0) { CLog::Log(LOGERROR, "CDRMUtils::%s - could not find a suitable primary plane format", __FUNCTION__); return false; } CLog::Log(LOGDEBUG, "CDRMUtils::%s - primary plane format: %c%c%c%c", __FUNCTION__, fourcc, fourcc >> 8, fourcc >> 16, fourcc >> 24); if (overlay_plane_id != 0) { // overlay plane m_overlay_plane->plane = drmModeGetPlane(m_fd, overlay_plane_id); if (!m_overlay_plane->plane) { CLog::Log(LOGERROR, "CDRMUtils::%s - could not get overlay plane %u: %s", __FUNCTION__, overlay_plane_id, strerror(errno)); return false; } if (!GetProperties(m_fd, overlay_plane_id, DRM_MODE_OBJECT_PLANE, m_overlay_plane)) { CLog::Log(LOGERROR, "CDRMUtils::%s - could not get overlay plane %u properties: %s", __FUNCTION__, overlay_plane_id, strerror(errno)); return false; } fourcc = 0; for (uint32_t i = 0; i < m_overlay_plane->plane->count_formats; i++) { /* we want an alpha layer so break if we find one */ if (m_overlay_plane->plane->formats[i] == DRM_FORMAT_XRGB8888) { fourcc = DRM_FORMAT_XRGB8888; m_overlay_plane->format = fourcc; } else if(m_overlay_plane->plane->formats[i] == DRM_FORMAT_ARGB8888) { fourcc = DRM_FORMAT_ARGB8888; m_overlay_plane->format = fourcc; break; } } if (fourcc == 0) { CLog::Log(LOGERROR, "CDRMUtils::%s - could not find a suitable overlay plane format", __FUNCTION__); return false; } CLog::Log(LOGDEBUG, "CDRMUtils::%s - overlay plane format: %c%c%c%c", __FUNCTION__, fourcc, fourcc >> 8, fourcc >> 16, fourcc >> 24); }
static DFBResult drmkmsPlaneInitLayer( CoreLayer *layer, void *driver_data, void *layer_data, DFBDisplayLayerDescription *description, DFBDisplayLayerConfig *config, DFBColorAdjustment *adjustment ) { DRMKMSData *drmkms = driver_data; DRMKMSDataShared *shared = drmkms->shared; DRMKMSLayerData *data = layer_data; drmModeObjectPropertiesPtr props; D_DEBUG_AT( DRMKMS_Layer, "%s()\n", __FUNCTION__ ); data->index = shared->layerplane_index_count++; data->plane_index = shared->plane_index_count++; data->level = data->index; D_DEBUG_AT( DRMKMS_Layer, " -> getting plane with index %d\n", data->plane_index ); data->plane = drmModeGetPlane(drmkms->fd, drmkms->plane_resources->planes[data->plane_index]); D_DEBUG_AT( DRMKMS_Layer, " -> plane_id is %d\n", data->plane->plane_id ); description->type = DLTF_GRAPHICS; description->caps = DLCAPS_SURFACE | DLCAPS_SCREEN_POSITION | DLCAPS_ALPHACHANNEL; description->surface_caps = DSCAPS_NONE; description->surface_accessor = CSAID_LAYER0; snprintf( description->name, DFB_DISPLAY_LAYER_DESC_NAME_LENGTH, "DRMKMS Plane Layer %d", data->plane_index ); config->flags = DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_PIXELFORMAT | DLCONF_BUFFERMODE; config->width = dfb_config->mode.width ?: shared->mode[0].hdisplay; config->height = dfb_config->mode.height ?: shared->mode[0].vdisplay; config->pixelformat = dfb_config->mode.format ?: DSPF_ARGB; config->buffermode = DLBM_FRONTONLY; props = drmModeObjectGetProperties( drmkms->fd, data->plane->plane_id, DRM_MODE_OBJECT_PLANE ); if (props) { int i; drmModePropertyPtr prop; D_INFO( "DirectFB/DRMKMS: supported properties for layer id %d\n", data->plane->plane_id ); for (i = 0; i < props->count_props; i++) { prop = drmModeGetProperty( drmkms->fd, props->props[i] ); if (!strcmp(prop->name, "colorkey")) { description->caps |= DLCAPS_SRC_COLORKEY; data->colorkey_propid = prop->prop_id; D_INFO( " colorkey\n" ); } else if (!strcmp(prop->name, "zpos")) { description->caps |= DLCAPS_LEVELS; data->zpos_propid = prop->prop_id; D_INFO( " zpos\n" ); drmModeObjectSetProperty( drmkms->fd, data->plane->plane_id, DRM_MODE_OBJECT_PLANE, data->zpos_propid, data->level ); } else if (!strcmp(prop->name, "alpha")) { description->caps |= DLCAPS_OPACITY; data->alpha_propid = prop->prop_id; D_INFO( " alpha\n" ); } drmModeFreeProperty( prop ); } drmModeFreeObjectProperties( props ); } shared->layer_data[data->index] = data; return DFB_OK; }
struct sp_dev* create_sp_dev(void) { struct sp_dev *dev; int ret, fd, i, j; drmModeRes *r = NULL; drmModePlaneRes *pr = NULL; fd = open("/dev/dri/card0", O_RDWR); if (fd < 0) { printf("failed to open card0\n"); return NULL; } dev = calloc(1, sizeof(*dev)); if (!dev) { printf("failed to allocate dev\n"); return NULL; } dev->fd = fd; #if 0 ret = drmSetClientCap(dev->fd, DRM_CLIENT_CAP_ATOMIC, 1); if (ret) { printf("failed to set client cap atomic\n"); goto err; } ret = drmSetClientCap(dev->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1); if (ret) { printf("failed to set client cap\n"); goto err; } #endif r = drmModeGetResources(dev->fd); if (!r) { printf("failed to get r\n"); goto err; } dev->num_connectors = r->count_connectors; dev->connectors = calloc(dev->num_connectors, sizeof(*dev->connectors)); if (!dev->connectors) { printf("failed to allocate connectors\n"); goto err; } for (i = 0; i < dev->num_connectors; i++) { dev->connectors[i] = drmModeGetConnector(dev->fd, r->connectors[i]); if (!dev->connectors[i]) { printf("failed to get connector %d\n", i); goto err; } } dev->num_encoders = r->count_encoders; dev->encoders = calloc(dev->num_encoders, sizeof(*dev->encoders)); if (!dev->encoders) { printf("failed to allocate encoders\n"); goto err; } for (i = 0; i < dev->num_encoders; i++) { dev->encoders[i] = drmModeGetEncoder(dev->fd, r->encoders[i]); if (!dev->encoders[i]) { printf("failed to get encoder %d\n", i); goto err; } } dev->num_crtcs = r->count_crtcs; dev->crtcs = calloc(dev->num_crtcs, sizeof(struct sp_crtc)); if (!dev->crtcs) { printf("failed to allocate crtcs\n"); goto err; } for (i = 0; i < dev->num_crtcs; i++) { dev->crtcs[i].crtc = drmModeGetCrtc(dev->fd, r->crtcs[i]); if (!dev->crtcs[i].crtc) { printf("failed to get crtc %d\n", i); goto err; } dev->crtcs[i].scanout = NULL; dev->crtcs[i].pipe = i; dev->crtcs[i].num_planes = 0; } pr = drmModeGetPlaneResources(dev->fd); if (!pr) { printf("failed to get plane resources\n"); goto err; } dev->num_planes = pr->count_planes; dev->planes = calloc(dev->num_planes, sizeof(struct sp_plane)); for (i = 0; i < dev->num_planes; i++) { drmModeObjectPropertiesPtr props; struct sp_plane *plane = &dev->planes[i]; plane->dev = dev; plane->plane = drmModeGetPlane(dev->fd, pr->planes[i]); if (!plane->plane) { printf("failed to get plane %d\n", i); goto err; } plane->bo = NULL; plane->in_use = 0; ret = get_supported_format(plane, &plane->format); if (ret) { printf("failed to get supported format: %d\n", ret); goto err; } for (j = 0; j < dev->num_crtcs; j++) { if (plane->plane->possible_crtcs & (1 << j)) dev->crtcs[j].num_planes++; } props = drmModeObjectGetProperties(dev->fd, pr->planes[i], DRM_MODE_OBJECT_PLANE); if (!props) { printf("failed to get plane properties\n"); goto err; } #if 0//def USE_ATOMIC_API plane->crtc_pid = get_prop_id(dev, props, "CRTC_ID"); if (!plane->crtc_pid) { drmModeFreeObjectProperties(props); goto err; } plane->fb_pid = get_prop_id(dev, props, "FB_ID"); if (!plane->fb_pid) { drmModeFreeObjectProperties(props); goto err; } plane->crtc_x_pid = get_prop_id(dev, props, "CRTC_X"); if (!plane->crtc_x_pid) { drmModeFreeObjectProperties(props); goto err; } plane->crtc_y_pid = get_prop_id(dev, props, "CRTC_Y"); if (!plane->crtc_y_pid) { drmModeFreeObjectProperties(props); goto err; } plane->crtc_w_pid = get_prop_id(dev, props, "CRTC_W"); if (!plane->crtc_w_pid) { drmModeFreeObjectProperties(props); goto err; } plane->crtc_h_pid = get_prop_id(dev, props, "CRTC_H"); if (!plane->crtc_h_pid) { drmModeFreeObjectProperties(props); goto err; } plane->src_x_pid = get_prop_id(dev, props, "SRC_X"); if (!plane->src_x_pid) { drmModeFreeObjectProperties(props); goto err; } plane->src_y_pid = get_prop_id(dev, props, "SRC_Y"); if (!plane->src_y_pid) { drmModeFreeObjectProperties(props); goto err; } plane->src_w_pid = get_prop_id(dev, props, "SRC_W"); if (!plane->src_w_pid) { drmModeFreeObjectProperties(props); goto err; } plane->src_h_pid = get_prop_id(dev, props, "SRC_H"); if (!plane->src_h_pid) { drmModeFreeObjectProperties(props); goto err; } #endif drmModeFreeObjectProperties(props); } if (pr) drmModeFreePlaneResources(pr); if (r) drmModeFreeResources(r); return dev; err: if (pr) drmModeFreePlaneResources(pr); if (r) drmModeFreeResources(r); destroy_sp_dev(dev); return NULL; }