derekf pushed a commit to branch master.

http://git.enlightenment.org/core/enlightenment.git/commit/?id=0fd23928f05b901957ea373d52c7b700fdd1dd8e

commit 0fd23928f05b901957ea373d52c7b700fdd1dd8e
Author: Derek Foreman <der...@osg.samsung.com>
Date:   Tue Aug 8 17:59:39 2017 -0500

    Add a compatibility layer to protect against ecore_drm2 api change
    
    In case we roll an E release before the next EFL one, we need these
    API changes to be hidden.
    
    Later we can remove this...
---
 src/bin/Makefile.mk             |   2 +-
 src/bin/e_alert_main.c          |  14 +++--
 src/bin/e_drm2.x                | 117 ++++++++++++++++++++++++++++++++++++++++
 src/modules/wl_drm/e_mod_main.c |  20 ++++---
 4 files changed, 139 insertions(+), 14 deletions(-)

diff --git a/src/bin/Makefile.mk b/src/bin/Makefile.mk
index 60d0f744e..323f2cdf4 100644
--- a/src/bin/Makefile.mk
+++ b/src/bin/Makefile.mk
@@ -539,7 +539,7 @@ endif
 src_bin_enlightenment_alert_SOURCES = \
 src/bin/e_alert_main.c
 
-src_bin_enlightenment_alert_LDADD = @E_ALERT_LIBS@
+src_bin_enlightenment_alert_LDADD = @E_ALERT_LIBS@ @dlopen_libs@
 src_bin_enlightenment_alert_CPPFLAGS = @E_ALERT_CFLAGS@
 
 src_bin_enlightenment_filemanager_SOURCES = \
diff --git a/src/bin/e_alert_main.c b/src/bin/e_alert_main.c
index b8c179672..ed41f4780 100644
--- a/src/bin/e_alert_main.c
+++ b/src/bin/e_alert_main.c
@@ -32,8 +32,11 @@
 # include <Evas_Engine_Buffer.h>
 #endif
 
+#include "e_drm2.x"
+
 #ifdef HAVE_WL_DRM
 # ifdef HAVE_DRM2
+
 /* DRM_FORMAT_XRGB8888 and fourcc_code borrowed from <drm_fourcc.h>
  *
  * Copyright 2011 Intel Corporation
@@ -389,13 +392,13 @@ _e_alert_drm_connect(void)
         return 0;
      }
 
-   if (!ecore_drm2_init())
+   if (!e_drm2_compat_init() || !ecore_drm2_init())
      {
         printf("\tCannot init ecore_drm\n");
         return 0;
      }
 
-   dev = ecore_drm2_device_open("seat0", 0);
+   dev = e_drm2_device_open("seat0", 0);
    if (!dev)
      {
         printf("\tCannot find drm device\n");
@@ -410,7 +413,7 @@ _e_alert_drm_connect(void)
      }
 
    output = ecore_drm2_output_find(dev, 0, 0);
-   if (output) ecore_drm2_output_info_get(output, NULL, NULL, &sw, &sh, NULL);
+   if (output) e_drm2_output_info_get(output, NULL, NULL, &sw, &sh, NULL);
    fprintf(stderr, "\tOutput Size: %d %d\n", sw, sh);
 
    ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
@@ -429,7 +432,7 @@ _e_alert_drm_create(void)
 
    fh = 13;
 
-   buffer = ecore_drm2_fb_create(dev, sw, sh, 24, 32, DRM_FORMAT_XRGB8888);
+   buffer = e_drm2_fb_create(dev, sw, sh, 24, 32, DRM_FORMAT_XRGB8888);
 
    method = evas_render_method_lookup("buffer");
    if (method <= 0)
@@ -496,11 +499,12 @@ _e_alert_drm_shutdown(void)
    if (dev)
      {
         ecore_drm2_outputs_destroy(dev);
-        ecore_drm2_device_close(dev);
+        e_drm2_device_close(dev);
      }
 
    ecore_drm2_shutdown();
    evas_shutdown();
+   e_drm2_compat_shutdown();
 }
 
 #  else
diff --git a/src/bin/e_drm2.x b/src/bin/e_drm2.x
new file mode 100644
index 000000000..1f852a0da
--- /dev/null
+++ b/src/bin/e_drm2.x
@@ -0,0 +1,117 @@
+# ifdef HAVE_DRM2
+# include <dlfcn.h>
+
+static int crude_hack_fd;
+static void *e_drm2_lib;
+
+void (*sym_ecore_drm2_output_crtc_size_get_120)(Ecore_Drm2_Output *output, int 
*w, int *h);
+void (*sym_ecore_drm2_output_geometry_get_120)(Ecore_Drm2_Output *output, int 
*x, int *y, int *w, int *h);
+void (*sym_ecore_drm2_output_resolution_get_120)(Ecore_Drm2_Output *output, 
int *w, int *h, unsigned int *refresh);
+Ecore_Drm2_Device *(*sym_ecore_drm2_device_find_120)(const char *seat, 
unsigned int tty);
+int (*sym_ecore_drm2_device_open_120)(Ecore_Drm2_Device *device);
+Ecore_Drm2_Device *(*sym_ecore_drm2_device_open_121)(const char *seat, 
unsigned int tty);
+void (*sym_ecore_drm2_device_free_120)(Ecore_Drm2_Device *device);
+void (*sym_ecore_drm2_output_info_get_121)(Ecore_Drm2_Output *output, int *x, 
int *y, int *w, int *h, unsigned int *refresh);
+Ecore_Drm2_Fb *(*sym_ecore_drm2_fb_create_120)(int fd, int width, int height, 
int depth, int bpp, unsigned int format);
+Ecore_Drm2_Fb *(*sym_ecore_drm2_fb_create_121)(Ecore_Drm2_Device *dev, int 
width, int height, int depth, int bpp, unsigned int format);
+
+#define E_DRM2_EFL_VERSION_MINIMUM(MAJ, MIN, MIC) \
+  ((eina_version->major > MAJ) || (eina_version->minor > MIN) ||\
+   ((eina_version->minor == MIN) && (eina_version->micro >= MIC)))
+
+static Eina_Bool
+e_drm2_compat_init(void)
+{
+#define EDRM2SYM(sym, ver) \
+   sym_##sym##_##ver = dlsym(e_drm2_lib, #sym); \
+   if (!sym_##sym##_##ver) \
+     { \
+        dlclose(e_drm2_lib); \
+        return EINA_FALSE; \
+     }
+
+   e_drm2_lib = dlopen("libecore_drm2.so", RTLD_NOW | RTLD_LOCAL);
+   if (E_DRM2_EFL_VERSION_MINIMUM(1, 20, 99))
+     {
+        EDRM2SYM(ecore_drm2_device_open, 121);
+        EDRM2SYM(ecore_drm2_output_info_get, 121);
+        EDRM2SYM(ecore_drm2_fb_create, 121);
+        return EINA_TRUE;
+     }
+
+   EDRM2SYM(ecore_drm2_output_crtc_size_get, 120);
+   EDRM2SYM(ecore_drm2_output_geometry_get, 120);
+   EDRM2SYM(ecore_drm2_output_resolution_get, 120);
+   EDRM2SYM(ecore_drm2_device_find, 120);
+   EDRM2SYM(ecore_drm2_device_open, 120);
+   EDRM2SYM(ecore_drm2_device_free, 120);
+   EDRM2SYM(ecore_drm2_fb_create, 120);
+   return EINA_TRUE;
+
+#undef EDRM2SYM
+}
+
+static void
+e_drm2_compat_shutdown(void)
+{
+   dlclose(e_drm2_lib);
+}
+
+static inline Ecore_Drm2_Device *
+e_drm2_device_open(const char *seat, int vt)
+{
+   Ecore_Drm2_Device *out;
+
+   if (E_DRM2_EFL_VERSION_MINIMUM(1, 20, 99))
+     {
+        return sym_ecore_drm2_device_open_121(seat, vt);
+     }
+
+   out = sym_ecore_drm2_device_find_120(seat, vt);
+   if (!out) return NULL;
+
+   crude_hack_fd = sym_ecore_drm2_device_open_120(out);
+   if (crude_hack_fd < 0)
+     {
+        ecore_drm2_device_close(out);
+        return NULL;
+     }
+   return out;
+}
+
+static inline void
+e_drm2_device_close(Ecore_Drm2_Device *device)
+{
+   if (E_DRM2_EFL_VERSION_MINIMUM(1, 20, 99))
+     {
+        ecore_drm2_device_close(device);
+        return;
+     }
+   ecore_drm2_device_close(device);
+   sym_ecore_drm2_device_free_120(device);
+}
+
+static inline void
+e_drm2_output_info_get(Ecore_Drm2_Output *op, int *x, int *y, int *w, int *h, 
unsigned int *refresh)
+{
+   if (E_DRM2_EFL_VERSION_MINIMUM(1, 20, 99))
+     {
+        sym_ecore_drm2_output_info_get_121(op, x, y, w, h, refresh);
+        return;
+     }
+   sym_ecore_drm2_output_geometry_get_120(op, x, y, w, h);
+   sym_ecore_drm2_output_resolution_get_120(op, NULL, NULL, refresh);
+}
+
+static inline Ecore_Drm2_Fb *
+e_drm2_fb_create(Ecore_Drm2_Device *device, int width, int height, int depth, 
int bpp, unsigned int format)
+{
+   if (E_DRM2_EFL_VERSION_MINIMUM(1, 20, 99))
+     {
+        return sym_ecore_drm2_fb_create_121(device, width, height, depth, bpp, 
format);
+     }
+   return sym_ecore_drm2_fb_create_120(crude_hack_fd, width, height, depth, 
bpp, format);
+}
+
+#undef E_DRM2_EFL_VERSION_MINIMUM
+#endif
diff --git a/src/modules/wl_drm/e_mod_main.c b/src/modules/wl_drm/e_mod_main.c
index 6843e92c5..e4ef7f91d 100644
--- a/src/modules/wl_drm/e_mod_main.c
+++ b/src/modules/wl_drm/e_mod_main.c
@@ -4,6 +4,8 @@
 
 #include <Ecore_Drm2.h>
 #include <Elput.h>
+#include "e_drm2.x"
+
 static Ecore_Event_Handler *seat_handler;
 
 E_API E_Module_Api e_modapi = { E_MODULE_API_VERSION, "Wl_Drm" };
@@ -391,12 +393,12 @@ _drm2_randr_create(void)
                {
                   unsigned int refresh;
 
-                  ecore_drm2_output_info_get(output,
-                                             &s->config.geom.x,
-                                             &s->config.geom.y,
-                                             &s->config.mode.w,
-                                             &s->config.mode.h,
-                                             &refresh);
+                  e_drm2_output_info_get(output,
+                                         &s->config.geom.x,
+                                         &s->config.geom.y,
+                                         &s->config.mode.w,
+                                         &s->config.mode.h,
+                                         &refresh);
                   s->config.mode.w = s->config.geom.w;
                   s->config.mode.h = s->config.geom.h;
                   s->config.mode.refresh = refresh;
@@ -547,7 +549,7 @@ _drm2_randr_apply(void)
         if (!ecore_drm2_output_enabled_get(output)) continue;
         if (ecore_drm2_output_cloned_get(output)) continue;
 
-        ecore_drm2_output_info_get(output, NULL, NULL, &ow, &oh, NULL);
+        e_drm2_output_info_get(output, NULL, NULL, &ow, &oh, NULL);
         pw += MAX(pw, ow);
         ph = MAX(ph, oh);
      }
@@ -785,6 +787,8 @@ e_modapi_init(E_Module *m)
    /*      return NULL; */
    /*   } */
 
+   if (!e_drm2_compat_init()) return NULL;
+
    if (e_comp_config_get()->engine == E_COMP_ENGINE_GL)
      {
         e_comp->ee = ecore_evas_new("gl_drm", 0, 0, 1, 1, NULL);
@@ -858,6 +862,6 @@ e_modapi_shutdown(E_Module *m EINA_UNUSED)
    activate_handler = NULL;
 
    E_FREE_FUNC(input_handler, ecore_event_handler_del);
-
+   e_drm2_compat_shutdown();
    return 1;
 }

-- 


Reply via email to