Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render to a second screen without being the DRM master?

I have an embedded process that renders to a screen directly using DRM & KMS APIs. It's running on a minimal Yocto distribution (no desktop or Wayland). I would like to render to a second screen that is attached to the same GPU from another process. The first process opens '/dev/dri/card0' and becomes the de-facto DRM master and it can do drmModeSetCrtc & drmModePageFlip on the primary screen to display the framebuffer. However, if I call drmDropMaster it can't do the page flip anymore. Therefore the second process cannot become the DRM master and render to the other display using the same technique.

There's plenty of examples on how to render to one screen using the Direct Rendering Manager (DRM) and Kernel Mode Setting (KMS), but I found none that can render to a second screen from another process.

I would like to not have a master if possible once the display mode is set, but the page flip is also a restricted API. If this cannot be achieved, maybe an example on how to grant the second process permission using drmAuthMagic?

like image 638
Fritz Avatar asked Dec 10 '18 20:12

Fritz


1 Answers

It isn't possible to do a page flip without being the DRM master. The IOCTL is protected in drm_ioctl.c:

DRM_IOCTL_DEF(DRM_IOCTL_MODE_PAGE_FLIP, drm_mode_page_flip_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED)
DRM_IOCTL_DEF(DRM_IOCTL_SET_MASTER, drm_setmaster_ioctl, DRM_ROOT_ONLY),
DRM_IOCTL_DEF(DRM_IOCTL_DROP_MASTER, drm_dropmaster_ioctl, DRM_ROOT_ONLY),

So I decided to put the flip into a critical section where the application calls drmSetMaster, schedules the flip, and calls drmDropMaster. It's heavy handed and both processes need to be root, but it works well enough for an embedded platform. The process has to authorize itself however using drmGetMagic and drmAuthMagic in order for it to be able to render while it isn't the master and to grab mastership again. I do this when it first becomes master and does the mode set.

like image 143
Fritz Avatar answered Oct 16 '22 15:10

Fritz