ecore-evas-drm: Fix broken init count
authorChristopher Michael <devilhorns@comcast.net>
Tue, 28 Apr 2020 16:35:07 +0000 (12:35 -0400)
committerJongmin Lee <jm105.lee@samsung.com>
Tue, 5 May 2020 21:28:23 +0000 (06:28 +0900)
We should not assume that there is only ever 1 drm ecore_evas here so
we need to handle init count properly

@fix

src/modules/ecore_evas/engines/drm/ecore_evas_drm.c

index 2f57ca2..56305b1 100644 (file)
@@ -142,9 +142,8 @@ _drm_device_change(void *d EINA_UNUSED, int t EINA_UNUSED, void *event)
 static int
 _ecore_evas_drm_init(Ecore_Evas *ee, Ecore_Evas_Engine_Drm_Data *edata, const char *device)
 {
-   // XXX: this is broken. we init once but in a per ecore evas struct so
-   // we assume there will be only 1 of these drm ecore evas's ever...
-   if (++_drm_init_count != 1) return _drm_init_count;
+   _drm_init_count++;
+   if (_drm_init_count > 1) return _drm_init_count;
 
    if (!ecore_drm2_init())
      {
@@ -201,24 +200,31 @@ static int
 _ecore_evas_drm_shutdown(Ecore_Evas_Engine_Drm_Data *edata)
 {
    Ecore_Event_Handler *h;
-   if (--_drm_init_count != 0) return _drm_init_count;
 
-   if (edata->focus_job)
+   _drm_init_count--;
+   if (_drm_init_count == 0)
      {
-        ecore_job_del(edata->focus_job);
-        edata->focus_job = NULL;
-     }
-   if (edata->dev)
-     {
-        ecore_drm2_outputs_destroy(edata->dev);
-        ecore_drm2_device_close(edata->dev);
-        edata->dev = NULL;
+        if (edata->focus_job)
+          {
+             ecore_job_del(edata->focus_job);
+             edata->focus_job = NULL;
+          }
+
+        if (edata->dev)
+          {
+             ecore_drm2_outputs_destroy(edata->dev);
+             ecore_drm2_device_close(edata->dev);
+             edata->dev = NULL;
+          }
+
+        ecore_drm2_shutdown();
+        ecore_event_evas_shutdown();
+
+        EINA_LIST_FREE(handlers, h)
+          ecore_event_handler_del(h);
      }
-   ecore_drm2_shutdown();
-   ecore_event_evas_shutdown();
-   EINA_LIST_FREE(handlers, h)
-     ecore_event_handler_del(h);
 
+   if (_drm_init_count < 0) _drm_init_count = 0;
    return _drm_init_count;
 }