Each EGL platform 'foo' calls setenv("EGL_PLATFORM", "foo") during
foo_platform_create(), and calls unsetenv("EGL_PLATFORM") during
foo_platform_destroy(). Move the setenv/unsetenv into the core EGL code,
into wegl_platform_init() and wegl_platform_finish().

This prepares for eventually using eglGetPlatformDisplay().

v2: Don't set EGL_PLATFORM on Anroid. (for emil)

Cc: Emil Velikov <emil.l.veli...@gmail.com>
---
 src/waffle/egl/wegl_platform.c        | 30 ++++++++++++++++++++++++++++++
 src/waffle/gbm/wgbm_platform.c        |  6 ------
 src/waffle/wayland/wayland_platform.c |  5 -----
 src/waffle/xegl/xegl_platform.c       |  6 ------
 4 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/src/waffle/egl/wegl_platform.c b/src/waffle/egl/wegl_platform.c
index 7f030bd..d09febc 100644
--- a/src/waffle/egl/wegl_platform.c
+++ b/src/waffle/egl/wegl_platform.c
@@ -23,6 +23,8 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+#define _POSIX_C_SOURCE 200112 // glib feature macro for unsetenv()
+
 #include <dlfcn.h>
 
 #include "wcore_error.h"
@@ -35,12 +37,38 @@ static const char *libEGL_filename = "libEGL.so";
 static const char *libEGL_filename = "libEGL.so.1";
 #endif
 
+static void
+setup_env(const struct wegl_platform *self)
+{
+    switch (self->egl_platform) {
+        case EGL_PLATFORM_ANDROID_KHR:
+            // Don't set EGL_PLATFORM because I don't know the impact doing so
+            // on Android. Does anything other than Mesa use it?
+            break;
+        case EGL_PLATFORM_GBM_KHR:
+            setenv("EGL_PLATFORM", "drm", true);
+            break;
+        case EGL_PLATFORM_WAYLAND_KHR:
+            setenv("EGL_PLATFORM", "wayland", true);
+            break;
+        case EGL_PLATFORM_X11_KHR:
+            setenv("EGL_PLATFORM", "x11", true);
+            break;
+        default:
+            assert(!"bad egl_platform enum");
+            break;
+    }
+}
+
 bool
 wegl_platform_teardown(struct wegl_platform *self)
 {
     bool ok = true;
     int error = 0;
 
+    if (self->egl_platform != EGL_PLATFORM_ANDROID_KHR)
+        unsetenv("EGL_PLATFORM");
+
     if (self->eglHandle) {
         error = dlclose(self->eglHandle);
         if (error) {
@@ -114,6 +142,8 @@ wegl_platform_init(struct wegl_platform *self, EGLenum 
egl_platform)
 
 #undef RETRIEVE_EGL_SYMBOL
 
+    setup_env(self);
+
 error:
     // On failure the caller of wegl_platform_init will trigger it's own
     // destruction which will execute wegl_platform_teardown.
diff --git a/src/waffle/gbm/wgbm_platform.c b/src/waffle/gbm/wgbm_platform.c
index ee25a26..e598a05 100644
--- a/src/waffle/gbm/wgbm_platform.c
+++ b/src/waffle/gbm/wgbm_platform.c
@@ -23,8 +23,6 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#define _POSIX_C_SOURCE 200112 // glib feature macro for unsetenv()
-
 #include <stdlib.h>
 #include <dlfcn.h>
 
@@ -55,8 +53,6 @@ wgbm_platform_teardown(struct wgbm_platform *self)
     if (!self)
         return true;
 
-    unsetenv("EGL_PLATFORM");
-
     if (self->linux)
         ok &= linux_platform_destroy(self->linux);
 
@@ -120,8 +116,6 @@ wgbm_platform_init(struct wgbm_platform *self)
     if (!self->linux)
         goto error;
 
-    setenv("EGL_PLATFORM", "drm", true);
-
     self->wegl.wcore.vtbl = &wgbm_platform_vtbl;
     return true;
 
diff --git a/src/waffle/wayland/wayland_platform.c 
b/src/waffle/wayland/wayland_platform.c
index 3627c88..a8fbafc 100644
--- a/src/waffle/wayland/wayland_platform.c
+++ b/src/waffle/wayland/wayland_platform.c
@@ -24,7 +24,6 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #define WL_EGL_PLATFORM 1
-#define _POSIX_C_SOURCE 200112 // glib feature macro for unsetenv()
 
 #include <stdlib.h>
 #include <dlfcn.h>
@@ -59,8 +58,6 @@ wayland_platform_destroy(struct wcore_platform *wc_self)
     if (!self)
         return true;
 
-    unsetenv("EGL_PLATFORM");
-
     if (self->linux)
         ok &= linux_platform_destroy(self->linux);
 
@@ -125,8 +122,6 @@ wayland_platform_create(void)
     if (!self->linux)
         goto error;
 
-    setenv("EGL_PLATFORM", "wayland", true);
-
     self->wegl.wcore.vtbl = &wayland_platform_vtbl;
     return &self->wegl.wcore;
 
diff --git a/src/waffle/xegl/xegl_platform.c b/src/waffle/xegl/xegl_platform.c
index 66d7ed6..f39ab93 100644
--- a/src/waffle/xegl/xegl_platform.c
+++ b/src/waffle/xegl/xegl_platform.c
@@ -23,8 +23,6 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 
USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#define _POSIX_C_SOURCE 200112 // glib feature macro for unsetenv()
-
 #include <stdlib.h>
 
 #include "wcore_error.h"
@@ -51,8 +49,6 @@ xegl_platform_destroy(struct wcore_platform *wc_self)
     if (!self)
         return true;
 
-    unsetenv("EGL_PLATFORM");
-
     if (self->linux)
         ok &= linux_platform_destroy(self->linux);
 
@@ -79,8 +75,6 @@ xegl_platform_create(void)
     if (!self->linux)
         goto error;
 
-    setenv("EGL_PLATFORM", "x11", true);
-
     self->wegl.wcore.vtbl = &xegl_platform_vtbl;
     return &self->wegl.wcore;
 
-- 
2.10.1

_______________________________________________
waffle mailing list
waffle@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/waffle

Reply via email to