evas-drm: Fix evas-gl_drm picking incorrect resolution/mode for outputs 40/38840/2 accepted/tizen/common/20150429.145322 accepted/tizen/mobile/20150430.012211 accepted/tizen/tv/20150430.012131 accepted/tizen/wearable/20150430.012147 submit/tizen/20150429.110658
authorMun, Gwan-gyeong <kk.moon@samsung.com>
Wed, 29 Apr 2015 08:06:03 +0000 (17:06 +0900)
committerGwanglim Lee <gl77.lee@samsung.com>
Wed, 29 Apr 2015 10:27:58 +0000 (03:27 -0700)
Change-Id: Ibf5fcb065141404cf6ad3287460817b8c96bbd1c

src/modules/evas/engines/gl_drm/evas_drm.c

index 32b76aa..b1c4446 100644 (file)
@@ -11,53 +11,6 @@ _evas_drm_fb_destroy_callback(struct gbm_bo *bo, void *data)
      drmModeRmFB(gbm_device_get_fd(gbm), buffer->fb);
 }
 
-static int
-_evas_drm_crtc_find(int fd, drmModeRes *res, drmModeConnector *conn)
-{
-   int crtc = -1;
-   drmModeEncoder *enc = NULL;
-
-   /* if this connector already has an encoder, get it */
-   if (conn->encoder_id) enc = drmModeGetEncoder(fd, conn->encoder_id);
-
-   /* if this encoder already has a crtc, lets try to use that */
-   if ((enc) && (enc->crtc_id)) crtc = enc->crtc_id;
-
-   if (crtc < 0)
-     {
-        int i = 0, c = 0;
-
-        /* if this connector has no encoder, we need to find one */
-        for (; i < conn->count_encoders; ++i)
-          {
-             /* try to get this encoder */
-             if (!(enc = drmModeGetEncoder(fd, conn->encoders[i])))
-               continue;
-
-             /* loop global crtcs */
-             for (; c < res->count_crtcs; ++c)
-               {
-                  /* does this crtc work with this encoder ? */
-                  if (!(enc->possible_crtcs & (1 << c))) continue;
-
-                  /* FIXME: We could be more proactive here and check that
-                   * nobody else is using this crtc */
-
-                  /* if it works, let's use it */
-                  crtc = res->crtcs[c];
-                  break;
-               }
-
-             if (crtc >= 0) break;
-          }
-     }
-
-   /* free the encoder */
-   if (enc) drmModeFreeEncoder(enc);
-
-   return crtc;
-}
-
 static unsigned int
 _evas_drm_crtc_buffer_get(int fd, int crtc_id)
 {
@@ -193,6 +146,8 @@ evas_drm_outbuf_setup(Outbuf *ob)
    drmModeRes *res;
    drmModeConnector *conn;
    drmModePlaneResPtr pres;
+   drmModeEncoder *enc;
+   drmModeModeInfo crtc_mode;
    int i = 0;
 
    /* check for valid Output buffer */
@@ -208,7 +163,7 @@ evas_drm_outbuf_setup(Outbuf *ob)
    /* loop the connectors */
    for (; i < res->count_connectors; ++i)
      {
-        int crtc = -1;
+        int crtc_id = -1;
         int m = 0;
 
         /* try to get this connector */
@@ -234,42 +189,48 @@ evas_drm_outbuf_setup(Outbuf *ob)
              continue;
           }
 
-        /* try to find a crtc for this connector */
-        if ((crtc = _evas_drm_crtc_find(ob->priv.fd, res, conn)) < 0)
-          {
-             /* free connector resources */
-             drmModeFreeConnector(conn);
-             continue;
-          }
-
         /* record the connector id */
         ob->priv.conn = conn->connector_id;
 
+        if ((enc = drmModeGetEncoder(ob->priv.fd, conn->encoder_id)))
+          {
+             drmModeCrtc *crtc;
+
+             if ((crtc = drmModeGetCrtc(ob->priv.fd, enc->crtc_id)))
+               {
+                  crtc_id = enc->crtc_id;
+                  if (crtc->mode_valid) crtc_mode = crtc->mode;
+                  drmModeFreeCrtc(crtc);
+               }
+
+             drmModeFreeEncoder(enc);
+          }
+
         /* record the crtc id */
-        ob->priv.crtc = crtc;
+        ob->priv.crtc = crtc_id;
 
         /* get the current framebuffer */
-        ob->priv.fb = _evas_drm_crtc_buffer_get(ob->priv.fd, crtc);
+        ob->priv.fb = _evas_drm_crtc_buffer_get(ob->priv.fd, crtc_id);
 
-        /* record the current mode */
-        memcpy(&ob->priv.mode, &conn->modes[0], sizeof(ob->priv.mode));
+        memset(&ob->priv.mode, 0, sizeof(ob->priv.mode));
 
         for (m = 0; m < conn->count_modes; m++)
           {
              DBG("Output Available Mode: %d: %d %d %d", ob->priv.conn,
                  conn->modes[m].hdisplay, conn->modes[m].vdisplay,
                  conn->modes[m].vrefresh);
-
-             /* try to find a mode which matches the requested size */
-             if ((conn->modes[m].hdisplay == ob->w) &&
-                 (conn->modes[m].vdisplay == ob->h) &&
-                 (conn->modes[m].vrefresh == 60))
+             if (!memcmp(&crtc_mode, &conn->modes[m], sizeof(crtc_mode)))
                {
-                  memcpy(&ob->priv.mode, &conn->modes[m],
-                         sizeof(ob->priv.mode));
+                  /* record the current mode */
+                  memcpy(&ob->priv.mode, &conn->modes[m], sizeof(ob->priv.mode));
+                  break;
                }
+
           }
 
+        if ((!ob->priv.mode.hdisplay) && (crtc_mode.clock != 0))
+          memcpy(&ob->priv.mode, &crtc_mode, sizeof(ob->priv.mode));
+
         DBG("Output Current Mode: %d: %d %d", ob->priv.conn,
             ob->priv.mode.hdisplay, ob->priv.mode.vdisplay);