ecore-drm: Add API function to test if an output can go on a given crtc
authorChris Michael <cp.michael@samsung.com>
Mon, 11 May 2015 16:37:24 +0000 (12:37 -0400)
committerChris Michael <cp.michael@samsung.com>
Tue, 12 May 2015 12:57:47 +0000 (08:57 -0400)
Summary: This adds a new API function to test if a given
Ecore_Drm_Output can be used on a given crtc. This is needed for DRM
RandR support

@feature

Signed-off-by: Chris Michael <cp.michael@samsung.com>
src/lib/ecore_drm/Ecore_Drm.h
src/lib/ecore_drm/ecore_drm_output.c

index 481da42..f468b56 100644 (file)
@@ -906,6 +906,22 @@ EAPI void ecore_drm_output_crtc_size_get(Ecore_Drm_Output *output, int *width, i
  */
 EAPI Ecore_Drm_Output *ecore_drm_device_output_name_find(Ecore_Drm_Device *dev, const char *name);
 
+/**
+ * Get if an Ecore_Drm_Output can be used on a given crtc
+ *
+ * This function will loop the possible crtcs of an encoder to determine if
+ * a given output can be assigned to a given crtc
+ *
+ * @param output The Ecore_Drm_Output to test if can be used on crtc
+ * @param crtc The crtc to test an Ecore_Drm_Output against
+ *
+ * @return EINA_TRUE if the output can be assigned to given crtc, EINA_FALSE otherwise
+ *
+ * @ingroup Ecore_Drm_Output_Group
+ * @since 1.15
+ */
+EAPI Eina_Bool ecore_drm_output_possible_crtc_get(Ecore_Drm_Output *output, unsigned int crtc);
+
 # ifdef __cplusplus
 }
 # endif
index 2596538..a76a8ec 100644 (file)
@@ -1291,3 +1291,67 @@ ecore_drm_output_crtc_size_get(Ecore_Drm_Output *output, int *width, int *height
    if (width) *width = output->crtc->width;
    if (height) *height = output->crtc->height;
 }
+
+EAPI Eina_Bool
+ecore_drm_output_possible_crtc_get(Ecore_Drm_Output *output, unsigned int crtc)
+{
+   Ecore_Drm_Device *dev;
+   drmModeRes *res;
+   drmModeConnector *conn;
+   drmModeEncoder *enc;
+   int i, j;
+   unsigned int p;
+   Eina_Bool ret = EINA_FALSE;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(output, EINA_FALSE);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(output->dev, EINA_FALSE);
+
+   dev = output->dev;
+   EINA_SAFETY_ON_TRUE_RETURN_VAL(dev->drm.fd < 0, EINA_FALSE);
+
+   /* get the resources */
+   if (!(res = drmModeGetResources(dev->drm.fd)))
+     {
+        ERR("Could not get resources for drm card: %m");
+        return EINA_FALSE;
+     }
+
+   for (i = 0; i < res->count_connectors; i++)
+     {
+        /* get the connector */
+        if (!(conn = drmModeGetConnector(dev->drm.fd, res->connectors[i])))
+          continue;
+
+        for (j = 0; j < conn->count_encoders; j++)
+          {
+             /* get the encoder on this connector */
+             if (!(enc = drmModeGetEncoder(dev->drm.fd, conn->encoders[j])))
+               {
+                  WRN("Failed to get encoder: %m");
+                  continue;
+               }
+
+             /* get the encoder for given crtc */
+             if (enc->crtc_id != crtc) goto next;
+
+             p = enc->possible_crtcs;
+
+             /* Does the CRTC match the list of possible CRTCs from the encoder? */
+             if (p & (1 << output->crtc_id))
+               ret = EINA_TRUE;
+
+next:
+             drmModeFreeEncoder(enc);
+             if (ret) break;
+          }
+
+        /* free the connector */
+        drmModeFreeConnector(conn);
+        if (ret) break;
+     }
+
+   /* free resources */
+   drmModeFreeResources(res);
+
+   return ret;
+}