From 541be05bf202778ece0cc08799586a873880f95a Mon Sep 17 00:00:00 2001 From: Chris Michael Date: Thu, 22 Sep 2016 10:34:03 -0400 Subject: [PATCH] ecore-drm2: Add code to check if Atomic Modesettting is usable This code will detect the drm driver name and check that the kernel itself is new enough to use Atomic Modesetting. This is needed as some drivers (i915) do not handle Atomic Modesetting propertly without a new enough kernel. Signed-off-by: Chris Michael --- src/lib/ecore_drm2/ecore_drm2_device.c | 59 ++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/src/lib/ecore_drm2/ecore_drm2_device.c b/src/lib/ecore_drm2/ecore_drm2_device.c index 8f2e43cfde..1ee7871f5a 100644 --- a/src/lib/ecore_drm2/ecore_drm2_device.c +++ b/src/lib/ecore_drm2/ecore_drm2_device.c @@ -8,6 +8,12 @@ # define DRM_CAP_CURSOR_HEIGHT 0x9 #endif +#ifdef HAVE_ATOMIC_DRM +# include +#endif + +Eina_Bool _ecore_drm2_use_atomic = EINA_FALSE; + static Eina_Bool _cb_session_active(void *data, int type EINA_UNUSED, void *event) { @@ -143,6 +149,50 @@ out: return ret; } +#ifdef HAVE_ATOMIC_DRM +static Eina_Bool +_ecore_drm2_atomic_usable(int fd) +{ + drmVersion *drmver; + Eina_Bool ret = EINA_FALSE; + + drmver = drmGetVersion(fd); + if (!drmver) return EINA_FALSE; + + /* detect driver */ + if ((!strcmp(drmver->name, "i915")) && + (!strcmp(drmver->desc, "Intel Graphics"))) + { + FILE *fp; + + /* detect kernel version + * NB: In order for atomic modesetting to work properly for Intel, + * we need to be using a kernel >= 4.8.0 */ + + fp = fopen("/proc/sys/kernel/osrelease", "rb"); + if (fp) + { + char buff[512]; + int maj = 0, min = 0; + + if (fgets(buff, sizeof(buff), fp)) + { + if (sscanf(buff, "%i.%i.%*s", &maj, &min) == 2) + { + if ((maj >= 4) && (min >= 8)) + ret = EINA_TRUE; + } + } + fclose(fp); + } + } + + drmFreeVersion(drmver); + + return ret; +} +#endif + EAPI Ecore_Drm2_Device * ecore_drm2_device_find(const char *seat, unsigned int tty) { @@ -191,6 +241,11 @@ ecore_drm2_device_open(Ecore_Drm2_Device *device) DBG("Device Path: %s", device->path); DBG("Device Fd: %d", device->fd); +#ifdef HAVE_ATOMIC_DRM + /* check that this system can do atomic */ + _ecore_drm2_use_atomic = _ecore_drm2_atomic_usable(device->fd); +#endif + device->active_hdlr = ecore_event_handler_add(ELPUT_EVENT_SESSION_ACTIVE, _cb_session_active, device); @@ -199,10 +254,6 @@ ecore_drm2_device_open(Ecore_Drm2_Device *device) ecore_event_handler_add(ELPUT_EVENT_DEVICE_CHANGE, _cb_device_change, device); - /* NB: Not going to enable planes if we don't support atomic */ - /* if (drmSetClientCap(device->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1) < 0) */ - /* ERR("Could not set Universal Plane support: %m"); */ - return device->fd; input_err: