Esempio n. 1
0
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;
}
Esempio n. 2
0
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 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;
}
Esempio n. 4
0
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);
}
Esempio n. 5
0
bool CDRMUtils::OpenDrm()
{
  std::vector<const char*>modules =
  {
    "i915",
    "amdgpu",
    "radeon",
    "nouveau",
    "vmwgfx",
    "msm",
    "imx-drm",
    "rockchip",
    "vc4",
    "virtio_gpu",
    "sun4i-drm",
  };

  for(int i = 0; i < 10; ++i)
  {
    std::string device = "/dev/dri/card";
    device.append(std::to_string(i));

    for (auto module : modules)
    {
      m_fd = drmOpen(module, device.c_str());
      if (m_fd >= 0)
      {
        if(!GetResources())
        {
          continue;
        }

        if(!GetConnector())
        {
          continue;
        }

        drmModeFreeResources(m_drm_resources);
        m_drm_resources = nullptr;

        drmModeFreeConnector(m_connector->connector);
        m_connector->connector = nullptr;

        drmModeFreeObjectProperties(m_connector->props);
        m_connector->props = nullptr;

        drmModeFreeProperty(*m_connector->props_info);
        *m_connector->props_info = nullptr;

        CLog::Log(LOGDEBUG, "CDRMUtils::%s - opened device: %s using module: %s", __FUNCTION__, device.c_str(), module);
        return true;
      }

      drmClose(m_fd);
      m_fd = -1;
    }
  }

  return false;
}
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);
}
Esempio n. 7
0
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);
}
Esempio n. 8
0
void CDRMUtils::DestroyDrm()
{
  RestoreOriginalMode();

  drmDropMaster(m_fd);
  close(m_fd);

  m_fd = -1;

  drmModeFreeResources(m_drm_resources);
  m_drm_resources = nullptr;

  drmModeFreeConnector(m_connector->connector);
  drmModeFreeObjectProperties(m_connector->props);
  delete [] m_connector->props_info;
  delete m_connector;
  m_connector = nullptr;

  drmModeFreeEncoder(m_encoder->encoder);
  delete m_encoder;
  m_encoder = nullptr;

  drmModeFreeCrtc(m_crtc->crtc);
  drmModeFreeObjectProperties(m_crtc->props);
  delete [] m_crtc->props_info;
  delete m_crtc;
  m_crtc = nullptr;

  drmModeFreePlane(m_primary_plane->plane);
  drmModeFreeObjectProperties(m_primary_plane->props);
  delete [] m_primary_plane->props_info;
  delete m_primary_plane;
  m_primary_plane = nullptr;

  drmModeFreePlane(m_overlay_plane->plane);
  drmModeFreeObjectProperties(m_overlay_plane->props);
  delete [] m_overlay_plane->props_info;
  delete m_overlay_plane;
  m_overlay_plane = nullptr;
}
Esempio n. 9
0
/* 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;
}
Esempio n. 10
0
static void FreeProperties(struct drm_object *object)
{
  if (object->props_info)
  {
    for (uint32_t i = 0; i < object->props->count_props; i++)
      drmModeFreeProperty(object->props_info[i]);

    delete [] object->props_info;
    object->props_info = nullptr;
  }

  drmModeFreeObjectProperties(object->props);
  object->props = nullptr;
  object->type = 0;
  object->id = 0;
}
Esempio n. 11
0
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);
}
Esempio n. 12
0
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);
}
Esempio n. 13
0
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);
}
Esempio n. 14
0
void drm_object_free_properties(struct drm_object *object)
{
    if (object->props) {
        for (int i = 0; i < object->props->count_props; i++) {
            if (object->props_info[i]) {
                drmModeFreeProperty(object->props_info[i]);
                object->props_info[i] = NULL;
            }
        }

        talloc_free(object->props_info);
        object->props_info = NULL;

        drmModeFreeObjectProperties(object->props);
        object->props = NULL;
    }
}
Esempio n. 15
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);
}
Esempio n. 16
0
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);
}
Esempio n. 17
0
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;
}
Esempio n. 18
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);
}
Esempio n. 19
0
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;
}
Esempio n. 20
0
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);
  }
Esempio n. 21
0
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;
}
Esempio n. 22
0
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;
}